爱简收旧衣按件回收前端代码仓库
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.

312 lines
6.7 KiB

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