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

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