- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面 - utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传 - 新增 utils/sse.ts 与 utils/wx-session.ts - 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶 - AGENTS.md 补充功能对接状态与小程序 UI 约定
151 lines
4.3 KiB
TypeScript
151 lines
4.3 KiB
TypeScript
import type { DevicePolicy } from '../../utils/api'
|
|
import { getDevicePolicy, toggleDevicePolicy } from '../../utils/api'
|
|
import { getDeviceSn } from '../../utils/token'
|
|
|
|
interface PolicyRow {
|
|
field: string
|
|
label: string
|
|
checked: boolean
|
|
}
|
|
|
|
interface PolicyGroup {
|
|
title: string
|
|
items: PolicyRow[]
|
|
}
|
|
|
|
/** 与 Flutter system_settings_page.dart 一致的策略分组,field 对应后台 DevicePolicy 字段名 */
|
|
const GROUPS: Array<{ title: string; items: Array<[string, string]> }> = [
|
|
{
|
|
title: '网络',
|
|
items: [
|
|
['wifiHotspot', 'WiFi热点'],
|
|
['bluetooth', '蓝牙开关'],
|
|
['bluetoothSharing', '蓝牙对外分享'],
|
|
['toggleAirplaneMode', '飞行模式'],
|
|
['modifyMobileApn', '修改移动网络/APN'],
|
|
['resetNetworkSettings', '重置网络设置']
|
|
]
|
|
},
|
|
{
|
|
title: '显示',
|
|
items: [
|
|
['wallpaper', '壁纸功能'],
|
|
['notificationBar', '通知栏显示'],
|
|
['statusBarPullDown', '状态栏下拉'],
|
|
['autoRotate', '自动旋转'],
|
|
['autoBrightness', '自动亮度'],
|
|
['manualAdjustBrightness', '手动调亮度'],
|
|
['eyeProtection', '护眼模式'],
|
|
['darkMode', '深色模式'],
|
|
['modifyScreenTimeout', '修改屏幕超时']
|
|
]
|
|
},
|
|
{
|
|
title: '系统',
|
|
items: [
|
|
['timeSetting', '时间设置管控'],
|
|
['manualAdjustTimeZone', '手动调时区'],
|
|
['modifySystemTimeZone', '修改时间与时区'],
|
|
['modifySystemLanguage', '修改系统语言'],
|
|
['systemNavBarShow', '系统导航条显示'],
|
|
['systemNavBarSetting', '系统导航栏设置'],
|
|
['navBarOptions', '导航条选项'],
|
|
['safeBoot', '安全模式'],
|
|
['otaUpgrade', 'OTA升级管控']
|
|
]
|
|
},
|
|
{
|
|
title: '存储与USB',
|
|
items: [
|
|
['usbData', 'USB偏好设置'],
|
|
['usbFileTransfer', 'USB文件传输'],
|
|
['storageCard', '存储卡'],
|
|
['mountPhysicalStorage', '挂载外部存储'],
|
|
['factoryReset', '恢复出厂设置'],
|
|
['adbUsbDebug', 'ADB/USB调试']
|
|
]
|
|
},
|
|
{
|
|
title: '应用与权限',
|
|
items: [
|
|
['installApps', '应用安装'],
|
|
['uninstallApps', '应用卸载'],
|
|
['camera', '摄像头'],
|
|
['modifyLocationSwitch', '修改定位开关'],
|
|
['adjustGlobalVolume', '调节全局音量']
|
|
]
|
|
}
|
|
]
|
|
|
|
Page({
|
|
data: {
|
|
groups: [] as PolicyGroup[],
|
|
loading: false,
|
|
saving: false,
|
|
loaded: false,
|
|
loadError: ''
|
|
},
|
|
|
|
onLoad() {
|
|
void this.loadPolicy()
|
|
},
|
|
|
|
onRetry() {
|
|
void this.loadPolicy()
|
|
},
|
|
|
|
async loadPolicy() {
|
|
const sn = getDeviceSn()
|
|
if (!sn) {
|
|
this.setData({ loaded: false, loadError: '请先在首页选择设备' })
|
|
return
|
|
}
|
|
if (this.data.loading) return
|
|
this.setData({ loading: true, loadError: '' })
|
|
try {
|
|
const policy: DevicePolicy = await getDevicePolicy(sn)
|
|
const checked = (field: string) => Number(policy?.[field]) === 1
|
|
this.setData({
|
|
groups: GROUPS.map((group) => ({
|
|
title: group.title,
|
|
items: group.items.map(([field, label]) => ({ field, label, checked: checked(field) }))
|
|
})),
|
|
loaded: true
|
|
})
|
|
} catch (err) {
|
|
this.setData({
|
|
loaded: false,
|
|
loadError: (err as Error).message || '系统设置加载失败'
|
|
})
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
/** 切换单个策略开关:即时下发 toggle 接口,失败回滚该项状态 */
|
|
async onToggleChange(e: WechatMiniprogram.SwitchChange) {
|
|
const sn = getDeviceSn()
|
|
const { gi, ii } = e.currentTarget.dataset as { gi: number; ii: number }
|
|
const groupIndex = Number(gi)
|
|
const itemIndex = Number(ii)
|
|
const row = this.data.groups[groupIndex]?.items[itemIndex]
|
|
if (!sn || !row || this.data.saving) return
|
|
const value: 0 | 1 = e.detail.value ? 1 : 0
|
|
const path = `groups[${groupIndex}].items[${itemIndex}].checked`
|
|
this.setData({ saving: true, [path]: e.detail.value })
|
|
try {
|
|
await toggleDevicePolicy(sn, row.field, value)
|
|
this.toast('设置已更新')
|
|
} catch (err) {
|
|
this.setData({ [path]: row.checked })
|
|
this.toast((err as Error).message || '设置失败')
|
|
} finally {
|
|
this.setData({ saving: false })
|
|
}
|
|
},
|
|
|
|
toast(title: string) {
|
|
wx.showToast({ title, icon: 'none', duration: 1800 })
|
|
}
|
|
})
|