Showing
8 changed files
with
117 additions
and
74 deletions
| ... | ... | @@ -12,11 +12,11 @@ export const getDeviceProfile = (deviceType?: string) => { |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | 14 | // 获取历史数据 |
| 15 | -export const getDeviceHistoryInfo = (params: Recordable, orderBy) => { | |
| 15 | +export const getDeviceHistoryInfo = (params: Recordable, orderBy?: string) => { | |
| 16 | 16 | return defHttp.get<HistoryData>( |
| 17 | 17 | { |
| 18 | 18 | url: `/plugins/telemetry/DEVICE/${params.entityId}/values/timeseries`, |
| 19 | - params: { ...params, entityId: null, orderBy }, | |
| 19 | + params: { ...params, entityId: null, orderBy: orderBy || 'DESC' }, | |
| 20 | 20 | }, |
| 21 | 21 | { |
| 22 | 22 | joinPrefix: false, | ... | ... |
| ... | ... | @@ -116,7 +116,7 @@ |
| 116 | 116 | const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); |
| 117 | 117 | const [registerModal, { openModal }] = useModal(); |
| 118 | 118 | // 表格hooks |
| 119 | - const [registerTable, { reload, setProps }] = useTable({ | |
| 119 | + const [registerTable, { reload, setProps, clearSelectedRowKeys }] = useTable({ | |
| 120 | 120 | title: '视频列表', |
| 121 | 121 | api: cameraPage, |
| 122 | 122 | columns, |
| ... | ... | @@ -145,6 +145,7 @@ |
| 145 | 145 | // 刷新 |
| 146 | 146 | const handleSuccess = () => { |
| 147 | 147 | reload(); |
| 148 | + clearSelectedRowKeys(); | |
| 148 | 149 | }; |
| 149 | 150 | const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete( |
| 150 | 151 | deleteCameraManage, | ... | ... |
| ... | ... | @@ -7,7 +7,7 @@ import { JSONEditor } from '/@/components/CodeEditor'; |
| 7 | 7 | import { DeviceTypeEnum } from '/@/api/device/model/deviceModel'; |
| 8 | 8 | import { getModelServices } from '/@/api/device/modelOfMatter'; |
| 9 | 9 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
| 10 | -import { toRaw, unref } from 'vue'; | |
| 10 | +import { nextTick, toRaw, unref } from 'vue'; | |
| 11 | 11 | import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/components/ObjectModelValidateForm/ObjectModelValidateForm.vue'; |
| 12 | 12 | import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum'; |
| 13 | 13 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
| ... | ... | @@ -246,8 +246,9 @@ export const step1Schemas: FormSchema[] = [ |
| 246 | 246 | required: true, |
| 247 | 247 | component: 'ApiSelect', |
| 248 | 248 | ifShow: ({ values }) => values.deviceType === 'SENSOR' && values.organizationId, |
| 249 | - componentProps: ({ formModel }) => { | |
| 249 | + componentProps: ({ formModel, formActionType }) => { | |
| 250 | 250 | const { organizationId, transportType } = formModel; |
| 251 | + const { validateFields } = formActionType; | |
| 251 | 252 | if (![organizationId, transportType].every(Boolean)) return {}; |
| 252 | 253 | return { |
| 253 | 254 | api: async (params: Recordable) => { |
| ... | ... | @@ -266,6 +267,10 @@ export const step1Schemas: FormSchema[] = [ |
| 266 | 267 | }, |
| 267 | 268 | valueField: 'tbDeviceId', |
| 268 | 269 | labelField: 'alias', |
| 270 | + onChange: async () => { | |
| 271 | + await nextTick(); | |
| 272 | + validateFields(['gatewayId']); | |
| 273 | + }, | |
| 269 | 274 | }; |
| 270 | 275 | }, |
| 271 | 276 | }, | ... | ... |
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | import { ColEx } from '/@/components/Form/src/types'; |
| 12 | 12 | import { useHistoryData } from '../../hook/useHistoryData'; |
| 13 | 13 | import { formatToDateTime } from '/@/utils/dateUtil'; |
| 14 | - import { useTable, BasicTable } from '/@/components/Table'; | |
| 14 | + import { useTable, BasicTable, BasicColumn } from '/@/components/Table'; | |
| 15 | 15 | import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
| 16 | 16 | import { |
| 17 | 17 | ModeSwitchButton, |
| ... | ... | @@ -60,13 +60,9 @@ |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - const [registerTable] = useTable({ | |
| 64 | - showIndexColumn: false, | |
| 65 | - showTableSetting: false, | |
| 66 | - dataSource: historyData, | |
| 67 | - maxHeight: 300, | |
| 68 | - size: 'small', | |
| 69 | - columns: [ | |
| 63 | + const sortOrder = ref<any>('descend'); | |
| 64 | + const columns: BasicColumn[] | any = computed(() => { | |
| 65 | + return [ | |
| 70 | 66 | { |
| 71 | 67 | title: '属性', |
| 72 | 68 | dataIndex: 'name', |
| ... | ... | @@ -84,18 +80,50 @@ |
| 84 | 80 | format: (val) => { |
| 85 | 81 | return formatToDateTime(val, 'YYYY-MM-DD HH:mm:ss'); |
| 86 | 82 | }, |
| 87 | - sorter: 'descend', | |
| 83 | + sorter: true, | |
| 84 | + sortOrder: unref(sortOrder), | |
| 85 | + sortDirections: ['descend', 'ascend', 'descend'], | |
| 88 | 86 | }, |
| 89 | - ], | |
| 87 | + ]; | |
| 88 | + }); | |
| 89 | + | |
| 90 | + const [registerTable, { setColumns }] = useTable({ | |
| 91 | + showIndexColumn: false, | |
| 92 | + showTableSetting: false, | |
| 93 | + dataSource: historyData, | |
| 94 | + maxHeight: 300, | |
| 95 | + columns: unref(columns), | |
| 96 | + size: 'small', | |
| 90 | 97 | }); |
| 91 | 98 | |
| 92 | - const handleTableChange = async (pag, filters, sorter: any) => { | |
| 93 | - console.log(pag, filters, sorter, 'pag, filters, sorter'); | |
| 99 | + const getTableList = async (orderBy?: string) => { | |
| 100 | + // 表单验证 | |
| 101 | + await method.validate(); | |
| 102 | + const value = method.getFieldsValue(); | |
| 103 | + const searchParams = getSearchParams(value); | |
| 104 | + | |
| 105 | + if (!hasDeviceAttr()) return; | |
| 106 | + // 发送请求 | |
| 107 | + loading.value = true; | |
| 108 | + const res = await getDeviceHistoryInfo( | |
| 109 | + { | |
| 110 | + ...searchParams, | |
| 111 | + entityId: props.deviceDetail.tbDeviceId, | |
| 112 | + }, | |
| 113 | + orderBy | |
| 114 | + ); | |
| 115 | + historyData.value = getTableHistoryData(res); | |
| 116 | + loading.value = false; | |
| 117 | + }; | |
| 118 | + | |
| 119 | + const handleTableChange = async (_pag, _filters, sorter: any) => { | |
| 120 | + sortOrder.value = sorter.order; | |
| 121 | + await setColumns(unref(columns)); | |
| 94 | 122 | if (sorter.field == 'ts') { |
| 95 | 123 | if (sorter.order == 'descend') { |
| 96 | - openHistoryPanel('ASC'); | |
| 124 | + getTableList('DESC'); | |
| 97 | 125 | } else { |
| 98 | - openHistoryPanel('DESC'); | |
| 126 | + getTableList('ASC'); | |
| 99 | 127 | } |
| 100 | 128 | } |
| 101 | 129 | }; |
| ... | ... | @@ -214,7 +242,7 @@ |
| 214 | 242 | setOptions(setChartOptions(res, selectedKeys)); |
| 215 | 243 | }; |
| 216 | 244 | |
| 217 | - const switchMode = (flag: EnumTableChartMode) => { | |
| 245 | + const switchMode = async (flag: EnumTableChartMode) => { | |
| 218 | 246 | mode.value = flag; |
| 219 | 247 | }; |
| 220 | 248 | ... | ... |
| 1 | 1 | import { BasicColumn, FormSchema } from '/@/components/Table'; |
| 2 | 2 | import { transformTime } from '/@/hooks/web/useDateToLocaleString'; |
| 3 | +import { isObject, isString } from '/@/utils/is'; | |
| 3 | 4 | |
| 4 | 5 | export const columns: BasicColumn[] = [ |
| 5 | 6 | { |
| ... | ... | @@ -55,6 +56,18 @@ export const exportJSONFile = (value: Recordable, name: string) => { |
| 55 | 56 | URL.revokeObjectURL(objectURL); |
| 56 | 57 | }; |
| 57 | 58 | |
| 59 | +export const paseJSON = (string: string) => { | |
| 60 | + let data = null; | |
| 61 | + let flag = false; | |
| 62 | + try { | |
| 63 | + if (!isString(string)) return { flag: false, data }; | |
| 64 | + data = JSON.parse(string); | |
| 65 | + flag = true; | |
| 66 | + if (!isObject(data)) flag = false; | |
| 67 | + } catch (error) {} | |
| 68 | + return { flag, data }; | |
| 69 | +}; | |
| 70 | + | |
| 58 | 71 | export enum RuleChainPermisssion { |
| 59 | 72 | DETAIL = 'rule:chain:detail', |
| 60 | 73 | } | ... | ... |
| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | <Upload :show-upload-list="false" :customRequest="handleImport"> |
| 9 | 9 | <Button type="primary" :loading="importLoading"> 导入规则链 </Button> |
| 10 | 10 | </Upload> |
| 11 | - <!-- <Authority> | |
| 11 | + <Authority> | |
| 12 | 12 | <Popconfirm |
| 13 | 13 | title="您确定要批量删除数据" |
| 14 | 14 | ok-text="确定" |
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | > |
| 18 | 18 | <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button> |
| 19 | 19 | </Popconfirm> |
| 20 | - </Authority> --> | |
| 20 | + </Authority> | |
| 21 | 21 | </template> |
| 22 | 22 | <template #root="{ record }"> |
| 23 | 23 | <Tag :color="record.root ? 'green' : 'red'"> {{ record.root ? '是' : '否' }}</Tag> |
| ... | ... | @@ -84,6 +84,7 @@ |
| 84 | 84 | encode, |
| 85 | 85 | exportJSONFile, |
| 86 | 86 | searchFormSchema, |
| 87 | + paseJSON, | |
| 87 | 88 | } from './config/config.data'; |
| 88 | 89 | import { |
| 89 | 90 | deleteRuleChine, |
| ... | ... | @@ -95,17 +96,45 @@ |
| 95 | 96 | } from '/@/api/ruleengine/ruleengineApi'; |
| 96 | 97 | import { useModal } from '/@/components/Modal'; |
| 97 | 98 | import { Authority } from '/@/components/Authority'; |
| 98 | - import { Tag, Button, Upload } from 'ant-design-vue'; | |
| 99 | + import { Tag, Button, Upload, Popconfirm } from 'ant-design-vue'; | |
| 99 | 100 | import { RuleChainModal } from './component/index'; |
| 100 | 101 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 101 | 102 | import { usePermission } from '/@/hooks/web/usePermission'; |
| 102 | 103 | import { useRouter } from 'vue-router'; |
| 103 | 104 | import { ref } from 'vue'; |
| 104 | - import { isObject, isString } from '/@/utils/is'; | |
| 105 | + import { isObject } from '/@/utils/is'; | |
| 105 | 106 | // import { ChainDetailDrawer } from './chainDetail/index'; |
| 106 | 107 | // import { useDrawer } from '/@/components/Drawer'; |
| 107 | 108 | |
| 108 | - const [registerTable, { reload, setProps }] = useTable({ | |
| 109 | + const [registerModal, { openModal }] = useModal(); | |
| 110 | + const { createMessage } = useMessage(); | |
| 111 | + const { hasPermission } = usePermission(); | |
| 112 | + const router = useRouter(); | |
| 113 | + | |
| 114 | + const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length; | |
| 115 | + const importLoading = ref<boolean>(false); | |
| 116 | + const hasBatchDelete = ref<boolean>(false); | |
| 117 | + | |
| 118 | + const beforeFetch = (params) => { | |
| 119 | + Reflect.set(params, 'page', params.page - 1); | |
| 120 | + Reflect.set(params, 'sortProperty', 'createdTime'); | |
| 121 | + Reflect.set(params, 'sortOrder', 'DESC'); | |
| 122 | + return params; | |
| 123 | + }; | |
| 124 | + | |
| 125 | + const rowSelection = () => { | |
| 126 | + return { | |
| 127 | + type: 'checkbox', | |
| 128 | + getCheckboxProps: (record: Recordable) => { | |
| 129 | + return { disabled: record.root }; | |
| 130 | + }, | |
| 131 | + onChange(rowKeys: string[]) { | |
| 132 | + hasBatchDelete.value = rowKeys.length <= 0; | |
| 133 | + }, | |
| 134 | + }; | |
| 135 | + }; | |
| 136 | + | |
| 137 | + const [registerTable, { reload, setProps, getSelectRowKeys, clearSelectedRowKeys }] = useTable({ | |
| 109 | 138 | title: '规则链库', |
| 110 | 139 | api: getRuleChinsList, |
| 111 | 140 | rowKey: (record) => record.id.id, |
| ... | ... | @@ -123,19 +152,8 @@ |
| 123 | 152 | pageField: 'page', |
| 124 | 153 | listField: 'data', |
| 125 | 154 | }, |
| 126 | - beforeFetch(params) { | |
| 127 | - Reflect.set(params, 'page', params.page - 1); | |
| 128 | - Reflect.set(params, 'sortProperty', 'createdTime'); | |
| 129 | - Reflect.set(params, 'sortOrder', 'DESC'); | |
| 130 | - return params; | |
| 131 | - }, | |
| 132 | - rowSelection: { | |
| 133 | - type: 'checkbox', | |
| 134 | - getCheckboxProps: (record: Recordable) => { | |
| 135 | - console.log(record, 'record'); | |
| 136 | - return { disabled: record.root }; | |
| 137 | - }, | |
| 138 | - }, | |
| 155 | + beforeFetch: (params) => beforeFetch(params), | |
| 156 | + rowSelection: rowSelection() as any, | |
| 139 | 157 | actionColumn: { |
| 140 | 158 | width: 220, |
| 141 | 159 | title: '操作', |
| ... | ... | @@ -145,10 +163,6 @@ |
| 145 | 163 | }, |
| 146 | 164 | }); |
| 147 | 165 | |
| 148 | - const [registerModal, { openModal }] = useModal(); | |
| 149 | - | |
| 150 | - // const [registerDrawer, { openDrawer }] = useDrawer(); | |
| 151 | - | |
| 152 | 166 | const handleSuccess = () => { |
| 153 | 167 | reload(); |
| 154 | 168 | }; |
| ... | ... | @@ -166,10 +180,6 @@ |
| 166 | 180 | }); |
| 167 | 181 | }; |
| 168 | 182 | |
| 169 | - const { createMessage } = useMessage(); | |
| 170 | - const { hasPermission } = usePermission(); | |
| 171 | - const router = useRouter(); | |
| 172 | - | |
| 173 | 183 | const handleView = (record: Recordable) => { |
| 174 | 184 | const hasDetailPermission = hasPermission(RuleChainPermisssion.DETAIL); |
| 175 | 185 | if (hasDetailPermission) { |
| ... | ... | @@ -178,30 +188,6 @@ |
| 178 | 188 | } else createMessage.warning('没有权限'); |
| 179 | 189 | }; |
| 180 | 190 | |
| 181 | - // const handleRowClick = (record) => { | |
| 182 | - // openDrawer(true, { record }); | |
| 183 | - // console.log('点击行', record); | |
| 184 | - // }; | |
| 185 | - | |
| 186 | - // const handleDetail = (record) => { | |
| 187 | - // console.log(record, '详情'); | |
| 188 | - // }; | |
| 189 | - | |
| 190 | - const paseJSON = (string: string) => { | |
| 191 | - let data = null; | |
| 192 | - let flag = false; | |
| 193 | - try { | |
| 194 | - if (!isString(string)) return { flag: false, data }; | |
| 195 | - data = JSON.parse(string); | |
| 196 | - flag = true; | |
| 197 | - if (!isObject(data)) flag = false; | |
| 198 | - } catch (error) {} | |
| 199 | - return { flag, data }; | |
| 200 | - }; | |
| 201 | - | |
| 202 | - const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length; | |
| 203 | - | |
| 204 | - const importLoading = ref<boolean>(false); | |
| 205 | 191 | const handleImport = (data: { file: File }) => { |
| 206 | 192 | const fileReader = new FileReader(); |
| 207 | 193 | |
| ... | ... | @@ -275,18 +261,25 @@ |
| 275 | 261 | reload(); |
| 276 | 262 | }; |
| 277 | 263 | |
| 278 | - const handleDeleteOrBatchDelete = async (record: Recordable) => { | |
| 264 | + const handleDeleteOrBatchDelete = async (record: Recordable | null) => { | |
| 279 | 265 | setProps({ |
| 280 | 266 | loading: true, |
| 281 | 267 | }); |
| 282 | 268 | try { |
| 269 | + if (!record) { | |
| 270 | + const ids = getSelectRowKeys(); | |
| 271 | + await Promise.all(ids.map((item) => deleteRuleChine(item))); | |
| 272 | + return; | |
| 273 | + } | |
| 283 | 274 | await deleteRuleChine(record.id.id); |
| 284 | - createMessage.success('删除成功'); | |
| 285 | 275 | } finally { |
| 286 | 276 | setProps({ |
| 287 | 277 | loading: false, |
| 288 | 278 | }); |
| 279 | + | |
| 280 | + createMessage.success('删除成功'); | |
| 281 | + clearSelectedRowKeys(); | |
| 282 | + reload(); | |
| 289 | 283 | } |
| 290 | - reload(); | |
| 291 | 284 | }; |
| 292 | 285 | </script> | ... | ... |
| ... | ... | @@ -173,10 +173,12 @@ |
| 173 | 173 | const { codeType, customCommand } = unref(getDesign) || {}; |
| 174 | 174 | const { transportType } = customCommand || {}; |
| 175 | 175 | const sendValue = ref<any>(unref(sliderValue)); |
| 176 | + const isModbusCommand = ref<boolean>(false); | |
| 176 | 177 | if (transportType == 'TCP' && codeType == TaskTypeEnum.MODBUS_RTU) { |
| 177 | 178 | sendValue.value = await getSendValue(unref(sliderValue)); |
| 179 | + isModbusCommand.value = true; | |
| 178 | 180 | } |
| 179 | - const flag = await sendCommand(props.config.option, unref(sendValue), true); | |
| 181 | + const flag = await sendCommand(props.config.option, unref(sendValue), unref(isModbusCommand)); | |
| 180 | 182 | flag |
| 181 | 183 | ? ((sliderValue.value = unref(sliderValue)), |
| 182 | 184 | (oldSliderValue.value = sliderValue.value), | ... | ... |