preview-card.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <!-- 发布器-预览卡片 -->
  2. <template>
  3. <div class="wrapper">
  4. <div class="card-container">
  5. <!-- 安装之后的卡片样式 -->
  6. <div v-show="installStatus" class="left" :style="{'width': reviewCanvasParams.width+ 'px'}">
  7. <div class="head" :style="{'zoom': reviewCanvasParams.zoom}">
  8. <img :src="userInfo.avatarUrl"
  9. class="avatar"/>
  10. <div class="article-wrapper">
  11. <div class="nickname">
  12. {{userInfo.name}}
  13. </div>
  14. <div class="name">
  15. @{{userInfo.nickName}}
  16. </div>
  17. </div>
  18. </div>
  19. <div class="after-cover-wrapper-parent" :style="{'zoom': reviewCanvasParams.zoom}">
  20. <div class="after-cover-wrapper">
  21. <custom-card-cover :data="{
  22. totalCount: baseFormData.totalCount,
  23. amountValue: baseFormData.amountValue,
  24. tokenSymbol: currentCurrencyInfo.tokenSymbol,
  25. currencyIconUrl: currentCurrencyInfo.iconPath,
  26. userInfo: {
  27. nickName: userInfo.name,
  28. avatarUrl: userInfo.avatarUrl
  29. }
  30. }"></custom-card-cover>
  31. </div>
  32. </div>
  33. </div>
  34. <!-- 安装之前的卡片样式 -->
  35. <div class="content-before"
  36. v-show="!installStatus"
  37. :style="{'width': reviewCanvasParams.width+ 'px'}">
  38. <div class="head"
  39. :style="{'zoom': reviewCanvasParams.zoom}">
  40. <img :src="userInfo.avatarUrl"
  41. class="avatar"/>
  42. <div class="article-wrapper">
  43. <div class="nickname">
  44. {{userInfo.name}}
  45. </div>
  46. <div class="name">
  47. @{{userInfo.nickName}}
  48. </div>
  49. </div>
  50. </div>
  51. <div class="card-wrapper"
  52. :style="{'zoom': reviewCanvasParams.zoom}">
  53. <img :src="require('@/assets/subject/img-card-cover-blue.png')"
  54. class="card-cover"/>
  55. <div class="bottom-bar">
  56. <div class="title">
  57. DeNet.me
  58. </div>
  59. <div class="desc">
  60. 🎁 <template v-if="currentCurrencyInfo.tokenSymbol=='USD'">$</template>{{baseFormData.amountValue}} GIVEAWAY
  61. </div>
  62. </div>
  63. <div class="user-info">
  64. <img :src="userInfo.avatarUrl"
  65. class="avatar"/> {{userInfo.name}}
  66. </div>
  67. <div class="content-text">
  68. <div class="title">
  69. {{currentCurrencyInfo.tokenSymbol}} GIVEAWAY
  70. </div>
  71. <div class="center"
  72. :style="{
  73. fontSize: amountFontSize + 'px'
  74. }">
  75. <img :src="currentCurrencyInfo.iconPath" class="icon">
  76. <span id="preview-before-amount">
  77. {{baseFormData.amountValue}}
  78. </span>
  79. </div>
  80. <div class="desc">
  81. {{baseFormData.totalCount}} WINNERS TO SHARE
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script setup>
  90. import { ref, defineProps, onMounted, nextTick, watch, reactive, inject, onUnmounted } from "vue";
  91. import customCardCover from '@/view/components/custom-card-cover.vue'
  92. import {getChromeStorage} from "@/uilts/chromeExtension"
  93. import {getUser} from "@/http/publishApi"
  94. let userInfo = ref({});
  95. let reviewCanvasParams = reactive({
  96. width: 396,
  97. zoom: 1
  98. });
  99. let timer = ref(null);
  100. let installStatus = inject('installStatus');
  101. defineProps({
  102. postData: {
  103. type: Object,
  104. default: () => {
  105. return {
  106. }
  107. }
  108. },
  109. baseFormData: {
  110. type: Object,
  111. default: () => {
  112. return {
  113. }
  114. }
  115. },
  116. currentCurrencyInfo: {
  117. type: Object,
  118. default: () => {
  119. return {
  120. }
  121. }
  122. },
  123. amountFontSize: {
  124. type: Number,
  125. default: '56'
  126. }
  127. })
  128. const getUserInfo = (cb) => {
  129. getChromeStorage('userInfo', (res) => {
  130. if(res) {
  131. userInfo.value = res;
  132. }
  133. cb && cb(res);
  134. })
  135. }
  136. const getUserName = (screenName) => {
  137. getUser({
  138. params:{
  139. screenName
  140. }
  141. }).then(res => {
  142. console.log(res);
  143. if(res.code == 0) {
  144. userInfo.value.name = res.data.name || ''
  145. }
  146. });
  147. }
  148. const calcPreviewCanvasParams = () => {
  149. nextTick(() => {
  150. let containerDom = document.querySelector('.card-container');
  151. let domHeight = containerDom && containerDom.offsetHeight || 500;
  152. const canvasHeight = 820, canvasWidth = 600;
  153. if(domHeight < canvasHeight) {
  154. //比例: 高 / 宽
  155. let hWRatio = canvasHeight / canvasWidth;
  156. //缩小宽度 = 高度 / 比例
  157. let width = domHeight / hWRatio;
  158. if(width > canvasWidth) {
  159. width = canvasWidth;
  160. }
  161. //缩小比例
  162. let zoom = width / canvasWidth;
  163. if(zoom > 1) {
  164. zoom = 1;
  165. }
  166. reviewCanvasParams.width = width;
  167. reviewCanvasParams.zoom = zoom;
  168. } else {
  169. reviewCanvasParams.width = canvasWidth;
  170. reviewCanvasParams.zoom = 1;
  171. }
  172. });
  173. }
  174. onMounted(() => {
  175. calcPreviewCanvasParams();
  176. getUserInfo((res) => {
  177. if(res) {
  178. getUserName(res.nickName);
  179. }
  180. clearInterval(timer.value);
  181. timer.value = setInterval(() => {
  182. installStatus.value = !installStatus.value;
  183. }, 3000)
  184. });
  185. window.addEventListener('resize',function () {
  186. calcPreviewCanvasParams();
  187. })
  188. })
  189. onUnmounted(() => {
  190. clearInterval(timer.value);
  191. })
  192. </script>
  193. <style lang="scss" scoped>
  194. .wrapper {
  195. width: 100%;
  196. height: 100%;
  197. box-sizing: border-box;
  198. overflow-y: auto;
  199. display: flex;
  200. &::-webkit-scrollbar {
  201. display: none;
  202. }
  203. .card-container {
  204. width: 100%;
  205. height: 100%;
  206. background: #ffffff;
  207. box-sizing: border-box;
  208. border-radius: 20px;
  209. display: flex;
  210. align-items: center;
  211. .preview-txt {
  212. width: 238px;
  213. font-weight: 600;
  214. font-size: 22px;
  215. span {
  216. color: #1D9BF0;
  217. }
  218. }
  219. .head {
  220. position: absolute;
  221. z-index: 1100;
  222. top: 132px;
  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, .name {
  238. font-size: 15px;
  239. }
  240. .name {
  241. color: #566370;
  242. margin-left: 7px;
  243. }
  244. .desc {
  245. margin-top: 8px;
  246. }
  247. }
  248. }
  249. .left {
  250. background: url('@/assets/img/img-preview-bg-after.png');
  251. width: 387px;
  252. height: 100%;
  253. background-size: contain;
  254. background-repeat: no-repeat;
  255. .tips {
  256. right: 15px !important;
  257. }
  258. }
  259. .after-cover-wrapper-parent {
  260. position: absolute;
  261. z-index: 100;
  262. top: 223px;
  263. left: 78px;
  264. }
  265. .after-cover-wrapper {
  266. position:relative;
  267. width:375px;
  268. .icon-gif {
  269. position: absolute;
  270. left: 50%;
  271. bottom: 80px;
  272. transform: translateX(-50%);
  273. width: 160px;
  274. height: 190px;
  275. }
  276. .content-after {
  277. width: 350px;
  278. border-radius: 16px;
  279. display: block;
  280. object-fit: contain;
  281. }
  282. }
  283. .content-before {
  284. background: url('@/assets/img/img-preview-bg-before.png');
  285. background-size: contain;
  286. background-repeat: no-repeat;
  287. height: 100%;
  288. .card-wrapper {
  289. width: 491px;
  290. border: 1px solid #D1D9DD;
  291. background: #ffffff;
  292. box-sizing: border-box;
  293. overflow: hidden;
  294. position: relative;
  295. box-sizing: border-box;
  296. border-radius: 16px;
  297. left: 73px;
  298. top: 238px;
  299. .user-info {
  300. position: absolute;
  301. left: 8px;
  302. top: 8px;
  303. z-index: 100;
  304. display: flex;
  305. align-items: center;
  306. font-size: 16px;
  307. color: #FFF;
  308. width: max-content;
  309. img {
  310. width: 24px;
  311. height: 24px;
  312. border: 2px solid #FFF4DB;
  313. box-sizing: border-box;
  314. border-radius: 50%;
  315. margin-right: 10px;
  316. }
  317. }
  318. .content-text {
  319. position: absolute;
  320. top: 53px;
  321. left: 35px;
  322. .title {
  323. font-weight: 800;
  324. font-size: 16px;
  325. color: #ffffff;
  326. }
  327. .center {
  328. padding: 12px 0;
  329. box-sizing: border-box;
  330. font-weight: 800;
  331. font-size: 56px;
  332. color: #fff;
  333. display: flex;
  334. align-items: center;
  335. .icon {
  336. width: 46px;
  337. height: 46px;
  338. margin-right: 10px;
  339. border: 3px solid #fff;
  340. border-radius: 50%;
  341. }
  342. }
  343. .desc {
  344. font-weight: 800;
  345. font-size: 13px;
  346. color: #ffffff;
  347. }
  348. }
  349. .card-cover {
  350. width: 100%;
  351. object-fit: contain;
  352. }
  353. .bottom-bar {
  354. padding: 12px;
  355. box-sizing: border-box;
  356. .title {
  357. color: #566370;
  358. font-weight: 400;
  359. font-size: 14px;
  360. margin-bottom: 6px;
  361. }
  362. .desc {
  363. font-weight: 500;
  364. font-size: 15px;
  365. color: #101419;
  366. }
  367. }
  368. }
  369. }
  370. .left, .content-before {
  371. position: relative;
  372. }
  373. }
  374. .select-btn-wrapper {
  375. padding-right: 16px;
  376. box-sizing: border-box;
  377. .title {
  378. font-size: 14px;
  379. margin-bottom: 15px;
  380. }
  381. .select-btn {
  382. margin-bottom: 16px;
  383. box-sizing: border-box;
  384. cursor: pointer;
  385. .icon {
  386. width: 14px;
  387. height: 14px;
  388. margin-right: 8px;
  389. }
  390. .text {
  391. font-size: 14px;
  392. display: flex;
  393. align-items: center;
  394. }
  395. .desc {
  396. white-space: nowrap;
  397. font-weight: 500;
  398. font-size: 13px;
  399. margin-left: 22px;
  400. }
  401. }
  402. .active {
  403. color: #000;
  404. }
  405. }
  406. }
  407. </style>