preview-card.vue 11 KB

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