userTuiImg.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="distribution-posters">
  3. <view class="banenr">
  4. <image class="slide-image" :src="url" mode="widthFix" show-menu-by-longpress />
  5. </view>
  6. <view class="btn-box">
  7. <view class="btn" @click="saveImg()">保存海报</view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import {getTuiImg} from '@/api/user'
  13. export default {
  14. name: 'Poster',
  15. components: {
  16. },
  17. props: {},
  18. data: function() {
  19. return {
  20. url:null,
  21. }
  22. },
  23. mounted: function() {
  24. this.getTuiImg()
  25. },
  26. methods: {
  27. getTuiImg: function() {
  28. let that = this
  29. getTuiImg().then(
  30. res => {
  31. var path=uni.getStorageSync('requestPath')
  32. that.url =path+ "/"+res.url
  33. },
  34. err => {
  35. uni.showToast({
  36. title: err.msg,
  37. icon: 'none',
  38. duration: 2000,
  39. })
  40. }
  41. )
  42. },
  43. downloadIamge(imgsrc, name) {
  44. var that = this
  45. this.isDown = true
  46. var downloadUrl = imgsrc
  47. // if (!wx.saveImageToPhotosAlbum) {
  48. // uni.showModal({
  49. // title: '提示',
  50. // content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
  51. // })
  52. // that.openDialogVisible = true
  53. // return
  54. // }
  55. that.downloadFile(downloadUrl)
  56. //可以通过 uni.getSetting 先查询一下用户是否授权了 "scope.writePhotosAlbum" 这个 scope
  57. // uni.getSetting({
  58. // success(res) {
  59. // if (!res.authSetting["scope.writePhotosAlbum"]) {
  60. // that.openDialogVisible = true;
  61. // // 接口调用询问
  62. // uni.authorize({
  63. // scope: "scope.writePhotosAlbum",
  64. // success() {
  65. // that.downloadFile(downloadUrl);
  66. // },
  67. // fail() {
  68. // // 用户拒绝了授权
  69. // // 打开设置页面
  70. // uni.openSetting({
  71. // success: function (data) {},
  72. // fail: function (data) {}
  73. // });
  74. // }
  75. // });
  76. // } else {
  77. // that.downloadFile(downloadUrl);
  78. // }
  79. // },
  80. // fail(res) {
  81. // that.openDialogVisible = true;
  82. // }
  83. // });
  84. },
  85. saveImg: function() {
  86. this.downloadIamge(this.url, 'poster')
  87. },
  88. downloadFile(url) {
  89. console.log(url);
  90. uni.showLoading({
  91. title: "图片保存中..."
  92. })
  93. uni.downloadFile({
  94. url,
  95. fail: function(res) {
  96. uni.showModal({
  97. title: '提示',
  98. content: '保存失败',
  99. })
  100. },
  101. success: function(res) {
  102. console.log(res)
  103. var tempFilePath = res.tempFilePath;
  104. uni.saveImageToPhotosAlbum({
  105. filePath: tempFilePath,
  106. success:()=> {
  107. // 5 提示保存成功
  108. uni.showToast({
  109. title: "保存成功",
  110. duration: 2000
  111. })
  112. },
  113. fail:()=>{
  114. // 6 失败关闭提示信息!!!
  115. console.log("saveImageToPhotosAlbum 失败");
  116. uni.hideLoading();
  117. },
  118. complete: function() {
  119. // 7 隐藏提示
  120. uni.hideLoading();
  121. }
  122. })
  123. },
  124. })
  125. },
  126. },
  127. }
  128. </script>
  129. <style lang="less">
  130. page {
  131. height: 100%;
  132. }
  133. .distribution-posters {
  134. height: 100%;
  135. }
  136. .banenr {
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. padding-bottom:140upx ;
  141. height: 100%;
  142. }
  143. .banner .slide-image {
  144. width: 100%;
  145. height: auto;
  146. }
  147. .btn-box{
  148. height: 140upx;
  149. z-index: 9999;
  150. width: 100%;
  151. padding: 0rpx 30upx;
  152. position: fixed;
  153. bottom: 0;
  154. left: 0;
  155. box-sizing: border-box;
  156. background-color: #ffffff;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. .btn{
  161. width: 100%;
  162. height: 88upx;
  163. line-height: 88upx;
  164. text-align: center;
  165. font-size: 34upx;
  166. font-family: PingFang SC;
  167. font-weight: 400;
  168. color: #ffffff;
  169. background:#018C39 !important;
  170. border-radius: 44upx;
  171. }
  172. }
  173. </style>