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

412 lines
9.1 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
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. <!-- 加载骨架屏 -->
  24. <view v-if="isLoading" class="qrcode-skeleton">
  25. <view class="skeleton-img"></view>
  26. <view class="skeleton-text"></view>
  27. </view>
  28. <!-- 二维码图片 -->
  29. <image
  30. v-else
  31. class="qrcode-img"
  32. :src="qrcodeUrl"
  33. mode="widthFix"
  34. :show-menu-by-longpress="true"
  35. @error="onImageError"
  36. @load="onImageLoad"
  37. />
  38. <view class="invite-code">邀请码{{inviteCode}}</view>
  39. </view>
  40. <!-- 底部按钮 -->
  41. <view class="bottom-btns-modal">
  42. <button class="btn gray" open-type="share">分享给好友</button>
  43. <button class="btn green" @tap="saveToAlbum">保存到本地</button>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
  50. import config from '@/config.js'
  51. import navbar from '@/compoent/base/navbar.vue'
  52. export default {
  53. components : {
  54. navbar
  55. },
  56. mixins: [pullRefreshMixin],
  57. data() {
  58. return {
  59. userInfo: {},
  60. qrcodeUrl: '/static/qrcode.png', // 二维码图片URL
  61. inviteCode: '888888',
  62. isLoading: true, // 加载状态
  63. }
  64. },
  65. onLoad() {
  66. // 获取用户信息和二维码
  67. this.fetchUserInfo()
  68. this.getQrcode()
  69. },
  70. // 微信小程序分享配置
  71. // #ifdef MP-WEIXIN
  72. onShareAppMessage() {
  73. return {
  74. title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收`,
  75. path: `/pages/component/home?shareId=${this.inviteCode}`,
  76. imageUrl: this.qrcodeUrl || '/static/share-default.png'
  77. }
  78. },
  79. onShareTimeline() {
  80. return {
  81. title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收,环保从我做起!`,
  82. query: `shareId=${this.inviteCode}`,
  83. imageUrl: this.qrcodeUrl || '/static/share-default.png'
  84. }
  85. },
  86. // #endif
  87. methods: {
  88. async onRefresh() {
  89. // 模拟刷新数据
  90. await new Promise(resolve => setTimeout(resolve, 1000))
  91. uni.stopPullRefresh()
  92. },
  93. navigateBack() {
  94. uni.navigateBack()
  95. },
  96. // 获取用户信息
  97. fetchUserInfo() {
  98. if (uni.getStorageSync('token')) {
  99. this.$api("getUserByToken", {}, (res) => {
  100. if (res.code == 200) {
  101. this.userInfo = res.result
  102. // 更新邀请码
  103. if (res.result.intentioCode) {
  104. this.inviteCode = res.result.intentioCode
  105. }
  106. }
  107. })
  108. }
  109. },
  110. getQrcode() {
  111. console.log('调用后端API生成二维码')
  112. uni.showLoading({
  113. title: '生成二维码中...'
  114. })
  115. this.generateQrcode()
  116. },
  117. // 生成二维码
  118. generateQrcode() {
  119. const token = uni.getStorageSync('token')
  120. const qrcodeUrl = `${config.baseUrl}/recycle-admin/applet/promotion/getInviteCode?token=${token}`
  121. console.log('二维码URL:', qrcodeUrl)
  122. // 直接使用网络图片
  123. this.qrcodeUrl = qrcodeUrl
  124. uni.hideLoading()
  125. this.onImageLoad();
  126. // 添加调试日志
  127. console.log('设置二维码URL:', this.qrcodeUrl)
  128. console.log('当前加载状态:', this.isLoading)
  129. },
  130. // 保存到手机相册
  131. saveToAlbum() {
  132. if (!this.qrcodeUrl || this.qrcodeUrl === '/static/qrcode.png') {
  133. uni.showToast({
  134. title: '二维码还未加载完成',
  135. icon: 'none'
  136. })
  137. return
  138. }
  139. // 先下载图片到本地
  140. uni.downloadFile({
  141. url: this.qrcodeUrl,
  142. success: res => {
  143. if (res.statusCode === 200) {
  144. this.saveLocalImage(res.tempFilePath)
  145. } else {
  146. uni.showToast({ title: '下载失败', icon: 'none' })
  147. }
  148. },
  149. fail: err => {
  150. console.log('下载失败:', err)
  151. uni.showToast({ title: '下载失败', icon: 'none' })
  152. }
  153. })
  154. },
  155. // 保存本地图片到相册
  156. saveLocalImage(tempFilePath) {
  157. // 使用新的权限检查方式
  158. uni.getSetting({
  159. success: (res) => {
  160. if (res.authSetting['scope.writePhotosAlbum'] === false) {
  161. // 权限被拒绝,引导用户手动开启
  162. uni.showModal({
  163. title: '提示',
  164. content: '需要您授权保存相册权限,请在设置中开启',
  165. showCancel: false,
  166. success: () => {
  167. uni.openSetting()
  168. }
  169. })
  170. } else {
  171. // 尝试保存,如果没有权限会自动弹出授权框
  172. uni.saveImageToPhotosAlbum({
  173. filePath: tempFilePath,
  174. success: () => {
  175. uni.showToast({
  176. title: '保存成功',
  177. icon: 'success'
  178. })
  179. },
  180. fail: (err) => {
  181. console.log('保存失败', err)
  182. uni.showToast({
  183. title: '保存失败',
  184. icon: 'none'
  185. })
  186. }
  187. })
  188. }
  189. },
  190. fail: () => {
  191. // 直接尝试保存
  192. uni.saveImageToPhotosAlbum({
  193. filePath: tempFilePath,
  194. success: () => {
  195. uni.showToast({
  196. title: '保存成功',
  197. icon: 'success'
  198. })
  199. },
  200. fail: (err) => {
  201. console.log('保存失败', err)
  202. uni.showToast({
  203. title: '保存失败',
  204. icon: 'none'
  205. })
  206. }
  207. })
  208. }
  209. })
  210. },
  211. // 图片加载成功
  212. onImageLoad() {
  213. console.log('二维码图片加载成功')
  214. this.isLoading = false
  215. console.log('加载状态已更新为:', this.isLoading)
  216. },
  217. // 图片加载失败
  218. onImageError() {
  219. console.log('二维码图片加载失败,使用默认图片')
  220. this.qrcodeUrl = '/static/qrcode.png'
  221. this.isLoading = false
  222. console.log('错误处理完成,加载状态:', this.isLoading)
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. .promo-modal-page {
  229. min-height: 100vh;
  230. background: #f8f8f8;
  231. // padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  232. overflow: hidden;
  233. }
  234. .nav-bar {
  235. display: flex;
  236. align-items: center;
  237. height: calc(150rpx + var(--status-bar-height));
  238. padding: 0 32rpx;
  239. padding-top: var(--status-bar-height);
  240. background: #fff;
  241. position: fixed;
  242. top: 0;
  243. left: 0;
  244. right: 0;
  245. z-index: 999;
  246. box-sizing: border-box;
  247. .back {
  248. padding: 20rpx;
  249. margin-left: -20rpx;
  250. }
  251. .title {
  252. flex: 1;
  253. text-align: center;
  254. font-size: 34rpx;
  255. font-weight: 500;
  256. color: #222;
  257. }
  258. }
  259. .content {
  260. // padding: 30rpx 0 0 0;
  261. padding: 20rpx;
  262. // margin-top: calc(150rpx + var(--status-bar-height) + 80rpx);
  263. height: 100%;
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. overflow: hidden;
  268. box-sizing: border-box;
  269. .user-info-modal {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. margin-bottom: 48rpx;
  274. .avatar-frame {
  275. width: 104rpx;
  276. height: 104rpx;
  277. border-radius: 10rpx;
  278. overflow: hidden;
  279. background: #f2f2f2;
  280. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.10);
  281. .avatar-img {
  282. width: 104rpx;
  283. height: 104rpx;
  284. object-fit: cover;
  285. display: block;
  286. }
  287. }
  288. .nickname {
  289. margin-top: 24rpx;
  290. font-size: 32rpx;
  291. font-weight: bold;
  292. color: #222;
  293. text-align: center;
  294. }
  295. }
  296. .qrcode-modal-section {
  297. width: 100%;
  298. display: flex;
  299. flex-direction: column;
  300. align-items: center;
  301. margin-bottom: 48rpx;
  302. .qrcode-img {
  303. width: 100%;
  304. height: 100%;
  305. background: #fff;
  306. border-radius: 24rpx;
  307. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  308. }
  309. /* 骨架屏样式 */
  310. .qrcode-skeleton {
  311. width: 100%;
  312. display: flex;
  313. flex-direction: column;
  314. align-items: center;
  315. }
  316. .skeleton-img {
  317. width: 300rpx;
  318. height: 300rpx;
  319. border-radius: 20rpx;
  320. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  321. background-size: 200% 100%;
  322. animation: skeleton-loading 1.5s infinite;
  323. margin-bottom: 20rpx;
  324. }
  325. .skeleton-text {
  326. width: 200rpx;
  327. height: 32rpx;
  328. border-radius: 16rpx;
  329. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  330. background-size: 200% 100%;
  331. animation: skeleton-loading 1.5s infinite;
  332. }
  333. @keyframes skeleton-loading {
  334. 0% {
  335. background-position: 200% 0;
  336. }
  337. 100% {
  338. background-position: -200% 0;
  339. }
  340. }
  341. .invite-code {
  342. margin-top: 32rpx;
  343. font-size: 30rpx;
  344. color: #222;
  345. font-weight: bold;
  346. text-align: center;
  347. }
  348. }
  349. .bottom-btns-modal {
  350. position: fixed;
  351. left: 0;
  352. right: 0;
  353. bottom: 0;
  354. display: flex;
  355. justify-content: space-between;
  356. padding: 24rpx 32rpx calc(env(safe-area-inset-bottom) + 24rpx) 32rpx;
  357. background: #fff;
  358. z-index: 100;
  359. .btn {
  360. flex: 1;
  361. height: 88rpx;
  362. border-radius: 44rpx;
  363. font-size: 32rpx;
  364. font-weight: bold;
  365. margin: 0 12rpx;
  366. border: none;
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. &.gray {
  371. background: linear-gradient(90deg, #b2f08d, #39e9d2);
  372. color: #fff;
  373. }
  374. &.green {
  375. background: linear-gradient(90deg, #b2f08d, #39e9d2);
  376. color: #fff;
  377. }
  378. }
  379. }
  380. }
  381. </style>