Files
ttstd_family_care_miniapp/pages/apps/index.ts
T
tongtong 9030938c84 feat(miniapp): 补齐设备功能页面与统一 UI 规范
- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面
- utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传
- 新增 utils/sse.ts 与 utils/wx-session.ts
- 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶
- AGENTS.md 补充功能对接状态与小程序 UI 约定
2026-11-28 18:19:19 +08:00

82 lines
2.2 KiB
TypeScript

import type { DeviceApp } from '../../utils/api'
import { clearAppData, launchApp, listDeviceApps, stopApp, uninstallApp } from '../../utils/api'
import { getDeviceSn } from '../../utils/token'
Page({
data: {
apps: [] as DeviceApp[]
},
onShow() {
this.load()
},
async load() {
const sn = getDeviceSn()
if (!sn) {
this.toast('请先选择设备')
return
}
wx.showLoading({ title: '读取应用' })
try {
this.setData({ apps: await listDeviceApps(sn) })
} catch (err) {
this.toast((err as Error).message || '应用列表加载失败')
} finally {
wx.hideLoading()
}
},
onAction(e: WechatMiniprogram.TouchEvent) {
const { packageName, appName } = e.currentTarget.dataset as {
packageName: string
appName: string
}
const sn = getDeviceSn()
if (!sn || !packageName) return
wx.showActionSheet({
itemList: ['启动应用', '停止应用', '清除数据', '卸载应用'],
success: (res) => {
const actions = [launchApp, stopApp, clearAppData, uninstallApp]
const action = actions[res.tapIndex]
if (!action) return
const labels = ['启动', '停止', '清除数据', '卸载']
if (res.tapIndex === 3) {
wx.showModal({
title: '卸载应用',
content: `确定卸载「${appName || packageName}」吗?`,
confirmColor: '#EF4444',
success: (confirm) => {
if (confirm.confirm) void this.run(action, sn, packageName, labels[res.tapIndex])
}
})
return
}
void this.run(action, sn, packageName, labels[res.tapIndex])
}
})
},
async run(
action: (sn: string, packageName: string) => Promise<boolean>,
sn: string,
packageName: string,
label: string
) {
wx.showLoading({ title: '处理中' })
try {
await action(sn, packageName)
wx.hideLoading()
this.toast(`${label}指令已下发`)
if (label === '卸载') setTimeout(() => this.load(), 1000)
} catch (err) {
wx.hideLoading()
this.toast((err as Error).message || `${label}失败`)
}
},
toast(title: string) {
wx.showToast({ title, icon: 'none', duration: 1800 })
}
})