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

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