- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面 - utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传 - 新增 utils/sse.ts 与 utils/wx-session.ts - 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶 - AGENTS.md 补充功能对接状态与小程序 UI 约定
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { deleteClientFile, transferFile, uploadClientFile } from '../../utils/api'
|
|
import { getDeviceSn } from '../../utils/token'
|
|
|
|
interface FileItem {
|
|
key: string
|
|
name: string
|
|
url: string
|
|
size: string
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
files: [] as FileItem[]
|
|
},
|
|
|
|
onChooseFile() {
|
|
wx.chooseMessageFile({
|
|
count: 1,
|
|
type: 'file',
|
|
success: (res) => {
|
|
const file = res.tempFiles[0]
|
|
if (!file) return
|
|
wx.showLoading({ title: '上传中' })
|
|
void uploadClientFile(file.path)
|
|
.then((info) => {
|
|
wx.hideLoading()
|
|
const item: FileItem = {
|
|
key: info.url || file.path,
|
|
name: info.name || file.name || '未命名文件',
|
|
url: info.url || '',
|
|
size: `${Math.round(file.size / 1024)} KB`
|
|
}
|
|
this.setData({ files: [item, ...this.data.files] })
|
|
this.toast('文件已上传')
|
|
})
|
|
.catch((err: Error) => {
|
|
wx.hideLoading()
|
|
this.toast(err.message || '上传失败')
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
onTransfer() {
|
|
const sn = getDeviceSn()
|
|
if (!sn) {
|
|
this.toast('请先选择设备')
|
|
return
|
|
}
|
|
void transferFile(sn)
|
|
.then(() => this.toast('文件传输指令已下发'))
|
|
.catch((err: Error) => this.toast(err.message || '下发失败'))
|
|
},
|
|
|
|
onDelete(e: WechatMiniprogram.TouchEvent) {
|
|
const { url } = e.currentTarget.dataset as { url: string }
|
|
if (!url) {
|
|
this.toast('该文件没有可删除的服务端路径')
|
|
return
|
|
}
|
|
void deleteClientFile(url)
|
|
.then(() => {
|
|
this.setData({ files: this.data.files.filter((item) => item.url !== url) })
|
|
this.toast('已删除')
|
|
})
|
|
.catch((err: Error) => this.toast(err.message || '删除失败'))
|
|
},
|
|
|
|
toast(title: string) {
|
|
wx.showToast({ title, icon: 'none', duration: 1800 })
|
|
}
|
|
})
|