瀏覽代碼

fix(share): 未登录点分享内容不再弹登录失效 + 新用户注册后绑定推荐人

- 商品/活动详情页未登录时跳过需登录接口(membership/coupon/spec),避免 401 强制跳登录
- user-edit 新用户流程保存后消费 inviteCode 绑定推荐人,修复注册后推荐人丢失
Sisyphus 1 周之前
父節點
當前提交
22b094ba49

+ 6 - 0
cfc-frontend/pages/activity/activity-detail/activity-detail.vue

@@ -355,6 +355,12 @@ export default {
     },
     checkMemberStatus: function() {
       var that = this
+      // 未登录(如从分享链接进入)时跳过会员查询,直接按非会员处理,
+      // 避免 /api/membership/my 返回 401 触发"登录已过期"并强制跳登录页
+      if (!uni.getStorageSync('token')) {
+        that.isMember = false
+        return
+      }
       getMyMembership().then(function(res) {
         if (res.data && res.data.memberLevel) {
           that.isMember = res.data.memberLevel !== 'FREE'

+ 13 - 0
cfc-frontend/pages/discover-detail/product-detail/product-detail.vue

@@ -340,6 +340,13 @@ export default {
   methods: {
     loadMembership: function() {
       var that = this
+      // 未登录(如从分享链接进入)时跳过会员查询,直接按非会员处理,
+      // 避免 /api/membership/my 返回 401 触发"登录已过期"并强制跳登录页
+      if (!uni.getStorageSync('token')) {
+        that.isMember = false
+        that.memberLevel = 'FREE'
+        return
+      }
       getMyMembership().then(function(res) {
         if (res && res.code === 200 && res.data) {
           var lvl = res.data.memberLevel || 'FREE'
@@ -395,6 +402,9 @@ export default {
     },
     loadSkuData: function(productId) {
       var that = this
+      // 未登录(如从分享链接进入)时跳过 SKU 规格查询,避免 /api/product/spec/map 返回 401
+      // 触发"登录已过期"并强制跳登录页;SKU 选择是购买流程功能,未登录无需加载
+      if (!uni.getStorageSync('token')) return
       productSpecMap({ productIds: [parseInt(productId)] }).then(function(res) {
         if (res.code === 200 && res.data) {
           var map = res.data
@@ -415,6 +425,9 @@ export default {
       if (that.product && that.product.price && that.product.pointsMultiplier) {
         that.cfEarnedValue = Math.floor(that.product.price / 100) * that.product.pointsMultiplier;
       }
+      // 未登录(如从分享链接进入)时跳过优惠券查询,避免 /api/coupon/product 返回 401
+      // 触发"登录已过期"并强制跳登录页;优惠券兑换是登录用户功能,未登录无需展示
+      if (!uni.getStorageSync('token')) return
       getProductCoupons({ productId: productId }).then(function(res) {
         if (res.code === 200) {
           that.productCoupons = res.data || []

+ 20 - 1
cfc-frontend/pages/user-edit/user-edit.vue

@@ -315,7 +315,7 @@
 </template>
 
 <script>
-import { updateUserInfo, createFamily, directRegister, getUserInfo, requestJoinByCode, getMyMembership } from '../../utils/api.js'
+import { updateUserInfo, createFamily, directRegister, getUserInfo, requestJoinByCode, getMyMembership, bindReferral } from '../../utils/api.js'
 import config from '@/config.js'
 
 export default {
@@ -936,6 +936,25 @@ export default {
 					console.error('保存 mascot 失败', e)
 				}
 			}
+			// 新用户流程:消费分享者推荐码,绑定推荐人(非 team 类型)
+			// 登录页 completeLogin 在 needsRoleSelect=true 时直接跳本页,跳过了 handleReferralBind,
+			// 因此在此处统一消费 storage 中的 inviteCode,避免推荐人绑定丢失
+			var inviteCode = uni.getStorageSync('inviteCode')
+			var inviteType = uni.getStorageSync('inviteType')
+			if (inviteCode && inviteType !== 'team') {
+				var self = this
+				bindReferral(inviteCode).then(function(res) {
+					if (res && res.code === 200) {
+						console.log('新用户绑定推荐人成功', inviteCode)
+					} else if (res && res.code === 400) {
+						console.log('用户已有推荐人,跳过绑定')
+					}
+				}).catch(function(e) {
+					console.log('新用户绑定推荐人失败', e)
+				})
+			}
+			uni.removeStorageSync('inviteCode')
+			uni.removeStorageSync('inviteType')
 			// 用 switchTab 跳转带底部 TabBar 的首页(行/身/智/心/富)
             // parent-index/child-index 是分包页面(非 TabBar 页),用 navigateTo 会丢失底部 TabBar
 			uni.switchTab({ url: '/pages/index-home/index' })