[AI Generated]: feat(*): 完善数据页切换成员、首页接口对接及我的页缓存信息展示
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { get } from '../../utils/request/index'
|
||||
|
||||
/** 加载状态机 */
|
||||
type LoadStatus = 'idle' | 'loading' | 'loaded'
|
||||
|
||||
/** 接口 type 参数:0=全部 1=近7天 2=近30天 3=近3月 */
|
||||
type RangeType = 0 | 1 | 2 | 3
|
||||
|
||||
@@ -69,7 +66,6 @@ function calcAge(birthday: string): number {
|
||||
|
||||
Page({
|
||||
data: {
|
||||
status: 'idle' as LoadStatus,
|
||||
activeType: 1 as RangeType,
|
||||
rangeTabs: [
|
||||
{ key: 1, label: '近7天' },
|
||||
@@ -85,18 +81,19 @@ Page({
|
||||
pageNo: 1,
|
||||
total: 0,
|
||||
hasMore: false,
|
||||
hasData: false,
|
||||
refresherTriggered: false,
|
||||
showSelectDrawer: false,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const raw = wx.getStorageSync('userInfo') as StorageUserInfo | null
|
||||
if (!raw?.userId) return
|
||||
const storedUserId = raw.userId
|
||||
const userInfo: PageUserInfo = {
|
||||
...raw,
|
||||
sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
|
||||
age: calcAge(raw.birthday),
|
||||
isSelf: String(raw.relationType ?? '') === '1',
|
||||
isSelf: raw.userId === storedUserId,
|
||||
}
|
||||
this.setData({ userInfo })
|
||||
this.loadData()
|
||||
@@ -146,12 +143,11 @@ Page({
|
||||
records,
|
||||
total,
|
||||
hasMore: records.length < total,
|
||||
hasData: records.length > 0,
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
this.setData({ status: 'loaded', refresherTriggered: false })
|
||||
this.setData({ refresherTriggered: false })
|
||||
})
|
||||
},
|
||||
|
||||
@@ -213,8 +209,45 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/** 切换成员占位 */
|
||||
/** 打开切换成员抽屉 */
|
||||
onTapSwitchMember() {
|
||||
wx.showToast({ title: '切换成员', icon: 'none' })
|
||||
this.setData({ showSelectDrawer: true })
|
||||
},
|
||||
|
||||
/** 抽屉关闭 */
|
||||
onCloseDrawer() {
|
||||
this.setData({ showSelectDrawer: false })
|
||||
},
|
||||
|
||||
/** 选中成员后更新 userInfo 并重新请求数据 */
|
||||
onSelectMember(e: WechatMiniprogram.CustomEvent) {
|
||||
const m = e.detail as {
|
||||
userId?: string
|
||||
id: string
|
||||
name: string
|
||||
gender: '男' | '女'
|
||||
age: number
|
||||
height: number
|
||||
sex?: number
|
||||
birthday?: string
|
||||
relationType?: number | string | null
|
||||
avatar?: string
|
||||
}
|
||||
const selectedUserId = m.userId ?? m.id
|
||||
const storedUserId = (wx.getStorageSync('userInfo') as StorageUserInfo | null)?.userId ?? ''
|
||||
const userInfo: PageUserInfo = {
|
||||
userId: selectedUserId,
|
||||
realname: m.name,
|
||||
sex: m.sex ?? (m.gender === '男' ? 1 : 2),
|
||||
height: m.height,
|
||||
birthday: m.birthday ?? '',
|
||||
avatar: m.avatar ?? null,
|
||||
relationType: m.relationType ?? null,
|
||||
sex_dictText: m.gender,
|
||||
age: m.age,
|
||||
isSelf: selectedUserId === storedUserId,
|
||||
}
|
||||
this.setData({ showSelectDrawer: false, userInfo })
|
||||
this.loadData()
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user