123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- <template>
- <div class="editor-preview-wrapper">
- <div class="top">
- <div class="card-container">
- <!-- 安装之后的卡片样式 -->
- <div class="content-after" v-show="installStatus" :style="{ 'width': reviewCanvasParams.width + 'px' }">
- <div class="head" :style="{ 'zoom': reviewCanvasParams.zoom }">
- <img :src="userInfo.avatarUrl" class="avatar" />
- <div class="article-wrapper">
- <div class="nickname">
- {{ userInfo.name }}
- </div>
- <div class="name">
- @{{ userInfo.nickName }}
- </div>
- </div>
- </div>
- <div class="after-cover-wrapper" :style="{ 'zoom': reviewCanvasParams.zoom }">
- <install-card :pre_view="true" :iframe_url="previewData.convertUrl"></install-card>
- </div>
- </div>
- <!-- 安装之前的卡片样式 -->
- <div class="content-before" v-show="!installStatus"
- :style="{ 'width': reviewCanvasParams.width + 'px' }">
- <div class="head" :style="{ 'zoom': reviewCanvasParams.zoom }">
- <img :src="userInfo.avatarUrl" class="avatar" />
- <div class="article-wrapper">
- <div class="nickname">
- {{ userInfo.name }}
- </div>
- <div class="name">
- @{{ userInfo.nickName }}
- </div>
- </div>
- </div>
- <div class="card-wrapper" :style="{ 'zoom': reviewCanvasParams.zoom }">
- <img class="cover" v-if="previewData.linkImagePath && previewData.appId"
- :src="previewData.linkImagePath" />
- <iframe class="iframe" :src="previewData.convertUrl" scrolling="no" v-else></iframe>
- <div class="bottom-bar">
- <div class="site-url">DeNet.me</div>
- <div class="desc">
- <template v-if="previewData.appId">
- {{ previewData.currentApp.linkTitle }}
- </template>
- <template v-else>
- {{ previewData.currentApp.defaultTit ? defaultLinkTitle :
- previewData.currentApp.name
- }}
- </template>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="font">
- Preview: <span>{{ installStatus ? 'After' : 'Before' }}</span> DeNet Installed
- </div>
- </div>
- <div class="bottom">
- <div class="btn" @click="publishHandler">NEXT</div>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, defineEmits, reactive, defineProps, onMounted, nextTick, onUnmounted, watch } from "vue";
- import { message } from "ant-design-vue";
- import installCard from '@/view/content/tool-box/index.vue'
- import { postPublish } from "@/http/publishApi";
- import { getChromeStorage, setChromeStorage } from "@/uilts/chromeExtension"
- import { getUser } from "@/http/publishApi"
- let installStatus = ref(false);
- let userInfo = ref({});
- let submitIng = ref(false);
- let reviewCanvasParams = reactive({
- width: 620,
- zoom: 1
- });
- let timer = ref(null);
- let loadingHide = null;
- const props = defineProps({
- previewData: {
- type: Object,
- default: () => {
- return {
- convertUrl: '',
- originUrl: '',
- appId: ''
- }
- }
- },
- screenshotWebsiteData: {
- type: Object,
- default: () => {
- return {
- url: '',
- status: ''
- }
- }
- },
- defaultLinkTitle: {
- type: String,
- default: ''
- },
- showCom: {
- type: String,
- default: 'EDITOR'
- }
- })
- watch(() => props.screenshotWebsiteData,
- (newVal) => {
- let { appId } = props.previewData;
- if (loadingHide && !appId && (newVal.url || newVal.status)) {
- loadingHide();
- loadingHide = null;
- submitPublish();
- }
- },
- {
- deep: true
- })
- watch(() => props.showCom,
- (newVal) => {
- if (newVal == 'EDITOR' && loadingHide) {
- loadingHide();
- loadingHide = null;
- }
- },
- {
- deep: true
- })
- const emits = defineEmits(["publishFinish"]);
- const getUserInfo = (cb) => {
- getChromeStorage('userInfo', (res) => {
- if (res) {
- userInfo.value = res;
- }
- cb && cb(res);
- })
- }
- const getUserName = (screenName) => {
- getUser({
- params: {
- screenName
- }
- }).then(res => {
- console.log(res);
- if (res.code == 0) {
- userInfo.value.name = res.data.name || ''
- }
- });
- }
- const calcPreviewCanvasParams = () => {
- nextTick(() => {
- let containerDom = document.querySelector('.card-container');
- let domHeight = containerDom && containerDom.offsetHeight || 500;
- const canvasHeight = 780, canvasWidth = 620;
- if (domHeight < canvasHeight) {
- //比例: 高 / 宽
- let hWRatio = canvasHeight / canvasWidth;
- //缩小宽度 = 高度 / 比例
- let width = domHeight / hWRatio;
- if (width > canvasWidth) {
- width = canvasWidth;
- }
- //缩小比例
- let zoom = width / canvasWidth;
- if (zoom > 1) {
- zoom = 1;
- }
- reviewCanvasParams.width = width;
- reviewCanvasParams.zoom = zoom;
- } else {
- reviewCanvasParams.width = canvasWidth;
- reviewCanvasParams.zoom = 1;
- }
- });
- }
- const publishHandler = () => {
- let { appId } = props.previewData;
- if (loadingHide) {
- return;
- }
- if (!appId && !props.screenshotWebsiteData.url) {
- loadingHide = message.loading('loading...', 0);
- return;
- }
- submitPublish();
- }
- const submitPublish = () => {
- let { convertUrl, originUrl, appId, currentApp } = props.previewData;
- if (submitIng.value) {
- return;
- }
- setHistoryData(currentApp);
- let linkTitle = currentApp.defaultTit ? '' : currentApp.name;
- let postBizData = {
- convertUrl,
- originUrl,
- appId,
- linkTitle: !appId ? linkTitle : '',
- linkImagePath: props.screenshotWebsiteData.url
- };
- let data = {
- params: {
- postBizData: JSON.stringify(postBizData),
- postSrc: 1, // 1 twitter
- postType: 3, //3 Tool box
- },
- };
- submitIng.value = true;
- postPublish(data).then((res) => {
- submitIng.value = false;
- if (res.code == 0) {
- let publishRes = res.data;
- emits("publishFinish", { publishRes });
- } else {
- }
- }).catch((err) => {
- console.log(err);
- });
- }
- const setHistoryData = async (params) => {
- const maxLength = 9;
- let { list = [] } = await getChromeStorage('toolBoxAppHistoryData') || {};
- if (list.length) {
- let hasSite = list.find(item => item.defaultUrl == params.defaultUrl);
- if (hasSite) {
- return;
- }
- list.unshift(params);
- if (list.length > maxLength) {
- list.length = maxLength;
- }
- setChromeStorage({
- toolBoxAppHistoryData: JSON.stringify({
- list: list
- })
- })
- } else {
- setChromeStorage({
- toolBoxAppHistoryData: JSON.stringify({
- list: [params]
- })
- })
- }
- };
- onMounted(() => {
- calcPreviewCanvasParams();
- getUserInfo((res) => {
- if (res) {
- getUserName(res.nickName);
- }
- clearInterval(timer.value);
- timer.value = setInterval(() => {
- installStatus.value = !installStatus.value;
- }, 3000)
- });
- window.addEventListener('resize', function () {
- calcPreviewCanvasParams();
- })
- })
- onUnmounted(() => {
- clearInterval(timer.value);
- })
- </script>
- <style lang="scss" scoped>
- .editor-preview-wrapper {
- width: 100%;
- height: 100%;
- .top {
- width: 100%;
- height: calc(100% - 80px);
- display: flex;
- align-items: center;
- justify-content: center;
- overflow-y: auto;
- padding: 20px 0;
- box-sizing: border-box;
- .card-container {
- height: 100%;
- margin-right: 50px;
- .content-after,
- .content-before {
- position: relative;
- }
- .head {
- position: absolute;
- z-index: 1100;
- top: 20px;
- left: 17px;
- display: flex;
- .avatar {
- width: 47px;
- height: 47px;
- border-radius: 50%;
- object-fit: cover;
- margin-right: 13px;
- }
- .article-wrapper {
- display: flex;
- .nickname {
- font-weight: 500;
- }
- .nickname,
- .name {
- font-size: 15px;
- }
- .name {
- color: #566370;
- margin-left: 7px;
- }
- }
- }
- .content-after {
- background: url('@/assets/img/img-tool-box-preview-after.png');
- width: 387px;
- height: 100%;
- background-size: contain;
- background-repeat: no-repeat;
- border: 1px solid #D1D9DD;
- border-radius: 13px;
- box-sizing: border-box;
- .after-cover-wrapper {
- position: absolute;
- z-index: 100;
- top: 108px;
- left: 78px;
- width: 425px;
- height: 458px;
- border-radius: 10px;
- // border: 1px solid #D1D9DD;
- }
- }
- .content-before {
- background: url('@/assets/img/img-tool-box-preview-before.png');
- background-size: contain;
- background-repeat: no-repeat;
- height: 100%;
- border: 1px solid #D1D9DD;
- border-radius: 13px;
- box-sizing: border-box;
- .card-wrapper {
- width: 505px;
- height: 338px;
- border: 1px solid #D1D9DD;
- background: #ffffff;
- box-sizing: border-box;
- overflow: hidden;
- position: relative;
- box-sizing: border-box;
- border-radius: 16px;
- left: 73px;
- top: 90px;
- .iframe {
- height: calc(100% - 73px);
- width: 100%;
- border: none;
- pointer-events: none;
- cursor: default;
- }
- .cover {
- height: calc(100% - 73px);
- width: 100%;
- object-fit: contain;
- }
- .bottom-bar {
- width: 100%;
- height: 73px;
- padding: 10px 10px 0 13px;
- border-top: 1px solid rgba(0, 0, 0, 0.3);
- .site-url {
- color: #566370;
- font-size: 14px;
- line-height: 20px;
- }
- .desc {
- font-weight: 500;
- font-size: 15px;
- line-height: 21px;
- font-weight: 500;
- }
- }
- }
- }
- }
- .font {
- width: 300px;
- font-weight: 600;
- font-size: 20px;
- span {
- color: #1D9BF0;
- }
- }
- }
- .bottom {
- width: 100%;
- height: 80px;
- box-shadow: 0px -1px 0px #ECECEC;
- box-sizing: border-box;
- border-bottom-left-radius: 16px;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- .btn {
- width: 200px;
- height: 50px;
- background: #1D9BF0;
- border-radius: 10000px;
- display: flex;
- align-items: center;
- justify-content: center;
- font-weight: 700;
- font-size: 18px;
- color: #fff;
- margin-right: 30px;
- cursor: pointer;
- }
- }
- }
- </style>
|