From 7c74ba1171fb95d4dacdc17ce5e19e446f58f10d Mon Sep 17 00:00:00 2001
From: wally <18603454788@163.com>
Date: Sat, 13 Nov 2021 11:30:19 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E5=A4=87=E6=95=B0=E9=87=8F?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A8=A1=E6=8B=9F=E8=8E=B7=E5=8F=96;?=
=?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=A6=82=E8=A7=88=E7=9B=B8=E5=85=B3=E5=AD=97?=
=?UTF-8?q?=E6=AE=B5=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.eslintrc.js | 16 +++++-
src/apis/index.js | 16 ++++++
.../overview/chart-device-count.vue | 55 ++++++++++++++-----
src/components/overview/device-table.vue | 20 +++++--
src/routers/index.js | 2 +-
src/store/device.js | 36 +++++++++++-
src/store/index.js | 2 +-
src/utils/overview.js | 30 ++++++++++
src/views/data-history.vue | 4 +-
src/views/data-realtime.vue | 4 +-
src/views/data-report.vue | 2 +-
src/views/device-create.vue | 6 ++
src/views/device-list.vue | 3 +-
src/views/overview.vue | 4 ++
14 files changed, 169 insertions(+), 31 deletions(-)
create mode 100644 src/utils/overview.js
diff --git a/.eslintrc.js b/.eslintrc.js
index 2b9b596..aca78d0 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -13,6 +13,14 @@ module.exports = {
'import/no-unresolved': 0,
'import/extensions': 0,
'no-plusplus': 0,
+ 'no-use-before-define': [
+ 'error',
+ {
+ functions: false,
+ classes: true,
+ variables: true,
+ },
+ ],
'consistent-return': 0,
'vue/html-self-closing': 'off',
'no-unused-expressions': 'off',
@@ -21,7 +29,13 @@ module.exports = {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-param-reassign': 'off',
- 'max-len': ['error', { code: 140, tabWidth: 2 }],
+ 'max-len': [
+ 'error',
+ {
+ code: 140,
+ tabWidth: 2,
+ },
+ ],
'object-curly-newline': ['error', { multiline: true }],
'arrow-parens': ['error', 'as-needed'],
'linebreak-style': 'off',
diff --git a/src/apis/index.js b/src/apis/index.js
index 3556198..3f460aa 100644
--- a/src/apis/index.js
+++ b/src/apis/index.js
@@ -12,6 +12,22 @@ export const getToken = userId => http.get(`${users}/userId`, { params: { userId
// 获取设备列表
export const getDevices = () => http.get(`${corrosion}/devices`);
+// 查设备概览 数据统计
+// export const getDevicesCount = () => http.get(`${corrosion}/devices/count`);
+export const getDevicesCount = () => {
+ return new Promise(resolve => {
+ setTimeout(() => {
+ resolve({
+ total: 100,
+ online: 10,
+ offline: 90,
+ fault: 10,
+ warning: 5,
+ });
+ }, 100);
+ });
+};
+
// 添加设备
export const createDevice = data => http.post(`${corrosion}/devices`, data);
diff --git a/src/components/overview/chart-device-count.vue b/src/components/overview/chart-device-count.vue
index 6900f55..8549d9d 100644
--- a/src/components/overview/chart-device-count.vue
+++ b/src/components/overview/chart-device-count.vue
@@ -3,18 +3,30 @@
diff --git a/src/components/overview/device-table.vue b/src/components/overview/device-table.vue
index 49fc95f..b33cd4a 100644
--- a/src/components/overview/device-table.vue
+++ b/src/components/overview/device-table.vue
@@ -1,13 +1,21 @@
-
+
-
-
-
-
-
+
+
+
+
+ {{ scope.row.status }}
+
+
+
+
+ {{ scope.row.type }}
+
+
+
import('@/views/overview.vue'),
},
diff --git a/src/store/device.js b/src/store/device.js
index 133ef7b..a927169 100644
--- a/src/store/device.js
+++ b/src/store/device.js
@@ -1,6 +1,6 @@
-import { getDevices, getDevicesAll } from 'apis/index';
-
+import { getDevices, getDevicesAll, getDevicesCount } from 'apis';
import dayjs from 'dayjs';
+import { ElMessage } from 'element-plus';
const user = {
namespaced: true,
@@ -9,6 +9,13 @@ const user = {
devices: [], // 站点列表 设备列表简版
devicesAll: null, // 设备列表完整版
currentDeviceId: '', // 当前正在编辑的设备deviceId
+ count: {
+ total: 0, // 总设备数量
+ online: 0, // 在线
+ offline: 0, // 离线
+ warning: 0, // 警告
+ fault: 0, // 故障
+ },
},
getters: {
@@ -37,6 +44,20 @@ const user = {
}
},
+ /**
+ * 设置设备统计数据信息
+ * @param {object} state
+ * @param {object} count // 服务端返回的对象
+ * @param {number} count.total // 总设备数量
+ * @param {number} count.online // 在线
+ * @param {number} count.offline // 离线
+ * @param {number} count.warning // 报警
+ * @param {number} count.fault // 故障
+ */
+ setDevicesCount(state, count) {
+ state.count = count;
+ },
+
/**
* 设置devicesAll的数据
* @param {*} state
@@ -106,6 +127,17 @@ const user = {
}
},
+ // 查询设备数量信息
+ async getDevicesCount({ commit }) {
+ try {
+ const data = await getDevicesCount();
+ commit('setDevicesCount', data);
+ } catch (error) {
+ ElMessage.error(error.message || '获取设备统计信息失败');
+ throw new Error(error);
+ }
+ },
+
// 获取设备列表(站点列表) 完整信息
async getDevicesAll({ commit }, params) {
try {
diff --git a/src/store/index.js b/src/store/index.js
index bd58b2a..d06b59f 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -5,7 +5,7 @@ import user from './user';
export default createStore({
modules: { user, device, statistics },
- state: { menu: { show: true, collapse: true } },
+ state: { menu: { show: true, collapse: false } },
getters: {},
mutations: {
toggleCollapse(state) {
diff --git a/src/utils/overview.js b/src/utils/overview.js
new file mode 100644
index 0000000..1112136
--- /dev/null
+++ b/src/utils/overview.js
@@ -0,0 +1,30 @@
+/**
+ * 生成设备概览 数量数据
+ * @param {object} count
+ * @param {number} count.online 在线数量
+ * @param {number} count.offline 离线数量
+ * @param {number} count.fault 故障数量
+ * @param {number} count.warning 报警数量
+ * @returns {[{type: string, value: number},{type: string, value: number},{type: string, value: number},{type: string, value: number}]}
+ */
+// eslint-disable-next-line import/prefer-default-export
+export function generateChartData(count) {
+ return [
+ {
+ type: '在线',
+ value: count.online || 0,
+ },
+ {
+ type: '故障',
+ value: count.fault || 0,
+ },
+ {
+ type: '离线',
+ value: count.offline || 0,
+ },
+ {
+ type: '报警',
+ value: count.warning || 0,
+ },
+ ];
+}
diff --git a/src/views/data-history.vue b/src/views/data-history.vue
index 349206d..2f88da1 100644
--- a/src/views/data-history.vue
+++ b/src/views/data-history.vue
@@ -140,7 +140,7 @@ function formatTime(time) {
-
+
@@ -160,7 +160,7 @@ function formatTime(time) {
{{ formatTime(+scope.row.time) }}
-
+
{{ formatTime(+scope.row.createdAt) }}
diff --git a/src/views/data-realtime.vue b/src/views/data-realtime.vue
index 0c17f5d..60e21be 100644
--- a/src/views/data-realtime.vue
+++ b/src/views/data-realtime.vue
@@ -1,5 +1,5 @@
-
+
@@ -15,7 +15,7 @@
{{ formatTime(+scope.row.time) }}
-
+
{{ formatTime(+scope.row.createdAt) }}
diff --git a/src/views/data-report.vue b/src/views/data-report.vue
index 5fa9e27..8466fa7 100644
--- a/src/views/data-report.vue
+++ b/src/views/data-report.vue
@@ -130,7 +130,7 @@ function formatTime(time) {
{{ formatTime(+scope.row.time) }}
-
+
{{ formatTime(+scope.row.createdAt) }}
diff --git a/src/views/device-create.vue b/src/views/device-create.vue
index e54d59e..8500d11 100644
--- a/src/views/device-create.vue
+++ b/src/views/device-create.vue
@@ -102,6 +102,11 @@
+
+
+
+
+
@@ -144,6 +149,7 @@ const data = reactive({
simple: '', // 试样
sim1: '', // sim卡1
joint: '', // 主站后台联调情况
+ operationRecord: '', // 维修记录
remark: '', // 备注
});
diff --git a/src/views/device-list.vue b/src/views/device-list.vue
index ffa374f..853d265 100644
--- a/src/views/device-list.vue
+++ b/src/views/device-list.vue
@@ -20,7 +20,8 @@
安装位置:{{ props.row.installLocation }}
sim1:{{ props.row.sim1 }}
与主站后台联调情况:{{ props.row.joint }}
- 备注:{{ props.row.remark }}
+ 维修记录:{{ props.row.operationRecord }}
+ 备注:{{ props.row.remark }}
diff --git a/src/views/overview.vue b/src/views/overview.vue
index 1b9ef03..43e0cfc 100644
--- a/src/views/overview.vue
+++ b/src/views/overview.vue
@@ -16,4 +16,8 @@
import ChartDeviceCount from 'components/overview/chart-device-count.vue';
import ChartDeviceDetail from 'components/overview/chart-device-detail.vue';
import DeviceTable from 'components/overview/device-table.vue';
+import { useStore } from 'vuex';
+
+const store = useStore();
+store.dispatch('device/getDevicesCount'); // 获取设备数量信息