consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题

This commit is contained in:
cyh666666
2026-02-27 08:20:43 +08:00
parent e606c597ca
commit b9acce6c35
1554 changed files with 23471 additions and 8551 deletions

View File

@@ -263,6 +263,7 @@ type OrderCountsType = {
pending: number
toship: number
shipped: number
review: number
}
type ServiceCountsType = {
@@ -306,7 +307,8 @@ export default {
pending: 0,
toship: 0,
shipped: 0,
} as any,
review: 0
} as OrderCountsType,
serviceCounts: {
coupons: 0,
favorites: 0
@@ -346,20 +348,32 @@ export default {
uni.$off('orderUpdated', this.handleOrderUpdated)
},
computed: {
// 根据当前Tab筛选订单
filteredOrders(): Array<OrderType> {
const result: Array<OrderType> = []
if (this.currentOrderTab === 'all') {
return this.allOrders
} else if (this.currentOrderTab === 'pending') {
return this.allOrders.filter((order: OrderType): boolean => order.status === 1)
} else if (this.currentOrderTab === 'toship') {
return this.allOrders.filter((order: OrderType): boolean => order.status === 2)
} else if (this.currentOrderTab === 'shipped') {
return this.allOrders.filter((order: OrderType): boolean => order.status === 3)
} else if (this.currentOrderTab === 'review') {
return this.allOrders.filter((order: OrderType): boolean => order.status === 4)
for (let i: number = 0; i < this.allOrders.length; i++) {
result.push(this.allOrders[i])
}
return result
}
return []
let targetStatus: number = 0
if (this.currentOrderTab === 'pending') {
targetStatus = 1
} else if (this.currentOrderTab === 'toship') {
targetStatus = 2
} else if (this.currentOrderTab === 'shipped') {
targetStatus = 3
} else if (this.currentOrderTab === 'review') {
targetStatus = 4
} else {
return result
}
for (let i: number = 0; i < this.allOrders.length; i++) {
if (this.allOrders[i].status === targetStatus) {
result.push(this.allOrders[i])
}
}
return result
}
},
methods: {
@@ -368,38 +382,70 @@ export default {
try {
const orders = await supabaseService.getOrders()
// 映射数据库字段到前端类型
this.allOrders = orders.map((o: any): OrderType => {
// 确保 status 字段存在
if (o['status'] == null && o['order_status'] != null) {
o['status'] = o['order_status']
}
// 确保 actual_amount 存在
if (o['actual_amount'] == null && o['total_amount'] != null) {
o['actual_amount'] = o['total_amount']
}
return o as OrderType
})
const mappedOrders: Array<OrderType> = []
for (let i: number = 0; i < orders.length; i++) {
const o = orders[i] as UTSJSONObject
const orderObj = new UTSJSONObject()
const keys = UTSJSONObject.keys(o)
for (let j: number = 0; j < keys.length; j++) {
const key = keys[j]
orderObj.set(key, o.get(key))
}
if (o.getNumber('status') == null && o.getNumber('order_status') != null) {
orderObj.set('status', o.getNumber('order_status'))
}
if (o.getNumber('actual_amount') == null && o.getNumber('total_amount') != null) {
orderObj.set('actual_amount', o.getNumber('total_amount'))
}
mappedOrders.push(orderObj as OrderType)
}
// 按时间倒序 (created_at)
this.allOrders.sort((a: any, b: any) => {
const dateA = a['created_at']
const dateB = b['created_at']
const timeA = new Date(dateA != null ? dateA : 0).getTime()
const timeB = new Date(dateB != null ? dateB : 0).getTime()
return timeB - timeA
})
for (let i: number = 0; i < mappedOrders.length; i++) {
for (let j: number = i + 1; j < mappedOrders.length; j++) {
const dateA = mappedOrders[i]['created_at'] as string
const dateB = mappedOrders[j]['created_at'] as string
const timeA = new Date(dateA != null ? dateA : '1970-01-01').getTime()
const timeB = new Date(dateB != null ? dateB : '1970-01-01').getTime()
if (timeA < timeB) {
const temp = mappedOrders[i]
mappedOrders[i] = mappedOrders[j]
mappedOrders[j] = temp
}
}
}
// 过滤最近的订单
this.recentOrders = this.allOrders.slice(0, 5)
this.allOrders = mappedOrders
const recentList: Array<OrderType> = []
const limit = mappedOrders.length < 5 ? mappedOrders.length : 5
for (let i: number = 0; i < limit; i++) {
recentList.push(mappedOrders[i])
}
this.recentOrders = recentList
let total = 0
let pending = 0
let toship = 0
let shipped = 0
let review = 0
for (let i: number = 0; i < mappedOrders.length; i++) {
total++
const status = mappedOrders[i].status
if (status === 1) pending++
else if (status === 2) toship++
else if (status === 3) shipped++
else if (status === 4) review++
}
// 更新角标统计 (确保状态码一致: 1=待支付, 2=待发货, 3=待收货, 4=待评价)
this.orderCounts = {
total: this.allOrders.length,
pending: this.allOrders.filter((o: any) => o.status === 1).length,
toship: this.allOrders.filter((o: any) => o.status === 2).length,
shipped: this.allOrders.filter((o: any) => o.status === 3).length,
review: this.allOrders.filter((o: any) => o.status === 4).length
total: total,
pending: pending,
toship: toship,
shipped: shipped,
review: review
}
} catch (e) {
console.error('加载订单异常', e)
@@ -413,14 +459,11 @@ export default {
// 获取当前订单部分标题
getOrderSectionTitle(): string {
const titles: Record<string, string> = {
'all': '全部订单',
'pending': '待支付订单',
'shipped': '待收货订单',
'review': '待评价订单'
}
const title = titles[this.currentOrderTab]
return title != null ? title : '我的订单'
if (this.currentOrderTab === 'all') return '全部订单'
if (this.currentOrderTab === 'pending') return '待支付订单'
if (this.currentOrderTab === 'shipped') return '待收货订单'
if (this.currentOrderTab === 'review') return '待评价订单'
return '我的订单'
},
initPage() {
@@ -448,16 +491,16 @@ export default {
uAvatar = profile.getString('avatar_url') ?? ''
uGender = profile.getNumber('gender') ?? 0
} else {
uId = (profile['user_id'] as string) ?? ''
uPhone = (profile['phone'] as string) ?? ''
uEmail = (profile['email'] as string) ?? ''
uNickname = (profile['nickname'] as string) ?? ''
uAvatar = (profile['avatar_url'] as string) ?? ''
uGender = (profile['gender'] as number) ?? 0
const profileObj = profile as UTSJSONObject
uId = (profileObj.getString('user_id') ?? '') as string
uPhone = (profileObj.getString('phone') ?? '') as string
uEmail = (profileObj.getString('email') ?? '') as string
uNickname = (profileObj.getString('nickname') ?? '') as string
uAvatar = (profileObj.getString('avatar_url') ?? '') as string
uGender = (profileObj.getNumber('gender') ?? 0) as number
}
// 如果昵称为空,使用手机号脱敏显示
if (!uNickname && uPhone) {
if (uNickname === '' && uPhone !== '') {
uNickname = uPhone.substring(0, 3) + '****' + uPhone.substring(7)
}
@@ -510,35 +553,35 @@ export default {
},
loadConsumptionStats() {
// 模拟加载消费统计数据
const statsData: Record<string, ConsumptionStatsType> = {
month: {
if (this.activeStatsPeriod === 'month') {
this.currentStats = {
total_amount: 1280.50,
order_count: 8,
avg_amount: 160.06,
save_amount: 85.20
},
quarter: {
} as ConsumptionStatsType
} else if (this.activeStatsPeriod === 'quarter') {
this.currentStats = {
total_amount: 3680.80,
order_count: 18,
avg_amount: 204.49,
save_amount: 256.30
},
year: {
} as ConsumptionStatsType
} else if (this.activeStatsPeriod === 'year') {
this.currentStats = {
total_amount: 15680.90,
order_count: 56,
avg_amount: 280.02,
save_amount: 986.50
},
all: {
} as ConsumptionStatsType
} else {
this.currentStats = {
total_amount: 25680.50,
order_count: 89,
avg_amount: 288.55,
save_amount: 1580.20
}
} as ConsumptionStatsType
}
this.currentStats = statsData[this.activeStatsPeriod]
},
refreshData() {
@@ -584,26 +627,29 @@ export default {
},
getOrderMainImage(order: any): string {
// 尝试从 ml_order_items 获取第一张图
const items = order['ml_order_items'] as any[]
if (items != null && items.length > 0) {
const firstItem = items[0]
// 数据库字段通常是 image_url
const imgUrl = firstItem['image_url'] as string
const prodImg = firstItem['product_image'] as string
const img = (imgUrl != null && imgUrl != '') ? imgUrl : prodImg
if (img != null && img != '') return img
const orderObj = order as UTSJSONObject
const itemsRaw = orderObj.get('ml_order_items')
if (itemsRaw == null) return '/static/product1.jpg'
const items = itemsRaw as any[]
if (items.length > 0) {
const firstItem = items[0] as UTSJSONObject
const imgUrl = firstItem.getString('image_url') ?? ''
const prodImg = firstItem.getString('product_image') ?? ''
const img = imgUrl !== '' ? imgUrl : prodImg
if (img !== '') return img
}
return '/static/product1.jpg'
},
getOrderTitle(order: any): string {
const items = order['ml_order_items'] as any[]
if (items != null && items.length > 0) {
const firstItem = items[0]
const pName = firstItem['product_name'] as string
const name = (pName != null && pName != '') ? pName : '商品'
const orderObj = order as UTSJSONObject
const itemsRaw = orderObj.get('ml_order_items')
if (itemsRaw == null) return '精选商品'
const items = itemsRaw as any[]
if (items.length > 0) {
const firstItem = items[0] as UTSJSONObject
const pName = firstItem.getString('product_name') ?? ''
const name = pName !== '' ? pName : '商品'
if (items.length > 1) {
return `${name} 等${items.length}件商品`
@@ -780,19 +826,18 @@ export default {
})
},
// 处理订单更新事件
handleOrderUpdated(data: any) {
// 当收到订单更新事件时,刷新订单数据
console.log('收到订单更新事件:', data)
this.refreshData()
// 显示提示
if (data.status === 1) {
const dataObj = data as UTSJSONObject
const status = dataObj.getNumber('status')
if (status === 1) {
uni.showToast({
title: '订单已保存到待支付',
icon: 'success'
})
} else if (data.status === 2) {
} else if (status === 2) {
uni.showToast({
title: '支付成功,订单待发货',
icon: 'success'