解决登录显示、首页显示bug
This commit is contained in:
@@ -50,11 +50,6 @@
|
||||
|
||||
<HomeServiceContent
|
||||
v-else
|
||||
:active-category="activeCategory"
|
||||
:categories="serviceCategories"
|
||||
:entries="serviceEntries"
|
||||
@change-category="handleHeaderCategoryChange"
|
||||
@select-entry="handleServiceEntrySelect"
|
||||
></HomeServiceContent>
|
||||
|
||||
<view class="safe-area" :style="{ height: bottomSafeArea + 88 + 'px' }"></view>
|
||||
@@ -118,49 +113,13 @@ type HeaderModuleItem = {
|
||||
label: string
|
||||
}
|
||||
|
||||
type ServiceHomeCategoryItem = {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
type ServiceEntryItem = {
|
||||
id: string
|
||||
title: string
|
||||
desc: string
|
||||
icon: string
|
||||
tone: string
|
||||
category: string
|
||||
linkText: string
|
||||
route: string
|
||||
}
|
||||
|
||||
const topModules: Array<HeaderModuleItem> = [
|
||||
{ key: 'home', label: '首页' },
|
||||
{ key: 'service', label: '服务' }
|
||||
]
|
||||
|
||||
const serviceCategories: Array<ServiceHomeCategoryItem> = [
|
||||
{ id: 'all', name: '推荐' },
|
||||
{ id: 'nursing', name: '居家护理' },
|
||||
{ id: 'rehab', name: '康复照护' },
|
||||
{ id: 'assist', name: '适老用品' },
|
||||
{ id: 'health', name: '健康管理' },
|
||||
{ id: 'life', name: '生活服务' }
|
||||
]
|
||||
|
||||
const serviceEntries: Array<ServiceEntryItem> = [
|
||||
{ id: 'apply', title: '服务申请', desc: '快速发起上门护理与健康随访申请。', icon: '📝', tone: 'red', category: 'nursing', linkText: '立即申请', route: '/pages/mall/consumer/home-service/apply' },
|
||||
{ id: 'service-home', title: '服务大厅', desc: '查看服务项目、适用对象与预约说明。', icon: '🏠', tone: 'blue', category: 'all', linkText: '查看大厅', route: '/pages/mall/consumer/home-service/index' },
|
||||
{ id: 'progress', title: '服务进度', desc: '追踪评估、方案、执行和验收节点。', icon: '📍', tone: 'green', category: 'health', linkText: '查看工单', route: '/pages/mall/consumer/home-service/order-detail?id=case-001' },
|
||||
{ id: 'assessment', title: '上门评估', desc: '了解评估前准备事项和风险核对重点。', icon: '🩺', tone: 'blue', category: 'rehab', linkText: '查看说明', route: '/pages/mall/consumer/home-service/assessment?id=case-001' },
|
||||
{ id: 'plan', title: '服务方案', desc: '查看护理频次、服务周期和执行建议。', icon: '📋', tone: 'green', category: 'rehab', linkText: '方案说明', route: '/pages/mall/consumer/home-service/service-plan?id=case-001' },
|
||||
{ id: 'execution', title: '上门执行', desc: '同步执行记录、签到留痕与异常处理。', icon: '🚪', tone: 'orange', category: 'life', linkText: '查看进展', route: '/pages/mall/consumer/home-service/order-detail?id=case-002' },
|
||||
{ id: 'feedback', title: '验收反馈', desc: '服务完成后提交验收意见和满意度反馈。', icon: '✅', tone: 'red', category: 'nursing', linkText: '去反馈', route: '/pages/mall/consumer/home-service/feedback?id=case-001' },
|
||||
{ id: 'settlement', title: '结算归档', desc: '查看归档说明、账单结果和服务闭环。', icon: '🗂️', tone: 'green', category: 'assist', linkText: '查看说明', route: '/pages/mall/consumer/home-service/settlement-archive?id=case-001' }
|
||||
]
|
||||
|
||||
const headerCategories = computed((): Array<ServiceHomeCategoryItem | CategoryItem> => {
|
||||
return activeTopModule.value == 'home' ? categoryList.value : serviceCategories
|
||||
const headerCategories = computed((): Array<CategoryItem> => {
|
||||
return categoryList.value
|
||||
})
|
||||
|
||||
const headerSearchPlaceholder = computed((): string => {
|
||||
@@ -337,7 +296,7 @@ function handleTopModuleChange(moduleKey: string) {
|
||||
if (moduleKey == 'home') {
|
||||
activeCategory.value = currentCategory.value
|
||||
} else {
|
||||
activeCategory.value = serviceCategories.length > 0 ? serviceCategories[0].id : 'all'
|
||||
activeCategory.value = 'all'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,14 +310,6 @@ function handleHeaderCategoryChange(categoryId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleServiceEntrySelect(entry: ServiceEntryItem) {
|
||||
if (entry.route == '') {
|
||||
uni.showToast({ title: '该入口下一步补页面', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.navigateTo({ url: entry.route })
|
||||
}
|
||||
|
||||
function handleMainScrollToLower() {
|
||||
if (activeTopModule.value == 'home') {
|
||||
void loadMore()
|
||||
@@ -1208,7 +1159,7 @@ const searchByKeyword = (keyword: string): void => {
|
||||
// 初始化数据
|
||||
const initData = async () => {
|
||||
logSupaConfig()
|
||||
console.log('[IndexInit] 准备加载首页数据,确认当前请求将使用上述 SUPA_URL')
|
||||
console.log('[consumer-db] 首页开始加载数据')
|
||||
// 首先确保用户资料已加载
|
||||
try {
|
||||
await getCurrentUser()
|
||||
|
||||
@@ -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