- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面 - utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传 - 新增 utils/sse.ts 与 utils/wx-session.ts - 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶 - AGENTS.md 补充功能对接状态与小程序 UI 约定
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import type { Profile } from '../../utils/api'
|
|
import { getProfile } from '../../utils/api'
|
|
import { ensureLogin, logout } from '../../utils/auth'
|
|
import { getCachedProfile, saveProfile } from '../../utils/token'
|
|
import { syncTabBar } from '../../utils/tab-bar'
|
|
import { resetWxSession } from '../../utils/wx-session'
|
|
|
|
interface MenuItem {
|
|
key: string
|
|
label: string
|
|
url: string
|
|
}
|
|
|
|
const ROUTES: Record<string, string> = {
|
|
account: '/pages/account-security/index',
|
|
devices: '/pages/device-manager/index',
|
|
notify: '/pages/info/index?type=notify',
|
|
family: '/pages/info/index?type=family',
|
|
about: '/pages/info/index?type=about'
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
loggedIn: false,
|
|
nickname: '未登录',
|
|
subtitle: '登录后可同步设备与家人',
|
|
avatar: '',
|
|
items: [
|
|
{ key: 'account', label: '账号与安全', url: ROUTES.account },
|
|
{ key: 'devices', label: '设备管理', url: ROUTES.devices },
|
|
{ key: 'notify', label: '通知设置', url: ROUTES.notify },
|
|
{ key: 'family', label: '家庭成员', url: ROUTES.family },
|
|
{ key: 'about', label: '关于同同关怀', url: ROUTES.about }
|
|
] as MenuItem[]
|
|
},
|
|
|
|
onShow() {
|
|
syncTabBar(this, 2)
|
|
if (!ensureLogin()) return
|
|
|
|
this.setData({ loggedIn: true })
|
|
// 先渲染缓存,避免每次进入都闪一下「未登录」
|
|
const cached = getCachedProfile<Profile>()
|
|
if (cached) {
|
|
this.renderProfile(cached)
|
|
}
|
|
this.loadProfile()
|
|
},
|
|
|
|
async loadProfile() {
|
|
try {
|
|
const profile = await getProfile()
|
|
saveProfile(profile)
|
|
this.renderProfile(profile)
|
|
} catch (err) {
|
|
this.toast((err as Error).message || '资料加载失败')
|
|
}
|
|
},
|
|
|
|
renderProfile(profile: Profile) {
|
|
this.setData({
|
|
nickname: profile.nickname || profile.username || '家属用户',
|
|
subtitle: profile.signature || '已登录',
|
|
avatar: profile.avatar || ''
|
|
})
|
|
},
|
|
|
|
onLogin() {
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
},
|
|
|
|
onLogout() {
|
|
wx.showModal({
|
|
title: '退出登录',
|
|
content: '确定退出当前账号吗?',
|
|
confirmText: '退出',
|
|
confirmColor: '#EF4444',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
logout()
|
|
resetWxSession()
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
onEditProfile() {
|
|
wx.navigateTo({ url: '/pages/profile-edit/index' })
|
|
},
|
|
|
|
onTap(e: WechatMiniprogram.TouchEvent) {
|
|
const { url } = e.currentTarget.dataset as { url: string }
|
|
if (!url) return
|
|
wx.navigateTo({ url })
|
|
},
|
|
|
|
toast(title: string) {
|
|
wx.showToast({ title, icon: 'none', duration: 1800 })
|
|
}
|
|
})
|