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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="app-share-qr-code-poster" :class="{'app-show-hidden': value}">
  3. <view class="app-bottom" v-if="buttonBoolean">
  4. <view class="app-icons dir-left-nowrap">
  5. <view class="box-grow-1" @click="showHiddenClick">
  6. <app-jump-button form arrangement="topCenter" open_type="share">
  7. <icon class="app-icon app-share"></icon>
  8. <text class="app-text">发送给朋友</text>
  9. </app-jump-button>
  10. </view>
  11. <!-- #ifndef MP-BAIDU -->
  12. <view class="box-grow-1" v-if="isHidden">
  13. <app-form-id @click="fenxianghaibao">
  14. <view class="dir-top-wrap main-center cross-center">
  15. <icon class="app-icon app-code"></icon>
  16. <text class="app-text">生成商品海报</text>
  17. </view>
  18. </app-form-id>
  19. </view>
  20. <!-- #endif -->
  21. </view>
  22. <view class="app-button">
  23. <app-form-id>
  24. <view style="height: 100rpx;background-color: #ffffff;text-align: center;line-height: 100rpx;font-size: 32rpx;color: #353535;" @click="showHiddenClick" type="general">取消</view>
  25. </app-form-id>
  26. </view>
  27. <view v-if="getBoolEmpty.XBoolean" :style="{height: getBoolEmpty.emptyHeight + 'rpx',}"></view>
  28. </view>
  29. <!-- #ifndef MP-BAIDU -->
  30. <view class="app-center dir-top-wrap main-center cross-center" v-else>
  31. <view class="app-close" @click="showHiddenClick"></view>
  32. <view class="app-image-iframe main-center dir-top-nowrap cross-center" v-if="loading">
  33. <image class="loading" src="../../../static/image/loading.gif"></image>
  34. <view class="text">海报生成中</view>
  35. </view>
  36. <image class="app-image-iframe" v-if="!loading" show-menu-by-longpress mode="aspectFit" @click="preview(shareImage)" :src="shareImage"></image>
  37. <view class="app-button">
  38. <button class="save-picture" :class="loading ? 'disabled-save' : ''" :disabled="loading" @click="savePicture">保存图片</button>
  39. </view>
  40. <text class="app-text">保存到相册</text>
  41. </view>
  42. <!-- #endif -->
  43. <app-permissions-auth :text="text" :isShow='is_can_save' @cancel="cancel"></app-permissions-auth>
  44. </view>
  45. </template>
  46. <script>
  47. import {mapGetters} from 'vuex';
  48. import appPermissionsAuth from '../../basic-component/app-layout/app-permissions-auth/app-permissions-auth.vue';
  49. export default {
  50. name: 'app-share-qr-code-poster',
  51. components: {
  52. appPermissionsAuth,
  53. },
  54. computed: {
  55. ...mapGetters('iPhoneX', {
  56. getBoolEmpty: 'getBoolEmpty'
  57. }),
  58. },
  59. props: {
  60. value: {
  61. type: Boolean,
  62. default() {
  63. return false;
  64. }
  65. },
  66. url: {
  67. type: String,
  68. default() {
  69. return '';
  70. }
  71. },
  72. disabled: {
  73. type: Boolean,
  74. default() {
  75. return false;
  76. }
  77. },
  78. isHidden: {
  79. type: Boolean,
  80. default() {
  81. return true;
  82. }
  83. }
  84. },
  85. data() {
  86. return {
  87. showHidden: this.value,
  88. buttonBoolean: true,
  89. shareImage: '',
  90. is_can_save: false,
  91. text: '保存图片需要您的授权。点击去设置,开启 保存到相册 权限',
  92. loading: true,
  93. }
  94. },
  95. methods: {
  96. fenxianghaibao() {
  97. this.buttonBoolean = false;
  98. this.getShareImg();
  99. },
  100. showHiddenClick() {
  101. this.showHidden = false;
  102. this.$emit('input', this.showHidden);
  103. this.buttonBoolean = true;
  104. },
  105. savePicture() {
  106. let self = this;
  107. // #ifndef MP-ALIPAY
  108. uni.showLoading({
  109. title: '图片保存中'
  110. });
  111. uni.downloadFile({
  112. url: this.shareImage,
  113. success(res) {
  114. uni.saveImageToPhotosAlbum({
  115. filePath: res.tempFilePath,
  116. success() {
  117. uni.hideLoading();
  118. uni.showToast({
  119. title: '保存成功',
  120. duration: 3000,
  121. icon: 'none',
  122. });
  123. },
  124. fail() {
  125. uni.hideLoading();
  126. self.getAuthSetting();
  127. },
  128. complete() {
  129. }
  130. })
  131. }
  132. });
  133. // #endif
  134. // #ifdef MP-ALIPAY
  135. my.showLoading({
  136. content: '图片保存中'
  137. });
  138. my.saveImage({
  139. url: this.shareImage,
  140. showActionSheet: true,
  141. success: () => {
  142. my.hideLoading();
  143. uni.showToast({
  144. title: '保存成功',
  145. duration: 3000,
  146. icon: 'none',
  147. });
  148. },
  149. fail() {
  150. my.hideLoading();
  151. },
  152. complete() {
  153. }
  154. });
  155. // #endif
  156. },
  157. getShareImg() {
  158. if (!this.url) return;
  159. this.$request({
  160. url: this.url,
  161. }).then(response => {
  162. if (response.code === 0) {
  163. this.shareImage = response.data.pic_url;
  164. this.loading = false;
  165. } else {
  166. uni.showModal({
  167. content: response.msg,
  168. showCancel: false,
  169. });
  170. }
  171. });
  172. },
  173. getAuthSetting() {
  174. let self = this;
  175. uni.getSetting({
  176. success(res) {
  177. self.is_can_save = !res.authSetting['scope.writePhotosAlbum'];
  178. }
  179. });
  180. },
  181. cancel(isShow) {
  182. this.is_can_save = isShow;
  183. },
  184. preview(data) {
  185. uni.previewImage({
  186. urls: [data],
  187. longPressActions: true,
  188. });
  189. }
  190. }
  191. }
  192. </script>
  193. <style scoped lang="scss">
  194. .save-picture {
  195. width: #{500upx};
  196. height: #{80upx};
  197. border-radius: #{40upx};
  198. font-size: #{32upx};
  199. line-height: #{80upx};
  200. text-align: center;
  201. background-color: #ff4544;
  202. margin: 0;
  203. padding: 0;
  204. border: none;
  205. color: #ffffff;
  206. }
  207. .disabled-save {
  208. background-color: #cdcdcd;
  209. }
  210. .app-share-qr-code-poster {
  211. width: #{750rpx};
  212. height: 100%;
  213. position: fixed;
  214. z-index: 1501;
  215. left: 0;
  216. opacity: 0;
  217. top: 0;
  218. visibility: hidden;
  219. background-color: rgba(153, 153, 153, 0.5);
  220. .loading {
  221. width: #{220rpx};
  222. height: #{220rpx};
  223. }
  224. .app-icons {
  225. height: #{290rpx};
  226. .app-text {
  227. font-size: #{26rpx};
  228. color: #353535;
  229. }
  230. > view {
  231. width: 50%;
  232. height: 100%;
  233. .app-icon {
  234. width: #{120rpx};
  235. height: #{120rpx};
  236. background-size: cover;
  237. background-repeat: no-repeat;
  238. background-color: white;
  239. border-radius: 50%;
  240. margin-top: #{60rpx};
  241. margin-bottom: #{24rpx};
  242. }
  243. .app-share {
  244. background-image: url('../../../static/image/icon/share.png');
  245. }
  246. .app-code {
  247. background-image: url('../../../static/image/icon/code.png');
  248. }
  249. .text {
  250. font-size: #{26rpx};
  251. color: #353535;
  252. }
  253. }
  254. }
  255. .app-bottom {
  256. width: 100%;
  257. position: fixed;
  258. bottom: 0;
  259. left: 0;
  260. background-color: #f2f2f2;
  261. .app-icons {
  262. width: 100%;
  263. height: #{290rpx};
  264. }
  265. .app-button {
  266. width: 100%;
  267. height: #{100rpx};
  268. /deep/ button {
  269. border-radius: 0;
  270. border: none;
  271. }
  272. }
  273. }
  274. .app-center {
  275. width: calc(100% - #{80rpx});
  276. padding-top: #{100rpx};
  277. padding-bottom: #{77rpx};
  278. border-radius: #{8rpx};
  279. background-color: white;
  280. position: absolute;
  281. top: 50%;
  282. left: 50%;
  283. transform: translate(-50%, -50%);
  284. .app-close {
  285. width: #{30rpx};
  286. height: #{30rpx};
  287. background-size: cover;
  288. background-repeat: no-repeat;
  289. background-image: url("../../../static/image/icon/close.png");
  290. position: absolute;
  291. top: #{28rpx};
  292. right: #{24rpx};
  293. }
  294. .app-image-iframe {
  295. width: #{440rpx};
  296. height: #{783rpx};
  297. position: relative;
  298. box-shadow: #{2rpx} #{2rpx} #{10rpx} #d9d9d9;
  299. .text {
  300. text-align: center;
  301. color: #888;
  302. }
  303. }
  304. .app-button {
  305. width: #{500rpx};
  306. height: #{80rpx};
  307. margin-top: #{38rpx};
  308. margin-bottom: #{24rpx};
  309. }
  310. .app-text {
  311. font-size: #{24rpx};
  312. color: #999999;
  313. }
  314. }
  315. }
  316. .app-show-hidden {
  317. opacity: 1;
  318. visibility: visible;
  319. }
  320. </style>