invite.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="invite">
  3. <view class="title">
  4. 邀请好友加入慧研学惠生活
  5. </view>
  6. <view class="desc">
  7. 您将获得现金红包奖励
  8. </view>
  9. <view class="code-box">
  10. <image class="head" :src="userInfo.imgPath" mode=""></image>
  11. <view class="user-name">
  12. {{ userInfo.nickname }}
  13. </view>
  14. <view class="qrcode-box">
  15. <u--image width="380rpx" height="380rpx" :src="src">
  16. <template v-slot:loading>
  17. <u-loading-icon size="56rpx" color="#FF4C3A"></u-loading-icon>
  18. </template>
  19. </u--image>
  20. </view>
  21. </view>
  22. <view class="save-btn">
  23. <u-button color="linear-gradient(265deg, #FF4A39 0%, #FC8B45 100%)" shape="circle" type="primary"
  24. @click="save">保存二维码</u-button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { BASE_URL } from '@/utils/config.js'
  30. export default {
  31. data() {
  32. return {
  33. src: '',
  34. userInfo: {}
  35. }
  36. },
  37. methods: {
  38. save() {
  39. // uni.getImageInfo({
  40. // src:this.src,
  41. // success: function (image) {
  42. // uni.saveImageToPhotosAlbum({
  43. // filePath:image.path
  44. // })
  45. // }
  46. // })
  47. uni.showLoading({
  48. title: '正在保存图片...'
  49. });
  50. //获取用户的当前设置。获取相册权限
  51. uni.getSetting({
  52. success: (res) => {
  53. //如果没有相册权限
  54. if (!res.authSetting["scope.writePhotosAlbum"]) {
  55. //向用户发起授权请求
  56. uni.authorize({
  57. scope: "scope.writePhotosAlbum",
  58. success: () => {
  59. //授权成功保存图片到系统相册
  60. // uni.saveImageToPhotosAlbum({
  61. // //图片路径,不支持网络图片路径
  62. // filePath: url,
  63. // success: (res) => {
  64. // uni.hideLoading();
  65. // return uni.showToast({
  66. // title: "保存成功!",
  67. // });
  68. // },
  69. // fail: (res) => {
  70. // console.log(res.errMsg);
  71. // return uni.showToast({
  72. // title: res.errMsg,
  73. // });
  74. // },
  75. // complete: (res) => { uni.hideLoading(); },
  76. // });
  77. console.log(this.src.slice(22))
  78. console.log(this.src)
  79. console.log( wx.env.USER_DATA_PATH + '/pic' + number + '.png')
  80. const number = Math.random()
  81. wx.getFileSystemManager().writeFile({
  82. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  83. data: this.src.slice(22),
  84. encoding: 'base64',
  85. success: res => {
  86. wx.saveImageToPhotosAlbum({
  87. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  88. success: function (res) {
  89. wx.showToast({ title: '保存成功', })
  90. },
  91. fail: function (err) {
  92. console.log(err)
  93. }
  94. })
  95. console.log(res)
  96. }, fail: err => {
  97. console.log(err)
  98. }
  99. })
  100. },
  101. //授权失败
  102. fail: () => {
  103. uni.hideLoading();
  104. uni.showModal({
  105. title: "您已拒绝获取相册权限",
  106. content: "是否进入权限管理,调整授权?",
  107. success: (res) => {
  108. if (res.confirm) {
  109. //调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权)
  110. uni.openSetting({
  111. success: (res) => {
  112. console.log(res.authSetting);
  113. },
  114. });
  115. } else if (res.cancel) {
  116. return uni.showToast({
  117. title: "已取消!",
  118. });
  119. }
  120. },
  121. });
  122. },
  123. });
  124. } else {
  125. //如果已有相册权限,直接保存图片到系统相册
  126. // uni.saveImageToPhotosAlbum({
  127. // filePath: url,
  128. // success: (res) => {
  129. // uni.hideLoading();
  130. // return uni.showToast({
  131. // title: "保存成功!",
  132. // });
  133. // },
  134. // fail: (res) => {
  135. // uni.hideLoading();
  136. // console.log(res.errMsg);
  137. // return uni.showToast({
  138. // title: res.errMsg,
  139. // });
  140. // },
  141. // //无论成功失败都走的回调
  142. // complete: (res) => { uni.hideLoading(); },
  143. // });
  144. const number = Math.random()
  145. wx.getFileSystemManager().writeFile({
  146. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  147. data: this.src.slice(22),
  148. encoding: 'base64',
  149. success: res => {
  150. wx.saveImageToPhotosAlbum({
  151. filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  152. success: function (res) {
  153. wx.showToast({ title: '保存成功', })
  154. },
  155. fail: function (err) {
  156. console.log(err)
  157. }
  158. })
  159. console.log(res)
  160. }, fail: err => {
  161. console.log(err)
  162. }
  163. })
  164. }
  165. },
  166. fail: (res) => { },
  167. });
  168. },
  169. },
  170. created() {
  171. this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  172. uni.request({
  173. url: BASE_URL + '/zswl-cloud-bdb/promotion/qrcode',
  174. method: "post",
  175. data: {
  176. "scene": JSON.parse(uni.getStorageSync('userInfo')).userId,
  177. },
  178. responseType: 'arraybuffer'
  179. }).then(res => {
  180. this.src = 'data:image/png;base64,' + uni.arrayBufferToBase64(res.data)
  181. })
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. .invite .u-image__loading,
  187. .u-image__error {
  188. background-color: #fff !important;
  189. }
  190. .invite {
  191. padding: 0 30rpx;
  192. min-height: 100vh;
  193. background: url('http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/SpRgpIr81Trt13ba08b3b78f59f72c0a555b82b73492.png/1.png') no-repeat;
  194. background-size: 100% 100%;
  195. .title {
  196. text-align: center;
  197. font-size: 48rpx;
  198. font-weight: 800;
  199. margin-top: 178rpx;
  200. }
  201. .desc {
  202. margin-top: 20rpx;
  203. font-size: 28rpx;
  204. color: #999999;
  205. text-align: center;
  206. }
  207. .code-box {
  208. width: 690rpx;
  209. height: 650rpx;
  210. background: #fff;
  211. box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(0, 0, 0, 0.06);
  212. border-radius: 16rpx;
  213. position: relative;
  214. margin-top: 110rpx;
  215. .head {
  216. width: 162rpx;
  217. height: 162rpx;
  218. border-radius: 50%;
  219. position: absolute;
  220. top: 0;
  221. left: 50%;
  222. transform: translate(-50%, -50%);
  223. }
  224. .user-name {
  225. padding-top: 100rpx;
  226. text-align: center;
  227. font-size: 32rpx;
  228. color: #222222;
  229. font-weight: bold;
  230. }
  231. .qrcode-box {
  232. width: 380rpx;
  233. height: 380rpx;
  234. margin: 80rpx auto;
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. }
  239. }
  240. .save-btn {
  241. position: fixed;
  242. bottom: 100rpx;
  243. width: calc(100% - 60rpx);
  244. }
  245. }
  246. </style>