consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题
This commit is contained in:
@@ -84,7 +84,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="transactions.length === 0 && !isLoading" class="empty-transactions">
|
||||
<view v-if="transactions.length === 0 && isLoading === false" class="empty-transactions">
|
||||
<text class="empty-icon">💰</text>
|
||||
<text class="empty-text">暂无交易记录</text>
|
||||
<text class="empty-subtext">快去使用钱包功能吧</text>
|
||||
@@ -117,7 +117,7 @@
|
||||
<view v-if="isLoading" class="loading-more">
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
<view v-if="!hasMore && transactions.length > 0" class="no-more">
|
||||
<view v-if="hasMore === false && transactions.length > 0" class="no-more">
|
||||
<text class="no-more-text">没有更多记录了</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -156,7 +156,7 @@
|
||||
<view class="popup-footer">
|
||||
<button class="cancel-btn" @click="closeRechargePopup">取消</button>
|
||||
<button class="confirm-btn"
|
||||
:class="{ disabled: !canRecharge }"
|
||||
:class="{ disabled: canRecharge === false }"
|
||||
@click="confirmRecharge">
|
||||
确认充值
|
||||
</button>
|
||||
@@ -185,8 +185,10 @@ type TransactionType = {
|
||||
id: string
|
||||
user_id: string
|
||||
change_amount: number
|
||||
amount: number
|
||||
current_balance: number
|
||||
change_type: string // 'recharge' | 'consume' | 'withdraw' | 'refund' | 'reward'
|
||||
change_type: string
|
||||
type: string
|
||||
related_id: string | null
|
||||
remark: string | null
|
||||
created_at: string
|
||||
@@ -214,67 +216,41 @@ const showRechargePopup = ref<boolean>(false)
|
||||
const rechargeAmount = ref<string>('')
|
||||
const quickAmounts = [50, 100, 200, 500, 1000]
|
||||
|
||||
// 计算属性
|
||||
const canRecharge = computed(() => {
|
||||
const amount = parseFloat(rechargeAmount.value)
|
||||
return !isNaN(amount) && amount >= 10 && amount <= 5000
|
||||
})
|
||||
|
||||
// 监听过滤器变化
|
||||
watch(activeFilter, () => {
|
||||
resetTransactions()
|
||||
loadTransactions()
|
||||
})
|
||||
|
||||
// 生命周期
|
||||
onShow(() => {
|
||||
loadWalletData()
|
||||
})
|
||||
// 获取当前用户ID
|
||||
const getCurrentUserId = (): string => {
|
||||
const userStore = uni.getStorageSync('userInfo')
|
||||
if (userStore == null) return ''
|
||||
const userInfo = userStore as UTSJSONObject
|
||||
return userInfo.getString('id') ?? ''
|
||||
}
|
||||
|
||||
// 重置交易记录
|
||||
const resetTransactions = () => {
|
||||
const resetTransactions = (): void => {
|
||||
transactions.value = []
|
||||
currentPage.value = 1
|
||||
hasMore.value = true
|
||||
}
|
||||
|
||||
// 加载钱包数据
|
||||
const loadWalletData = async () => {
|
||||
const userId = getCurrentUserId()
|
||||
if (userId == '') {
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/user/login'
|
||||
// })
|
||||
return
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
loadBalance(),
|
||||
loadTransactions()
|
||||
])
|
||||
}
|
||||
|
||||
// 加载余额信息
|
||||
const loadBalance = async () => {
|
||||
const loadBalance = async (): Promise<void> => {
|
||||
try {
|
||||
// 调用 Supabase 服务获取真实余额
|
||||
const realBalance = await supabaseService.getUserBalance()
|
||||
balance.value = realBalance
|
||||
|
||||
// 统计数据暂时保持 mock 或设为 0,因为后端还未实现具体统计接口
|
||||
stats.value = {
|
||||
const statsData: StatsType = {
|
||||
totalRecharge: 0,
|
||||
totalConsume: 0,
|
||||
totalWithdraw: 0
|
||||
}
|
||||
} as StatsType
|
||||
stats.value = statsData
|
||||
} catch (err) {
|
||||
console.error('加载钱包异常:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载交易记录
|
||||
const loadTransactions = async (loadMore: boolean = false) => {
|
||||
if (isLoading.value || (!hasMore.value && loadMore)) {
|
||||
const loadTransactions = async (loadMore: boolean): Promise<void> => {
|
||||
if (isLoading.value || (hasMore.value === false && loadMore)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -290,16 +266,14 @@ const loadTransactions = async (loadMore: boolean = false) => {
|
||||
const page = loadMore ? currentPage.value + 1 : 1
|
||||
const limit = 20
|
||||
|
||||
// 使用 Supabase 获取真实数据
|
||||
// 注意:目前后端接口暂不支持 activeFilter 筛选,会返回所有记录
|
||||
const data = await supabaseService.getTransactions(page, limit)
|
||||
|
||||
const mappedData: TransactionType[] = []
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const mappedData: Array<TransactionType> = []
|
||||
for (let i: number = 0; i < data.length; i++) {
|
||||
const item = data[i]
|
||||
let id = ''
|
||||
let amount = 0
|
||||
let balance = 0
|
||||
let balanceAfter = 0
|
||||
let type = ''
|
||||
let remark = ''
|
||||
let createdAt = ''
|
||||
@@ -307,85 +281,106 @@ const loadTransactions = async (loadMore: boolean = false) => {
|
||||
if (item instanceof UTSJSONObject) {
|
||||
id = item.getString('id') ?? ''
|
||||
amount = item.getNumber('amount') ?? 0
|
||||
balance = item.getNumber('balance_after') ?? 0
|
||||
balanceAfter = item.getNumber('balance_after') ?? 0
|
||||
type = item.getString('type') ?? 'consume'
|
||||
remark = item.getString('description') ?? ''
|
||||
createdAt = item.getString('created_at') ?? ''
|
||||
} else {
|
||||
id = (item['id'] as string) ?? ''
|
||||
amount = (item['amount'] as number) ?? 0
|
||||
balance = (item['balance_after'] as number) ?? 0
|
||||
type = (item['type'] as string) ?? 'consume'
|
||||
remark = (item['description'] as string) ?? ''
|
||||
createdAt = (item['created_at'] as string) ?? ''
|
||||
const itemObj = item as UTSJSONObject
|
||||
id = itemObj.getString('id') ?? ''
|
||||
amount = itemObj.getNumber('amount') ?? 0
|
||||
balanceAfter = itemObj.getNumber('balance_after') ?? 0
|
||||
type = itemObj.getString('type') ?? 'consume'
|
||||
remark = itemObj.getString('description') ?? ''
|
||||
createdAt = itemObj.getString('created_at') ?? ''
|
||||
}
|
||||
|
||||
mappedData.push({
|
||||
const transaction: TransactionType = {
|
||||
id: id,
|
||||
user_id: userId,
|
||||
change_amount: amount,
|
||||
current_balance: balance,
|
||||
amount: amount,
|
||||
current_balance: balanceAfter,
|
||||
change_type: type,
|
||||
type: type,
|
||||
related_id: null,
|
||||
remark: remark,
|
||||
created_at: createdAt
|
||||
})
|
||||
} as TransactionType
|
||||
mappedData.push(transaction)
|
||||
}
|
||||
|
||||
if (loadMore) {
|
||||
for (let i: number = 0; i < mappedData.length; i++) {
|
||||
transactions.value.push(mappedData[i])
|
||||
}
|
||||
currentPage.value = page
|
||||
} else {
|
||||
transactions.value = mappedData
|
||||
currentPage.value = 1
|
||||
}
|
||||
|
||||
hasMore.value = mappedData.length >= limit
|
||||
} catch (err) {
|
||||
console.error('加载交易记录失败:', err)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
if (loadMore) {
|
||||
transactions.value.push(...mappedData)
|
||||
} else {
|
||||
transactions.value = mappedData
|
||||
}
|
||||
|
||||
if (mappedData.length < limit) {
|
||||
hasMore.value = false
|
||||
} else {
|
||||
hasMore.value = true
|
||||
}
|
||||
|
||||
currentPage.value = page
|
||||
} catch (err) {
|
||||
console.error('加载交易记录异常:', err)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
// 加载钱包数据
|
||||
const loadWalletData = async (): Promise<void> => {
|
||||
const userId = getCurrentUserId()
|
||||
if (userId == '') {
|
||||
return
|
||||
}
|
||||
|
||||
loadBalance()
|
||||
loadTransactions(false)
|
||||
}
|
||||
|
||||
// 获取当前用户ID
|
||||
const getCurrentUserId = (): string => {
|
||||
const userStore = uni.getStorageSync('userInfo')
|
||||
return userStore?.getString('id') ?? ''
|
||||
}
|
||||
// 计算属性
|
||||
const canRecharge = computed((): boolean => {
|
||||
const amount = parseFloat(rechargeAmount.value)
|
||||
if (amount == null || amount < 10 || amount > 5000) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
// 监听过滤器变化
|
||||
watch(activeFilter, () => {
|
||||
resetTransactions()
|
||||
loadTransactions(false)
|
||||
})
|
||||
|
||||
// 生命周期
|
||||
onShow(() => {
|
||||
loadWalletData()
|
||||
})
|
||||
|
||||
// 获取交易图标
|
||||
const getTransactionIcon = (type: string): string => {
|
||||
const icons: Record<string, string> = {
|
||||
recharge: '💳',
|
||||
consume: '🛒',
|
||||
withdraw: '🏦',
|
||||
refund: '🔄',
|
||||
reward: '🎁',
|
||||
income: '💰',
|
||||
expense: '📤'
|
||||
}
|
||||
const icon = icons[type]
|
||||
return icon != null ? icon : '💰'
|
||||
if (type === 'recharge') return '💳'
|
||||
if (type === 'consume') return '🛒'
|
||||
if (type === 'withdraw') return '🏦'
|
||||
if (type === 'refund') return '🔄'
|
||||
if (type === 'reward') return '🎁'
|
||||
if (type === 'income') return '💰'
|
||||
if (type === 'expense') return '📤'
|
||||
return '💰'
|
||||
}
|
||||
|
||||
// 获取交易标题
|
||||
const getTransactionTitle = (type: string): string => {
|
||||
const titles: Record<string, string> = {
|
||||
recharge: '账户充值',
|
||||
consume: '商品消费',
|
||||
withdraw: '余额提现',
|
||||
refund: '订单退款',
|
||||
reward: '活动奖励',
|
||||
income: '收入',
|
||||
expense: '支出'
|
||||
}
|
||||
const title = titles[type]
|
||||
return title != null ? title : '交易'
|
||||
if (type === 'recharge') return '账户充值'
|
||||
if (type === 'consume') return '商品消费'
|
||||
if (type === 'withdraw') return '余额提现'
|
||||
if (type === 'refund') return '订单退款'
|
||||
if (type === 'reward') return '活动奖励'
|
||||
if (type === 'income') return '收入'
|
||||
if (type === 'expense') return '支出'
|
||||
return '交易'
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
@@ -471,22 +466,28 @@ const changeFilter = (filter: string) => {
|
||||
|
||||
// 加载更多
|
||||
const loadMore = () => {
|
||||
if (hasMore.value && !isLoading.value) {
|
||||
if (hasMore.value && isLoading.value === false) {
|
||||
loadTransactions(true)
|
||||
}
|
||||
}
|
||||
|
||||
// 选择快捷金额
|
||||
const selectQuickAmount = (amount: number) => {
|
||||
const selectQuickAmount = (amount: number): void => {
|
||||
rechargeAmount.value = amount.toString()
|
||||
}
|
||||
|
||||
// 关闭充值弹窗
|
||||
const closeRechargePopup = (): void => {
|
||||
showRechargePopup.value = false
|
||||
rechargeAmount.value = ''
|
||||
}
|
||||
|
||||
// 确认充值
|
||||
const confirmRecharge = async () => {
|
||||
if (!canRecharge.value) return
|
||||
const confirmRecharge = async (): Promise<void> => {
|
||||
if (canRecharge.value === false) return
|
||||
|
||||
const amount = parseFloat(rechargeAmount.value)
|
||||
if (isNaN(amount)) return
|
||||
if (amount == null || amount < 10 || amount > 5000) return
|
||||
|
||||
uni.showLoading({ title: '处理中...' })
|
||||
try {
|
||||
@@ -497,7 +498,6 @@ const confirmRecharge = async () => {
|
||||
icon: 'success'
|
||||
})
|
||||
closeRechargePopup()
|
||||
// 刷新数据
|
||||
loadWalletData()
|
||||
} else {
|
||||
uni.showToast({
|
||||
@@ -516,14 +516,8 @@ const confirmRecharge = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭充值弹窗
|
||||
const closeRechargePopup = () => {
|
||||
showRechargePopup.value = false
|
||||
rechargeAmount.value = ''
|
||||
}
|
||||
|
||||
// 返回
|
||||
const goBack = () => {
|
||||
const goBack = (): void => {
|
||||
uni.navigateBack()
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user