full.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="denet-toolbox">
  3. <div class="head">
  4. <span></span>
  5. <div>
  6. <!-- 缩小 -->
  7. <img v-if="state.status == '全屏'" :src="require('@/assets/svg/icon-iframe-small.svg')" alt class="full"
  8. @click="clickFull" />
  9. <img v-else :src="require('@/assets/svg/icon-iframe-full.svg')" alt class="full" @click="clickFull" />
  10. <!-- 关闭 -->
  11. <img :src="require('@/assets/svg/icon-iframe-close.svg')" alt class="fixed" @click="clickClose" />
  12. </div>
  13. </div>
  14. <div class="content">
  15. <template v-if="showMask">
  16. <div class="mask" @click="confirmStatus">
  17. <img class="luck" :src=" require('@/assets/svg/icon-post-lock.svg') " />
  18. <div class="btn">
  19. <img class="img" v-if="detail.nftProjectIcon" :src=" detail.nftProjectIcon " />
  20. <div class="font">Available for holders of {{detail.nftProjectName}} NFT</div>
  21. </div>
  22. </div>
  23. <img class="mask_bg" v-if="detail.linkImagePath" :src=" detail.linkImagePath " />
  24. </template>
  25. <iframe :src="state.iframe_url" frameborder="0" allow="camera *;microphone *"></iframe>
  26. </div>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { reactive, ref } from "vue";
  31. import { ElMessage } from 'element-plus'
  32. import { unlockNftCert } from '@/http/toolBoxApi'
  33. import { getChromeStorage, sendChromeTabMessage } from "@/uilts/chromeExtension";
  34. import "element-plus/es/components/message/style/css";
  35. let state = reactive({
  36. status: '固定右上角', // 全屏
  37. iframe_url: '',
  38. tweetId: ''
  39. })
  40. let detail = ref(null)
  41. let nftAuthINfo = ref(null)
  42. let showMask = ref(false)
  43. let postId = ref('')
  44. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  45. switch (req.actionType) {
  46. // 事件传输
  47. case 'Set_ToolBox_Fixed':
  48. if (req.data.type == '全屏' || req.data.type == '固定右上角') {
  49. state.status = req.data.type
  50. nftAuthINfo.value = req.data.nftAuthINfo;
  51. showMask.value = req.data.showMask;
  52. detail.value = req.data.detail;
  53. postId.value = req.data.postId;
  54. if (state.tweetId != req.data.tweetId) {
  55. state.tweetId = req.data.tweetId
  56. }
  57. if (state.iframe_url != req.data.iframe_url) {
  58. state.iframe_url = req.data.iframe_url
  59. }
  60. }
  61. break
  62. case 'FINISH_ToolBox_By_Nft':
  63. hideMask(req.data)
  64. break;
  65. }
  66. sendResponse && sendResponse();
  67. })
  68. const clickFull = () => {
  69. if (state.status == '固定右上角') {
  70. state.status = '全屏'
  71. changeFull()
  72. } else {
  73. state.status = '固定右上角'
  74. changeFixed()
  75. }
  76. }
  77. const changeFull = () => {
  78. sendChromeTabMessage({
  79. actionType: 'Set_ToolBox_Fixed',
  80. data: {
  81. type: '全屏',
  82. iframe_url: state.iframe_url,
  83. tweetId: state.tweetId,
  84. }
  85. })
  86. }
  87. const changeFixed = () => {
  88. sendChromeTabMessage({
  89. actionType: 'Set_ToolBox_Fixed',
  90. data: {
  91. type: '固定右上角',
  92. iframe_url: state.iframe_url,
  93. tweetId: state.tweetId,
  94. nftAuthINfo: nftAuthINfo.value,
  95. showMask: showMask.value,
  96. detail: detail.value,
  97. postId: postId.value,
  98. }
  99. })
  100. }
  101. const clickClose = () => {
  102. sendClose()
  103. }
  104. const sendClose = () => {
  105. sendChromeTabMessage({
  106. actionType: 'Set_ToolBox_Fixed',
  107. data: {
  108. type: '关闭',
  109. iframe_url: state.iframe_url,
  110. tweetId: state.tweetId,
  111. nftAuthINfo: nftAuthINfo.value,
  112. showMask: showMask.value,
  113. detail: detail.value,
  114. postId: postId.value,
  115. }
  116. })
  117. state.iframe_url = ''
  118. state.tweetId = ''
  119. }
  120. const confirmStatus = () => {
  121. getChromeStorage('userInfo', (_userInfo) => {
  122. if (!_userInfo) {
  123. chrome.runtime.sendMessage(
  124. { actionType: "POPUP_LOGIN", data: "" },
  125. (response) => {
  126. console.log("res", response);
  127. }
  128. )
  129. } else {
  130. if (nftAuthINfo.value && nftAuthINfo.value?.certStatus === 1) {
  131. succBack()
  132. } else {
  133. sendChromeTabMessage({
  134. actionType: 'Set_ToolBox_By_Nft',
  135. data: {
  136. postId: postId.value,
  137. }
  138. })
  139. }
  140. }
  141. })
  142. }
  143. const succBack = () => {
  144. ElMessage({
  145. message: `NFT validated!`,
  146. type: 'success'
  147. })
  148. showMask.value = false;
  149. // 记录解锁
  150. unlockNftCert({
  151. params: {
  152. postId: postId.value,
  153. }
  154. })
  155. }
  156. const hideMask = (data) => {
  157. if (data && data.post_Id && data.post_Id === postId.value) {
  158. succBack()
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .denet-toolbox {
  164. width: 100%;
  165. height: 100%;
  166. filter: drop-shadow(0px 4px 20px rgba(0, 0, 0, 0.2));
  167. border-radius: 12px;
  168. overflow: hidden;
  169. .head {
  170. width: 100%;
  171. height: 40px;
  172. background: #373737;
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. span {
  177. color: #FFFFFF;
  178. font-style: normal;
  179. font-weight: 500;
  180. font-size: 14px;
  181. margin-left: 16px;
  182. }
  183. div {
  184. display: flex;
  185. justify-content: center;
  186. }
  187. svg {
  188. width: 20px;
  189. height: 20px;
  190. cursor: pointer;
  191. }
  192. .full {
  193. margin-right: 16px;
  194. }
  195. .fixed {
  196. margin-right: 20px;
  197. }
  198. }
  199. .content {
  200. position: relative;
  201. width: 100%;
  202. height: calc(100% - 40px);
  203. background: #686868;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. .mask {
  208. position: absolute;
  209. z-index: 2;
  210. display: flex;
  211. cursor: pointer;
  212. align-items: center;
  213. justify-content: center;
  214. flex-direction: column;
  215. width: 100%;
  216. height: 100%;
  217. background-color: rgba($color: #000000, $alpha: .8);
  218. .luck {
  219. width: 100px;
  220. height: 100px;
  221. }
  222. .btn {
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. width: 345px;
  227. height: 70px;
  228. cursor: pointer;
  229. margin-top: 12px;
  230. border-radius: 100px;
  231. background: #1D9BF0;
  232. .img {
  233. overflow: hidden;
  234. width: 35px;
  235. height: 35px;
  236. margin-right: 16px;
  237. border-radius: 4px;
  238. }
  239. .font {
  240. width: 188px;
  241. color: #fff;
  242. font-weight: 700;
  243. font-size: 16px;
  244. line-height: 19px;
  245. letter-spacing: 0.3px;
  246. }
  247. }
  248. }
  249. .mask_bg {
  250. position: absolute;
  251. z-index: 1;
  252. width: 100%;
  253. height: 100%;
  254. object-fit: contain;
  255. background-color: #000000;
  256. }
  257. iframe {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. }
  262. }
  263. </style>