From b1d91ffc19b95acc8069d1830ff46a607031f39b Mon Sep 17 00:00:00 2001 From: hwj Date: Fri, 6 Feb 2026 14:49:39 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E9=87=87=E9=9B=86=E8=AE=BE?= =?UTF-8?q?=E5=A4=87-=E6=98=AF=E6=88=96=E5=90=A6=E5=88=97=E6=94=B9?= =?UTF-8?q?=E6=88=90switch=E7=BB=84=E4=BB=B6=E5=88=87=E6=8D=A2/=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=AE=BE=E7=BD=AE=E5=BC=B9=E6=A1=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E4=B8=BB=E9=A2=98=E8=BE=93=E5=85=A5=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/device/index.ts | 5 +++++ src/locales/en.ts | 4 +++- src/locales/zh-CN.ts | 4 +++- src/views/iot/device/DeviceForm.vue | 26 +++++++------------------- src/views/iot/device/index.vue | 27 ++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts index 339a517e..c9efd899 100644 --- a/src/api/iot/device/index.ts +++ b/src/api/iot/device/index.ts @@ -145,6 +145,11 @@ export const DeviceApi = { return await request.get({ url: `/iot/device/devicePointList` }) }, + updateDeviceEnabled: async (id: number | string, enabled: string) => { + const data = { id, enabled } + return await request.put({ url: `/iot/device/update-enabled`, data }) + }, + // ==================== 子表(设备属性) ==================== // 获得设备属性分页 diff --git a/src/locales/en.ts b/src/locales/en.ts index e8e580aa..96e4f225 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -3574,7 +3574,7 @@ export default { protocol: 'Protocol', status: 'Connection Status', sampleCycle: 'Sample Cycle(s)', - isEnable: 'Enabled', + isEnable: 'Yes or No', collectionTime: 'Collection Time', operate: 'Operation', @@ -3591,11 +3591,13 @@ export default { placeholderUrl: 'Please enter endpoint URL', placeholderUsername: 'Please enter username', placeholderPassword: 'Please enter password', + placeholderTopic: 'Please enter subscription topic', model: 'Device Model', url: 'Endpoint URL', username: 'Username', password: 'Password', + topic: 'Subscription Topic', settingDialogTitle: 'Device Settings', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 2bb971b6..060387bc 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -3415,7 +3415,7 @@ export default { protocol: '采集协议', status: '连接状态', sampleCycle: '采集周期(s)', - isEnable: '是否启用', + isEnable: '是或否', collectionTime: '采集时间', operate: '操作', @@ -3432,11 +3432,13 @@ export default { placeholderUrl: '请输入端点URL', placeholderUsername: '请输入用户名', placeholderPassword: '请输入密码', + placeholderTopic: '请输入订阅主题', model: '设备模型', url: '端点URL', username: '用户名', password: '密码', + topic: '订阅主题', settingDialogTitle: '设备设置', diff --git a/src/views/iot/device/DeviceForm.vue b/src/views/iot/device/DeviceForm.vue index 8565fd7d..86e9e2fd 100644 --- a/src/views/iot/device/DeviceForm.vue +++ b/src/views/iot/device/DeviceForm.vue @@ -122,23 +122,10 @@ @@ -187,6 +174,7 @@ const formData = ref({ url: undefined, username: undefined, password: undefined, + topic: undefined, }) const formRules = reactive({ create: { @@ -200,7 +188,7 @@ const formRules = reactive({ isEnable: [{ required: true, message: '是否启用不能为空', trigger: 'blur' }] }, setting: { - url: [{ required: true, message: '端点URL不能为空', trigger: 'blur' }] + topic: [{ required: true, message: '订阅主题不能为空', trigger: 'blur' }] } }) @@ -236,7 +224,7 @@ const submitForm = async () => { // 提交请求 formLoading.value = true try { - const { id, deviceCode, deviceName, deviceModelId, sampleCycle, remark, isEnable, url, username, password } = formData.value as any + const { id, deviceCode, deviceName, deviceModelId, sampleCycle, remark, isEnable, topic } = formData.value as any if (formType.value === 'create') { const data: Partial = { deviceCode, deviceName, deviceModelId, sampleCycle, remark, isEnable } @@ -247,7 +235,7 @@ const submitForm = async () => { await DeviceApi.updateDevice(data) message.success(t('common.updateSuccess')) } else { - const data: any = { id, deviceCode, deviceName, deviceModelId, isEnable, url, username, password } + const data: any = { id, deviceCode, deviceName, deviceModelId, isEnable, topic } await DeviceApi.updateDevice(data) message.success(t('common.updateSuccess')) } diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue index 5b90b359..3f79b0ff 100644 --- a/src/views/iot/device/index.vue +++ b/src/views/iot/device/index.vue @@ -125,7 +125,10 @@ /> --> { return 'info' } +const isDeviceEnabled = (row: DeviceVO) => { + const value = (row as any)?.isEnable + if (typeof value === 'boolean') return value + const text = String(value ?? '').toLowerCase().trim() + if (!text) return false + if (text === 'true' || text === '1' || text === 'yes') return true + return false +} + +const handleDeviceEnableChange = async (row: DeviceVO, value: boolean) => { + if (!row.id) return + const oldValue = (row as any).isEnable + ;(row as any).isEnable = value + try { + await DeviceApi.updateDeviceEnabled(row.id, value ? 'true' : 'false') + message.success(t('common.updateSuccess')) + } catch { + ;(row as any).isEnable = oldValue + message.error(t('common.updateFail')) + } +} + const selectedIds = ref([]) const handleSelectionChange = (rows: any[]) => { selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []