FrameWindow.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <!-- 状态详情 -->
  3. <div>
  4. <div
  5. v-if="showFrame"
  6. class="frame-window"
  7. >
  8. <div class="frame-window-title">
  9. {{ title }}
  10. <img
  11. class="close-btn"
  12. src="/static/assets/client-base-v4/image/close.png"
  13. @click="close"
  14. />
  15. </div>
  16. <div class="frame-window-content">
  17. <iframe
  18. id="ifr_diagnose"
  19. :src="frameSrc"
  20. class="frame-window-content-iframe"
  21. />
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. components: {
  29. },
  30. props: [],
  31. emits: ['close'],
  32. data: function () {
  33. return {
  34. title: null,
  35. frameSrc: null,
  36. showFrame: false,
  37. };
  38. },
  39. mounted: function(){
  40. var _self = this;
  41. window.addEventListener('message', this.onMessage);
  42. },
  43. beforeUnmount : function() {
  44. // 在组件生命周期结束的时候销毁。
  45. window.removeEventListener('message', this.onMessage, false);
  46. },
  47. methods: {
  48. /**
  49. * 打开一个网址
  50. * @param src 待打开的网址
  51. * @param title 标题
  52. */
  53. open: function (src, title) {
  54. this.title = title;
  55. this.frameSrc = src;
  56. this.showFrame = true;
  57. },
  58. close: function () {
  59. this.showFrame = false;
  60. this.$emit('close');
  61. },
  62. onMessage: function(e){
  63. var _self = this;
  64. if(e.data.cmd === 'close'){
  65. _self.close();
  66. }
  67. },
  68. },
  69. };
  70. </script>
  71. <style scoped>
  72. .frame-window {
  73. position: fixed;
  74. top: 50px;
  75. right: 50px;
  76. bottom: 50px;
  77. left: 50px;
  78. }
  79. .frame-window .frame-window-title {
  80. position: fixed;
  81. top: 0px;
  82. right: 0px;
  83. left: 0px;
  84. height: 30px;
  85. background: #f1f1f1;
  86. padding-left: 5px;
  87. padding-top: 5px;
  88. font-size: 16px;
  89. font-weight: bold;
  90. }
  91. .frame-window .frame-window-title .close-btn {
  92. position: fixed;
  93. top: 0px;
  94. right: 0px;
  95. width: 30px;
  96. height: 30px;
  97. cursor: pointer;
  98. }
  99. .frame-window .frame-window-content {
  100. position: fixed;
  101. top: 30px;
  102. right: 0px;
  103. bottom: 0px;
  104. left: 0px;
  105. }
  106. .frame-window-content-iframe {
  107. width: 100%;
  108. height: 100%;
  109. }
  110. </style>