爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
7.0 KiB

4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="promo-modal-page">
  3. <!-- 顶部导航栏 -->
  4. <!-- <view class="nav-bar">
  5. <view class="back" @tap="navigateBack">
  6. <uni-icons type="left" size="20" />
  7. </view>
  8. <text class="title">推广链接</text>
  9. </view> -->
  10. <navbar title="推广链接" leftClick
  11. @leftClick="$utils.navigateBack" />
  12. <!-- 页面内容 -->
  13. <view class="content">
  14. <!-- 用户信息 -->
  15. <!-- <view class="user-info-modal">
  16. <view class="avatar-frame">
  17. <image class="avatar-img" :src="userInfo.headImage || '/static/avatar.png'" mode="aspectFill" />
  18. </view>
  19. <view class="nickname">{{ userInfo.nickName || '用户' }}</view>
  20. </view> -->
  21. <!-- 二维码区 -->
  22. <view class="qrcode-modal-section">
  23. <image class="qrcode-img" :src="qrcodeUrl" mode="widthFix" />
  24. <!-- <view class="invite-code">邀请码{{inviteCode}}</view> -->
  25. </view>
  26. <!-- 底部按钮 -->
  27. <view class="bottom-btns-modal">
  28. <button class="btn gray" open-type="share">分享给好友</button>
  29. <button class="btn green" @tap="saveToAlbum">保存到本地</button>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
  36. import config from '@/config.js'
  37. import navbar from '@/compoent/base/navbar.vue'
  38. export default {
  39. components : {
  40. navbar
  41. },
  42. mixins: [pullRefreshMixin],
  43. data() {
  44. return {
  45. userInfo: {},
  46. qrcodeUrl: '/static/qrcode.png',
  47. inviteCode: '888888',
  48. }
  49. },
  50. onLoad() {
  51. // 获取用户信息和二维码
  52. this.fetchUserInfo()
  53. this.getQrcode()
  54. },
  55. // 微信小程序分享配置
  56. // #ifdef MP-WEIXIN
  57. onShareAppMessage() {
  58. return {
  59. title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收`,
  60. path: `/pages/component/home?shareId=${this.inviteCode}`,
  61. imageUrl: this.qrcodeUrl || '/static/share-default.png'
  62. }
  63. },
  64. onShareTimeline() {
  65. return {
  66. title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收,环保从我做起!`,
  67. query: `shareId=${this.inviteCode}`,
  68. imageUrl: this.qrcodeUrl || '/static/share-default.png'
  69. }
  70. },
  71. // #endif
  72. methods: {
  73. async onRefresh() {
  74. // 模拟刷新数据
  75. await new Promise(resolve => setTimeout(resolve, 1000))
  76. uni.stopPullRefresh()
  77. },
  78. navigateBack() {
  79. uni.navigateBack()
  80. },
  81. // 获取用户信息
  82. fetchUserInfo() {
  83. if (uni.getStorageSync('token')) {
  84. this.$api("getUserByToken", {}, (res) => {
  85. if (res.code == 200) {
  86. this.userInfo = res.result
  87. // 更新邀请码
  88. if (res.result.intentioCode) {
  89. this.inviteCode = res.result.intentioCode
  90. }
  91. }
  92. })
  93. }
  94. },
  95. getQrcode() {
  96. // 获取全局二维码路径
  97. if (getApp().globalData.qr_path) {
  98. console.log('获取到二维码路径', getApp().globalData.qr_path)
  99. this.qrcodeUrl = getApp().globalData.qr_path
  100. } else {
  101. console.log('全局二维码路径不存在')
  102. uni.showLoading({
  103. title: '拼命绘画中...'
  104. })
  105. uni.getImageInfo({
  106. src: `${config.baseUrl}/recycle-admin/applet/promotion/getInviteCode?token=${uni.getStorageSync('token')}`,
  107. success: res => {
  108. console.log(res);
  109. getApp().globalData.qr_path = res.path
  110. console.log(getApp().globalData.qr_path, 'qr_path')
  111. this.qrcodeUrl = res.path
  112. },
  113. fail: err => {
  114. console.log('QR code load failed:', err)
  115. },
  116. complete() {
  117. uni.hideLoading()
  118. }
  119. })
  120. }
  121. },
  122. // 保存到手机相册
  123. saveToAlbum() {
  124. if (!this.qrcodeUrl) {
  125. uni.showToast({
  126. title: '二维码还未加载完成',
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. // 先授权相册权限
  132. uni.getSetting({
  133. success: (res) => {
  134. if (!res.authSetting['scope.writePhotosAlbum']) {
  135. // 没有权限,申请权限
  136. uni.authorize({
  137. scope: 'scope.writePhotosAlbum',
  138. success: () => {
  139. this.doSaveImage()
  140. },
  141. fail: () => {
  142. // 权限被拒绝,引导用户手动开启
  143. uni.showModal({
  144. title: '提示',
  145. content: '需要您授权保存相册权限',
  146. showCancel: false,
  147. success: () => {
  148. uni.openSetting()
  149. }
  150. })
  151. }
  152. })
  153. } else {
  154. // 已有权限,直接保存
  155. this.doSaveImage()
  156. }
  157. }
  158. })
  159. },
  160. // 执行保存图片
  161. doSaveImage() {
  162. uni.saveImageToPhotosAlbum({
  163. filePath: this.qrcodeUrl,
  164. success: () => {
  165. uni.showToast({
  166. title: '保存成功',
  167. icon: 'success'
  168. })
  169. },
  170. fail: (err) => {
  171. console.log('保存失败', err)
  172. uni.showToast({
  173. title: '保存失败',
  174. icon: 'none'
  175. })
  176. }
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .promo-modal-page {
  184. min-height: 100vh;
  185. background: #f8f8f8;
  186. // padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  187. overflow: hidden;
  188. }
  189. .nav-bar {
  190. display: flex;
  191. align-items: center;
  192. height: calc(150rpx + var(--status-bar-height));
  193. padding: 0 32rpx;
  194. padding-top: var(--status-bar-height);
  195. background: #fff;
  196. position: fixed;
  197. top: 0;
  198. left: 0;
  199. right: 0;
  200. z-index: 999;
  201. box-sizing: border-box;
  202. .back {
  203. padding: 20rpx;
  204. margin-left: -20rpx;
  205. }
  206. .title {
  207. flex: 1;
  208. text-align: center;
  209. font-size: 34rpx;
  210. font-weight: 500;
  211. color: #222;
  212. }
  213. }
  214. .content {
  215. // padding: 30rpx 0 0 0;
  216. padding: 20rpx;
  217. // margin-top: calc(150rpx + var(--status-bar-height) + 80rpx);
  218. height: 100%;
  219. display: flex;
  220. flex-direction: column;
  221. align-items: center;
  222. overflow: hidden;
  223. box-sizing: border-box;
  224. .user-info-modal {
  225. display: flex;
  226. flex-direction: column;
  227. align-items: center;
  228. margin-bottom: 48rpx;
  229. .avatar-frame {
  230. width: 104rpx;
  231. height: 104rpx;
  232. border-radius: 10rpx;
  233. overflow: hidden;
  234. background: #f2f2f2;
  235. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.10);
  236. .avatar-img {
  237. width: 104rpx;
  238. height: 104rpx;
  239. object-fit: cover;
  240. display: block;
  241. }
  242. }
  243. .nickname {
  244. margin-top: 24rpx;
  245. font-size: 32rpx;
  246. font-weight: bold;
  247. color: #222;
  248. text-align: center;
  249. }
  250. }
  251. .qrcode-modal-section {
  252. width: 100%;
  253. display: flex;
  254. flex-direction: column;
  255. align-items: center;
  256. margin-bottom: 48rpx;
  257. .qrcode-img {
  258. width: 100%;
  259. height: 100%;
  260. background: #fff;
  261. border-radius: 24rpx;
  262. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  263. }
  264. .invite-code {
  265. margin-top: 32rpx;
  266. font-size: 30rpx;
  267. color: #222;
  268. font-weight: bold;
  269. text-align: center;
  270. }
  271. }
  272. .bottom-btns-modal {
  273. position: fixed;
  274. left: 0;
  275. right: 0;
  276. bottom: 0;
  277. display: flex;
  278. justify-content: space-between;
  279. padding: 24rpx 32rpx calc(env(safe-area-inset-bottom) + 24rpx) 32rpx;
  280. background: #fff;
  281. z-index: 100;
  282. .btn {
  283. flex: 1;
  284. height: 88rpx;
  285. border-radius: 44rpx;
  286. font-size: 32rpx;
  287. font-weight: bold;
  288. margin: 0 12rpx;
  289. border: none;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. &.gray {
  294. background: linear-gradient(90deg, #b2f08d, #39e9d2);
  295. color: #fff;
  296. }
  297. &.green {
  298. background: linear-gradient(90deg, #b2f08d, #39e9d2);
  299. color: #fff;
  300. }
  301. }
  302. }
  303. }
  304. </style>