full.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="denet-toolbox">
  3. <div class="head">
  4. <span></span>
  5. <div>
  6. <!-- 缩放 -->
  7. <img :src="require('@/assets/img/icon-full.png')" alt class="fixed" @click="clickFull" />
  8. <!-- 关闭 -->
  9. <img :src="require('@/assets/img/icon-close.png')" alt class="full" @click="clickClose" />
  10. </div>
  11. </div>
  12. <div class="content">
  13. <iframe :src="state.iframe_url" frameborder="0"></iframe>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { onMounted, reactive, ref } from "vue";
  19. import { sendEventInfo } from "@/uilts/event";
  20. let state = reactive({
  21. status: '固定', // 全屏
  22. dom_fixed: null,
  23. iframe_url: '',
  24. tweetId: ''
  25. })
  26. window.addEventListener("onEvent", e => {
  27. let info = e.detail
  28. switch (info.event_type) {
  29. // 固定
  30. case 'ToolBox_To_Fixed':
  31. // 替换
  32. if (state.iframe_url || state.tweetId) {
  33. sendClose()
  34. }
  35. state.iframe_url = info.data.iframe_url
  36. state.tweetId = info.data.tweetId
  37. break
  38. }
  39. });
  40. const clickFull = () => {
  41. if (state.status == '固定') {
  42. state.status = '全屏'
  43. changeFull()
  44. } else {
  45. state.status = '固定'
  46. changeFixed()
  47. }
  48. }
  49. onMounted(() => {
  50. state.dom_fixed = document.querySelector('#denet-tool-box-fixed')
  51. })
  52. const changeFull = () => {
  53. state.dom_fixed.style.cssText = `
  54. width:100%;
  55. height: 100%;
  56. position: fixed;
  57. right: 0px;
  58. top: 0px;`
  59. }
  60. const changeFixed = () => {
  61. state.dom_fixed.style.cssText = `
  62. width: 505px;
  63. height: 544px;
  64. position: fixed;
  65. right: 10px;
  66. top: 10px;`
  67. }
  68. const clickClose = () => {
  69. state.dom_fixed.style.display = 'none'
  70. sendClose()
  71. }
  72. const sendClose = () => {
  73. let url = state.iframe_url
  74. let tweetId = state.tweetId
  75. sendEventInfo({
  76. event_type: 'ToolBox_Fixed_Close',
  77. data: {
  78. url,
  79. tweetId,
  80. }
  81. })
  82. state.iframe_url = ''
  83. state.tweetId = ''
  84. }
  85. </script>
  86. <style lang="scss">
  87. .denet-toolbox {
  88. width: 100%;
  89. height: 100%;
  90. filter: drop-shadow(0px 4px 20px rgba(0, 0, 0, 0.2));
  91. border-radius: 12px;
  92. overflow: hidden;
  93. .head {
  94. width: 100%;
  95. height: 40px;
  96. background: #373737;
  97. display: flex;
  98. align-items: center;
  99. justify-content: space-between;
  100. span {
  101. color: #FFFFFF;
  102. font-style: normal;
  103. font-weight: 500;
  104. font-size: 14px;
  105. margin-left: 16px;
  106. }
  107. img {
  108. width: 20px;
  109. height: 20px;
  110. cursor: pointer;
  111. }
  112. .full {
  113. margin-right: 16px;
  114. }
  115. .fixed {
  116. margin-right: 20px;
  117. }
  118. }
  119. .content {
  120. width: 100%;
  121. height: calc(100% - 40px);
  122. background: #686868;
  123. display: flex;
  124. align-items: center;
  125. justify-content: center;
  126. iframe {
  127. width: 100%;
  128. height: 100%;
  129. }
  130. }
  131. }
  132. </style>