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

313 lines
7.2 KiB

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