card.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. <template>
  2. <div class="denet-toolbox" :class="{ 'pre-view': pre_view }">
  3. <div class="head">
  4. <span></span>
  5. <div v-show="state.show_btn && state.status == 'iframe'">
  6. <img :src="require('@/assets/svg/icon-iframe-fixed.svg')" alt class="fixed" @click="clickFixed" />
  7. <img :src="require('@/assets/svg/icon-iframe-full.svg')" alt class="full" @click="clickFull" />
  8. </div>
  9. </div>
  10. <div class="content" v-if="pre_view">
  11. <iframe :src="iframe_url" frameborder="0" sandbox></iframe>
  12. </div>
  13. <div class="content" v-else>
  14. <template v-if="state.showMask && state.status != '固定右上角'">
  15. <div class="mask" @click="confirmStatus">
  16. <img class="luck" :src=" require('@/assets/svg/icon-post-lock.svg') " />
  17. <div class="btn">
  18. <img class="img" v-if="state.detail && state.detail.nftProjectIcon" :src=" state.detail.nftProjectIcon " />
  19. <div class="font">Available for holders of {{state.detail.nftProjectName}} NFT</div>
  20. </div>
  21. </div>
  22. <img class="mask_bg" v-if="state.detail.linkImagePath" :src=" state.detail.linkImagePath " />
  23. </template>
  24. <iframe :src="state.iframe_url" v-show="state.status == 'iframe'" ref="dom_iframe" frameborder="0"
  25. scrolling="yes" allow="camera *;microphone *"></iframe>
  26. <!-- sandbox="allow-same-origin allow-scripts allow-popups allow-top-navigation allow-forms allow-modals allow-popups-to-escape-sandbox" -->
  27. <!-- 网页错误 -->
  28. <div class="state" v-show="state.status == '网页错误'">
  29. <img :src="state.cover_url" alt="" class="cover" />
  30. <div class="info">
  31. <img :src="require('@/assets/svg/icon-iframe-error.svg')" alt />
  32. <div>Oops, this link is invalid</div>
  33. </div>
  34. </div>
  35. <!-- 加载 -->
  36. <div class="state" v-show="state.status == '加载'">
  37. <img :src="state.cover_url" alt="" class="cover" />
  38. <div class="info">
  39. <img :src="require('@/assets/svg/icon-iframe-loading.svg')" alt class="icon-loading" />
  40. </div>
  41. </div>
  42. <!-- 关闭 -->
  43. <div class="state" v-show="state.status == '关闭'">
  44. </div>
  45. <!-- 固定右上角 -->
  46. <div class="state" v-show="state.status == '固定右上角'">
  47. <div class="info">
  48. <img :src="require('@/assets/svg/icon-iframe-pinned.svg')" alt />
  49. <div class="pinned">Pinned to the top right</div>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- alert -->
  54. <div class="alert" v-show="state.show_alert">
  55. <div class="back" @click.stop="clickCancel"></div>
  56. <div class="confirm">
  57. <div class="check">
  58. <input :id="state.checkbox_id" type='checkbox' v-model="state.checkbox" />
  59. <label :for="state.checkbox_id">Don't remind</label>
  60. </div>
  61. <div class="title">Web Page Progress May Reset</div>
  62. <div class="handle">
  63. <div class="cancel" @click.stop="clickCancel">Cancel</div>
  64. <div class="continue" @click.stop="clickContinue">Continue</div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script setup>
  71. import { getChromeStorage, setChromeStorage, defineProps, sendChromeTabMessage } from "@/uilts/chromeExtension";
  72. import { getPostDetail } from '@/http/redPacket.js'
  73. import { getPostEditorNftCertInfo, unlockNftCert } from '@/http/toolBoxApi'
  74. import { guid, getQueryString } from "@/uilts/help";
  75. import { onMounted, reactive, ref, onBeforeUnmount } from "vue";
  76. import { ElMessage } from 'element-plus'
  77. import { reSetBindTwtterId } from '@/http/help.js'
  78. import Report from "@/log-center/log"
  79. import "element-plus/es/components/message/style/css";
  80. let dom_iframe = ref(null)
  81. let state = reactive({
  82. status: '', //
  83. show_alert: false,
  84. show_btn: false,
  85. list: [],
  86. checkbox: false,
  87. checkbox_id: `denet-${guid()}`,
  88. postId: '',
  89. tweetId: '',
  90. detail: {},
  91. handle_type: '',
  92. showMask: false,
  93. cover_url: require('@/assets/img/back-loading.png')
  94. })
  95. let dom = {}
  96. let nftAuthINfo = ref(null)
  97. let loadTime = (new Date).getTime()
  98. let props = defineProps({
  99. pre_view: {
  100. type: Boolean,
  101. default: false,
  102. },
  103. iframe_url: {
  104. type: String,
  105. default: ''
  106. }
  107. })
  108. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  109. switch (req.actionType) {
  110. // 事件传输
  111. case 'Set_ToolBox_Fixed':
  112. if (req.data.tweetId == state.tweetId && req.data.type == '关闭') {
  113. state.show_btn = true
  114. state.status = 'iframe'
  115. state.iframe_url = req.data.iframe_url
  116. nftAuthINfo.value = req.data.nftAuthINfo
  117. state.showMask = req.data.showMask
  118. state.detail = req.data.detail
  119. state.postId = req.data.postId
  120. }
  121. break
  122. }
  123. sendResponse && sendResponse();
  124. })
  125. const clickContinue = () => {
  126. if (state.checkbox) {
  127. setChromeStorage({ fullCheck: JSON.stringify({ fullCheck: 1 }) })
  128. }
  129. if (state.handle_type == '全屏') {
  130. handleFull()
  131. } else {
  132. handleFixed()
  133. }
  134. state.show_alert = false
  135. }
  136. onMounted(() => {
  137. if (props.pre_view) {
  138. return
  139. }
  140. state.postId = getQueryString('postId')
  141. state.tweetId = getQueryString('tweetId')
  142. sendChromeTabMessage({
  143. actionType: 'Get_ToolBox_Fixed_TweetId'
  144. }, (res) => {
  145. if (res == state.tweetId) {
  146. state.status = '固定右上角'
  147. } else {
  148. state.status = '加载'
  149. getDetail()
  150. }
  151. })
  152. chrome.runtime.onMessage.addListener(msgListener)
  153. // 页面返回重试状态
  154. document.addEventListener('visibilitychange', function () {
  155. let isHidden = document.hidden;
  156. if (!isHidden && !nftAuthINfo.value) {
  157. getDetail();
  158. }
  159. });
  160. })
  161. onBeforeUnmount(() => {
  162. chrome.runtime.onMessage.removeListener(msgListener);
  163. })
  164. // detail函数
  165. const getDetail = () => {
  166. let iframe = dom_iframe.value
  167. iframe.onerror = () => {
  168. state.status = '网页错误'
  169. }
  170. getPostDetail({
  171. params: {
  172. postId: state.postId
  173. }
  174. }).then((res) => {
  175. if (res && res.code == 0) {
  176. state.detail = JSON.parse(res.data.postBizData)
  177. if (!res.data.srcContentId) {
  178. reSetBindTwtterId({
  179. postId: state.postId,
  180. tweetId: state.tweetId
  181. }, () => {
  182. Report.reportLog({
  183. objectType: Report.objectType.tweetPostBinded,
  184. redPacketType: 5,
  185. postId: state.postId,
  186. }, {
  187. 'post-editor-url': state.detail.convertUrl
  188. });
  189. })
  190. }
  191. console.log('postBizData', state.detail)
  192. // 加载iframe
  193. if (state.detail.viewBgImagePath) {
  194. state.cover_url = state.detail.viewBgImagePath
  195. }
  196. state.iframe_url = state.detail.convertUrl
  197. state.show_btn = true
  198. state.status = 'iframe'
  199. // 蒙层
  200. if (state.detail && state.detail.certNftProjectId) {
  201. if (state.detail?.certNftUnlockStatus == 0) {
  202. state.showMask = true;
  203. // report
  204. reportFail()
  205. } else {
  206. // report
  207. reportSucc()
  208. }
  209. // 确权信息
  210. getChromeStorage('userInfo', (_userInfo) => {
  211. if (_userInfo) {
  212. getNftInfoStatus()
  213. }
  214. })
  215. } else {
  216. reportSucc(false)
  217. }
  218. // report
  219. Report.reportLog({
  220. redPacketType: Report.redPacketType.postEditor,
  221. businessType: Report.businessType.pageView,
  222. pageSource: Report.pageSource.pe_loading_page,
  223. postId: state.postId || '',
  224. postEditorUrl: state.detail.convertUrl
  225. });
  226. } else {
  227. state.status = '网页错误'
  228. }
  229. })
  230. }
  231. const getNftInfoStatus = () => {
  232. getPostEditorNftCertInfo({
  233. params: {
  234. postId: state.postId,
  235. }
  236. }).then(res => {
  237. let { code, data } = res;
  238. if ( code === 0 ) {
  239. nftAuthINfo.value = data;
  240. }
  241. })
  242. }
  243. const reportSucc = (isEncrypted = true) => {
  244. let params = {}
  245. if (isEncrypted) {
  246. params['nft-encrypted-status'] = 1;
  247. }
  248. // report
  249. Report.reportLog({
  250. redPacketType: Report.redPacketType.postEditor,
  251. businessType: Report.businessType.pageView,
  252. pageSource: Report.pageSource.pe_display_page,
  253. postId: state.postId || '',
  254. postEditorUrl: state.detail.convertUrl,
  255. ...params,
  256. }, {
  257. 'loading-time': (new Date).getTime() - loadTime,
  258. });
  259. }
  260. const reportFail = () => {
  261. Report.reportLog({
  262. redPacketType: Report.redPacketType.postEditor,
  263. businessType: Report.businessType.pageView,
  264. pageSource: Report.pageSource.pe_display_page,
  265. postId: state.postId || '',
  266. postEditorUrl: state.detail.convertUrl,
  267. 'nft-encrypted-status': 0,
  268. }, {
  269. 'loading-time': (new Date).getTime() - loadTime,
  270. });
  271. }
  272. const confirmStatus = () => {
  273. getChromeStorage('userInfo', (_userInfo) => {
  274. if (!_userInfo) {
  275. chrome.runtime.sendMessage(
  276. { actionType: "POPUP_LOGIN", data: "" },
  277. (response) => {
  278. console.log("res", response);
  279. }
  280. )
  281. } else {
  282. if (nftAuthINfo.value && nftAuthINfo.value?.certStatus === 1) {
  283. succBack()
  284. } else {
  285. sendChromeTabMessage({
  286. actionType: 'Set_ToolBox_By_Nft',
  287. data: {
  288. postId: state.postId,
  289. }
  290. })
  291. }
  292. }
  293. })
  294. // report
  295. let params = {}
  296. if (nftAuthINfo.value?.certStatus === 1) {
  297. if (state.showMask) {
  298. params['nft-encrypted-status'] = 0
  299. } else {
  300. params['nft-encrypted-status'] = 1
  301. }
  302. }
  303. Report.reportLog({
  304. redPacketType: Report.redPacketType.postEditor,
  305. businessType: Report.businessType.buttonClick,
  306. pageSource: Report.pageSource.pe_display_page,
  307. objectType: Report.objectType.encrypte_nft_button,
  308. postId: state.postId || '',
  309. postEditorUrl: state.detail.convertUrl,
  310. ...params,
  311. });
  312. }
  313. const succBack = () => {
  314. ElMessage({
  315. message: `NFT validated!`,
  316. type: 'success'
  317. })
  318. state.showMask = false;
  319. // 解锁
  320. unlockNftCert({
  321. params: {
  322. postId: state.postId,
  323. }
  324. })
  325. }
  326. const hideMask = (data) => {
  327. if (data && data.post_Id && data.post_Id === state.postId) {
  328. succBack()
  329. }
  330. }
  331. const clickCancel = () => {
  332. state.show_alert = false
  333. }
  334. const clickFixed = () => {
  335. getChromeStorage('userInfo', (_userInfo) => {
  336. if (!_userInfo) {
  337. chrome.runtime.sendMessage(
  338. { actionType: "POPUP_LOGIN", data: "" },
  339. (response) => {
  340. console.log("res", response);
  341. }
  342. )
  343. } else {
  344. state.handle_type = '固定右上角'
  345. getChromeStorage('fullCheck', (res) => {
  346. if (res && res.fullCheck) {
  347. // 固定
  348. handleFixed()
  349. } else {
  350. state.show_alert = true
  351. }
  352. })
  353. }
  354. })
  355. // report
  356. let params = {}
  357. if (nftAuthINfo.value?.certStatus === 1) {
  358. if (state.showMask) {
  359. params['nft-encrypted-status'] = 0
  360. } else {
  361. params['nft-encrypted-status'] = 1
  362. }
  363. }
  364. Report.reportLog({
  365. redPacketType: Report.redPacketType.postEditor,
  366. businessType: Report.businessType.buttonClick,
  367. pageSource: Report.pageSource.pe_display_page,
  368. objectType: Report.objectType.top_right_button,
  369. postId: state.postId || '',
  370. postEditorUrl: state.detail.convertUrl,
  371. ...params,
  372. });
  373. }
  374. // 固定
  375. const handleFull = () => {
  376. if (state.status != 'iframe' || !state.iframe_url) {
  377. return
  378. }
  379. getChromeStorage('userInfo', (_userInfo) => {
  380. if (!_userInfo) {
  381. chrome.runtime.sendMessage(
  382. { actionType: "POPUP_LOGIN", data: "" },
  383. (response) => {
  384. console.log("res", response);
  385. }
  386. )
  387. } else {
  388. // 切换状态
  389. state.status = '固定右上角'
  390. state.show_btn = false
  391. sendChromeTabMessage({
  392. actionType: 'Set_ToolBox_Fixed',
  393. data: {
  394. type: '全屏',
  395. iframe_url: state.iframe_url,
  396. tweetId: state.tweetId,
  397. nftAuthINfo: nftAuthINfo.value,
  398. showMask: state.showMask,
  399. detail: state.detail,
  400. postId: state.postId,
  401. }
  402. })
  403. // 清除当前iframe src
  404. state.iframe_url = ''
  405. }
  406. })
  407. }
  408. // 全屏
  409. const handleFixed = () => {
  410. // 切换状态
  411. state.show_btn = false
  412. state.status = '固定右上角'
  413. sendChromeTabMessage({
  414. actionType: 'Set_ToolBox_Fixed',
  415. data: {
  416. type: '固定右上角',
  417. iframe_url: state.iframe_url,
  418. tweetId: state.tweetId,
  419. nftAuthINfo: nftAuthINfo.value,
  420. showMask: state.showMask,
  421. detail: state.detail,
  422. postId: state.postId,
  423. }
  424. })
  425. // 清除当前iframe src
  426. state.iframe_url = ''
  427. }
  428. const clickFull = () => {
  429. state.handle_type = '全屏'
  430. getChromeStorage('fullCheck', (res) => {
  431. if (res && res.fullCheck) {
  432. // 全屏
  433. handleFull()
  434. } else {
  435. state.show_alert = true
  436. }
  437. })
  438. // report
  439. let params = {}
  440. if (nftAuthINfo.value?.certStatus === 1) {
  441. if (state.showMask) {
  442. params['nft-encrypted-status'] = 0
  443. } else {
  444. params['nft-encrypted-status'] = 1
  445. }
  446. }
  447. Report.reportLog({
  448. redPacketType: Report.redPacketType.postEditor,
  449. businessType: Report.businessType.buttonClick,
  450. pageSource: Report.pageSource.pe_display_page,
  451. objectType: Report.objectType.fullscreen_button,
  452. postId: state.postId || '',
  453. postEditorUrl: state.detail.convertUrl,
  454. ...params,
  455. });
  456. }
  457. const msgListener = (req, sender, sendResponse) => {
  458. switch (req.actionType) {
  459. case 'BG_LOGIN_SET_USERINFO_CB':
  460. getDetail()
  461. break;
  462. case 'FINISH_ToolBox_By_Nft':
  463. hideMask(req.data)
  464. break;
  465. }
  466. }
  467. </script>
  468. <style lang="scss" >
  469. .pre-view {
  470. pointer-events: none;
  471. cursor: default;
  472. }
  473. .denet-toolbox {
  474. width: 100%;
  475. height: 100%;
  476. min-height: 100%;
  477. filter: drop-shadow(0px 4px 20px rgba(0, 0, 0, 0.2));
  478. border-radius: 12px;
  479. overflow: hidden;
  480. position: relative;
  481. .alert {
  482. text-align: center;
  483. position: absolute;
  484. z-index: 3;
  485. top: 0;
  486. left: 0;
  487. width: 100%;
  488. height: 100%;
  489. .back {
  490. background: #000000;
  491. opacity: 0.8;
  492. position: absolute;
  493. top: 0;
  494. left: 0;
  495. width: 100%;
  496. height: 100%;
  497. cursor: auto;
  498. }
  499. .confirm {
  500. position: absolute;
  501. width: 355px;
  502. height: 180px;
  503. background: #FFFFFF;
  504. border-radius: 20px;
  505. top: 173px;
  506. left: 50%;
  507. margin-left: -180px;
  508. .title {
  509. font-weight: 600;
  510. font-size: 18px;
  511. color: #000000;
  512. margin-bottom: 34px;
  513. }
  514. .check {
  515. color: #899099;
  516. font-weight: 400;
  517. font-size: 14px;
  518. margin: 12px 15px 32px 0;
  519. text-align: right;
  520. align-content: center;
  521. justify-content: flex-end;
  522. display: flex;
  523. line-height: 17px;
  524. input {
  525. margin-right: 8px;
  526. }
  527. label {
  528. line-height: 19px;
  529. }
  530. }
  531. .handle {
  532. display: flex;
  533. justify-content: center;
  534. align-items: center;
  535. div {
  536. font-weight: 600;
  537. font-size: 16px;
  538. width: 156px;
  539. height: 47px;
  540. line-height: 47px;
  541. cursor: pointer;
  542. border-radius: 1000px;
  543. user-select: none;
  544. }
  545. .cancel {
  546. color: #000000;
  547. background: rgba(56, 154, 255, 0.01);
  548. border: 1px solid #E6E6E6;
  549. }
  550. .continue {
  551. background: #1D9BF0;
  552. font-weight: 600;
  553. margin-left: 11px;
  554. color: #FFFFFF;
  555. }
  556. }
  557. }
  558. }
  559. .head {
  560. width: 100%;
  561. height: 40px;
  562. background: #373737;
  563. display: flex;
  564. align-items: center;
  565. justify-content: space-between;
  566. div {
  567. display: flex;
  568. justify-content: center;
  569. }
  570. span {
  571. color: #FFFFFF;
  572. font-style: normal;
  573. font-weight: 500;
  574. font-size: 14px;
  575. margin-left: 16px;
  576. }
  577. img {
  578. width: 20px;
  579. height: 20px;
  580. cursor: pointer;
  581. }
  582. .full {
  583. margin-right: 16px;
  584. }
  585. .fixed {
  586. margin-right: 20px;
  587. }
  588. }
  589. .content {
  590. position: relative;
  591. width: 100%;
  592. height: calc(100% - 40px);
  593. background: #686868;
  594. display: flex;
  595. align-items: center;
  596. justify-content: center;
  597. .mask {
  598. position: absolute;
  599. z-index: 2;
  600. display: flex;
  601. cursor: pointer;
  602. align-items: center;
  603. justify-content: center;
  604. flex-direction: column;
  605. width: 100%;
  606. height: 100%;
  607. background-color: rgba($color: #000000, $alpha: .8);
  608. .luck {
  609. width: 100px;
  610. height: 100px;
  611. }
  612. .btn {
  613. display: flex;
  614. align-items: center;
  615. justify-content: center;
  616. width: 345px;
  617. height: 70px;
  618. margin-top: 12px;
  619. border-radius: 100px;
  620. background: #1D9BF0;
  621. .img {
  622. overflow: hidden;
  623. width: 35px;
  624. height: 35px;
  625. margin-right: 16px;
  626. border-radius: 4px;
  627. }
  628. .font {
  629. width: 188px;
  630. color: #fff;
  631. font-weight: 700;
  632. font-size: 16px;
  633. line-height: 19px;
  634. letter-spacing: 0.3px;
  635. }
  636. }
  637. }
  638. .mask_bg {
  639. position: absolute;
  640. z-index: 1;
  641. width: 100%;
  642. height: 100%;
  643. object-fit: contain;
  644. background-color: #000000;
  645. }
  646. iframe {
  647. background: #fff;
  648. width: 100%;
  649. height: 100%;
  650. border: medium none;
  651. }
  652. .state {
  653. text-align: center;
  654. width: 100%;
  655. height: 100%;
  656. position: relative;
  657. display: flex;
  658. justify-content: center;
  659. align-items: center;
  660. .cover {
  661. width: 100%;
  662. height: 100%;
  663. background: #000000;
  664. opacity: 0.6;
  665. }
  666. .icon-loading {
  667. animation: loading 1s infinite linear;
  668. }
  669. .info {
  670. position: absolute;
  671. width: 100%;
  672. height: 100%;
  673. top: 0;
  674. z-index: 1;
  675. display: flex;
  676. flex-wrap: wrap;
  677. flex-direction: column;
  678. justify-content: center;
  679. img {
  680. margin-bottom: 14px;
  681. }
  682. div {
  683. margin-bottom: 40px;
  684. color: #fff;
  685. text-align: center;
  686. font-weight: 500;
  687. font-size: 22px;
  688. }
  689. .pinned {
  690. color: #8E8E8E;
  691. }
  692. }
  693. }
  694. }
  695. }
  696. @keyframes loading {
  697. from {
  698. transform: rotate(0deg);
  699. }
  700. to {
  701. transform: rotate(360deg);
  702. }
  703. }
  704. </style>