style:采集设备-是或否列改成switch组件切换/设备设置弹框添加订阅主题输入框

main
黄伟杰 1 month ago
parent 6da4bae9c3
commit b1d91ffc19

@ -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 })
},
// ==================== 子表(设备属性) ====================
// 获得设备属性分页

@ -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',

@ -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: '设备设置',

@ -122,23 +122,10 @@
</template>
<template v-else>
<el-form-item :label="t('DataCollection.Device.url')" prop="url">
<el-form-item :label="t('DataCollection.Device.topic')" prop="topic">
<el-input
v-model="formData.url"
:placeholder="t('DataCollection.Device.placeholderUrl')"
/>
</el-form-item>
<el-form-item :label="t('DataCollection.Device.username')" prop="username">
<el-input
v-model="formData.username"
:placeholder="t('DataCollection.Device.placeholderUsername')"
/>
</el-form-item>
<el-form-item :label="t('DataCollection.Device.password')" prop="password">
<el-input
v-model="formData.password"
:placeholder="t('DataCollection.Device.placeholderPassword')"
show-password
v-model="formData.topic"
:placeholder="t('DataCollection.Device.placeholderTopic')"
/>
</el-form-item>
</template>
@ -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<DeviceVO> = { 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'))
}

@ -125,7 +125,10 @@
/> -->
<el-table-column :label="t('DataCollection.Device.isEnable')" align="center" prop="isEnable" width="120px">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.isEnable" />
<el-switch
:model-value="isDeviceEnabled(scope.row)"
@change="(val) => handleDeviceEnableChange(scope.row, val)"
/>
</template>
</el-table-column>
<el-table-column
@ -651,6 +654,28 @@ const getOperatingStatusType = (value: string | number | undefined) => {
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<number[]>([])
const handleSelectionChange = (rows: any[]) => {
selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []

Loading…
Cancel
Save