index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.newUrl = this.replaceUrlVariables(this.config.url)
  45. },
  46. methods: {
  47. replaceUrlVariables (url) {
  48. const variableRegex = /\${([A-Za-z0-9_.]+)}/g
  49. const variables = {}
  50. let match
  51. while ((match = variableRegex.exec(url))) {
  52. const variable = match[1]
  53. try {
  54. const value = eval(variable)
  55. variables[variable] = value !== undefined ? value : ''
  56. } catch (e) {
  57. variables[variable] = ''
  58. }
  59. }
  60. const replacedUrl = url.replace(variableRegex, (match, variable) => {
  61. return variables[variable] || match
  62. })
  63. return replacedUrl
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .bs-design-wrap {
  70. position: relative;
  71. overflow: hidden;
  72. background: #fff;
  73. width: 100%;
  74. height: 100%;
  75. .iframe-wrap {
  76. height: 100%;
  77. }
  78. }
  79. .no-pointer {
  80. pointer-events: none;
  81. }
  82. </style>