解决登录显示、首页显示bug
This commit is contained in:
@@ -368,7 +368,7 @@ export default {
|
||||
image: '/static/consumer/receipt.png',
|
||||
statusText: '商品运输中',
|
||||
name: '您有 1 件商品正在配送,请注意查收'
|
||||
} as PendingReceiptGoodsType,
|
||||
} as PendingReceiptGoodsType | null,
|
||||
allOrders: [] as Array<OrderItemType>
|
||||
}
|
||||
},
|
||||
@@ -380,6 +380,7 @@ export default {
|
||||
|
||||
// 监听订单更新事件
|
||||
uni.$on('orderUpdated', this.handleOrderUpdated)
|
||||
uni.$on('authChanged', this.handleAuthChanged)
|
||||
},
|
||||
onShow() {
|
||||
this.refreshData()
|
||||
@@ -387,6 +388,7 @@ export default {
|
||||
onUnload() {
|
||||
// 移除事件监听
|
||||
uni.$off('orderUpdated', this.handleOrderUpdated)
|
||||
uni.$off('authChanged', this.handleAuthChanged)
|
||||
},
|
||||
computed: {
|
||||
filteredOrders(): Array<OrderItemType> {
|
||||
@@ -646,7 +648,61 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
resetGuestProfileState() {
|
||||
this.userInfo = {
|
||||
id: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
nickname: '立即登录',
|
||||
avatar_url: '',
|
||||
gender: 0,
|
||||
user_type: 0,
|
||||
status: 0,
|
||||
created_at: ''
|
||||
} as UserType
|
||||
|
||||
this.userStats = {
|
||||
points: 0,
|
||||
balance: 0,
|
||||
level: 0
|
||||
} as UserStatsType
|
||||
|
||||
this.serviceCounts = {
|
||||
coupons: 0,
|
||||
favorites: 0,
|
||||
unreadMessages: 0
|
||||
} as ServiceCountsType
|
||||
|
||||
this.orderCounts = {
|
||||
total: 0,
|
||||
pending: 0,
|
||||
toship: 0,
|
||||
shipped: 0,
|
||||
review: 0
|
||||
} as OrderCountsType
|
||||
|
||||
this.recentOrders = [] as Array<OrderItemType>
|
||||
this.allOrders = [] as Array<OrderItemType>
|
||||
this.currentOrderTab = 'all'
|
||||
this.pendingReceiptGoods = null
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId === '') {
|
||||
this.orderCounts = {
|
||||
total: 0,
|
||||
pending: 0,
|
||||
toship: 0,
|
||||
shipped: 0,
|
||||
review: 0
|
||||
} as OrderCountsType
|
||||
this.recentOrders = [] as Array<OrderItemType>
|
||||
this.allOrders = [] as Array<OrderItemType>
|
||||
this.pendingReceiptGoods = null
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const orders = await supabaseService.getOrders()
|
||||
|
||||
@@ -740,6 +796,8 @@ export default {
|
||||
statusText: '商品运输中',
|
||||
name: '您有 ' + shipped + ' 件商品正在配送,请注意查收'
|
||||
} as PendingReceiptGoodsType
|
||||
} else {
|
||||
this.pendingReceiptGoods = null
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载订单异常', e)
|
||||
@@ -866,6 +924,12 @@ export default {
|
||||
return 'height:' + this.pageWindowHeight + 'px;min-height:' + this.pageWindowHeight + 'px;'
|
||||
},
|
||||
async loadUserProfile() {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId === '') {
|
||||
this.resetGuestProfileState()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取用户资料
|
||||
const profile = await supabaseService.getUserProfile()
|
||||
@@ -914,14 +978,9 @@ export default {
|
||||
created_at: new Date().toISOString()
|
||||
} as UserType
|
||||
} else {
|
||||
// 如果获取失败(未登录或无档案),尝试获取当前登录ID
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId != null) {
|
||||
this.userInfo.id = userId
|
||||
this.userInfo.nickname = '用户' + userId.substring(0, 4)
|
||||
} else {
|
||||
this.userInfo.nickname = '未登录'
|
||||
}
|
||||
this.resetGuestProfileState()
|
||||
this.userInfo.id = userId
|
||||
this.userInfo.nickname = '用户' + userId.substring(0, 4)
|
||||
}
|
||||
|
||||
// 获取积分和余额(顺序获取,UTS不支持Promise.all数组解构)
|
||||
@@ -983,6 +1042,15 @@ export default {
|
||||
},
|
||||
|
||||
refreshData() {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId === '') {
|
||||
this.resetGuestProfileState()
|
||||
if (!this.recommendInitialized) {
|
||||
this.loadRecommendProducts(true)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 刷新页面数据
|
||||
this.loadUserProfile()
|
||||
this.loadOrders()
|
||||
@@ -993,6 +1061,12 @@ export default {
|
||||
},
|
||||
|
||||
async updateCouponCount() {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId === '') {
|
||||
this.serviceCounts.coupons = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 从 Supabase 获取真实的优惠券数量
|
||||
try {
|
||||
const count = await supabaseService.getUserCouponCount()
|
||||
@@ -1668,6 +1742,32 @@ export default {
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleAuthChanged(data: any) {
|
||||
let payload: UTSJSONObject | null = null
|
||||
|
||||
if (data instanceof UTSJSONObject) {
|
||||
payload = data as UTSJSONObject
|
||||
} else {
|
||||
try {
|
||||
const raw = JSON.stringify(data)
|
||||
if (raw !== '' && raw !== 'null') {
|
||||
payload = JSON.parse(raw) as UTSJSONObject
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[profile] authChanged payload parse failed:', e)
|
||||
}
|
||||
}
|
||||
|
||||
if (payload == null) {
|
||||
return
|
||||
}
|
||||
|
||||
const loggedIn = payload.getBoolean('loggedIn')
|
||||
if (loggedIn === false) {
|
||||
this.resetGuestProfileState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user