diff --git a/package.json b/package.json index 978c1d3c..942a5662 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "ant-design-vue": "^3.2.15", "axios": "^1.2.1", "echarts": "^5.4.1", + "event-source-polyfill": "^1.0.31", "jetlinks-store": "^0.0.3", "js-cookie": "^3.0.1", "less": "^4.1.3", diff --git a/src/api/device/instance.ts b/src/api/device/instance.ts index 8886dcbe..fb34ebd1 100644 --- a/src/api/device/instance.ts +++ b/src/api/device/instance.ts @@ -51,4 +51,25 @@ export const _deploy = (id: string) => server.post(`/device-instance/${id}/deplo * @param data * @returns */ - export const _undeploy = (id: string) => server.post(`/device-instance/${id}/undeploy`) \ No newline at end of file +export const _undeploy = (id: string) => server.post(`/device-instance/${id}/undeploy`) + +/** + * 批量激活设备 + * @param data 设备id数组 + * @returns + */ +export const batchDeployDevice = (data: string[]) => server.put(`/device-instance/batch/_deploy`, data) + +/** + * 批量注销设备 + * @param data 设备id数组 + * @returns + */ +export const batchUndeployDevice = (data: string[]) => server.put(`/device-instance/batch/_unDeploy`, data) + +/** + * 批量删除 + * @param data 设备id数组 + * @returns + */ +export const batchDeleteDevice = (data: string[]) => server.put(`/device-instance/batch/_delete`, data) diff --git a/src/components/AIcon/index.tsx b/src/components/AIcon/index.tsx index eb1703a1..bcc04f86 100644 --- a/src/components/AIcon/index.tsx +++ b/src/components/AIcon/index.tsx @@ -21,7 +21,11 @@ const iconKeys = [ 'StopOutlined', 'CheckOutlined', 'CloseOutlined', - 'DownOutlined' + 'DownOutlined', + 'ImportOutlined', + 'ExportOutlined', + 'SyncOutlined', + 'ExclamationCircleOutlined' ] const Icon = (props: {type: string}) => { diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 8aa9d3c1..9e76e074 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -204,9 +204,13 @@ const JTable = defineComponent({ loading.value = false } - watchEffect(() => { - handleSearch(props.params) - }) + watch( + () => props.params, + (newValue) => { + handleSearch(newValue) + }, + {deep: true, immediate: true} + ) onMounted(() => { window.onresize = () => { @@ -266,7 +270,7 @@ const JTable = defineComponent({ onClose={() => { emit('cancelSelect') }} - closeText={取消选择} + closeText={取消选择} /> : null } diff --git a/src/utils/encodeQuery.ts b/src/utils/encodeQuery.ts new file mode 100644 index 00000000..19d11640 --- /dev/null +++ b/src/utils/encodeQuery.ts @@ -0,0 +1,64 @@ +export default function encodeQuery(params: any) { + if (!params) return {}; + const queryParam = { + // pageIndex: 0, + current: params.current, + }; + const { terms, sorts } = params; + Object.keys(params).forEach((key: string) => { + if (key === 'terms') { + let index = 0; + if (!terms) return; + Object.keys(terms).forEach((k: string) => { + if ( + !( + terms[k] === '' || + terms[k] === undefined || + terms[k].length === 0 || + terms[k] === {} || + terms[k] === null + ) + ) { + if (k.indexOf('$LIKE') > -1 && terms[k].toString().indexOf('%') === -1) { + terms[k] = `%${terms[k]}%`; + } + if (k.indexOf('$IN') > -1) { + terms[k] = terms[k].toString(); + } else if (k.indexOf('$START') > -1) { + terms[k] = `%${terms[k]}`; + } else if (k.indexOf('$END') > -1) { + terms[k] = `${terms[k]}%`; + } + if (k.indexOf('@') > -1) { + const temp = k.split('@'); + // eslint-disable-next-line prefer-destructuring + queryParam[`terms[${index}].column`] = temp[0]; + // eslint-disable-next-line prefer-destructuring + queryParam[`terms[${index}].type`] = temp[1]; + } else { + queryParam[`terms[${index}].column`] = k; + } + queryParam[`terms[${index}].value`] = terms[k]; + index += 1; + } + }); + } else if (key === 'sorts') { + // 当前Ant Design排序只支持单字段排序 + if (!sorts) return; + Object.keys(sorts).forEach((s, index) => { + queryParam[`sorts[${index}].name`] = s; + queryParam[`sorts[${index}].order`] = sorts[s].replace('end', ''); + }); + // if (Object.keys(sorts).length > 0) { + // queryParam[`sorts[0].name`] = sorts.field; + // queryParam[`sorts[0].order`] = (sorts.order || '').replace('end', ''); + // } + } else { + queryParam[key] = params[key]; + } + }); + + // queryParam.pageIndex = current - 1; + + return queryParam; +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index a238c5cc..3e5df69b 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,3 +1,7 @@ +import moment from "moment"; +import { LocalStore } from "./comm"; +import { TOKEN_KEY } from "./variable"; + /** * 把数据下载成JSON * @param record @@ -18,4 +22,34 @@ export const downloadObject = (record: Record, fileName: string, fo ghostLink.click(); //移除 document.body.removeChild(ghostLink); +}; + +/** + * 下载文件 + * @param url 下载链接 + * @param params 参数 + */ + export const downloadFile = (url: string, params?: Record) => { + const formElement = document.createElement('form'); + formElement.style.display = 'display:none;'; + formElement.method = 'GET'; + formElement.action = url; + // 添加参数 + if (params) { + Object.keys(params).forEach((key: string) => { + const inputElement = document.createElement('input'); + inputElement.type = 'hidden'; + inputElement.name = key; + inputElement.value = params[key]; + formElement.appendChild(inputElement); + }); + } + const inputElement = document.createElement('input'); + inputElement.type = 'hidden'; + inputElement.name = ':X_Access_Token'; + inputElement.value = LocalStore.get(TOKEN_KEY); + formElement.appendChild(inputElement); + document.body.appendChild(formElement); + formElement.submit(); + document.body.removeChild(formElement); }; \ No newline at end of file diff --git a/src/views/device/Instance/Export/index.vue b/src/views/device/Instance/Export/index.vue new file mode 100644 index 00000000..8db0d050 --- /dev/null +++ b/src/views/device/Instance/Export/index.vue @@ -0,0 +1,75 @@ + + + \ No newline at end of file diff --git a/src/views/device/Instance/Import/index.vue b/src/views/device/Instance/Import/index.vue new file mode 100644 index 00000000..f3e68440 --- /dev/null +++ b/src/views/device/Instance/Import/index.vue @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/src/views/device/Instance/Process/index.vue b/src/views/device/Instance/Process/index.vue new file mode 100644 index 00000000..972da530 --- /dev/null +++ b/src/views/device/Instance/Process/index.vue @@ -0,0 +1,51 @@ + + + \ No newline at end of file diff --git a/src/views/device/Instance/index.vue b/src/views/device/Instance/index.vue index ad22365b..447a2053 100644 --- a/src/views/device/Instance/index.vue +++ b/src/views/device/Instance/index.vue @@ -1,5 +1,16 @@