Post.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div ref="share">
  3. <van-overlay :show="show" @click="show = false" z-index="99">
  4. <div class="wrapper">
  5. <div class="img" ref="wrap" v-if="img">
  6. <!-- @click.stop="preview(0, [img])" -->
  7. <img :src="img" />
  8. </div>
  9. <template v-if="!img">
  10. <div class="assignmentPost" v-if="assignment && pageUrl === 'productDetail'" ref="post">
  11. <van-image class="assignmentPostBg" width="300" height="500" :src="shareBg" />
  12. <div class="qrcode">
  13. <vue-qrcode :value="url" :options="{ width: 82, margin: 0 }"></vue-qrcode>
  14. </div>
  15. </div>
  16. <div class="content" v-else ref="post">
  17. <!-- @load="loadImg" -->
  18. <!-- <img crossOrigin="anonymous" :src="banners" class="detailImg" /> -->
  19. <van-image :src="detailImg" class="detailImg" fit="cover" />
  20. <div class="info">
  21. <div class="name van-multi-ellipsis--l2">
  22. {{ info.name }}
  23. </div>
  24. <div class="title_tip">发现一款超赞的数字藏品,快来看看</div>
  25. <!-- <div class="tabs">
  26. <span v-if="info.category">{{ info.category }}</span>
  27. <span v-if="info.number">编号{{ info.number }}</span>
  28. </div> -->
  29. <!-- <template v-if="pageUrl !== 'assetDetail'">
  30. <div class="text" v-if="isBuy">
  31. <div class="price">
  32. <img src="@assets/jiage_huang.png" alt="" />
  33. <span>{{ info.price }}</span>
  34. </div>
  35. <div class="text1" v-if="info.stock && !time">
  36. <span>已售 {{ Math.max(Math.min(info.sale, info.total), 0) }}</span>
  37. <span>剩余 {{ Math.min(Math.max(info.stock, 0), info.total) }}</span>
  38. </div>
  39. </div>
  40. <div class="status" v-if="!info.salable">仅展示</div>
  41. </template> -->
  42. <!-- <template v-else>
  43. <div class="text" v-if="info.consignment">
  44. <div class="price">
  45. <img src="@assets/jiage_huang.png" alt="" />
  46. <span>{{ info.sellPrice || 0 }}</span>
  47. </div>
  48. </div>
  49. <div class="status" v-else-if="info.status == 'NORMAL'">
  50. {{ info.publicShow ? '仅展示' : '未展示' }}
  51. </div>
  52. </template> -->
  53. </div>
  54. <div class="minter">
  55. <div class="minter_con">
  56. <div>
  57. <div class="minter_con_one">
  58. <img :src="logoImg" alt="" class="minter_con_one_text1" />
  59. <!-- <div class="minter_con_one_text1">拉索</div> -->
  60. <div class="minter_con_one_text2" v-if="info.category">{{ info.category }}</div>
  61. </div>
  62. <div class="minter_con_two">扫码打开拉索APP,发现有趣数字藏品</div>
  63. </div>
  64. <div>
  65. <vue-qrcode
  66. :value="url"
  67. :options="{ width: 70, margin: 3 }"
  68. class="code"
  69. ></vue-qrcode>
  70. </div>
  71. </div>
  72. <!-- <div class="minter-content">
  73. <van-image width="26" height="26" round :src="userImg" fit="cover" />
  74. <div class="text1">{{ info.minter }}</div>
  75. <div class="text2">铸造者</div>
  76. </div> -->
  77. </div>
  78. <!-- <div class="sold xianliang" v-if="time">
  79. <img src="@assets/shizhong.png" alt="" />
  80. <span>即将开售:{{ time }}</span>
  81. </div> -->
  82. </div>
  83. </template>
  84. <div class="btn" @click.stop="" v-if="cordova">
  85. <van-button type="primary" @click="save">保存图片</van-button>
  86. </div>
  87. <div class="tips" v-else @click="save">长按图片保存</div>
  88. </div>
  89. </van-overlay>
  90. <div class="share" v-if="!noButton" @click="init">
  91. <img src="@assets/svgs/icon-share.svg" alt="" />
  92. <span>分享</span>
  93. </div>
  94. </div>
  95. </template>
  96. <script>
  97. import vueQrcode from '@chenfengyuan/vue-qrcode';
  98. import html2canvas from 'html2canvas';
  99. import product from '../mixins/product';
  100. import resolveUrl from 'resolve-url';
  101. import axios from 'axios';
  102. import { isBefore, format } from 'date-fns';
  103. import { abs } from 'mathjs';
  104. import { ImagePreview } from 'vant';
  105. export default {
  106. mixins: [product],
  107. props: {
  108. info: {
  109. type: Object,
  110. default: () => {
  111. return {
  112. pic: []
  113. };
  114. }
  115. },
  116. pageUrl: {
  117. type: String,
  118. default: 'productDetail'
  119. },
  120. noButton: {
  121. type: Boolean,
  122. default: false
  123. }
  124. },
  125. data() {
  126. return {
  127. show: false,
  128. share: null,
  129. img: '',
  130. detailImg: '',
  131. userImg: '',
  132. cordova: window.cordova,
  133. shareBg: '',
  134. logoImg: ''
  135. };
  136. },
  137. computed: {
  138. url() {
  139. let pageUrl = this.pageUrl;
  140. let id = this.info.id;
  141. if (pageUrl === 'assetDetail') {
  142. id = this.info.collectionId;
  143. pageUrl = 'productDetail';
  144. }
  145. if (pageUrl === 'productDetail' && !this.assignment) {
  146. pageUrl = 'productDetail';
  147. }
  148. if (this.isLogin && this.assignment && pageUrl === 'productDetail') {
  149. return resolveUrl(
  150. this.$baseUrl,
  151. '9th/productTasks?id=' + id + '&invitor=' + this.$store.state.userInfo.id
  152. );
  153. } else if (this.isLogin) {
  154. return resolveUrl(
  155. this.$baseUrl,
  156. '9th/' + pageUrl + '?collectionId=' + id + '&invitor=' + this.$store.state.userInfo.id
  157. );
  158. } else {
  159. return resolveUrl(this.$baseUrl, '9th/' + pageUrl + '?id=' + id);
  160. }
  161. },
  162. banners() {
  163. return this.getImg(this.changeImgs(this.info.pic || []), '', 900);
  164. },
  165. isBuy() {
  166. return this.info.stock && this.info.onShelf && this.info.salable;
  167. },
  168. time() {
  169. if (this.info.startTime) {
  170. if (isBefore(new Date(this.info.startTime), new Date())) {
  171. return format(new Date(this.info.startTime), 'mm月dd日');
  172. }
  173. }
  174. return '';
  175. }
  176. },
  177. components: {
  178. vueQrcode
  179. },
  180. methods: {
  181. init(value) {
  182. this.show = true;
  183. if (!this.img) {
  184. this.$toast.loading({
  185. message: '加载中...',
  186. forbidClick: true
  187. });
  188. this.$nextTick(() => {
  189. this.getImgBase64(require('@assets/icon@3x.png'), 'logoImg');
  190. if (this.assignment && this.pageUrl === 'productDetail') {
  191. this.getImgBase64(this.info.shareBg, 'shareBg');
  192. } else {
  193. this.getImgBase64(this.banners, 'detailImg');
  194. this.getImgBase64(this.info.minterAvatar, 'userImg');
  195. }
  196. setTimeout(() => {
  197. this.loadImg();
  198. }, 1000);
  199. });
  200. }
  201. },
  202. loadImg() {
  203. html2canvas(this.$refs.post, {
  204. useCORS: true,
  205. allowTaint: true,
  206. backgroundColor: null,
  207. scale: 3
  208. }).then(canvas => {
  209. this.$toast.clear();
  210. this.img = canvas.toDataURL('image/png');
  211. });
  212. },
  213. getImgBase64(img2, key) {
  214. let img = new Image();
  215. img.crossOrigin = 'anonymous';
  216. let _this = this;
  217. img.onload = function () {
  218. let src = _this.image2Base64(img);
  219. _this[key] = src;
  220. };
  221. img.src = img2;
  222. },
  223. image2Base64(img) {
  224. let canvas = document.createElement('canvas');
  225. canvas.width = img.width;
  226. canvas.height = img.height;
  227. let ctx = canvas.getContext('2d');
  228. ctx.drawImage(img, 0, 0, img.width, img.height);
  229. let dataURL = canvas.toDataURL('image/png');
  230. return dataURL;
  231. },
  232. preview(index = 0, list = []) {
  233. console.log('266716');
  234. ImagePreview({
  235. images: [...list],
  236. startPosition: index
  237. });
  238. },
  239. save() {
  240. if (window.cordova) {
  241. let _this = this;
  242. imageSaver.saveBase64Image(
  243. { data: this.img },
  244. function (filePath) {
  245. _this.$toast('图片已保存至文件夹');
  246. _this.show = false;
  247. console.log('File saved on ' + filePath);
  248. },
  249. function (msg) {
  250. _this.$dialog.alert({
  251. title: '提示',
  252. message: msg + ',请尝试截图保存分享'
  253. });
  254. (1).then(() => {
  255. _this.preview(0, [_this.img]);
  256. });
  257. }
  258. );
  259. }
  260. }
  261. }
  262. };
  263. </script>
  264. <style lang="less" scoped>
  265. .wrapper {
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. flex-direction: column;
  270. height: 100%;
  271. }
  272. .content {
  273. width: 80vw;
  274. background: @bg;
  275. border-radius: 30px;
  276. overflow: hidden;
  277. position: relative;
  278. }
  279. .img {
  280. img {
  281. width: 80vw;
  282. display: block;
  283. }
  284. }
  285. .info {
  286. // padding: 12px 10px 7px;
  287. padding: 15px;
  288. .name {
  289. font-size: 16px;
  290. font-family: PingFangSC-Medium, PingFang SC;
  291. font-weight: 500;
  292. color: #ffffff;
  293. line-height: 22px;
  294. }
  295. .title_tip {
  296. font-size: 12px;
  297. font-family: PingFangSC-Regular, PingFang SC;
  298. font-weight: 400;
  299. color: #ffffff;
  300. line-height: 18px;
  301. opacity: 0.5;
  302. }
  303. .text {
  304. display: flex;
  305. justify-content: space-between;
  306. align-items: flex-end;
  307. margin-top: 6px;
  308. .price {
  309. img {
  310. width: 10px;
  311. height: 11px;
  312. }
  313. span {
  314. font-size: 24px;
  315. font-family: OSP-DIN, OSP;
  316. color: @prim;
  317. line-height: 36px;
  318. }
  319. }
  320. .text1 {
  321. font-size: 14px;
  322. color: @text3;
  323. line-height: 24px;
  324. span + span {
  325. margin-left: 10px;
  326. }
  327. }
  328. }
  329. }
  330. .code {
  331. border-radius: 6px;
  332. }
  333. .minter {
  334. width: 100%;
  335. // display: flex;
  336. // justify-content: space-between;
  337. // align-items: center;
  338. padding: 0px 10px 20px;
  339. box-sizing: border-box;
  340. .minter_con {
  341. width: 100%;
  342. display: flex;
  343. justify-content: space-between;
  344. align-items: center;
  345. background: #1e222c;
  346. border-radius: 8px;
  347. .minter_con_one {
  348. display: flex;
  349. padding: 0 0px 6px 15px;
  350. box-sizing: border-box;
  351. align-items: center;
  352. .minter_con_one_text1 {
  353. width: 60px;
  354. height: 32px;
  355. position: relative;
  356. z-index: 99;
  357. // margin-right: 7px;
  358. // font-size: 20px;
  359. // color: #eacc9b;
  360. }
  361. .minter_con_one_text2 {
  362. padding: 2px 4px;
  363. border: 1px solid #f9ddb3;
  364. border-radius: 4px;
  365. font-size: 14px;
  366. color: #f9ddb3;
  367. margin-left: 1px;
  368. line-height: 14px;
  369. }
  370. }
  371. .minter_con_two {
  372. padding: 0px 0px 0px 15px;
  373. box-sizing: border-box;
  374. font-size: 10px;
  375. font-family: PingFangSC-Regular, PingFang SC;
  376. font-weight: 400;
  377. color: #f9ddb3;
  378. line-height: 18px;
  379. }
  380. }
  381. .minter-content {
  382. /deep/.van-image {
  383. img {
  384. display: block;
  385. }
  386. }
  387. .text1 {
  388. font-size: @font1;
  389. color: @text0;
  390. line-height: 17px;
  391. margin-top: 1px;
  392. }
  393. .text2 {
  394. font-size: @font1;
  395. color: @text3;
  396. line-height: 17px;
  397. }
  398. }
  399. }
  400. .tips {
  401. font-size: 17px;
  402. color: rgba(255, 255, 255, 1);
  403. line-height: 22px;
  404. margin-top: 30px;
  405. }
  406. .share {
  407. position: fixed;
  408. right: 16px;
  409. bottom: 20vh;
  410. width: 48px;
  411. height: 48px;
  412. background: linear-gradient(135deg, @prim 0%, @warn 100%);
  413. z-index: 20;
  414. display: flex;
  415. flex-direction: column;
  416. align-items: center;
  417. border-radius: 100px;
  418. justify-content: center;
  419. span {
  420. font-size: 12px;
  421. color: #333230;
  422. line-height: 17px;
  423. }
  424. img {
  425. display: block;
  426. }
  427. }
  428. .detailImg {
  429. width: 80vw;
  430. height: 80vw;
  431. display: block;
  432. }
  433. .tabs {
  434. .flex();
  435. margin-top: 6px;
  436. span {
  437. font-size: 12px;
  438. color: #939599;
  439. line-height: 22px;
  440. padding: 0 10px;
  441. background: @bg3;
  442. border-radius: 4px;
  443. margin-right: 6px;
  444. }
  445. }
  446. .status {
  447. font-size: 14px;
  448. color: #939599;
  449. line-height: 24px;
  450. padding-top: 11px;
  451. }
  452. .sold {
  453. background-color: #1c1e25;
  454. font-size: @font1;
  455. color: #939599;
  456. padding: 0 17px;
  457. border-radius: 13px;
  458. line-height: 24px;
  459. position: absolute;
  460. top: 16px;
  461. left: 16px;
  462. z-index: 3;
  463. &.xianliang {
  464. position: absolute;
  465. top: 16px;
  466. left: 16px;
  467. font-size: @font1;
  468. color: @prim;
  469. display: flex;
  470. align-items: center;
  471. // border-radius: 13px !important;
  472. z-index: 4;
  473. padding: 0 10px !important;
  474. img {
  475. width: 18px;
  476. height: 18px;
  477. margin-right: 3px;
  478. }
  479. }
  480. }
  481. .btn {
  482. padding: 40px;
  483. // width: 150px;
  484. font-size: 18px;
  485. align-self: center;
  486. /deep/ .van-button {
  487. height: 46px;
  488. }
  489. }
  490. .assignmentPost {
  491. width: 300px;
  492. height: 500px;
  493. background: #ffffff;
  494. border-radius: 30px;
  495. position: relative;
  496. .qrcode {
  497. background-color: @bg3;
  498. padding: 6px;
  499. position: absolute;
  500. left: 50%;
  501. transform: translateX(-50%);
  502. bottom: 94px;
  503. border-radius: 6px;
  504. z-index: 20;
  505. /deep/canvas {
  506. display: block;
  507. }
  508. }
  509. }
  510. </style>