重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userApi = require('../../api/user')
|
||||
/**
|
||||
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const navigation = require('../../utils/navigation')
|
||||
|
||||
/**
|
||||
* Purpose: money supports index.js by holding or executing the money page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function money(value) {
|
||||
return Number(value || 0).toFixed(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formatTime supports index.js by holding or executing the format time page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function formatTime(value) {
|
||||
return value ? String(value).replace('T', ' ').slice(0, 16) : '--'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sceneText supports index.js by holding or executing the scene text page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function sceneText(scene) {
|
||||
const map = {
|
||||
MANUAL_RECHARGE: '手工充值',
|
||||
MANUAL_DEDUCT: '手工扣减',
|
||||
ORDER_PAY: '订单消费',
|
||||
ORDER_REFUND: '订单退款',
|
||||
RECHARGE: '充值',
|
||||
CONSUME: '消费'
|
||||
}
|
||||
return map[scene] || scene || '余额变动'
|
||||
}
|
||||
|
||||
/**
|
||||
* vip-center page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
/**
|
||||
* Purpose: data supports index.js by holding or executing the data page or API role.
|
||||
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
data: {
|
||||
/**
|
||||
* Purpose: asset supports index.js by holding or executing the asset page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
asset: {
|
||||
/**
|
||||
* Purpose: vipLevel supports index.js by holding or executing the vip level page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
vipLevel: '普通',
|
||||
/**
|
||||
* Purpose: balanceText supports index.js by holding or executing the balance text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
balanceText: '0.00',
|
||||
/**
|
||||
* Purpose: totalRechargeText supports index.js by holding or executing the total recharge text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
totalRechargeText: '0.00',
|
||||
/**
|
||||
* Purpose: lastRechargeText supports index.js by holding or executing the last recharge text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
lastRechargeText: '--',
|
||||
/**
|
||||
* Purpose: vipStartText supports index.js by holding or executing the vip start text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
vipStartText: '--',
|
||||
/**
|
||||
* Purpose: manualOverride supports index.js by holding or executing the manual override page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
manualOverride: false
|
||||
},
|
||||
/**
|
||||
* Purpose: history supports index.js by holding or executing the history page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
history: [],
|
||||
/**
|
||||
* Purpose: rechargePlans supports index.js by holding or executing the recharge plans page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
rechargePlans: [],
|
||||
/**
|
||||
* Purpose: rechargePanelVisible supports index.js by holding or executing the recharge panel visible page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
rechargePanelVisible: false
|
||||
},
|
||||
|
||||
/**
|
||||
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('查看 VIP 中心')) {
|
||||
return
|
||||
}
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
try {
|
||||
const [asset, history, plans] = await Promise.all([
|
||||
userApi.getMyAsset(),
|
||||
userApi.getMyBalanceHistory(),
|
||||
userApi.listMyVipRechargePlans().catch(() => [])
|
||||
])
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: asset supports index.js by holding or executing the asset page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
asset: {
|
||||
...asset,
|
||||
/**
|
||||
* Purpose: balanceText supports index.js by holding or executing the balance text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
balanceText: money(asset && asset.balance),
|
||||
/**
|
||||
* Purpose: totalRechargeText supports index.js by holding or executing the total recharge text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
totalRechargeText: money(asset && asset.totalRechargeAmount),
|
||||
/**
|
||||
* Purpose: lastRechargeText supports index.js by holding or executing the last recharge text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
lastRechargeText: formatTime(asset && asset.lastRechargeTime),
|
||||
/**
|
||||
* Purpose: vipStartText supports index.js by holding or executing the vip start text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
vipStartText: formatTime(asset && asset.vipStartTime)
|
||||
},
|
||||
/**
|
||||
* Purpose: history supports index.js by holding or executing the history page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
history: (Array.isArray(history) ? history : []).map(item => {
|
||||
const amountNumber = Number(item.amount || 0)
|
||||
return {
|
||||
...item,
|
||||
amountNumber,
|
||||
/**
|
||||
* Purpose: amountText supports index.js by holding or executing the amount text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
amountText: `${amountNumber > 0 ? '+' : ''}¥${money(amountNumber)}`,
|
||||
/**
|
||||
* Purpose: sceneText supports index.js by holding or executing the scene text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
sceneText: sceneText(item.changeScene || item.type),
|
||||
/**
|
||||
* Purpose: changeTimeText supports index.js by holding or executing the change time text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
changeTimeText: formatTime(item.changeTime)
|
||||
}
|
||||
}),
|
||||
/**
|
||||
* Purpose: rechargePlans supports index.js by holding or executing the recharge plans page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
rechargePlans: (Array.isArray(plans) ? plans : []).map(item => ({
|
||||
...item,
|
||||
/**
|
||||
* Purpose: amountText supports index.js by holding or executing the amount text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
amountText: `充 ${money(item.rechargeAmount)} 送 ${money(item.giftAmount)}`
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
/**
|
||||
* Purpose: title supports index.js by holding or executing the title page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
title: error.message || 'VIP 信息加载失败',
|
||||
/**
|
||||
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `openRechargePanel` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
openRechargePanel() {
|
||||
this.setData({ rechargePanelVisible: true })
|
||||
},
|
||||
|
||||
/**
|
||||
* `closeRechargePanel` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
closeRechargePanel() {
|
||||
this.setData({ rechargePanelVisible: false })
|
||||
},
|
||||
|
||||
/**
|
||||
* `noop` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
noop() {
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user