From 1733be9113ae6a960a1547273d1acb5e5897cb67 Mon Sep 17 00:00:00 2001
From: wally <18603454788@163.com>
Date: Tue, 2 Nov 2021 11:06:19 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E7=8A=B6=E6=80=81=E4=B8=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=9B?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0devices=EF=BC=9Bexport=E6=9C=AA=E5=AE=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/apis/index.js | 3 ++
src/components/device-select-and-status.vue | 23 +++++++++-
src/components/search-bar-data.vue | 48 ++++++++++++++++-----
src/store/device.js | 15 +++++++
src/views/data-history.vue | 2 +-
src/views/device-create.vue | 3 ++
src/views/device-edit.vue | 1 +
src/views/device-list.vue | 11 +----
src/views/function-config.vue | 16 ++++---
src/views/network-config.vue | 14 +++---
10 files changed, 102 insertions(+), 34 deletions(-)
diff --git a/src/apis/index.js b/src/apis/index.js
index fb2d03a..ea152d4 100644
--- a/src/apis/index.js
+++ b/src/apis/index.js
@@ -42,3 +42,6 @@ export const createConfigNetwork = data => http.post(`${corrosion}/config/networ
// 提交功能配置参数
export const createConfigFunction = data => http.post(`${corrosion}/config/function`, data);
+
+// 导出历史数据
+export const exportHistory = params => http.get(`${corrosion}/export`, { params });
diff --git a/src/components/device-select-and-status.vue b/src/components/device-select-and-status.vue
index 76853e6..90ee2ba 100644
--- a/src/components/device-select-and-status.vue
+++ b/src/components/device-select-and-status.vue
@@ -11,7 +11,26 @@ const devices = computed(() => store.state.device.devices); // 设备/站点列
const deviceId = ref(''); // 选中的设备id
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // 正在操作的设备的id
// const get = computed(() => (props.status.get ? '设置生效' : '等待下发'));
-const set = computed(() => (props.status.set ? '设置生效' : '等待下发'));
+// const set = computed(() => (props.status.set ? '设置生效' : '等待下发'));
+
+const statusType = computed(() => {
+ let type = 'success';
+ switch (props.status) {
+ case 'PENDING':
+ type = 'primary';
+ break;
+ case 'FAIL':
+ type = 'danger';
+ break;
+ case 'SUCCESS':
+ type = 'success';
+ break;
+ default:
+ type = 'primary';
+ break;
+ }
+ return type;
+});
// 监听currentDeviceId
watch(
@@ -36,6 +55,6 @@ watch(
{{ get }}-->
设置状态:
- {{ set }}
+ {{ props.status || 'PENDING' }}
diff --git a/src/components/search-bar-data.vue b/src/components/search-bar-data.vue
index 1044113..f68157f 100644
--- a/src/components/search-bar-data.vue
+++ b/src/components/search-bar-data.vue
@@ -20,13 +20,18 @@
查询
+
+
+ 导出
+
diff --git a/src/store/device.js b/src/store/device.js
index 3647c44..09fff3b 100644
--- a/src/store/device.js
+++ b/src/store/device.js
@@ -1,5 +1,7 @@
import { getDevices, getDevicesAll } from 'apis/index';
+import dayjs from 'dayjs';
+
const user = {
namespaced: true,
@@ -36,6 +38,17 @@ const user = {
* @param {object} devices {page, data}
*/
setDevicesAll(state, devices) {
+ if (devices && devices.data) {
+ for (let i = 0; i < devices.data.length; i++) {
+ const device = devices.data[i];
+ if (device.installTime) {
+ devices.data[i].installTime = dayjs(new Date(+device.installTime)).format('YYYY-MM-DD HH:mm:ss');
+ }
+ if (device.runTime) {
+ devices.data[i].runTime = dayjs(new Date(+device.runTime)).format('YYYY-MM-DD HH:mm:ss');
+ }
+ }
+ }
state.devicesAll = devices;
},
@@ -57,6 +70,8 @@ const user = {
for (let i = 0; i < devicesAll.data.length; i++) {
const item = devicesAll.data[i];
if (item && item.deviceId === newData.deviceId) {
+ newData.installTime = dayjs(new Date(+item.installTime)).format('YYYY-MM-DD HH:mm:ss');
+ newData.runTime = dayjs(new Date(+item.runTime)).format('YYYY-MM-DD HH:mm:ss');
devicesAll.data[i] = newData;
break;
}
diff --git a/src/views/data-history.vue b/src/views/data-history.vue
index fc13646..75c2cec 100644
--- a/src/views/data-history.vue
+++ b/src/views/data-history.vue
@@ -84,7 +84,7 @@ const onPrev = e => {
-
+
diff --git a/src/views/device-create.vue b/src/views/device-create.vue
index 96f3e4a..5becda9 100644
--- a/src/views/device-create.vue
+++ b/src/views/device-create.vue
@@ -122,6 +122,7 @@
import { reactive, ref } from 'vue';
import { ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router';
+import { useStore } from 'vuex';
import { createDevice } from '../apis/index';
const data = reactive({
@@ -147,6 +148,7 @@ const data = reactive({
});
const deviceCreate = ref(null); // form
const router = useRouter();
+const store = useStore();
// 重置表单
const onReset = () => {
@@ -177,6 +179,7 @@ const onSubmit = () => {
// 取消/关闭 跳转到设备管理列表
router.push({ name: 'devices' });
});
+ store.dispatch('device/getDevices'); // 更新站点列表
} catch (error) {
throw new Error(error);
}
diff --git a/src/views/device-edit.vue b/src/views/device-edit.vue
index ad9f9f5..9258b77 100644
--- a/src/views/device-edit.vue
+++ b/src/views/device-edit.vue
@@ -175,6 +175,7 @@ const onSubmit = () => {
ElMessage.success('更新成功');
emit('cancel');
store.commit('device/updateDevice', data);
+ store.dispatch('device/getDevices'); // 更新站点列表
} catch (error) {
ElMessage.error('更新失败, 请稍后重试');
throw new Error(error);
diff --git a/src/views/device-list.vue b/src/views/device-list.vue
index 1ec79fd..2cd409d 100644
--- a/src/views/device-list.vue
+++ b/src/views/device-list.vue
@@ -85,7 +85,6 @@ import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import SearchBar from 'components/search-bar.vue';
import DeviceEdit from 'components/device-edit.vue';
-import deepClone from 'lodash/cloneDeep';
import { deleteDevice } from 'apis/index';
import { ElMessage } from 'element-plus';
@@ -94,14 +93,7 @@ const store = useStore();
const router = useRouter();
const token = computed(() => store.getters['user/token']);
const devicesAll = computed(() => {
- const devices = deepClone(store.state.device.devicesAll);
- if (devices && devices.data && devices.data.length) {
- for (let i = 0; i < devices.data.length; i++) {
- devices.data[i].installTime = new Date(+devices.data[i].installTime).toLocaleString();
- devices.data[i].runTime = new Date(+devices.data[i].runTime).toLocaleString();
- }
- }
- return devices;
+ return store.state.device.devicesAll;
});
const currentDeviceId = computed(() => store.state.device.currentDeviceId);
let contentHeight = 600;
@@ -166,6 +158,7 @@ const handleDelete = async deviceId => {
await deleteDevice(deviceId);
store.commit('device/deleteDevice', deviceId);
ElMessage.success('删除成功');
+ store.dispatch('device/getDevices'); // 更新站点列表
} catch (error) {
ElMessage.error('删除失败, 请稍后重试');
throw new Error(error);
diff --git a/src/views/function-config.vue b/src/views/function-config.vue
index bfcb755..486dc32 100644
--- a/src/views/function-config.vue
+++ b/src/views/function-config.vue
@@ -1,6 +1,6 @@
-
+
@@ -158,10 +158,10 @@ import { useStore } from 'vuex';
import { ElMessage } from 'element-plus';
import { cloneDeep, isDate } from 'lodash';
import { getConfigFunction, createConfigFunction } from 'apis/index';
-import DeviceSelectAndSelect from 'components/device-select-and-status.vue';
+import DeviceSelectAndStatus from 'components/device-select-and-status.vue';
import Refresh from 'components/refresh.vue';
-const data = ref({
+const originData = {
frequency: {
so2: 0, // SO2采样频率
metal: 0, // 金属腐蚀采样频率
@@ -187,7 +187,8 @@ const data = ref({
cycle: 0, // 上报周期分钟数
},
status: { get: 0, set: 0 },
-});
+};
+const data = ref(originData);
// 金属腐蚀的类型
const types = ref([
@@ -249,6 +250,11 @@ const onSearch = async (deviceId, type = 0) => {
const params = { deviceId, type };
store.commit('device/setCurrentDeviceId', deviceId);
const resData = await getConfigFunction(params);
- data.value = resData;
+ if (resData && resData.time) {
+ resData.time = new Date(+resData.time);
+ }
+ data.value = resData || originData;
};
+
+currentDeviceId && onSearch(currentDeviceId.value);
diff --git a/src/views/network-config.vue b/src/views/network-config.vue
index fe8b7fb..251896f 100644
--- a/src/views/network-config.vue
+++ b/src/views/network-config.vue
@@ -86,7 +86,7 @@ import { getConfigNetwork, createConfigNetwork } from 'apis/index';
import DeviceSelectAndSelect from 'components/device-select-and-status.vue';
import Refresh from 'components/refresh.vue';
-const data = ref({
+const originData = {
ip1: '',
port1: '',
ip2: '',
@@ -98,11 +98,9 @@ const data = ref({
account: '',
password: '',
apn: '',
- status: {
- get: 0,
- set: 0,
- },
-});
+ status: 'PENDING',
+};
+const data = ref(originData);
const networkForm = ref(null); // form
const store = useStore();
@@ -136,6 +134,8 @@ const onSearch = async (deviceId, type = 0) => {
const params = { deviceId, type };
store.commit('device/setCurrentDeviceId', deviceId);
const resData = await getConfigNetwork(params);
- data.value = resData;
+ data.value = resData || originData;
};
+
+currentDeviceId && onSearch(currentDeviceId.value);