preview.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="editor-preview-wrapper">
  3. <div class="top">
  4. <div class="card-container">
  5. <!-- 安装之后的卡片样式 -->
  6. <div class="content-after" v-show="installStatus" :style="{ 'width': reviewCanvasParams.width + 'px' }">
  7. <div class="head" :style="{ 'zoom': reviewCanvasParams.zoom }">
  8. <img :src="userInfo.avatarUrl" class="avatar" />
  9. <div class="article-wrapper">
  10. <div class="nickname">
  11. {{ userInfo.name }}
  12. </div>
  13. <div class="name">
  14. @{{ userInfo.nickName }}
  15. </div>
  16. </div>
  17. </div>
  18. <div class="after-cover-wrapper" :style="{ 'zoom': reviewCanvasParams.zoom }">
  19. <install-card :pre_view="true" :iframe_url="previewData.convertUrl"></install-card>
  20. </div>
  21. </div>
  22. <!-- 安装之前的卡片样式 -->
  23. <div class="content-before" v-show="!installStatus"
  24. :style="{ 'width': reviewCanvasParams.width + 'px' }">
  25. <div class="head" :style="{ 'zoom': reviewCanvasParams.zoom }">
  26. <img :src="userInfo.avatarUrl" class="avatar" />
  27. <div class="article-wrapper">
  28. <div class="nickname">
  29. {{ userInfo.name }}
  30. </div>
  31. <div class="name">
  32. @{{ userInfo.nickName }}
  33. </div>
  34. </div>
  35. </div>
  36. <div class="card-wrapper" :style="{ 'zoom': reviewCanvasParams.zoom }">
  37. <img class="cover" :src="previewData.linkImagePath || require('@/assets/svg/img-default-site-cover.svg')" />
  38. <!-- v-if="previewData.linkImagePath && previewData.appId" <iframe class="iframe"
  39. :src="previewData.convertUrl"
  40. v-else></iframe> -->
  41. <div class="bottom-bar">
  42. <div class="site-url">DeNet.me</div>
  43. <div class="desc">Install DeNet Plugin to Participate</div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="font">
  49. Preview: <span>{{ installStatus ? 'After' : 'Before' }}</span> DeNet Installed
  50. </div>
  51. </div>
  52. <div class="bottom">
  53. <div class="btn" @click="publishHandler">NEXT</div>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. import { ref, defineEmits, reactive, defineProps, onMounted, nextTick, onUnmounted } from "vue";
  59. import { postPublish } from "@/http/publishApi";
  60. import installCard from '@/view/content/tool-box/index.vue'
  61. import { getChromeStorage, setChromeStorage } from "@/uilts/chromeExtension"
  62. import { getUser } from "@/http/publishApi"
  63. let installStatus = ref(false);
  64. let userInfo = ref({});
  65. let submitIng = ref(false);
  66. let reviewCanvasParams = reactive({
  67. width: 620,
  68. zoom: 1
  69. });
  70. let timer = ref(null);
  71. const props = defineProps({
  72. previewData: {
  73. type: Object,
  74. default: {
  75. convertUrl: '',
  76. originUrl: '',
  77. appId: ''
  78. }
  79. }
  80. })
  81. const emits = defineEmits(["publishFinish"]);
  82. const getUserInfo = (cb) => {
  83. getChromeStorage('userInfo', (res) => {
  84. if (res) {
  85. userInfo.value = res;
  86. }
  87. cb && cb(res);
  88. })
  89. }
  90. const getUserName = (screenName) => {
  91. getUser({
  92. params: {
  93. screenName
  94. }
  95. }).then(res => {
  96. console.log(res);
  97. if (res.code == 0) {
  98. userInfo.value.name = res.data.name || ''
  99. }
  100. });
  101. }
  102. const calcPreviewCanvasParams = () => {
  103. nextTick(() => {
  104. let containerDom = document.querySelector('.card-container');
  105. let domHeight = containerDom && containerDom.offsetHeight || 500;
  106. const canvasHeight = 780, canvasWidth = 620;
  107. if (domHeight < canvasHeight) {
  108. //比例: 高 / 宽
  109. let hWRatio = canvasHeight / canvasWidth;
  110. //缩小宽度 = 高度 / 比例
  111. let width = domHeight / hWRatio;
  112. if (width > canvasWidth) {
  113. width = canvasWidth;
  114. }
  115. //缩小比例
  116. let zoom = width / canvasWidth;
  117. if (zoom > 1) {
  118. zoom = 1;
  119. }
  120. reviewCanvasParams.width = width;
  121. reviewCanvasParams.zoom = zoom;
  122. } else {
  123. reviewCanvasParams.width = canvasWidth;
  124. reviewCanvasParams.zoom = 1;
  125. }
  126. });
  127. }
  128. const publishHandler = () => {
  129. if(submitIng.value) {
  130. return;
  131. }
  132. let {convertUrl, originUrl, appId, currentApp} = props.previewData;
  133. setHistoryData(currentApp);
  134. let postBizData = {
  135. convertUrl,
  136. originUrl,
  137. appId
  138. };
  139. let data = {
  140. params: {
  141. postBizData: JSON.stringify(postBizData),
  142. postSrc: 1, // 1 twitter
  143. postType: 3, //3 Tool box
  144. },
  145. };
  146. submitIng.value = true;
  147. postPublish(data).then((res) => {
  148. submitIng.value = false;
  149. if (res.code == 0) {
  150. let publishRes = res.data;
  151. emits("publishFinish", { publishRes });
  152. } else {
  153. }
  154. })
  155. .catch((err) => {
  156. console.log(err);
  157. });
  158. }
  159. const setHistoryData = async (params) => {
  160. const maxLength = 9;
  161. let {list = []} = await getChromeStorage('toolBoxAppHistoryData') || {};
  162. if(list.length) {
  163. let hasSite = list.find(item => item.defaultUrl == params.defaultUrl);
  164. if(hasSite) {
  165. return;
  166. }
  167. list.unshift(params);
  168. if(list.length > maxLength) {
  169. list.length = maxLength;
  170. }
  171. setChromeStorage({ toolBoxAppHistoryData : JSON.stringify({
  172. list: list
  173. })})
  174. } else {
  175. setChromeStorage({ toolBoxAppHistoryData : JSON.stringify({
  176. list: [params]
  177. })})
  178. }
  179. };
  180. onMounted(() => {
  181. calcPreviewCanvasParams();
  182. getUserInfo((res) => {
  183. if (res) {
  184. getUserName(res.nickName);
  185. }
  186. clearInterval(timer.value);
  187. timer.value = setInterval(() => {
  188. installStatus.value = !installStatus.value;
  189. }, 3000)
  190. });
  191. window.addEventListener('resize', function () {
  192. calcPreviewCanvasParams();
  193. })
  194. })
  195. onUnmounted(() => {
  196. clearInterval(timer.value);
  197. })
  198. </script>
  199. <style lang="scss" scoped>
  200. .editor-preview-wrapper {
  201. width: 100%;
  202. height: 100%;
  203. .top {
  204. width: 100%;
  205. height: calc(100% - 80px);
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. overflow-y: auto;
  210. padding: 20px 0;
  211. box-sizing: border-box;
  212. .card-container {
  213. height: 100%;
  214. margin-right: 50px;
  215. .content-after,
  216. .content-before {
  217. position: relative;
  218. }
  219. .head {
  220. position: absolute;
  221. z-index: 1100;
  222. top: 20px;
  223. left: 17px;
  224. display: flex;
  225. .avatar {
  226. width: 47px;
  227. height: 47px;
  228. border-radius: 50%;
  229. object-fit: cover;
  230. margin-right: 13px;
  231. }
  232. .article-wrapper {
  233. display: flex;
  234. .nickname {
  235. font-weight: 500;
  236. }
  237. .nickname,
  238. .name {
  239. font-size: 15px;
  240. }
  241. .name {
  242. color: #566370;
  243. margin-left: 7px;
  244. }
  245. }
  246. }
  247. .content-after {
  248. background: url('@/assets/img/img-tool-box-preview-after.png');
  249. width: 387px;
  250. height: 100%;
  251. background-size: contain;
  252. background-repeat: no-repeat;
  253. border: 1px solid #D1D9DD;
  254. border-radius: 13px;
  255. box-sizing: border-box;
  256. .after-cover-wrapper {
  257. position: absolute;
  258. z-index: 100;
  259. top: 108px;
  260. left: 78px;
  261. width: 425px;
  262. height: 458px;
  263. border-radius: 10px;
  264. // border: 1px solid #D1D9DD;
  265. }
  266. }
  267. .content-before {
  268. background: url('@/assets/img/img-tool-box-preview-before.png');
  269. background-size: contain;
  270. background-repeat: no-repeat;
  271. height: 100%;
  272. border: 1px solid #D1D9DD;
  273. border-radius: 13px;
  274. box-sizing: border-box;
  275. .card-wrapper {
  276. width: 505px;
  277. height: 338px;
  278. border: 1px solid #D1D9DD;
  279. background: #ffffff;
  280. box-sizing: border-box;
  281. overflow: hidden;
  282. position: relative;
  283. box-sizing: border-box;
  284. border-radius: 16px;
  285. left: 73px;
  286. top: 90px;
  287. .iframe {
  288. height: calc(100% - 73px);
  289. width: 100%;
  290. border: none;
  291. pointer-events: none;
  292. cursor: default;
  293. }
  294. .cover {
  295. height: calc(100% - 73px);
  296. width: 100%;
  297. object-fit: contain;
  298. }
  299. .bottom-bar {
  300. width: 100%;
  301. height: 73px;
  302. padding: 10px 10px 0 13px;
  303. border-top: 1px solid rgba(0, 0, 0, 0.3);
  304. .site-url {
  305. color: #566370;
  306. font-size: 14px;
  307. line-height: 20px;
  308. }
  309. .desc {
  310. font-weight: 500;
  311. font-size: 15px;
  312. line-height: 21px;
  313. font-weight: 500;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. .font {
  320. width: 300px;
  321. font-weight: 600;
  322. font-size: 20px;
  323. span {
  324. color: #1D9BF0;
  325. }
  326. }
  327. }
  328. .bottom {
  329. width: 100%;
  330. height: 80px;
  331. box-shadow: 0px -1px 0px #ECECEC;
  332. box-sizing: border-box;
  333. border-bottom-left-radius: 16px;
  334. display: flex;
  335. align-items: center;
  336. justify-content: flex-end;
  337. .btn {
  338. width: 200px;
  339. height: 50px;
  340. background: #1D9BF0;
  341. border-radius: 10000px;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. font-weight: 700;
  346. font-size: 18px;
  347. color: #fff;
  348. margin-right: 30px;
  349. cursor: pointer;
  350. }
  351. }
  352. }
  353. </style>