share.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <app-layout>
  3. <view class='poster' @click="screen">
  4. <image :src='poster'></image>
  5. </view>
  6. <view class='choose'>
  7. <view class='share-title'>选择模版</view>
  8. <view class='share-bg main-center'>
  9. <view class='cross-left box-grow-0' @click='chooseImg(1)'>
  10. <image src='/static/image/step/left.png' v-if="left"></image>
  11. </view>
  12. <view class='pic_list box-grow-0 dir-left-nowrap'>
  13. <view v-for="item in pic" :key="item" :class="[`bg-item`,`${currentItem==item.id?'active':''}`]" @click="tagChoose(item.id)">
  14. <image :src='item.pic_url'></image>
  15. </view>
  16. </view>
  17. <view class='cross-right box-grow-0' @click='chooseImg(2)'>
  18. <image src='/static/image/step/xi-right.png' v-if="right"></image>
  19. </view>
  20. </view>
  21. <view @click='saveImage'>
  22. <button class='share-btn'>保存图片</button>
  23. </view>
  24. <view class='share-tip'>保存至相册</view>
  25. </view>
  26. </app-layout>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. todayStep: 0,
  33. pic_list: [],
  34. poster: '',
  35. pic: [],
  36. page: 0,
  37. currentItem: '',
  38. left: false,
  39. right: true,
  40. }
  41. },
  42. methods: {
  43. screen() {
  44. let img = this.poster
  45. uni.previewImage({
  46. urls: [img]
  47. })
  48. },
  49. chooseImg(id) {
  50. let that = this;
  51. let length = Math.floor(that.pic_list.length / 4 -0.0001);
  52. if(id == 1) {
  53. if (that.left == false ) {
  54. return
  55. }
  56. that.page--;
  57. that.right = true;
  58. if (that.page == 0) {
  59. that.left = false;
  60. }
  61. that.pic = that.pic_list.slice(that.page * 4, that.page * 4 + 4)
  62. } else if (id == 2){
  63. if (that.right == false) {
  64. return
  65. }
  66. that.page++;
  67. that.left = true;
  68. if (that.page == length) {
  69. that.right = false;
  70. }
  71. that.pic = that.pic_list.slice(that.page * 4, that.page * 4 + 4)
  72. }
  73. },
  74. tagChoose(id) {
  75. this.currentItem = id;
  76. this.getPoster();
  77. },
  78. saveImage: function () {
  79. let that = this;
  80. // #ifndef MP-ALIPAY
  81. uni.showLoading({
  82. mask: true,
  83. text: '保存中...'
  84. });
  85. uni.authorize({
  86. scope: 'scope.writePhotosAlbum',
  87. success(res) {
  88. if (res.errMsg == "authorize:ok") {
  89. uni.getImageInfo({
  90. src: that.poster,
  91. success(res) {
  92. uni.hideLoading();
  93. uni.saveImageToPhotosAlbum({
  94. filePath: res.path,
  95. success(res) {
  96. uni.showToast({
  97. title: '保存成功!',
  98. icon: 'success',
  99. duration: 2000
  100. });
  101. },
  102. fail(res) {
  103. uni.showToast({
  104. title: '保存失败!',
  105. icon: 'none',
  106. duration: 1000
  107. });
  108. }
  109. })
  110. },
  111. fail(res) {
  112. uni.hideLoading();
  113. uni.showToast({
  114. title: '保存失败!',
  115. icon: 'none',
  116. duration: 1000
  117. });
  118. }
  119. })
  120. }
  121. },
  122. fail(res) {
  123. uni.hideLoading();
  124. uni.showModal({
  125. title: '提示',
  126. content: '保存失败,需要授权保存到相册权限',
  127. showCancel: false,
  128. confirmText: '打开授权',
  129. success(e) {
  130. if (e.confirm) {
  131. uni.openSetting({});
  132. }
  133. }
  134. });
  135. }
  136. })
  137. // #endif
  138. // #ifdef MP-ALIPAY
  139. my.showLoading({
  140. content: '图片保存中'
  141. });
  142. my.saveImage({
  143. url: that.poster,
  144. showActionSheet: true,
  145. success: (res) => {
  146. uni.showToast({
  147. title: '保存成功',
  148. icon: 'success',
  149. duration: 1000
  150. })
  151. },
  152. fail() {
  153. uni.showToast({
  154. title: '保存失败',
  155. icon: 'none',
  156. duration: 1000
  157. })
  158. },
  159. complete() {
  160. my.hideLoading();
  161. }
  162. });
  163. // #endif
  164. },
  165. getPoster() {
  166. let that = this;
  167. uni.showLoading({
  168. mask: true,
  169. title: '生成中...'
  170. });
  171. that.$request({
  172. url: that.$api.step.poster,
  173. data: {
  174. pic_id: that.currentItem,
  175. num: that.todayStep
  176. },
  177. }).then(response=>{
  178. uni.hideLoading();
  179. if(response.code == 0) {
  180. that.poster = response.data.pic_url;
  181. }else {
  182. uni.showToast({
  183. title: response.msg,
  184. icon: 'none',
  185. duration: 1000
  186. });
  187. }
  188. }).catch(response => {
  189. uni.hideLoading();
  190. });
  191. },
  192. getList() {
  193. let that = this;
  194. that.$showLoading({
  195. type: 'global',
  196. text: '步数加载中...'
  197. });
  198. that.$request({
  199. url: that.$api.step.setting,
  200. }).then(response=>{
  201. that.$hideLoading();
  202. if(response.code == 0) {
  203. that.pic_list = response.data.qrcode_pic;
  204. that.pic = response.data.qrcode_pic;
  205. that.qrcode_title = response.data.qrcode_title;
  206. that.currentItem = response.data.qrcode_pic[0].id;
  207. if(response.data.qrcode_pic.length > 4) {
  208. that.pic = response.data.qrcode_pic.slice(0, 4);
  209. }else {
  210. that.left = false;
  211. that.right = false;
  212. }
  213. that.getPoster();
  214. }else {
  215. uni.showToast({
  216. title: response.msg,
  217. icon: 'none',
  218. duration: 1000
  219. });
  220. }
  221. }).catch(response => {
  222. that.$hideLoading();
  223. });
  224. },
  225. },
  226. onLoad(options) { this.$commonLoad.onload(options);
  227. let that = this;
  228. if (options.step > -1) {
  229. that.todayStep = options.step
  230. }
  231. that.getList();
  232. }
  233. }
  234. </script>
  235. <style scoped lang="scss">
  236. .poster {
  237. height: #{750rpx};
  238. width: #{422rpx};
  239. margin: #{46rpx} auto #{48rpx};
  240. background-color: whtie;
  241. display: block;
  242. box-shadow: 0 0 #{20rpx} rgba(0, 0, 0, 0.15);
  243. }
  244. .poster image {
  245. height: #{750rpx};
  246. width: #{422rpx};
  247. }
  248. .mycanvas {
  249. height: #{1165rpx};
  250. width: #{750rpx};
  251. }
  252. .share-title {
  253. font-size: #{30rpx};
  254. color: #999;
  255. text-align: center;
  256. margin-bottom: #{20rpx};
  257. }
  258. .share-bg {
  259. height: #{144rpx};
  260. text-align: center;
  261. position: relative;
  262. width: 100%;
  263. }
  264. .cross-left {
  265. height: #{144rpx};
  266. width: #{80rpx};
  267. }
  268. .cross-right {
  269. height: #{144rpx};
  270. width: #{80rpx};
  271. }
  272. .cross-left image, .cross-right image {
  273. height: #{26rpx};
  274. width: #{26rpx};
  275. display: block;
  276. margin-top: #{59rpx};
  277. margin-left: #{37rpx};
  278. }
  279. .share-bg .bg-item {
  280. margin-right: #{20rpx};
  281. }
  282. .share-bg .bg-item.active image {
  283. border: #{4rpx} solid #ff4544;
  284. }
  285. .pic_list {
  286. height: #{144rpx};
  287. width: #{540rpx};
  288. margin: 0 #{10rpx};
  289. }
  290. .bg-item,.bg-item image {
  291. height: #{144rpx};
  292. width: #{120rpx};
  293. }
  294. .share-btn {
  295. height: #{80rpx};
  296. width: #{500rpx};
  297. margin: #{40rpx} auto #{20rpx};
  298. color: white;
  299. font-size: #{32rpx};
  300. background-color: #ff4544;
  301. border-radius: #{40rpx};
  302. line-height: #{80rpx};
  303. }
  304. .share-tip {
  305. font-size: #{24rpx};
  306. color: #999;
  307. text-align: center;
  308. }
  309. </style>