full.vue 3.7 KB

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