share.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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='./../image/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='./../image/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. text: '保存中...'
  83. });
  84. uni.authorize({
  85. scope: 'scope.writePhotosAlbum',
  86. success(res) {
  87. if (res.errMsg == "authorize:ok") {
  88. uni.getImageInfo({
  89. src: that.poster,
  90. success(res) {
  91. uni.hideLoading();
  92. uni.saveImageToPhotosAlbum({
  93. filePath: res.path,
  94. success(res) {
  95. uni.showToast({
  96. title: '保存成功!',
  97. icon: 'success',
  98. duration: 2000
  99. });
  100. },
  101. fail(res) {
  102. uni.showToast({
  103. title: '保存失败!',
  104. icon: 'none',
  105. duration: 1000
  106. });
  107. }
  108. })
  109. },
  110. fail(res) {
  111. uni.hideLoading();
  112. uni.showToast({
  113. title: '保存失败!',
  114. icon: 'none',
  115. duration: 1000
  116. });
  117. }
  118. })
  119. }
  120. },
  121. fail(res) {
  122. uni.hideLoading();
  123. uni.showModal({
  124. title: '提示',
  125. content: '保存失败,需要授权保存到相册权限',
  126. showCancel: false,
  127. confirmText: '打开授权',
  128. success(e) {
  129. if (e.confirm) {
  130. uni.openSetting({});
  131. }
  132. }
  133. });
  134. }
  135. })
  136. // #endif
  137. // #ifdef MP-ALIPAY
  138. my.showLoading({
  139. content: '图片保存中'
  140. });
  141. my.saveImage({
  142. url: that.poster,
  143. showActionSheet: true,
  144. success: (res) => {
  145. uni.showToast({
  146. title: '保存成功',
  147. icon: 'success',
  148. duration: 1000
  149. })
  150. },
  151. fail() {
  152. uni.showToast({
  153. title: '保存失败',
  154. icon: 'none',
  155. duration: 1000
  156. })
  157. },
  158. complete() {
  159. my.hideLoading();
  160. }
  161. });
  162. // #endif
  163. },
  164. getPoster() {
  165. let that = this;
  166. uni.showLoading({
  167. title: '生成中...'
  168. });
  169. that.$request({
  170. url: that.$api.step.poster,
  171. data: {
  172. pic_id: that.currentItem,
  173. num: that.todayStep
  174. },
  175. }).then(response=>{
  176. uni.hideLoading();
  177. if(response.code == 0) {
  178. that.poster = response.data.pic_url;
  179. }else {
  180. uni.showToast({
  181. title: response.msg,
  182. icon: 'none',
  183. duration: 1000
  184. });
  185. }
  186. }).catch(response => {
  187. uni.hideLoading();
  188. });
  189. },
  190. getList() {
  191. let that = this;
  192. that.$showLoading({
  193. type: 'global',
  194. text: '步数加载中...'
  195. });
  196. that.$request({
  197. url: that.$api.step.setting,
  198. }).then(response=>{
  199. that.$hideLoading();
  200. if(response.code == 0) {
  201. that.pic_list = response.data.qrcode_pic;
  202. that.pic = response.data.qrcode_pic;
  203. that.qrcode_title = response.data.qrcode_title;
  204. that.currentItem = response.data.qrcode_pic[0].id;
  205. if(response.data.qrcode_pic.length > 4) {
  206. that.pic = response.data.qrcode_pic.slice(0, 4);
  207. }else {
  208. that.left = false;
  209. that.right = false;
  210. }
  211. that.getPoster();
  212. }else {
  213. uni.showToast({
  214. title: response.msg,
  215. icon: 'none',
  216. duration: 1000
  217. });
  218. }
  219. }).catch(response => {
  220. that.$hideLoading();
  221. });
  222. },
  223. },
  224. onLoad(options) {
  225. let that = this;
  226. if (options.step > -1) {
  227. that.todayStep = options.step
  228. }
  229. that.getList();
  230. }
  231. }
  232. </script>
  233. <style scoped lang="scss">
  234. .poster {
  235. height: #{750rpx};
  236. width: #{422rpx};
  237. margin: #{46rpx} auto #{48rpx};
  238. background-color: whtie;
  239. display: block;
  240. box-shadow: 0 0 #{20rpx} rgba(0, 0, 0, 0.15);
  241. }
  242. .poster image {
  243. height: #{750rpx};
  244. width: #{422rpx};
  245. }
  246. .mycanvas {
  247. height: #{1165rpx};
  248. width: #{750rpx};
  249. }
  250. .share-title {
  251. font-size: #{30rpx};
  252. color: #999;
  253. text-align: center;
  254. margin-bottom: #{20rpx};
  255. }
  256. .share-bg {
  257. height: #{144rpx};
  258. text-align: center;
  259. position: relative;
  260. width: 100%;
  261. }
  262. .cross-left {
  263. height: #{144rpx};
  264. width: #{80rpx};
  265. }
  266. .cross-right {
  267. height: #{144rpx};
  268. width: #{80rpx};
  269. }
  270. .cross-left image, .cross-right image {
  271. height: #{26rpx};
  272. width: #{26rpx};
  273. display: block;
  274. margin-top: #{59rpx};
  275. margin-left: #{37rpx};
  276. }
  277. .share-bg .bg-item {
  278. margin-right: #{20rpx};
  279. }
  280. .share-bg .bg-item.active image {
  281. border: #{4rpx} solid #ff4544;
  282. }
  283. .pic_list {
  284. height: #{144rpx};
  285. width: #{540rpx};
  286. margin: 0 #{10rpx};
  287. }
  288. .bg-item,.bg-item image {
  289. height: #{144rpx};
  290. width: #{120rpx};
  291. }
  292. .share-btn {
  293. height: #{80rpx};
  294. width: #{500rpx};
  295. margin: #{40rpx} auto #{20rpx};
  296. color: white;
  297. font-size: #{32rpx};
  298. background-color: #ff4544;
  299. border-radius: #{40rpx};
  300. line-height: #{80rpx};
  301. }
  302. .share-tip {
  303. font-size: #{24rpx};
  304. color: #999;
  305. text-align: center;
  306. }
  307. </style>