diff --git a/.env.test b/.env.test
new file mode 100644
index 0000000..9bcb052
--- /dev/null
+++ b/.env.test
@@ -0,0 +1 @@
+VITE_API_URL=https://test.tall.wiki
diff --git a/package.json b/package.json
index 00e4081..d9aceaa 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "0.0.0",
"scripts": {
"dev": "vite --mode development",
+ "dev-test": "vite --mode test",
"build": "vite build",
"serve": "vite preview",
"cz": "git add . && git cz",
diff --git a/src/apis/index.js b/src/apis/index.js
index efc13cd..fb2d03a 100644
--- a/src/apis/index.js
+++ b/src/apis/index.js
@@ -10,8 +10,17 @@ export const getToken = userId => http.get(`${users}/userId`, { params: { userId
// 获取设备列表
export const getDevices = () => http.get(`${corrosion}/devices`);
+// 添加设备
+export const createDevice = data => http.post(`${corrosion}/devices`, data);
+
// 获取设备列表 完整信息
-export const getDevicesAll = () => http.get(`${corrosion}/devices/all`);
+export const getDevicesAll = (params = { deviceId: '', page: 1, size: 50 }) => http.get(`${corrosion}/devices/all`, { params });
+
+// 更新设备
+export const updateDevice = (deviceId, data) => http.put(`${corrosion}/devices/all/${deviceId}`, data);
+
+// 删除设备
+export const deleteDevice = deviceId => http.delete(`${corrosion}/devices/all/${deviceId}`);
// 查历史数据
export const getHistories = params => http.get(`${corrosion}/histories`, { params });
diff --git a/src/components/search-bar-data.vue b/src/components/search-bar-data.vue
index b227740..1044113 100644
--- a/src/components/search-bar-data.vue
+++ b/src/components/search-bar-data.vue
@@ -55,8 +55,8 @@ const onSubmit = () => {
searchDeviceForm.value.validate(() => {
const { deviceId, date } = searchDevice;
if (date) {
- const start = dayjs(date[0]).format('X');
- const end = dayjs(date[1]).format('X');
+ const start = dayjs(date[0]).format('x');
+ const end = dayjs(date[1]).format('x');
const daterange = [start, end];
emit('search', { deviceId, date: daterange });
} else {
diff --git a/src/store/device.js b/src/store/device.js
index 1966708..3647c44 100644
--- a/src/store/device.js
+++ b/src/store/device.js
@@ -33,7 +33,7 @@ const user = {
/**
* 设置devicesAll的数据
* @param {*} state
- * @param {array} devices
+ * @param {object} devices {page, data}
*/
setDevicesAll(state, devices) {
state.devicesAll = devices;
@@ -47,6 +47,31 @@ const user = {
setCurrentDeviceId(state, deviceId) {
state.currentDeviceId = deviceId;
},
+
+ /**
+ * 更新某个设备的信息
+ * @param {*} param0
+ * @param {object} newData 设备更新后的信息
+ */
+ updateDevice({ devicesAll }, newData) {
+ for (let i = 0; i < devicesAll.data.length; i++) {
+ const item = devicesAll.data[i];
+ if (item && item.deviceId === newData.deviceId) {
+ devicesAll.data[i] = newData;
+ break;
+ }
+ }
+ },
+
+ /**
+ * 删除设备
+ * @param {*} param0
+ * @param {string} deviceId 设备id
+ */
+ deleteDevice({ devicesAll }, deviceId) {
+ if (!devicesAll || !devicesAll.data || !devicesAll.data.length) return;
+ devicesAll.data = devicesAll.data.filter(item => item.deviceId !== deviceId);
+ },
},
actions: {
@@ -62,9 +87,9 @@ const user = {
},
// 获取设备列表(站点列表) 完整信息
- async getDevicesAll({ commit }) {
+ async getDevicesAll({ commit }, params) {
try {
- const data = await getDevicesAll();
+ const data = await getDevicesAll(params);
commit('setDevicesAll', data || null);
return data;
} catch (error) {
diff --git a/src/views/data-history.vue b/src/views/data-history.vue
index 2acc80a..fc13646 100644
--- a/src/views/data-history.vue
+++ b/src/views/data-history.vue
@@ -5,7 +5,7 @@ import SearchBar from 'components/search-bar-data.vue';
import { getHistories } from 'apis/index';
const search = ref({});
-const page = ref({ page: 2, size: 10 });
+const page = ref({ page: 1, size: 50 });
let timer = null;
const store = useStore();
const token = computed(() => store.getters['user/token']);
@@ -112,7 +112,7 @@ const onPrev = e => {
background
:current-page="page.page"
:page-size="page.size"
- :default-page-size="10"
+ :default-page-size="50"
:page-count="page.count"
layout="total, sizes, prev, pager, next, jumper"
:page-sizes="[1, 10, 20, 50, 100]"
diff --git a/src/views/device-create.vue b/src/views/device-create.vue
index 6d32abb..96f3e4a 100644
--- a/src/views/device-create.vue
+++ b/src/views/device-create.vue
@@ -58,12 +58,12 @@
-
+
-
+
@@ -120,6 +120,9 @@
diff --git a/src/views/device-edit.vue b/src/views/device-edit.vue
index 66a1309..ad9f9f5 100644
--- a/src/views/device-edit.vue
+++ b/src/views/device-edit.vue
@@ -1,116 +1,100 @@
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
-
-
-
+
-
+
@@ -118,7 +102,7 @@
-
+
@@ -135,8 +119,10 @@
diff --git a/src/views/device-list.vue b/src/views/device-list.vue
index 231a32d..5fdb0c9 100644
--- a/src/views/device-list.vue
+++ b/src/views/device-list.vue
@@ -1,5 +1,9 @@
-
+
+
+
+ 添加设备
+
@@ -42,7 +46,7 @@
-
+
@@ -60,13 +64,14 @@
background
:current-page="devicesAll.page.page"
:page-size="devicesAll.page.size"
- :default-page-size="10"
+ :default-page-size="50"
:page-count="devicesAll.page.count"
+ :total="devicesAll.page.total"
class="my-3 float-right"
+ layout="total, sizes, prev, pager, next, jumper"
+ :page-sizes="[1, 10, 20, 50, 100]"
@size-change="onSizeChange"
@current-change="onCurrentPageChange"
- @prev-click="onPrev"
- @next-click="onNext"
>
@@ -80,12 +85,25 @@ 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';
let timer = null;
const store = useStore();
const router = useRouter();
const token = computed(() => store.getters['user/token']);
-const devicesAll = computed(() => store.state.device.devicesAll);
+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;
+});
+const currentDeviceId = computed(() => store.state.device.currentDeviceId);
let contentHeight = 600;
const editting = ref(false);
@@ -102,7 +120,7 @@ const getDevicesAllData = () => {
});
}
} catch (error) {
- console.log('error: ', error);
+ throw new Error(error);
}
};
@@ -114,29 +132,43 @@ onMounted(() => {
contentHeight = winHeight - 150;
});
+/**
+ * 删除
+ * @param {number} page 页码
+ * @param {number} size 每页条数
+ */
+function onSearch(page, size = 50) {
+ const deviceId = currentDeviceId.value;
+ const params = {
+ deviceId,
+ page,
+ size,
+ };
+ store.dispatch('device/getDevicesAll', params);
+}
+
// 当前页码变化
-const onCurrentPageChange = e => {
- console.log(e);
+const onCurrentPageChange = page => {
+ onSearch(page, devicesAll.value.page.size || 50);
};
// 每页条数变化
-const onSizeChange = e => {
- console.log(e);
-};
-
-// 下一页
-const onNext = e => {
- console.log(e);
-};
-
-// 上一页
-const onPrev = e => {
- console.log(e);
+const onSizeChange = size => {
+ onSearch(1, size);
};
-// 删除设备
-const handleDelete = () => {
- console.log('delete');
+/**
+ * 删除某设备
+ * @param {string} deviceId 设备id
+ */
+const handleDelete = async deviceId => {
+ try {
+ await deleteDevice(deviceId);
+ store.commit('device/deleteDevice', deviceId);
+ } catch (error) {
+ ElMessage.error('删除失败, 请稍后重试');
+ throw new Error(error);
+ }
};
// 编辑设备信息
@@ -145,8 +177,13 @@ const handleEdit = item => {
editting.value = true;
};
-const openPage = (item, path) => {
+/**
+ * 打开页面
+ * @param {object} item 设备对象
+ * @param {string} pageName 页面name
+ */
+const openPage = (item, pageName) => {
store.commit('device/setCurrentDeviceId', item.deviceId);
- router.push({ name: path });
+ router.push({ name: pageName });
};
diff --git a/src/views/statistical-history.vue b/src/views/statistical-history.vue
index 8894060..8e1f1dd 100644
--- a/src/views/statistical-history.vue
+++ b/src/views/statistical-history.vue
@@ -61,6 +61,7 @@ getDate();
*/
const onSearch = payload => {
search.value = { ...payload };
+ console.log('search: ', search.value);
getDate();
};