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 @@
/> -->
-
+ handleDeviceEnableChange(scope.row, val)"
+ />
{
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) ?? []