app-share-qr-code-poster.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <view class="app-share-qr-code-poster" @click.prevent.stop="showHiddenClick" :class="{'app-show-hidden': value}">
  3. <view class="safe-area-inset-bottom app-bottom" v-if="buttonBoolean">
  4. <view class="app-icons dir-left-nowrap">
  5. <!-- #ifndef H5 -->
  6. <view class="box-grow-1" @click="showHiddenClick" v-if="isShowFriend">
  7. <app-jump-button form arrangement="topCenter" open_type="share" >
  8. <icon class="app-icon app-share" type></icon>
  9. <text class="app-text">发送给朋友</text>
  10. </app-jump-button>
  11. </view>
  12. <!-- #endif -->
  13. <!-- #ifdef H5 -->
  14. <view class="box-grow-1" @click="shareUrl" v-if="isShowFriend">
  15. <app-jump-button form arrangement="topCenter">
  16. <icon class="app-icon app-share" type></icon>
  17. <text class="app-text">发送给朋友</text>
  18. </app-jump-button>
  19. </view>
  20. <!-- #endif -->
  21. <!-- #ifndef MP-BAIDU -->
  22. <view class="box-grow-1" v-if="isHidden">
  23. <view class="box-grow-1" @click.prevent.stop="fenxianghaibao">
  24. <app-form-id>
  25. <view class="dir-top-wrap main-center cross-center">
  26. <icon class="app-icon app-code" type></icon>
  27. <text class="app-text">{{title}}</text>
  28. </view>
  29. </app-form-id>
  30. </view>
  31. </view>
  32. <!-- #endif -->
  33. <!-- #ifdef MP-WEIXIN || H5 -->
  34. <view v-if="goods.is_video_number && isShowFriend" class="box-grow-1">
  35. <view class="box-grow-1" @click.prevent.stop="isShowVideoNumber = true">
  36. <app-form-id>
  37. <view class="dir-top-wrap main-center cross-center">
  38. <icon class="app-icon app-video-number" type></icon>
  39. <text class="app-text">生成视频号链接</text>
  40. </view>
  41. </app-form-id>
  42. </view>
  43. </view>
  44. <!-- #endif -->
  45. </view>
  46. <view class="app-button">
  47. <app-form-id>
  48. <view style="height: 100rpx;background-color: #ffffff;text-align: center;line-height: 100rpx;font-size: 32rpx;color: #353535;"
  49. @click="showHiddenClick"
  50. type="general">取消</view>
  51. </app-form-id>
  52. </view>
  53. </view>
  54. <!-- #ifndef MP-BAIDU -->
  55. <view class="app-center dir-top-wrap main-center cross-center" v-else>
  56. <view class="app-close" @click="showHiddenClick"></view>
  57. <view class="app-image-iframe main-center dir-top-nowrap cross-center" v-if="loading">
  58. <image class="loading" src="/static/image/loading.gif"></image>
  59. <view class="text">海报生成中</view>
  60. </view>
  61. <image class="app-image-iframe" v-if="!loading" show-menu-by-longpress mode="aspectFit" @click="preview(shareImage)" :src="shareImage"></image>
  62. <view class="app-button">
  63. <button class="save-picture" :style="{'background-color': loading ? '#cdcdcd' : sign !== 'gift' ? theme.color : ''}" :class="[sign === 'gift' ? theme + '-background' : '' ]" :disabled="loading" @click="savePicture">保存图片</button>
  64. </view>
  65. <text class="app-text">保存到相册</text>
  66. </view>
  67. <!-- #endif -->
  68. <app-permissions-auth :text="text" :isShow='is_can_save' @cancel="cancel"></app-permissions-auth>
  69. <!-- 视频号弹框 -->
  70. <app-share-video-number :goods-id="goods.id" :is-show="isShowVideoNumber" @close="closeVideoNumber"></app-share-video-number>
  71. </view>
  72. </template>
  73. <script>
  74. import {mapGetters} from 'vuex';
  75. import appPermissionsAuth from '../../basic-component/app-layout/app-permissions-auth/app-permissions-auth.vue';
  76. import appShareVideoNumber from '../../page-component/app-share-video-number/app-share-video-number.vue';
  77. export default {
  78. name: 'app-share-qr-code-poster',
  79. components: {
  80. appPermissionsAuth,
  81. appShareVideoNumber
  82. },
  83. computed: {
  84. ...mapGetters('iPhoneX', {
  85. getBoolEmpty: 'getBoolEmpty'
  86. })
  87. },
  88. props: {
  89. title: {
  90. type: String,
  91. default() {
  92. return '生成商品海报';
  93. }
  94. },
  95. posterConfig: String,
  96. posterGenerate: String,
  97. hasPosterNav: {
  98. type: Boolean,
  99. default() {
  100. return false
  101. },
  102. },
  103. value: {
  104. type: Boolean,
  105. default() {
  106. return false;
  107. }
  108. },
  109. url: {
  110. type: String,
  111. default() {
  112. return '';
  113. }
  114. },
  115. disabled: {
  116. type: Boolean,
  117. default() {
  118. return false;
  119. }
  120. },
  121. isHidden: {
  122. type: Boolean,
  123. default() {
  124. return true;
  125. }
  126. },
  127. posterUrl: {
  128. type: String,
  129. default() {
  130. return ''
  131. }
  132. },
  133. theme: [Object,String],
  134. sign: String,
  135. isShowFriend: {
  136. type: Boolean,
  137. default() {
  138. return true;
  139. }
  140. },
  141. appShareTitle: String,
  142. appSharePic: String,
  143. goods: {
  144. type: Object,
  145. default() {
  146. return {}
  147. }
  148. }
  149. },
  150. data() {
  151. return {
  152. showHidden: this.value,
  153. buttonBoolean: true,
  154. shareImage: '',
  155. is_can_save: false,
  156. text: '保存图片需要您的授权。点击去设置,开启 保存到相册 权限',
  157. loading: true,
  158. isShowVideoNumber: false,
  159. article_url: '',
  160. number: 1,
  161. isClick: true,
  162. isShow: false,
  163. }
  164. },
  165. methods: {
  166. fenxianghaibao() {
  167. if (this.hasPosterNav) {
  168. let url = this.posterUrl;
  169. if (this.posterUrl == '') {
  170. // #ifdef MP
  171. url = `/pages/poster/goods?poster_config=${escape(this.posterConfig)}&poster_generate=${escape(this.posterGenerate)}`
  172. // #endif
  173. // #ifdef H5
  174. url = `/pages/poster/goods?poster_config=${btoa(this.posterConfig)}&poster_generate=${btoa(this.posterGenerate)}`
  175. // #endif
  176. }
  177. uni.navigateTo({
  178. url: url
  179. });
  180. } else {
  181. this.buttonBoolean = false;
  182. this.getShareImg();
  183. }
  184. },
  185. showHiddenClick() {
  186. this.showHidden = false;
  187. this.$emit('input', this.showHidden);
  188. this.buttonBoolean = true;
  189. },
  190. savePicture() {
  191. if (this.loading) return;
  192. this.$utils.batchSave(this.shareImage, 'image').then(() => {
  193. uni.showToast({title: '保存成功'});
  194. });
  195. },
  196. getShareImg() {
  197. if (!this.url) return;
  198. this.$request({
  199. url: this.url,
  200. }).then(response => {
  201. if (response.code === 0) {
  202. this.shareImage = response.data.pic_url;
  203. this.loading = false;
  204. } else {
  205. uni.showModal({
  206. content: response.msg,
  207. showCancel: false,
  208. });
  209. }
  210. });
  211. },
  212. getAuthSetting() {
  213. let self = this;
  214. uni.getSetting({
  215. success(res) {
  216. // #ifndef MP-TOUTIAO
  217. self.is_can_save = !res.authSetting['scope.writePhotosAlbum'];
  218. // #endif
  219. // #ifdef MP-TOUTIAO
  220. self.is_can_save = !res.authSetting['scope.album'];
  221. // #endif
  222. }
  223. });
  224. },
  225. cancel(isShow) {
  226. this.is_can_save = isShow;
  227. },
  228. preview(data) {
  229. uni.previewImage({
  230. urls: [data],
  231. longPressActions: true,
  232. });
  233. },
  234. // #ifdef H5
  235. open() {
  236. this.$jwx.showMenuItems({
  237. success() {
  238. }
  239. })
  240. },
  241. // #endif
  242. videoNumberClick() {
  243. if (!this.isClick) {
  244. return
  245. }
  246. this.isClick = false;
  247. uni.showLoading({title: '加载中'});
  248. this.$request({
  249. url: this.$api.goods.addMaterial,
  250. data: {
  251. goods_id: this.goods.id
  252. }
  253. }).then(response => {
  254. uni.hideLoading();
  255. if (response.code === 0) {
  256. this.isShowVideoNumber = true;
  257. this.getArticleUrl(response.data.media_id);
  258. } else {
  259. this.resetVideoNumber()
  260. uni.showModal({
  261. content: response.msg,
  262. showCancel: false,
  263. });
  264. }
  265. }).catch(() => {
  266. this.resetVideoNumber()
  267. });
  268. },
  269. getArticleUrl(mediaId) {
  270. let interval = setInterval(() => {
  271. if (this.article_url) {
  272. clearInterval(interval);
  273. }
  274. if (this.number > 30) {
  275. clearInterval(interval);
  276. this.resetVideoNumber()
  277. uni.showModal({
  278. content: '获取视频号链接异常,请稍后重试',
  279. showCancel: false,
  280. });
  281. }
  282. this.number++;
  283. this.$request({
  284. url: this.$api.goods.articleUrl,
  285. data: {
  286. media_id: mediaId
  287. }
  288. }).then(response => {
  289. uni.hideLoading();
  290. if (response.code === 0) {
  291. this.article_url = response.data.url;
  292. } else {
  293. this.resetVideoNumber()
  294. uni.showModal({
  295. content: response.msg,
  296. showCancel: false,
  297. });
  298. clearInterval(interval);
  299. }
  300. });
  301. }, 1000)
  302. },
  303. resetVideoNumber() {
  304. this.number = 1;
  305. this.isShowVideoNumber = false;
  306. this.isClick = true;
  307. },
  308. copyText() {
  309. this.$utils.uniCopy({
  310. data: this.article_url,
  311. success() {
  312. uni.showToast({title: '复制成功'});
  313. this.resetVideoNumber()
  314. }
  315. });
  316. },
  317. closeVideoNumber() {
  318. this.isShowVideoNumber = false;
  319. },
  320. // #ifdef H5
  321. shareUrl() {
  322. this.showHidden = false;
  323. this.$emit('input', this.showHidden);
  324. this.buttonBoolean = true;
  325. this.$emit('share', true);
  326. }
  327. // #endif
  328. }
  329. }
  330. </script>
  331. <style scoped lang="scss">
  332. .save-picture {
  333. width: #{500upx};
  334. height: #{80upx};
  335. border-radius: #{40upx};
  336. font-size: #{32upx};
  337. line-height: #{80upx};
  338. text-align: center;
  339. margin: 0;
  340. padding: 0;
  341. border: none;
  342. color: #ffffff;
  343. }
  344. .app-share-qr-code-poster {
  345. width: #{750rpx};
  346. height: 100%;
  347. position: fixed;
  348. z-index: 1701;
  349. left: 0;
  350. opacity: 0;
  351. top: 0;
  352. visibility: hidden;
  353. background-color: rgba(153, 153, 153, 0.5);
  354. .loading {
  355. width: #{220rpx};
  356. height: #{220rpx};
  357. }
  358. .app-icons {
  359. height: #{290rpx};
  360. .app-text {
  361. font-size: #{26rpx};
  362. color: #353535;
  363. }
  364. > view {
  365. width: 50%;
  366. height: 100%;
  367. .app-icon {
  368. width: #{120rpx};
  369. height: #{120rpx};
  370. background-size: cover;
  371. background-repeat: no-repeat;
  372. background-color: white;
  373. border-radius: 50%;
  374. margin-top: #{60rpx};
  375. margin-bottom: #{24rpx};
  376. }
  377. .app-share {
  378. background-image: url('../../../static/image/icon/share.png');
  379. }
  380. .app-code {
  381. background-image: url('../../../static/image/icon/code.png');
  382. }
  383. .app-video-number {
  384. background-image: url('../../../static/image/icon/video-number.png');
  385. }
  386. .text {
  387. font-size: #{26rpx};
  388. color: #353535;
  389. }
  390. }
  391. }
  392. .app-bottom {
  393. width: 100%;
  394. position: fixed;
  395. bottom: 0;
  396. left: 0;
  397. background-color: #f2f2f2;
  398. .app-icons {
  399. width: 100%;
  400. height: #{290rpx};
  401. }
  402. .app-button {
  403. width: 100%;
  404. height: #{100rpx};
  405. /deep/ button {
  406. border-radius: 0;
  407. border: none;
  408. }
  409. }
  410. }
  411. .app-center {
  412. width: calc(100% - #{80rpx});
  413. padding-top: #{100rpx};
  414. padding-bottom: #{77rpx};
  415. border-radius: #{8rpx};
  416. background-color: white;
  417. position: absolute;
  418. top: 50%;
  419. left: 50%;
  420. transform: translate(-50%, -50%);
  421. .app-close {
  422. width: #{30rpx};
  423. height: #{30rpx};
  424. background-size: cover;
  425. background-repeat: no-repeat;
  426. background-image: url("../../../static/image/icon/close.png");
  427. position: absolute;
  428. top: #{28rpx};
  429. right: #{24rpx};
  430. }
  431. .app-image-iframe {
  432. width: #{440rpx};
  433. height: #{783rpx};
  434. position: relative;
  435. box-shadow: #{2rpx} #{2rpx} #{10rpx} #d9d9d9;
  436. .text {
  437. text-align: center;
  438. color: #888;
  439. }
  440. }
  441. .app-button {
  442. width: #{500rpx};
  443. height: #{80rpx};
  444. margin-top: #{38rpx};
  445. margin-bottom: #{24rpx};
  446. }
  447. .app-text {
  448. font-size: #{24rpx};
  449. color: #999999;
  450. }
  451. }
  452. .video-number-dialog {
  453. position: absolute;
  454. top: 0;
  455. left: 0;
  456. width: 100%;
  457. height: 100%;
  458. display: flex;
  459. justify-content: center;
  460. align-items: center;
  461. .item {
  462. width: #{622rpx};
  463. border-radius: #{16rpx};
  464. position: relative;
  465. background: #ffffff;
  466. .close {
  467. width: #{30rpx};
  468. height: #{30rpx};
  469. position: absolute;
  470. top: #{24rpx};
  471. right: #{24rpx};
  472. z-index: 10;
  473. }
  474. .title {
  475. width: 100%;
  476. display: flex;
  477. justify-content: center;
  478. align-items: center;
  479. color: #353535;
  480. font-size: #{32rpx};
  481. margin: #{40rpx} 0;
  482. }
  483. .content {
  484. width: #{558rpx};
  485. height: #{82rpx};
  486. border-radius: #{16rpx};
  487. background: #f7f7f7;
  488. color: #353535;
  489. font-size: #{28rpx};
  490. padding: #{20rpx};
  491. margin: 0 #{30rpx} #{30rpx};
  492. overflow: hidden;
  493. display: inline-block;
  494. white-space: nowrap;
  495. overflow: hidden;
  496. text-overflow: ellipsis;
  497. }
  498. .copy {
  499. height: #{90rpx};
  500. display: flex;
  501. justify-content: center;
  502. align-items: center;
  503. font-size: #{34rpx};
  504. color: #ff4544;
  505. border-top: #{1rpx} solid #e2e2e2;
  506. }
  507. .hint {
  508. text-align: center;
  509. margin: #{30rpx} 0;
  510. }
  511. }
  512. }
  513. }
  514. .app-show-hidden {
  515. opacity: 1;
  516. visibility: visible;
  517. }
  518. </style>