chartMap.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="iframe-wrap">
  3. <iframe id="mapFrame" ref="mapFrame" src="/gis/index.html" frameborder="none" :onload="loadDone"/>
  4. </div>
  5. </template>
  6. <script>
  7. import {chartMap} from '@/api/dashboard-json'
  8. export default {
  9. name: 'ChartMap',
  10. created() {
  11. window['mapFrame'] = this.$refs.mapFrame
  12. },
  13. mounted() {
  14. this.$refs.mapFrame.onload = () => {
  15. this.loadDone()
  16. }
  17. },
  18. methods: {
  19. loadDone() {
  20. chartMap().then(res => {
  21. const data = (res.info || []).map(item => {
  22. const ret = {
  23. title: item.title?.replace('运行工区', ''),
  24. data: {}
  25. }
  26. item.xaxis.forEach((key, index) => {
  27. ret.data[key] = item.series[index].data
  28. })
  29. return ret
  30. })
  31. window['mapData'] = data;
  32. this.$refs.mapFrame.contentWindow.postMessage(
  33. {
  34. data: data
  35. },
  36. '*'
  37. )
  38. this.$refs.mapFrame.contentWindow.addEventListener('message', (evt) => {
  39. console.log('onMessage', evt)
  40. })
  41. console.log('data', data)
  42. })
  43. console.log('loadDone')
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped lang="scss">
  49. .iframe-wrap {
  50. width: 100%;
  51. height: 100%;
  52. iframe {
  53. width: 100%;
  54. height: 100%;
  55. }
  56. }
  57. ::v-deep {
  58. #container {
  59. background-image: none !important;
  60. }
  61. }
  62. </style>