123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772 |
- <template>
- <div class="denet-toolbox" :class="{ 'pre-view': pre_view }">
- <div class="head">
- <span></span>
- <div v-show="state.show_btn && state.status == 'iframe'">
- <img :src="require('@/assets/svg/icon-iframe-fixed.svg')" alt class="fixed" @click="clickFixed" />
- <img :src="require('@/assets/svg/icon-iframe-full.svg')" alt class="full" @click="clickFull" />
- </div>
- </div>
- <div class="content" v-if="pre_view">
- <iframe :src="iframe_url" frameborder="0" sandbox></iframe>
- </div>
- <div class="content" v-else>
- <template v-if="state.showMask && state.status != '固定右上角'">
- <div class="mask" @click="confirmStatus">
- <img class="luck" :src=" require('@/assets/svg/icon-post-lock.svg') " />
- <div class="btn">
- <img class="img" v-if="state.detail && state.detail.nftProjectIcon" :src=" state.detail.nftProjectIcon " />
- <div class="font">Available for holders of {{state.detail.nftProjectName}} NFT</div>
- </div>
- </div>
- <img class="mask_bg" v-if="state.detail.linkImagePath" :src=" state.detail.linkImagePath " />
- </template>
- <iframe :src="state.iframe_url" v-show="state.status == 'iframe'" ref="dom_iframe" frameborder="0"
- scrolling="yes" allow="camera *;microphone *"></iframe>
- <!-- sandbox="allow-same-origin allow-scripts allow-popups allow-top-navigation allow-forms allow-modals allow-popups-to-escape-sandbox" -->
- <!-- 网页错误 -->
- <div class="state" v-show="state.status == '网页错误'">
- <img :src="state.cover_url" alt="" class="cover" />
- <div class="info">
- <img :src="require('@/assets/svg/icon-iframe-error.svg')" alt />
- <div>Oops, this link is invalid</div>
- </div>
- </div>
- <!-- 加载 -->
- <div class="state" v-show="state.status == '加载'">
- <img :src="state.cover_url" alt="" class="cover" />
- <div class="info">
- <img :src="require('@/assets/svg/icon-iframe-loading.svg')" alt class="icon-loading" />
- </div>
- </div>
- <!-- 关闭 -->
- <div class="state" v-show="state.status == '关闭'">
- </div>
- <!-- 固定右上角 -->
- <div class="state" v-show="state.status == '固定右上角'">
- <div class="info">
- <img :src="require('@/assets/svg/icon-iframe-pinned.svg')" alt />
- <div class="pinned">Pinned to the top right</div>
- </div>
- </div>
- </div>
- <!-- alert -->
- <div class="alert" v-show="state.show_alert">
- <div class="back" @click.stop="clickCancel"></div>
- <div class="confirm">
- <div class="check">
- <input :id="state.checkbox_id" type='checkbox' v-model="state.checkbox" />
- <label :for="state.checkbox_id">Don't remind</label>
- </div>
- <div class="title">Web Page Progress May Reset</div>
- <div class="handle">
- <div class="cancel" @click.stop="clickCancel">Cancel</div>
- <div class="continue" @click.stop="clickContinue">Continue</div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { getChromeStorage, setChromeStorage, defineProps, sendChromeTabMessage } from "@/uilts/chromeExtension";
- import { getPostDetail } from '@/http/redPacket.js'
- import { getPostEditorNftCertInfo, unlockNftCert } from '@/http/toolBoxApi'
- import { guid, getQueryString } from "@/uilts/help";
- import { onMounted, reactive, ref, onBeforeUnmount } from "vue";
- import { ElMessage } from 'element-plus'
- import { reSetBindTwtterId } from '@/http/help.js'
- import Report from "@/log-center/log"
- import "element-plus/es/components/message/style/css";
- let dom_iframe = ref(null)
- let state = reactive({
- status: '', //
- show_alert: false,
- show_btn: false,
- list: [],
- checkbox: false,
- checkbox_id: `denet-${guid()}`,
- postId: '',
- tweetId: '',
- detail: {},
- handle_type: '',
- showMask: false,
- cover_url: require('@/assets/img/back-loading.png')
- })
- let dom = {}
- let nftAuthINfo = ref(null)
- let loadTime = (new Date).getTime()
- let props = defineProps({
- pre_view: {
- type: Boolean,
- default: false,
- },
- iframe_url: {
- type: String,
- default: ''
- }
- })
- chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
- switch (req.actionType) {
- // 事件传输
- case 'Set_ToolBox_Fixed':
- if (req.data.tweetId == state.tweetId && req.data.type == '关闭') {
- state.show_btn = true
- state.status = 'iframe'
- state.iframe_url = req.data.iframe_url
- nftAuthINfo.value = req.data.nftAuthINfo
- state.showMask = req.data.showMask
- state.detail = req.data.detail
- state.postId = req.data.postId
- }
- break
- }
- sendResponse && sendResponse();
- })
- const clickContinue = () => {
- if (state.checkbox) {
- setChromeStorage({ fullCheck: JSON.stringify({ fullCheck: 1 }) })
- }
- if (state.handle_type == '全屏') {
- handleFull()
- } else {
- handleFixed()
- }
- state.show_alert = false
- }
- onMounted(() => {
- if (props.pre_view) {
- return
- }
- state.postId = getQueryString('postId')
- state.tweetId = getQueryString('tweetId')
- sendChromeTabMessage({
- actionType: 'Get_ToolBox_Fixed_TweetId'
- }, (res) => {
- if (res == state.tweetId) {
- state.status = '固定右上角'
- } else {
- state.status = '加载'
- getDetail()
- }
- })
- chrome.runtime.onMessage.addListener(msgListener)
- // 页面返回重试状态
- document.addEventListener('visibilitychange', function () {
- let isHidden = document.hidden;
- if (!isHidden && !nftAuthINfo.value) {
- getDetail();
- }
- });
- })
- onBeforeUnmount(() => {
- chrome.runtime.onMessage.removeListener(msgListener);
- })
- // detail函数
- const getDetail = () => {
- let iframe = dom_iframe.value
- iframe.onerror = () => {
- state.status = '网页错误'
- }
- getPostDetail({
- params: {
- postId: state.postId
- }
- }).then((res) => {
- if (res && res.code == 0) {
- state.detail = JSON.parse(res.data.postBizData)
- if (!res.data.srcContentId) {
- reSetBindTwtterId({
- postId: state.postId,
- tweetId: state.tweetId
- }, () => {
- Report.reportLog({
- objectType: Report.objectType.tweetPostBinded,
- redPacketType: 5,
- postId: state.postId,
- }, {
- 'post-editor-url': state.detail.convertUrl
- });
- })
- }
- console.log('postBizData', state.detail)
- // 加载iframe
- if (state.detail.viewBgImagePath) {
- state.cover_url = state.detail.viewBgImagePath
- }
- state.iframe_url = state.detail.convertUrl
- state.show_btn = true
- state.status = 'iframe'
- // 蒙层
- if (state.detail && state.detail.certNftProjectId) {
- if (state.detail?.certNftUnlockStatus == 0) {
- state.showMask = true;
- // report
- reportFail()
- } else {
- // report
- reportSucc()
- }
- // 确权信息
- getChromeStorage('userInfo', (_userInfo) => {
- if (_userInfo) {
- getNftInfoStatus()
- }
- })
- } else {
- reportSucc(false)
- }
- // report
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.pageView,
- pageSource: Report.pageSource.pe_loading_page,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl
- });
- } else {
- state.status = '网页错误'
- }
- })
- }
- const getNftInfoStatus = () => {
- getPostEditorNftCertInfo({
- params: {
- postId: state.postId,
- }
- }).then(res => {
- let { code, data } = res;
- if ( code === 0 ) {
- nftAuthINfo.value = data;
- }
- })
- }
- const reportSucc = (isEncrypted = true) => {
- let params = {}
- if (isEncrypted) {
- params['nft-encrypted-status'] = 1;
- }
- // report
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.pageView,
- pageSource: Report.pageSource.pe_display_page,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl,
- ...params,
- }, {
- 'loading-time': (new Date).getTime() - loadTime,
- });
- }
- const reportFail = () => {
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.pageView,
- pageSource: Report.pageSource.pe_display_page,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl,
- 'nft-encrypted-status': 0,
- }, {
- 'loading-time': (new Date).getTime() - loadTime,
- });
- }
- const confirmStatus = () => {
- getChromeStorage('userInfo', (_userInfo) => {
- if (!_userInfo) {
- chrome.runtime.sendMessage(
- { actionType: "POPUP_LOGIN", data: "" },
- (response) => {
- console.log("res", response);
- }
- )
- } else {
- if (nftAuthINfo.value && nftAuthINfo.value?.certStatus === 1) {
- succBack()
- } else {
- sendChromeTabMessage({
- actionType: 'Set_ToolBox_By_Nft',
- data: {
- postId: state.postId,
- }
- })
- }
- }
- })
- // report
- let params = {}
- if (nftAuthINfo.value?.certStatus === 1) {
- if (state.showMask) {
- params['nft-encrypted-status'] = 0
- } else {
- params['nft-encrypted-status'] = 1
- }
- }
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.buttonClick,
- pageSource: Report.pageSource.pe_display_page,
- objectType: Report.objectType.encrypte_nft_button,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl,
- ...params,
- });
- }
- const succBack = () => {
- ElMessage({
- message: `NFT validated!`,
- type: 'success'
- })
- state.showMask = false;
- // 解锁
- unlockNftCert({
- params: {
- postId: state.postId,
- }
- })
- }
- const hideMask = (data) => {
- if (data && data.post_Id && data.post_Id === state.postId) {
- succBack()
- }
- }
- const clickCancel = () => {
- state.show_alert = false
- }
- const clickFixed = () => {
- getChromeStorage('userInfo', (_userInfo) => {
- if (!_userInfo) {
- chrome.runtime.sendMessage(
- { actionType: "POPUP_LOGIN", data: "" },
- (response) => {
- console.log("res", response);
- }
- )
- } else {
- state.handle_type = '固定右上角'
- getChromeStorage('fullCheck', (res) => {
- if (res && res.fullCheck) {
- // 固定
- handleFixed()
- } else {
- state.show_alert = true
- }
- })
- }
- })
- // report
- let params = {}
- if (nftAuthINfo.value?.certStatus === 1) {
- if (state.showMask) {
- params['nft-encrypted-status'] = 0
- } else {
- params['nft-encrypted-status'] = 1
- }
- }
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.buttonClick,
- pageSource: Report.pageSource.pe_display_page,
- objectType: Report.objectType.top_right_button,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl,
- ...params,
- });
- }
- // 固定
- const handleFull = () => {
- if (state.status != 'iframe' || !state.iframe_url) {
- return
- }
- getChromeStorage('userInfo', (_userInfo) => {
- if (!_userInfo) {
- chrome.runtime.sendMessage(
- { actionType: "POPUP_LOGIN", data: "" },
- (response) => {
- console.log("res", response);
- }
- )
- } else {
- // 切换状态
- state.status = '固定右上角'
- state.show_btn = false
- sendChromeTabMessage({
- actionType: 'Set_ToolBox_Fixed',
- data: {
- type: '全屏',
- iframe_url: state.iframe_url,
- tweetId: state.tweetId,
- nftAuthINfo: nftAuthINfo.value,
- showMask: state.showMask,
- detail: state.detail,
- postId: state.postId,
- }
- })
- // 清除当前iframe src
- state.iframe_url = ''
- }
- })
- }
- // 全屏
- const handleFixed = () => {
- // 切换状态
- state.show_btn = false
- state.status = '固定右上角'
- sendChromeTabMessage({
- actionType: 'Set_ToolBox_Fixed',
- data: {
- type: '固定右上角',
- iframe_url: state.iframe_url,
- tweetId: state.tweetId,
- nftAuthINfo: nftAuthINfo.value,
- showMask: state.showMask,
- detail: state.detail,
- postId: state.postId,
- }
- })
- // 清除当前iframe src
- state.iframe_url = ''
- }
- const clickFull = () => {
- state.handle_type = '全屏'
- getChromeStorage('fullCheck', (res) => {
- if (res && res.fullCheck) {
- // 全屏
- handleFull()
- } else {
- state.show_alert = true
- }
- })
- // report
- let params = {}
- if (nftAuthINfo.value?.certStatus === 1) {
- if (state.showMask) {
- params['nft-encrypted-status'] = 0
- } else {
- params['nft-encrypted-status'] = 1
- }
- }
- Report.reportLog({
- redPacketType: Report.redPacketType.postEditor,
- businessType: Report.businessType.buttonClick,
- pageSource: Report.pageSource.pe_display_page,
- objectType: Report.objectType.fullscreen_button,
- postId: state.postId || '',
- postEditorUrl: state.detail.convertUrl,
- ...params,
- });
- }
- const msgListener = (req, sender, sendResponse) => {
- switch (req.actionType) {
- case 'BG_LOGIN_SET_USERINFO_CB':
- getDetail()
- break;
- case 'FINISH_ToolBox_By_Nft':
- hideMask(req.data)
- break;
- }
- }
- </script>
- <style lang="scss" >
- .pre-view {
- pointer-events: none;
- cursor: default;
- }
- .denet-toolbox {
- width: 100%;
- height: 100%;
- min-height: 100%;
- filter: drop-shadow(0px 4px 20px rgba(0, 0, 0, 0.2));
- border-radius: 12px;
- overflow: hidden;
- position: relative;
- .alert {
- text-align: center;
- position: absolute;
- z-index: 3;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- .back {
- background: #000000;
- opacity: 0.8;
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- cursor: auto;
- }
- .confirm {
- position: absolute;
- width: 355px;
- height: 180px;
- background: #FFFFFF;
- border-radius: 20px;
- top: 173px;
- left: 50%;
- margin-left: -180px;
- .title {
- font-weight: 600;
- font-size: 18px;
- color: #000000;
- margin-bottom: 34px;
- }
- .check {
- color: #899099;
- font-weight: 400;
- font-size: 14px;
- margin: 12px 15px 32px 0;
- text-align: right;
- align-content: center;
- justify-content: flex-end;
- display: flex;
- line-height: 17px;
- input {
- margin-right: 8px;
- }
- label {
- line-height: 19px;
- }
- }
- .handle {
- display: flex;
- justify-content: center;
- align-items: center;
- div {
- font-weight: 600;
- font-size: 16px;
- width: 156px;
- height: 47px;
- line-height: 47px;
- cursor: pointer;
- border-radius: 1000px;
- user-select: none;
- }
- .cancel {
- color: #000000;
- background: rgba(56, 154, 255, 0.01);
- border: 1px solid #E6E6E6;
- }
- .continue {
- background: #1D9BF0;
- font-weight: 600;
- margin-left: 11px;
- color: #FFFFFF;
- }
- }
- }
- }
- .head {
- width: 100%;
- height: 40px;
- background: #373737;
- display: flex;
- align-items: center;
- justify-content: space-between;
- div {
- display: flex;
- justify-content: center;
- }
- span {
- color: #FFFFFF;
- font-style: normal;
- font-weight: 500;
- font-size: 14px;
- margin-left: 16px;
- }
- img {
- width: 20px;
- height: 20px;
- cursor: pointer;
- }
- .full {
- margin-right: 16px;
- }
- .fixed {
- margin-right: 20px;
- }
- }
- .content {
- position: relative;
- width: 100%;
- height: calc(100% - 40px);
- background: #686868;
- display: flex;
- align-items: center;
- justify-content: center;
- .mask {
- position: absolute;
- z-index: 2;
- display: flex;
- cursor: pointer;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- width: 100%;
- height: 100%;
- background-color: rgba($color: #000000, $alpha: .8);
- .luck {
- width: 100px;
- height: 100px;
- }
- .btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 345px;
- height: 70px;
- margin-top: 12px;
- border-radius: 100px;
- background: #1D9BF0;
- .img {
- overflow: hidden;
- width: 35px;
- height: 35px;
- margin-right: 16px;
- border-radius: 4px;
- }
- .font {
- width: 188px;
- color: #fff;
- font-weight: 700;
- font-size: 16px;
- line-height: 19px;
- letter-spacing: 0.3px;
- }
- }
- }
- .mask_bg {
- position: absolute;
- z-index: 1;
- width: 100%;
- height: 100%;
- object-fit: contain;
- background-color: #000000;
- }
- iframe {
- background: #fff;
- width: 100%;
- height: 100%;
- border: medium none;
- }
- .state {
- text-align: center;
- width: 100%;
- height: 100%;
- position: relative;
- display: flex;
- justify-content: center;
- align-items: center;
- .cover {
- width: 100%;
- height: 100%;
- background: #000000;
- opacity: 0.6;
- }
- .icon-loading {
- animation: loading 1s infinite linear;
- }
- .info {
- position: absolute;
- width: 100%;
- height: 100%;
- top: 0;
- z-index: 1;
- display: flex;
- flex-wrap: wrap;
- flex-direction: column;
- justify-content: center;
- img {
- margin-bottom: 14px;
- }
- div {
- margin-bottom: 40px;
- color: #fff;
- text-align: center;
- font-weight: 500;
- font-size: 22px;
- }
- .pinned {
- color: #8E8E8E;
- }
- }
- }
- }
- }
- @keyframes loading {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
- }
- </style>
|