app-goods-preview-poster.vue 4.7 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. components: {},
  30. props: {
  31. value: {
  32. type: Boolean,
  33. default() {
  34. return false;
  35. }
  36. },
  37. url: {
  38. type: String,
  39. default() {
  40. return '';
  41. }
  42. },
  43. disabled: {
  44. type: Boolean,
  45. default() {
  46. return false;
  47. }
  48. }
  49. },
  50. created: function () {
  51. this.value = this.value + '';
  52. },
  53. watch: {
  54. value(newVal, oldVal) {
  55. if (newVal) {
  56. this.getShareImg();
  57. }
  58. }
  59. },
  60. data() {
  61. return {
  62. showHidden: this.value,
  63. loading: true,
  64. shareImage: '',
  65. }
  66. },
  67. methods: {
  68. showHiddenClick() {
  69. this.$emit('close', false);
  70. },
  71. savePicture() {
  72. this.$utils.batchSave(this.shareImage, 'image').then((e) => {
  73. uni.showToast({title: '保存成功'});
  74. });
  75. },
  76. getShareImg() {
  77. if (!this.url) return;
  78. this.loading = true;
  79. this.$request({
  80. url: this.url,
  81. }).then(response => {
  82. if (response.code === 0) {
  83. this.shareImage = response.data.pic_url;
  84. this.loading = false;
  85. } else {
  86. uni.showModal({
  87. content: response.msg,
  88. showCancel: false,
  89. });
  90. }
  91. });
  92. },
  93. preview() {
  94. uni.previewImage({
  95. urls: [this.shareImage]
  96. });
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .app-goods-preview-poster {
  103. .app-center {
  104. width: calc(100% - #{80rpx});
  105. padding-top: #{100rpx};
  106. padding-bottom: #{77rpx};
  107. border-radius: #{8rpx};
  108. background-color: white;
  109. position: absolute;
  110. top: 50%;
  111. left: 50%;
  112. transform: translate(-50%, -50%);
  113. .loading {
  114. width: #{220rpx};
  115. height: #{220rpx};
  116. }
  117. .app-close {
  118. width: #{30rpx};
  119. height: #{30rpx};
  120. background-size: cover;
  121. background-repeat: no-repeat;
  122. background-image: url("../../../static/image/icon/close.png");
  123. position: absolute;
  124. top: #{28rpx};
  125. right: #{24rpx};
  126. }
  127. .app-image-iframe {
  128. width: #{440rpx};
  129. height: #{783rpx};
  130. position: relative;
  131. box-shadow: #{2rpx} #{2rpx} #{10rpx} #d9d9d9;
  132. .text {
  133. text-align: center;
  134. color: #888;
  135. }
  136. }
  137. .app-button {
  138. width: #{500rpx};
  139. height: #{80rpx};
  140. margin-top: #{38rpx};
  141. margin-bottom: #{24rpx};
  142. }
  143. .app-text {
  144. font-size: #{24rpx};
  145. color: #999999;
  146. }
  147. }
  148. }
  149. </style>