giveaway-poster.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="show">
  3. <div class="row">
  4. <img class="tagImg" :src=" require('@/assets/svg/poster-befor.svg') " />
  5. <div class="l">
  6. <div :style="{'zoom': reviewCanvasParams.zoomL}">
  7. <custom-card-horizontal-cover
  8. :data="{
  9. totalCount: baseFormData.totalCount,
  10. amountValue: baseFormData.amountValue,
  11. tokenSymbol: currentCurrencyInfo.tokenSymbol,
  12. currencyIconUrl: currentCurrencyInfo.iconPath,
  13. type: baseFormData.type,
  14. validityDuration: baseFormData.validityDuration,
  15. customPosterUrl: customPosterInfo && customPosterInfo.before && customPosterInfo.before.imagePath || '',
  16. userInfo: {
  17. nickName: userInfo.name,
  18. avatarUrl: userInfo.avatarUrl
  19. },
  20. rewardType: baseFormData.rewardType,
  21. customizedReward: baseFormData.customizedReward
  22. }"
  23. :showBottom="false">
  24. </custom-card-horizontal-cover>
  25. </div>
  26. </div>
  27. <div class="r">
  28. <div class="desc"><span>1080*567</span> JPG, PNG</div>
  29. <div
  30. class="box"
  31. data-type="1"
  32. @drop="dragImg"
  33. @dragenter="dragEnter"
  34. @dragover="dragEnter"
  35. @dragleave="dragLeave">
  36. <span class="drag">Drag Image Here</span>
  37. <div class="upload">
  38. <input
  39. class="file"
  40. type="file"
  41. data-type="1"
  42. @change="fileChange"
  43. accept="image/png,image/jpg,image/jpeg" />
  44. <span>Browse</span>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="row">
  50. <img class="tagImg" :src=" require('@/assets/svg/poster-after.svg') " />
  51. <div class="t">
  52. <div
  53. :style="{
  54. 'zoom': reviewCanvasParams.zoomT,
  55. 'position': 'absolute',
  56. 'width': '350px',
  57. }">
  58. <custom-card-cover
  59. :data="{
  60. totalCount: baseFormData.totalCount,
  61. amountValue: baseFormData.amountValue,
  62. tokenSymbol: currentCurrencyInfo.tokenSymbol,
  63. currencyIconUrl: currentCurrencyInfo.iconPath,
  64. type: baseFormData.type,
  65. validityDuration: baseFormData.validityDuration,
  66. customPosterUrl: customPosterInfo && customPosterInfo.after && customPosterInfo.after.imagePath || '',
  67. userInfo: {
  68. nickName: userInfo.name,
  69. avatarUrl: userInfo.avatarUrl
  70. },
  71. rewardType: baseFormData.rewardType,
  72. customizedReward: baseFormData.customizedReward
  73. }">
  74. </custom-card-cover>
  75. </div>
  76. </div>
  77. <div class="r">
  78. <div class="desc"><span>1080*1080</span> JPG, PNG</div>
  79. <div
  80. class="box"
  81. data-type="2"
  82. @drop="dragImg"
  83. @dragenter="dragEnter"
  84. @dragover="dragEnter"
  85. @dragleave="dragLeave">
  86. <span class="drag">Drag Image Here</span>
  87. <div class="upload">
  88. <input
  89. class="file"
  90. type="file"
  91. data-type="2"
  92. @change="fileChange"
  93. accept="image/png,image/jpg,image/jpeg" />
  94. <span>Browse</span>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="footer">
  100. <button class="confirm" @click="confirmAction">Confirm</button>
  101. </div>
  102. </div>
  103. </template>
  104. <script setup>
  105. import { ref, reactive, nextTick, defineEmits, defineProps, onMounted } from 'vue';
  106. import { message } from 'ant-design-vue';
  107. import customCardCover from '@/view/components/custom-card-cover.vue'
  108. import customCardHorizontalCover from '@/view/components/custom-card-horizontal-cover.vue'
  109. import { getChromeStorage } from "@/uilts/chromeExtension"
  110. import { getUser } from "@/http/publishApi"
  111. const userInfo = ref({});
  112. const emits = defineEmits(['selectImage', 'confirmData']);
  113. const reviewCanvasParams = reactive({
  114. zoomL: 1,
  115. zoomT: 1
  116. });
  117. defineProps({
  118. baseFormData: {
  119. type: Object,
  120. default: () => {
  121. return {
  122. }
  123. }
  124. },
  125. currentCurrencyInfo: {
  126. type: Object,
  127. default: () => {
  128. return {
  129. }
  130. }
  131. },
  132. customPosterInfo: {
  133. type: Object,
  134. default: () => {
  135. return {
  136. }
  137. }
  138. }
  139. })
  140. const getUserInfo = (cb) => {
  141. getChromeStorage('userInfo', (res) => {
  142. if(res) {
  143. userInfo.value = res;
  144. }
  145. cb && cb(res);
  146. })
  147. }
  148. const getUserName = (screenName) => {
  149. getUser({
  150. params:{
  151. screenName
  152. }
  153. }).then(res => {
  154. console.log(res);
  155. if(res.code == 0) {
  156. userInfo.value.name = res.data.name || ''
  157. }
  158. });
  159. }
  160. const fileChange = (e) => {
  161. if (e && e.target) {
  162. let file = e.target.files[0]
  163. let type = e.target.dataset && e.target.dataset.type || '';
  164. cropImage(file, type)
  165. e.target.value = '';
  166. }
  167. }
  168. const dragImg = (e) => {
  169. e.preventDefault();
  170. e.target.classList.remove('light');
  171. // upload
  172. if (e && e.dataTransfer) {
  173. let file = e.dataTransfer.files[0];
  174. let type = e.target.dataset && e.target.dataset.type || '';
  175. // 格式判断
  176. if (['image/png', 'image/jpg', 'image/jpeg'].indexOf(String(file.type).toLowerCase()) == -1) {
  177. message.warning(`This format is not currently supported`);
  178. } else {
  179. cropImage(file, type)
  180. }
  181. }
  182. }
  183. const dragEnter = (e) => {
  184. e.preventDefault();
  185. e.target.classList.add('light')
  186. }
  187. const dragLeave = (e) => {
  188. e.preventDefault();
  189. e.target.classList.remove('light')
  190. }
  191. const cropImage = (file, type) => {
  192. emits('selectImage', {
  193. file: URL.createObjectURL(file),
  194. type,
  195. })
  196. }
  197. const calcPreviewCanvasParams = () => {
  198. nextTick(() => {
  199. let lH = document.querySelector('div.row').offsetHeight;
  200. reviewCanvasParams.zoomL = (lH - 100) / 266;
  201. reviewCanvasParams.zoomT = (lH - 20) / 500;
  202. });
  203. }
  204. const confirmAction = () => {
  205. emits('confirmData')
  206. }
  207. onMounted(() => {
  208. calcPreviewCanvasParams();
  209. getUserInfo((res) => {
  210. if(res) {
  211. getUserName(res.nickName);
  212. }
  213. });
  214. window.addEventListener('resize',function () {
  215. calcPreviewCanvasParams();
  216. })
  217. })
  218. </script>
  219. <style lang="scss" scoped>
  220. .show {
  221. display: flex;
  222. flex-direction: column;
  223. width: 100%;
  224. height: 100%;
  225. .row {
  226. position: relative;
  227. height: calc(50% - 40px);
  228. padding: 0 75px;
  229. display: flex;
  230. flex-direction: row;
  231. align-items: center;
  232. justify-content: center;
  233. &:nth-child(2) {
  234. border-top: 1px solid #ececec;
  235. }
  236. .tagImg {
  237. position: absolute;
  238. top: 0;
  239. left: 0;
  240. width: 177px;
  241. height: 32px;
  242. }
  243. .l {
  244. display: flex;
  245. width: 50%;
  246. align-items: center;
  247. justify-content: center;
  248. height: calc(100% - 100px);
  249. }
  250. .t {
  251. display: flex;
  252. width: 50%;
  253. align-items: center;
  254. justify-content: center;
  255. height: calc(100% - 20px);
  256. }
  257. .r {
  258. width: 50%;
  259. margin-left: 63px;
  260. height: calc(100% - 100px);
  261. .desc {
  262. height: 33px;
  263. font-size: 16px;
  264. font-weight: 600;
  265. span {
  266. color: #1D9BF0;
  267. }
  268. }
  269. .box {
  270. height: calc(100% - 33px);
  271. display: flex;
  272. flex-direction: column;
  273. align-items: center;
  274. justify-content: center;
  275. border-radius: 10px;
  276. border: 1px dashed #B4B4B4;
  277. &.light {
  278. border: 1px dashed #ff0000;
  279. }
  280. .drag {
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. color: #AEAEAE;
  285. font-size: 15px;
  286. font-weight: 500;
  287. height: calc(100% - 76px);
  288. }
  289. .upload {
  290. user-select: none;
  291. position: relative;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. width: calc(100% - 32px);
  296. height: 44px;
  297. margin: 0 16px;
  298. font-size: 15px;
  299. color: #1D9BF0;
  300. border-radius: 22px;
  301. background-color: rgba($color: #1D9BF0, $alpha: .1);
  302. .file {
  303. position: absolute;
  304. z-index: 2;
  305. opacity: 0;
  306. cursor: pointer;
  307. top: 0;
  308. left: 0;
  309. width: 100%;
  310. height: 100%;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. .footer {
  317. display: flex;
  318. align-items: center;
  319. justify-content: right;
  320. height: 80px;
  321. text-align: right;
  322. padding-right: 30px;
  323. border-top: 1px solid #ececec;
  324. .confirm {
  325. cursor: pointer;
  326. border: 0;
  327. width: 200px;
  328. height: 50px;
  329. color: #ffffff;
  330. font-size: 18px;
  331. font-weight: 700;
  332. border-radius: 25px;
  333. background: #1D9BF0;
  334. }
  335. }
  336. }
  337. :deep() .card-wrapper {
  338. top: unset;
  339. left: unset;
  340. }
  341. </style>