app-goods-preview-poster.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="app-goods-preview-poster">
  3. <view class="app-center dir-top-wrap main-center cross-center">
  4. <view class="app-close" @click="showHiddenClick"></view>
  5. <view class="app-image-iframe main-center dir-top-nowrap cross-center" v-if="loading">
  6. <image class="loading" src="../../../static/image/loading.gif"></image>
  7. <view class="text">海报生成中</view>
  8. </view>
  9. <image class="app-image-iframe" v-if="!loading" show-menu-by-longpress mode="aspectFit"
  10. @click="preview" :src="shareImage"></image>
  11. <view class="app-button">
  12. <app-button width="500"
  13. :disabled="disabled"
  14. height="80"
  15. :background="disabled ? '#cdcdcd' : '#ff4544'"
  16. fontSize="32rpx"
  17. color="white"
  18. roundSize="40rpx"
  19. @click="savePicture"
  20. >保存图片
  21. </app-button>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: "app-goods-preview-poster",
  29. props: {
  30. value: {
  31. type: Boolean,
  32. default() {
  33. return false;
  34. }
  35. },
  36. url: {
  37. type: String,
  38. default() {
  39. return '';
  40. }
  41. },
  42. disabled: {
  43. type: Boolean,
  44. default() {
  45. return false;
  46. }
  47. }
  48. },
  49. created: function () {
  50. this.value = this.value + '';
  51. },
  52. watch: {
  53. value(newVal) {
  54. if (newVal) {
  55. this.getShareImg();
  56. }
  57. }
  58. },
  59. data() {
  60. return {
  61. showHidden: this.value,
  62. loading: true,
  63. shareImage: '',
  64. }
  65. },
  66. methods: {
  67. showHiddenClick() {
  68. this.$emit('close', false);
  69. },
  70. savePicture() {
  71. this.$utils.batchSave(this.shareImage, 'image').then(() => {
  72. uni.showToast({title: '保存成功'});
  73. });
  74. },
  75. getShareImg() {
  76. if (!this.url) return;
  77. this.loading = true;
  78. this.$request({
  79. url: this.url,
  80. }).then(response => {
  81. if (response.code === 0) {
  82. this.shareImage = response.data.pic_url;
  83. this.loading = false;
  84. } else {
  85. uni.showModal({
  86. content: response.msg,
  87. showCancel: false
  88. });
  89. }
  90. });
  91. },
  92. preview() {
  93. uni.previewImage({
  94. urls: [this.shareImage]
  95. });
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped lang="scss">
  101. .app-goods-preview-poster {
  102. .app-center {
  103. width: calc(100% - #{80rpx});
  104. padding-top: #{100rpx};
  105. padding-bottom: #{77rpx};
  106. border-radius: #{8rpx};
  107. background-color: white;
  108. position: absolute;
  109. top: 50%;
  110. left: 50%;
  111. transform: translate(-50%, -50%);
  112. .loading {
  113. width: #{220rpx};
  114. height: #{220rpx};
  115. }
  116. .app-close {
  117. width: #{30rpx};
  118. height: #{30rpx};
  119. background-size: cover;
  120. background-repeat: no-repeat;
  121. background-image: url("../../../static/image/icon/close.png");
  122. position: absolute;
  123. top: #{28rpx};
  124. right: #{24rpx};
  125. }
  126. .app-image-iframe {
  127. width: #{440rpx};
  128. height: #{783rpx};
  129. position: relative;
  130. box-shadow: #{2rpx} #{2rpx} #{10rpx} #d9d9d9;
  131. .text {
  132. text-align: center;
  133. color: #888;
  134. }
  135. }
  136. .app-button {
  137. width: #{500rpx};
  138. height: #{80rpx};
  139. margin-top: #{38rpx};
  140. margin-bottom: #{24rpx};
  141. }
  142. .app-text {
  143. font-size: #{24rpx};
  144. color: #999999;
  145. }
  146. }
  147. }
  148. </style>