main-content.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <main class="smp-content" :class="{'isIframe':isIframe}">
  3. <iframe :key="iframeIndex" v-if="isIframe" ref="myIframe" :src="iframeURL" width="100%" height="100%" frameborder="0" scrolling="yes" allowfullscreen="true"></iframe>
  4. <router-view v-else />
  5. </main>
  6. </template>
  7. <script>
  8. import { isURL } from '@/utils/validate'
  9. import Cookies from 'js-cookie'
  10. export default {
  11. data () {
  12. return {
  13. iframeURL: this.addParams(this.$route.meta.iframeURL),
  14. iframeIndex: 0,
  15. isIframe: false
  16. }
  17. },
  18. watch: {
  19. $route () {
  20. this.iframeURL = this.addParams(this.$route.meta.iframeURL)
  21. this.iframeIndex++
  22. this.initUrl()
  23. }
  24. },
  25. mounted () {
  26. this.initUrl()
  27. this.addSelfToAllComponent()
  28. },
  29. inject: ['allComponent'],
  30. methods: {
  31. addSelfToAllComponent () {
  32. this.allComponent['main-content'] = this
  33. },
  34. resetIframe (item) {
  35. if (this.isIframe) {
  36. this.$refs.myIframe.src = this.iframeURL
  37. }
  38. },
  39. initUrl () {
  40. this.isIframe = this.tabIsIframe(this.iframeURL)
  41. },
  42. // tabs, 是否通过iframe展示
  43. tabIsIframe (url) {
  44. return isURL(url)
  45. },
  46. addParams (url) {
  47. // console.log(this.$route)
  48. if (!this.tabIsIframe(this.$route.meta.iframeURL)) {
  49. return ''
  50. }
  51. let prevWord = '?'
  52. if (url.indexOf(prevWord) > -1) {
  53. prevWord = '&'
  54. }
  55. let _url = url + prevWord + 'sessionToken=' + Cookies.get('token') + '&menu=' + this.$route.name
  56. let params = this.$route.params
  57. if (params.tab) {
  58. _url += '&tab=' + params.tab
  59. }
  60. return _url
  61. }
  62. }
  63. }
  64. </script>