preview-card.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. usdEstimateOrderAmount: baseFormData.usdEstimateOrderAmount,
  25. tokenSymbol: currentCurrencyInfo.tokenSymbol,
  26. currencyCode: currentCurrencyInfo.currencyCode,
  27. currencyIconUrl: currentCurrencyInfo.iconPath,
  28. type: baseFormData.type,
  29. validityDuration: baseFormData.validityDuration,
  30. customPosterUrl: customPosterInfo && customPosterInfo.after && customPosterInfo.after.imagePath || '',
  31. userInfo: {
  32. nickName: userInfo.nickName,
  33. avatarUrl: userInfo.avatarUrl
  34. },
  35. rewardType: baseFormData.rewardType,
  36. customizedReward: baseFormData.customizedReward,
  37. upGainAmountUsdValue: upGainAmountUsdValue
  38. }"
  39. :show="installStatus"></custom-card-cover>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- 安装之前的卡片样式 -->
  44. <div class="content-before"
  45. v-show="!installStatus"
  46. :style="{'width': (baseFormData.rewardType === RewardType.money) ? `${reviewCanvasParams.width}px` : '100%'}">
  47. <div class="head"
  48. :style="{'zoom': reviewCanvasParams.zoom}">
  49. <img :src="userInfo.avatarUrl"
  50. class="avatar"/>
  51. <div class="article-wrapper">
  52. <div class="nickname">
  53. {{userInfo.name}}
  54. </div>
  55. <div class="name">
  56. @{{userInfo.nickName}}
  57. </div>
  58. </div>
  59. </div>
  60. <div
  61. :style="{'zoom': baseFormData.rewardType === RewardType.money ? reviewCanvasParams.zoom : 1}">
  62. <custom-card-horizontal-cover
  63. :class="baseFormData.rewardType === RewardType.money ? '' : 'custom-prize-card-wrapper'"
  64. :data="{
  65. totalCount: baseFormData.totalCount,
  66. amountValue: baseFormData.amountValue,
  67. usdEstimateOrderAmount: baseFormData.usdEstimateOrderAmount,
  68. tokenSymbol: currentCurrencyInfo.tokenSymbol,
  69. currencyCode: currentCurrencyInfo.currencyCode,
  70. currencyIconUrl: currentCurrencyInfo.iconPath,
  71. type: baseFormData.type,
  72. validityDuration: baseFormData.validityDuration,
  73. customPosterUrl: customPosterInfo && customPosterInfo.before && customPosterInfo.before.imagePath || '',
  74. addFans: baseFormData.addFans,
  75. userInfo: {
  76. nickName: userInfo.nickName,
  77. avatarUrl: userInfo.avatarUrl
  78. },
  79. rewardType: baseFormData.rewardType,
  80. customizedReward: baseFormData.customizedReward,
  81. upGainAmountUsdValue: upGainAmountUsdValue
  82. }">
  83. </custom-card-horizontal-cover>
  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 customCardHorizontalCover from '@/view/components/custom-card-horizontal-cover.vue'
  93. import {getChromeStorage} from "@/uilts/chromeExtension"
  94. import { getUser } from "@/http/publishApi"
  95. import { RewardType } from '@/types';
  96. let userInfo = ref({});
  97. let reviewCanvasParams = reactive({
  98. width: 396,
  99. zoom: 1
  100. });
  101. let timer = ref(null);
  102. let installStatus = inject('installStatus');
  103. defineProps({
  104. postData: {
  105. type: Object,
  106. default: () => {
  107. return {
  108. }
  109. }
  110. },
  111. baseFormData: {
  112. type: Object,
  113. default: () => {
  114. return {
  115. }
  116. }
  117. },
  118. currentCurrencyInfo: {
  119. type: Object,
  120. default: () => {
  121. return {
  122. }
  123. }
  124. },
  125. amountFontSize: {
  126. type: Number,
  127. default: '56'
  128. },
  129. customPosterInfo: {
  130. type: Object,
  131. default: () => {
  132. return {
  133. }
  134. }
  135. },
  136. upGainAmountUsdValue: {
  137. type: String,
  138. default: ''
  139. }
  140. })
  141. const getUserInfo = (cb) => {
  142. getChromeStorage('userInfo', (res) => {
  143. if(res) {
  144. userInfo.value = res;
  145. }
  146. cb && cb(res);
  147. })
  148. }
  149. const getUserName = (screenName) => {
  150. getUser({
  151. params:{
  152. screenName
  153. }
  154. }).then(res => {
  155. console.log(res);
  156. if(res.code == 0) {
  157. userInfo.value.name = res.data.name || ''
  158. }
  159. });
  160. }
  161. const calcPreviewCanvasParams = () => {
  162. nextTick(() => {
  163. let containerDom = document.querySelector('.card-container');
  164. let domHeight = containerDom && containerDom.offsetHeight || 500;
  165. const canvasHeight = 820, canvasWidth = 600;
  166. if(domHeight < canvasHeight) {
  167. //比例: 高 / 宽
  168. let hWRatio = canvasHeight / canvasWidth;
  169. //缩小宽度 = 高度 / 比例
  170. let width = domHeight / hWRatio;
  171. if(width > canvasWidth) {
  172. width = canvasWidth;
  173. }
  174. //缩小比例
  175. let zoom = width / canvasWidth;
  176. if(zoom > 1) {
  177. zoom = 1;
  178. }
  179. reviewCanvasParams.width = width;
  180. reviewCanvasParams.zoom = zoom;
  181. } else {
  182. reviewCanvasParams.width = canvasWidth;
  183. reviewCanvasParams.zoom = 1;
  184. }
  185. });
  186. }
  187. onMounted(() => {
  188. calcPreviewCanvasParams();
  189. getUserInfo((res) => {
  190. if(res) {
  191. getUserName(res.nickName);
  192. }
  193. clearInterval(timer.value);
  194. timer.value = setInterval(() => {
  195. installStatus.value = !installStatus.value;
  196. }, 3000)
  197. });
  198. window.addEventListener('resize',function () {
  199. calcPreviewCanvasParams();
  200. })
  201. })
  202. onUnmounted(() => {
  203. clearInterval(timer.value);
  204. })
  205. </script>
  206. <style lang="scss" scoped>
  207. .wrapper {
  208. width: 100%;
  209. height: 100%;
  210. box-sizing: border-box;
  211. overflow-y: auto;
  212. display: flex;
  213. &::-webkit-scrollbar {
  214. display: none;
  215. }
  216. .card-container {
  217. width: 100%;
  218. height: 100%;
  219. background: #ffffff;
  220. box-sizing: border-box;
  221. border-radius: 20px;
  222. display: flex;
  223. align-items: center;
  224. .preview-txt {
  225. width: 238px;
  226. font-weight: 600;
  227. font-size: 22px;
  228. span {
  229. color: #1D9BF0;
  230. }
  231. }
  232. .head {
  233. position: absolute;
  234. z-index: 1100;
  235. top: 132px;
  236. left: 17px;
  237. display: flex;
  238. .avatar {
  239. width: 47px;
  240. height: 47px;
  241. border-radius: 50%;
  242. object-fit: cover;
  243. margin-right: 13px;
  244. }
  245. .article-wrapper {
  246. display: flex;
  247. .nickname {
  248. font-weight: 500;
  249. }
  250. .nickname, .name {
  251. font-size: 15px;
  252. }
  253. .name {
  254. color: #566370;
  255. margin-left: 7px;
  256. }
  257. .desc {
  258. margin-top: 8px;
  259. }
  260. }
  261. }
  262. .left {
  263. background: url('@/assets/img/img-preview-bg-after.png');
  264. width: 387px;
  265. height: 100%;
  266. background-size: contain;
  267. background-repeat: no-repeat;
  268. .tips {
  269. right: 15px !important;
  270. }
  271. }
  272. .after-cover-wrapper-parent {
  273. position: absolute;
  274. z-index: 100;
  275. top: 223px;
  276. left: 78px;
  277. }
  278. .after-cover-wrapper {
  279. position:relative;
  280. width:375px;
  281. .icon-gif {
  282. position: absolute;
  283. left: 50%;
  284. bottom: 80px;
  285. transform: translateX(-50%);
  286. width: 160px;
  287. height: 190px;
  288. }
  289. .content-after {
  290. width: 350px;
  291. border-radius: 16px;
  292. display: block;
  293. object-fit: contain;
  294. }
  295. }
  296. .content-before {
  297. background: url('@/assets/img/img-preview-bg-before.png');
  298. background-size: contain;
  299. background-repeat: no-repeat;
  300. height: 100%;
  301. .custom-prize-card-wrapper {
  302. width: 370px;
  303. left: 56px;
  304. top: 170px;
  305. }
  306. }
  307. .left, .content-before {
  308. position: relative;
  309. }
  310. }
  311. .select-btn-wrapper {
  312. padding-right: 16px;
  313. box-sizing: border-box;
  314. .title {
  315. font-size: 14px;
  316. margin-bottom: 15px;
  317. }
  318. .select-btn {
  319. margin-bottom: 16px;
  320. box-sizing: border-box;
  321. cursor: pointer;
  322. .icon {
  323. width: 14px;
  324. height: 14px;
  325. margin-right: 8px;
  326. }
  327. .text {
  328. font-size: 14px;
  329. display: flex;
  330. align-items: center;
  331. }
  332. .desc {
  333. white-space: nowrap;
  334. font-weight: 500;
  335. font-size: 13px;
  336. margin-left: 22px;
  337. }
  338. }
  339. .active {
  340. color: #000;
  341. }
  342. }
  343. }
  344. </style>