From 02349238af964e19a46da93e20466a48d755a453 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 02 九月 2024 17:38:04 +0800
Subject: [PATCH] 正在实现设备管理模块

---
 src/components/map/MapScene.vue        |    1 
 /dev/null                              |   12 ---
 src/api/deviceApi.js                   |   21 +++++
 src/views/LoginPage.vue                |    6 +
 src/components/device/DeviceManage.vue |  102 +++++++++++++++++++++++++
 src/constant/device-type.js            |    2 
 src/api/missionApi.js                  |    2 
 src/components.d.ts                    |    2 
 src/components/device/DeviceCreate.vue |    0 
 src/stores/device.js                   |   42 ++++++++++
 10 files changed, 174 insertions(+), 16 deletions(-)

diff --git a/src/api/deviceApi.js b/src/api/deviceApi.js
new file mode 100644
index 0000000..b2a8390
--- /dev/null
+++ b/src/api/deviceApi.js
@@ -0,0 +1,21 @@
+import { $http } from './index';
+
+/**
+ * 璧拌埅璁惧鐩稿叧鎺ュ彛API
+ */
+export default {
+  fethchDevice({ type, page, pageSize }) {
+    let params = `page=${page}&perPage=${pageSize}`;
+    params += type ? `&type=${type}` : '';
+    return $http.get(`air/device/type?${params}`).then((res) => res.data);
+  },
+
+  putNewDevice(device) {
+    return $http.post(`air/device/create`, device).then((res) => res.data);
+  },
+
+  deleteDevice(deviceCode) {
+    let params = `deviceCode=${deviceCode}`;
+    return $http.post(`air/device/delete?${params}`).then((res) => res.data);
+  }
+};
diff --git a/src/api/missionApi.js b/src/api/missionApi.js
index 764199a..d33ebf0 100644
--- a/src/api/missionApi.js
+++ b/src/api/missionApi.js
@@ -2,7 +2,7 @@
 import { Base64 } from 'js-base64';
 
 /**
- *
+ * 璧拌埅浠诲姟鐩稿叧鎺ュ彛API
  */
 export default {
   fethchMission({ type, page, pageSize }) {
diff --git a/src/components.d.ts b/src/components.d.ts
index 216f2b2..890072c 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -16,6 +16,8 @@
     CoreMenu: typeof import('./components/core/CoreMenu.vue')['default']
     DataSummary: typeof import('./components/monitor/DataSummary.vue')['default']
     DataTable: typeof import('./components/monitor/DataTable.vue')['default']
+    DeviceCreate: typeof import('./components/device/DeviceCreate.vue')['default']
+    DeviceManage: typeof import('./components/device/DeviceManage.vue')['default']
     ElButton: typeof import('element-plus/es')['ElButton']
     ElCascader: typeof import('element-plus/es')['ElCascader']
     ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
diff --git a/src/components/device/DeviceCreate.vue b/src/components/device/DeviceCreate.vue
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/components/device/DeviceCreate.vue
diff --git a/src/components/device/DeviceManage.vue b/src/components/device/DeviceManage.vue
new file mode 100644
index 0000000..b892027
--- /dev/null
+++ b/src/components/device/DeviceManage.vue
@@ -0,0 +1,102 @@
+<template>
+  <el-button
+    type="primary"
+    icon="Memo"
+    class="el-button-custom p-events-auto"
+    @click="dialogVisible = !dialogVisible"
+  >
+    璁惧绠$悊
+  </el-button>
+  <CardDialog v-model="dialogVisible" title="璧拌埅璁惧绠$悊">
+    <el-row class="mission-table">
+      <el-col :span="20">
+        <el-table
+          :data="deviceStore.deviceList"
+          table-layout="fixed"
+          size="small"
+          :show-overflow-tooltip="true"
+          border
+          height="64vh"
+          row-class-name="t-row"
+          cell-class-name="t-cell"
+          header-row-class-name="t-header-row"
+          header-cell-class-name="t-header-cell"
+        >
+          <el-table-column
+            type="index"
+            label="搴忓彿"
+            align="center"
+            width="50"
+          />
+          <el-table-column prop="deviceType" label="璁惧绫诲瀷" align="center" />
+          <el-table-column prop="deviceCode" label="璁惧缂栧彿" align="center" />
+          <el-table-column
+            prop="createTime"
+            label="鍒涘缓鏃堕棿"
+            align="center"
+            :formatter="timeFormatter"
+          />
+          <el-table-column label="绠$悊" width="140" align="center">
+            <template #default="{ row }">
+              <el-button
+                type="primary"
+                size="small"
+                class="el-button-custom"
+                @click="deleteDevice(row)"
+                >鍒犻櫎</el-button
+              >
+            </template>
+          </el-table-column>
+        </el-table>
+      </el-col>
+      <el-col :span="4" class="flex-col">
+        <div>
+          <!-- todo 璁惧鍒涘缓 -->
+        </div>
+      </el-col>
+    </el-row>
+  </CardDialog>
+  <MessageBox
+    v-model="msgBoxVisible"
+    :on-confirm="onConfirm"
+    title="鍒犻櫎璧拌埅浠诲姟"
+    msg="纭鏄惁鍒犻櫎璇ヨ蛋鑸换鍔�"
+    confirmText="鍒犻櫎"
+  ></MessageBox>
+</template>
+<script>
+import moment from 'moment';
+import deviceApi from '@/api/deviceApi';
+import { mapStores } from 'pinia';
+import { useDeviceStore } from '@/stores/device';
+import { useFetchData } from '@/composables/fetchData';
+
+export default {
+  setup() {
+    const { loading, fetchData } = useFetchData();
+    return { loading, fetchData };
+  },
+  props: {},
+  data() {
+    return {
+      dialogVisible: false,
+      msgBoxVisible: false,
+      onConfirm: undefined
+    };
+  },
+  computed: {
+    ...mapStores(useDeviceStore)
+  },
+  methods: {
+    deleteDevice(row) {
+      this.onConfirm = () => {
+        this.deviceStore.deleteDevice(row.deviceCode);
+      };
+      this.msgBoxVisible = true;
+    },
+    timeFormatter(row, col, cellValue, index) {
+      return moment(cellValue).format('YYYY-MM-DD HH:mm:ss');
+    }
+  }
+};
+</script>
diff --git a/src/components/map/MapScene.vue b/src/components/map/MapScene.vue
index c3cb97a..163b5a3 100644
--- a/src/components/map/MapScene.vue
+++ b/src/components/map/MapScene.vue
@@ -7,6 +7,7 @@
         class="el-button-custom p-events-auto"
       >
         鍦烘櫙鏍囨敞
+        <el-icon class="el-icon--right"><arrow-down /></el-icon>
       </el-button>
     </template>
     <OptionLocation v-model="districtCode"></OptionLocation>
diff --git a/src/constant/device-type.js b/src/constant/device-type.js
index dde0588..6291f18 100644
--- a/src/constant/device-type.js
+++ b/src/constant/device-type.js
@@ -51,7 +51,7 @@
       return v.value == t;
     });
     return [1, 2, 3].map((v) => {
-      const label = `${typeStr}璁惧${v}鍙穈;
+      const label = `${typeStr.label}璁惧${v}鍙穈;
       const value = `${t}000000000${v}`;
       return {
         label: label,
diff --git a/src/stores/counter.js b/src/stores/counter.js
deleted file mode 100644
index b6757ba..0000000
--- a/src/stores/counter.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { ref, computed } from 'vue'
-import { defineStore } from 'pinia'
-
-export const useCounterStore = defineStore('counter', () => {
-  const count = ref(0)
-  const doubleCount = computed(() => count.value * 2)
-  function increment() {
-    count.value++
-  }
-
-  return { count, doubleCount, increment }
-})
diff --git a/src/stores/device.js b/src/stores/device.js
new file mode 100644
index 0000000..c75f474
--- /dev/null
+++ b/src/stores/device.js
@@ -0,0 +1,42 @@
+import { ref } from 'vue';
+import { defineStore } from 'pinia';
+import deviceApi from '@/api/deviceApi';
+import { useFetchData } from '@/composables/fetchData';
+
+// 璧拌埅浠诲姟
+export const useDeviceStore = defineStore('device', () => {
+  const deviceList = ref([]);
+  const { loading, fetchData } = useFetchData();
+
+  function fetchDevice(type) {
+    return fetchData((page, pageSize) => {
+      return deviceApi
+        .fethchDevice({ type: type, page, pageSize })
+        .then((res) => {
+          deviceList.value = res.data;
+          return res;
+        });
+    });
+  }
+
+  function deleteDevice(deviceCode) {
+    return fetchData(() => {
+      return deviceApi.deleteDevice(deviceCode).then((res) => {
+        let index = -1;
+        for (let i = 0; i < deviceList.value.length; i++) {
+          const e = deviceList.value[i];
+          if (e.deviceCode == deviceCode) {
+            index = i;
+            break;
+          }
+        }
+        if (index != -1) {
+          deviceList.value.splice(index, 1);
+        }
+        return res;
+      });
+    });
+  }
+
+  return { deviceList, loading, fetchDevice, deleteDevice };
+});
diff --git a/src/views/LoginPage.vue b/src/views/LoginPage.vue
index e02c33d..fa815f7 100644
--- a/src/views/LoginPage.vue
+++ b/src/views/LoginPage.vue
@@ -73,8 +73,10 @@
       this.$refs.formRef.validate((valid) => {
         if (valid) {
           if (
-            this.formObj.userName == 'jingan' &&
-            this.formObj.password == 'jingan123'
+            (this.formObj.userName == 'jingan' &&
+              this.formObj.password == 'jingan123') ||
+            (this.formObj.userName == 'feiyu' &&
+              this.formObj.password == 'fyhb123')
           ) {
             this.$router.replace('/index/hmode');
           } else {

--
Gitblit v1.9.3