74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { getMockRecords, calcStats } from '../../mock/data.mock'
|
|
import type { TimeRange, RecordItem, StatsData } from '../../mock/data.mock'
|
|
import type { MemberItem } from '../../mock/member.mock'
|
|
import { mockMembers } from '../../mock/member.mock'
|
|
|
|
/** 加载状态机 */
|
|
type LoadStatus = 'idle' | 'loading' | 'loaded'
|
|
|
|
/** 时间范围 Tab 项 */
|
|
interface RangeTab {
|
|
key: TimeRange
|
|
label: string
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
status: 'idle' as LoadStatus,
|
|
activeRange: '7d' as TimeRange,
|
|
rangeTabs: [
|
|
{ key: '7d', label: '近7天' },
|
|
{ key: '30d', label: '近30天' },
|
|
{ key: '3m', label: '近3月' },
|
|
] as RangeTab[],
|
|
|
|
/** 当前查看的成员(默认本人) */
|
|
currentMember: null as MemberItem | null,
|
|
|
|
stats: null as StatsData | null,
|
|
recordList: [] as RecordItem[],
|
|
},
|
|
|
|
onLoad() {
|
|
// 默认选本人(isSelf=true),后备取第一个
|
|
const members: MemberItem[] = wx.getStorageSync('memberList') || mockMembers
|
|
const self = members.find(m => m.isSelf) || members[0] || null
|
|
this.setData({ currentMember: self })
|
|
this.loadData()
|
|
},
|
|
|
|
onReady() {},
|
|
onShow() {},
|
|
onHide() {},
|
|
onUnload() {},
|
|
onPullDownRefresh() {},
|
|
onReachBottom() {},
|
|
|
|
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
|
return {}
|
|
},
|
|
|
|
/** 加载数据(切 Tab / 切成员 复用同一入口) */
|
|
loadData() {
|
|
this.setData({ status: 'loading' })
|
|
setTimeout(() => {
|
|
const records = getMockRecords(this.data.activeRange)
|
|
const stats = calcStats(records)
|
|
this.setData({ recordList: records, stats, status: 'loaded' })
|
|
}, 300)
|
|
},
|
|
|
|
/** 切换时间范围 Tab */
|
|
onTapRange(e: WechatMiniprogram.TouchEvent) {
|
|
const key = e.currentTarget.dataset.key as TimeRange
|
|
if (key === this.data.activeRange) return
|
|
this.setData({ activeRange: key })
|
|
this.loadData()
|
|
},
|
|
|
|
/** 切换成员 */
|
|
onTapSwitchMember() {
|
|
wx.showToast({ title: '切换成员', icon: 'none' })
|
|
},
|
|
})
|