Browse Source

feat: update

Hu Cheng 2 years ago
parent
commit
6db14767d6

+ 1 - 1
src/main.js

@@ -2,7 +2,7 @@ import { createApp } from "vue";
 import { createPinia } from "pinia";
 import App from "./App.vue";
 import router from "./router";
-import "./plugins/highcharts";
+import "./plugin/highcharts";
 import "virtual:windi.css";
 import "./assets/main.css";
 

+ 0 - 0
src/plugins/highcharts.js → src/plugin/highcharts.js


+ 0 - 0
src/plugins/naive-ui.js → src/plugin/naive-ui.js


+ 1 - 1
src/router/index.js

@@ -2,7 +2,7 @@ import { createRouter, createWebHashHistory } from "vue-router";
 import LayoutView from "../layout/index.vue";
 import LoginView from "../login/index.vue";
 import { getToken } from "@/utils/storage/sessionToken";
-import { loadingBar } from "@/plugins/naive-ui";
+import { loadingBar } from "@/plugin/naive-ui";
 
 const router = createRouter({
   history: createWebHashHistory(import.meta.env.BASE_URL),

+ 0 - 0
src/stores/task.js → src/store/task.js


+ 1 - 1
src/utils/axios.js

@@ -1,7 +1,7 @@
 import axios from "axios";
 import { getToken } from "@/utils/storage/sessionToken";
 import { TOKEN } from "@/constant";
-import { loadingBar, message } from "@/plugins/naive-ui";
+import { loadingBar, message } from "@/plugin/naive-ui";
 
 // 显示消息
 const showMessage = (res) => {

+ 1 - 0
src/views/data/edit/AddVue.vue

@@ -81,6 +81,7 @@ const handleUpdateValue = (value, option) => {
 // 显示添加
 const showAddModal = () => {
   showModal.value = true;
+  Object.keys(formValue).forEach((key) => (formValue[key] = null));
 };
 
 // 获取设备列表

+ 7 - 3
src/views/data/edit/ImportPlatform.vue

@@ -79,7 +79,7 @@
 
 <script setup>
 import { getV3DataList, addTaskData } from "@/api";
-import { message } from "@/plugins/naive-ui";
+import { message } from "@/plugin/naive-ui";
 
 const props = defineProps({
   task: {
@@ -101,8 +101,8 @@ const data = ref({});
 const formValue = reactive({
   Time_start: null,
   Time_end: null,
-  T_sn: "",
-  T_id: "",
+  T_sn: null,
+  T_id: null,
   page: 1,
   page_z: 9999,
 });
@@ -110,6 +110,10 @@ const formValue = reactive({
 // 显示导入
 const showImportModal = () => {
   showModal.value = true;
+  formValue.Time_start = null;
+  formValue.Time_end = null;
+  formValue.T_sn = null;
+  formValue.T_id = null;
 };
 
 //

+ 49 - 14
src/views/data/edit/ImportVue.vue

@@ -1,18 +1,17 @@
 <template>
   <n-button type="primary" @click="showImportModal">导入数据</n-button>
   <n-modal
-    style="width: 30%"
     v-model:show="showModal"
     :show-icon="false"
     preset="dialog"
     title="导入"
     positive-text="确认"
     negative-text="取消"
-    @positive-click="addTask"
+    @positive-click="submitCallback"
   >
     <n-form :model="formValue" label-width="auto" show-require-mark>
       <n-form-item label="数据">
-        <n-upload :default-upload="false" @change="handleChange">
+        <n-upload :default-upload="false" :max="1" @change="handleChange">
           <n-button>上传文件</n-button>
         </n-upload>
       </n-form-item>
@@ -22,7 +21,8 @@
 
 <script setup>
 import { addTaskData } from "@/api";
-import { read } from "xlsx";
+import { read, utils } from "xlsx";
+import { useDateFormat } from "@vueuse/core";
 
 const props = defineProps({
   task: {
@@ -36,11 +36,35 @@ const message = useMessage();
 // 是否展示 Modal
 const showModal = ref(false);
 
+//
+const dataList = ref([]);
+
+/* 读取文件 */
+const readFile = (file) => {
+  return new Promise((resolve) => {
+    const reader = new FileReader();
+    reader.readAsBinaryString(file);
+    reader.onload = (ev) => {
+      resolve(ev.target.result);
+    };
+  });
+};
+
 // 组件状态变化的回调
-const handleChange = (options) => {
-  console.log(options);
-  const data = read(options.file.file, { type: "File" });
-  console.log(data);
+const handleChange = async ({ file }) => {
+  const dataBinary = await readFile(file.file);
+  const workBook = read(dataBinary, {
+    type: "binary",
+    cellDates: true,
+  });
+  const workSheet = workBook.Sheets[workBook.SheetNames[0]];
+  dataList.value = utils.sheet_to_json(workSheet);
+  dataList.value.forEach((item) => {
+    item["记录时间"] = useDateFormat(
+      item["记录时间"],
+      "YYYY-MM-DD HH:mm:ss"
+    ).value;
+  });
 };
 
 // 表单数据
@@ -59,16 +83,27 @@ const showImportModal = () => {
 };
 
 //
+const submitCallback = () => {
+  if (dataList.value.length > 0) {
+    dataList.value.forEach((item) => {
+      addTask(item);
+    });
+  }
+};
+
+//
 const addTask = async (item) => {
   const { data: res } = await addTaskData({
     T_task_id: props.task.T_task_id,
-    T_sn: formValue.T_sn,
-    T_id: item.T_id,
-    T_t: item.T_t,
-    T_rh: item.T_rh,
-    T_time: item.T_time,
+    T_sn: item["SN"],
+    T_id: item["编号"],
+    T_t: item["温度"],
+    T_rh: item["湿度"],
+    T_time: item["记录时间"],
   });
-  console.log(res);
+  if (res.Code === 200) {
+    message.success(res.Msg);
+  }
 };
 </script>
 

+ 1 - 0
src/views/data/edit/SetVue.vue

@@ -50,6 +50,7 @@ const formValue = reactive({
 // 显示设置
 const showSetModal = () => {
   showModal.value = true;
+  Object.keys(formValue).forEach((key) => (formValue[key] = null));
 };
 </script>
 

+ 13 - 10
src/views/data/edit/index.vue

@@ -485,16 +485,19 @@ const getDataList = async () => {
 
 getClassList();
 
-notification.info({
-  title:
-    task.T_collection_state === 0
-      ? "未完成"
-      : task.T_collection_state === 1
-      ? "已完成"
-      : "采集中",
-  duration: 2500,
-  keepAliveOnHover: true,
-});
+if (task.T_collection_state === 0) {
+  notification.info({
+    title: "未完成",
+    duration: 2500,
+    keepAliveOnHover: true,
+  });
+} else if (task.T_collection_state === 2) {
+  notification.info({
+    title: "采集中",
+    duration: 2500,
+    keepAliveOnHover: true,
+  });
+}
 </script>
 
 <style lang="scss" scoped></style>

+ 1 - 1
src/views/data/source/index.vue

@@ -75,7 +75,7 @@
 <script setup>
 import { NSpace } from "naive-ui";
 import { extractTaskData, getTaskDataList } from "@/api";
-import { message } from "@/plugins/naive-ui";
+import { message } from "@/plugin/naive-ui";
 
 const dialog = useDialog();