app-share-video-number.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view v-if="isShow" class="app-share-video-number" @click.prevent.stop="">
  3. <!-- 视频号弹框 -->
  4. <view class="item" v-if="isLoading">
  5. <image @click.prevent.stop="close" class="close" src="/static/image/icon/icon-close.png"></image>
  6. <view class="title">视频号链接</view>
  7. <view v-if="article_url">
  8. <view class="content">{{article_url}}</view>
  9. <view @click.prevent.stop="copyText" class="copy">复制</view>
  10. </view>
  11. <image v-else :src="sph.loading" class="loading"></image>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import {mapGetters, mapState} from 'vuex';
  17. export default {
  18. name: 'app-share-video-number',
  19. props: {
  20. title: {
  21. type: String,
  22. default() {
  23. return '生成商品海报';
  24. }
  25. },
  26. isShow: {
  27. type: Boolean,
  28. default() {
  29. return false
  30. }
  31. },
  32. goodsId: null
  33. },
  34. data() {
  35. return {
  36. article_url: '',
  37. number: 0,
  38. isLoading: false,
  39. interval: null,
  40. }
  41. },
  42. computed: {
  43. ...mapState({
  44. sph: state => state.mallConfig.__wxapp_img.sph,
  45. }),
  46. },
  47. watch: {
  48. isShow(newVal, oldVal) {
  49. if (newVal) {
  50. this.addMaterial()
  51. }
  52. }
  53. },
  54. methods: {
  55. addMaterial() {
  56. uni.showLoading({title: '加载中'});
  57. this.$request({
  58. url: this.$api.goods.addMaterial,
  59. data: {
  60. goods_id:this.goodsId
  61. }
  62. }).then(response => {
  63. uni.hideLoading();
  64. if (response.code === 0) {
  65. this.getArticleUrl(response.data.media_id);
  66. } else {
  67. this.showModal(response.msg, this.interval);
  68. }
  69. }).catch(() => {
  70. });
  71. },
  72. getArticleUrl(mediaId) {
  73. this.article_url = '';
  74. this.isLoading = true;
  75. let interval = setInterval(()=> {
  76. this.number++;
  77. if (this.number > 15) {
  78. this.showModal('获取视频号链接异常,请稍后重试', interval);
  79. }
  80. this.$request({
  81. url: this.$api.goods.articleUrl,
  82. data: {
  83. media_id: mediaId
  84. }
  85. }).then(response => {
  86. uni.hideLoading();
  87. if (response.code === 0) {
  88. this.article_url = response.data.url;
  89. if (this.article_url) {
  90. clearInterval(interval);
  91. }
  92. } else {
  93. this.showModal(response.msg, interval);
  94. }
  95. });
  96. }, 1000)
  97. this.interval = interval;
  98. },
  99. showModal(msg, interval) {
  100. this.isLoading = false;
  101. this.number = 0;
  102. uni.showModal({
  103. content: msg,
  104. showCancel: false,
  105. success: (() => {
  106. this.close();
  107. })
  108. });
  109. clearInterval(interval);
  110. },
  111. copyText() {
  112. this.$utils.uniCopy({
  113. data: this.article_url,
  114. success(){
  115. uni.showToast({ title: '复制成功'});
  116. this.close()
  117. }
  118. });
  119. },
  120. close() {
  121. this.isLoading = false;
  122. clearInterval(this.interval);
  123. this.$emit('close', false);
  124. }
  125. }
  126. }
  127. </script>
  128. <style scoped lang="scss">
  129. .app-share-video-number {
  130. display: flex;
  131. justify-content: center;
  132. align-items: center;
  133. width: #{750rpx};
  134. height: 100%;
  135. z-index: 3000;
  136. position: fixed;
  137. left: 0;
  138. top: 0;
  139. background-color: rgba(153, 153, 153, 0.5);
  140. .item {
  141. display: flex;
  142. align-items: center;
  143. flex-direction: column;
  144. width: #{622rpx};
  145. border-radius: #{16rpx};
  146. position: relative;
  147. background: #ffffff;
  148. .close {
  149. width: #{30rpx};
  150. height: #{30rpx};
  151. position: absolute;
  152. top: #{24rpx};
  153. right: #{24rpx};
  154. }
  155. .title {
  156. color: #353535;
  157. font-size: #{32rpx};
  158. margin: #{40rpx} 0;
  159. }
  160. .content {
  161. width: #{558rpx};
  162. height: #{82rpx};
  163. border-radius: #{16rpx};
  164. background: #f7f7f7;
  165. color: #353535;
  166. font-size: #{28rpx};
  167. padding: #{20rpx};
  168. margin: 0 #{30rpx} #{30rpx};
  169. overflow: hidden;
  170. display: inline-block;
  171. white-space: nowrap;
  172. overflow: hidden;
  173. text-overflow: ellipsis;
  174. }
  175. .copy {
  176. height: #{90rpx};
  177. display: flex;
  178. justify-content: center;
  179. align-items: center;
  180. font-size: #{34rpx};
  181. color: #ff4544;
  182. border-top: #{1rpx} solid #e2e2e2;
  183. }
  184. .hint {
  185. text-align: center;
  186. margin: #{30rpx} 0;
  187. }
  188. .loading {
  189. width: #{150rpx};
  190. height: #{150rpx};
  191. margin-bottom: #{20rpx};
  192. }
  193. }
  194. }
  195. </style>