index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div
  3. class="bs-design-wrap"
  4. :class="{ 'no-pointer': isDesign }"
  5. >
  6. <div class="iframe-wrap">
  7. <iframe
  8. class="iframe"
  9. allowfullscreen="true"
  10. webkitallowfullscreen="true"
  11. mozallowfullscreen="true"
  12. oallowfullscreen="true"
  13. msallowfullscreen="true"
  14. :style="{
  15. width: '200%',
  16. height: '200%',
  17. transform: 'scale(.5, .5) translate(-50%, -50%)',
  18. border: 'none'
  19. }"
  20. :src="newUrl"
  21. />
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. name: 'IframeChart',
  28. props: {
  29. config: {
  30. type: Object,
  31. default: () => {}
  32. }
  33. },
  34. data () {
  35. return { newUrl: '' }
  36. },
  37. computed: {
  38. isDesign () {
  39. return (window?.BS_CONFIG?.routers?.designUrl || '/big-screen/design') === this.$route.path
  40. }
  41. },
  42. watch: {},
  43. mounted () {
  44. this.changeStyle()
  45. },
  46. methods: {
  47. changeStyle (config) {
  48. this.newUrl = this.replaceUrlVariables(this.config.url)
  49. },
  50. replaceUrlVariables (url) {
  51. const variableRegex = /\${([A-Za-z0-9_.]+)}/g
  52. const variables = {}
  53. let match
  54. while ((match = variableRegex.exec(url))) {
  55. const variable = match[1]
  56. try {
  57. const value = eval(variable)
  58. variables[variable] = value !== undefined ? value : ''
  59. } catch (e) {
  60. variables[variable] = ''
  61. }
  62. }
  63. const replacedUrl = url.replace(variableRegex, (match, variable) => {
  64. return variables[variable] || match
  65. })
  66. return replacedUrl
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .bs-design-wrap {
  73. position: relative;
  74. overflow: hidden;
  75. background: #fff;
  76. width: 100%;
  77. height: 100%;
  78. .iframe-wrap {
  79. height: 100%;
  80. }
  81. }
  82. .no-pointer {
  83. pointer-events: none;
  84. }
  85. </style>