From aa1f56d5ef2d48b980a2fab3e88379efbe09b0d1 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 26 十二月 2023 17:04:27 +0800
Subject: [PATCH] 评估任务模块新增任务状态管理逻辑

---
 src/api/fysp/bgtaskApi.js                            |   50 +++++++
 src/components/bg-task/FYBgTaskCard.vue              |   52 +++++++
 src/composables/fetchData.js                         |   28 ++-
 src/enum/bgTask.js                                   |   74 ++++++++++
 src/enum/enum.js                                     |   19 ++
 /dev/null                                            |   10 -
 src/views/fysp/evaluation/components/CompEvaTask.vue |  125 +++++++++++++++++
 src/components.d.ts                                  |    1 
 src/views/fytz/user/components/CompUserInfo.vue      |   19 +-
 src/composables/formConfirm.js                       |   21 +-
 src/components/form/FYForm.vue                       |    2 
 src/views/fysp/evaluation/DataSource.vue             |   17 --
 12 files changed, 364 insertions(+), 54 deletions(-)

diff --git a/src/api/fysp/bgtaskApi.js b/src/api/fysp/bgtaskApi.js
new file mode 100644
index 0000000..e2dd4cd
--- /dev/null
+++ b/src/api/fysp/bgtaskApi.js
@@ -0,0 +1,50 @@
+import { $fysp } from '../index';
+
+/**
+ * 鑰楁椂浠诲姟鐩稿叧API
+ */
+export default {
+  /**
+   * 鑾峰彇鍚庡彴浠诲姟鐘舵��
+   * @param {Object} param 鍚庡彴浠诲姟鏌ヨ鏉′欢
+   */
+  fetchTaskStatus(param) {
+    return $fysp.post(`bgTask/status`, param).then((res) => res.data);
+  },
+
+  /**
+   * 鏂板缓涓�涓祴璇曚换鍔�
+   * @param {String} taskId 
+   * @returns {Promise}
+   */
+  newTestTask(taskId) {
+    return $fysp.put(`bgTask/newTask/test?taskId=${taskId}`).then((res) => res.data);
+  },
+
+  /**
+   * 鏂板缓涓�涓祴璇曚换鍔�
+   * @param {String} taskId 
+   * @returns {Promise}
+   */
+  startTask(param) {
+    return $fysp.put(`bgTask/start`, param).then((res) => res.data);
+  },
+
+  /**
+   * 鏂板缓骞惰繍琛屼竴涓祴璇曚换鍔�
+   * @param {String} taskId 
+   * @returns {Promise}
+   */
+  startNewTestTask(taskId) {
+    return $fysp.put(`bgTask/newTask/test/start?taskId=${taskId}`).then((res) => res.data);
+  },
+
+  /**
+   * 寮哄埗鍏抽棴娴嬭瘯浠诲姟
+   * @param {Object} param 鍚庡彴浠诲姟鏌ヨ鏉′欢
+   * @returns {Promise}
+   */
+  shutDownTask(param) {
+    return $fysp.put(`bgTask/shutDown`, param).then((res) => res.data);
+  },
+};
diff --git a/src/components.d.ts b/src/components.d.ts
index 6eff6e0..aff2c0b 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -64,6 +64,7 @@
     ElTree: typeof import('element-plus/es')['ElTree']
     Footer: typeof import('./components/core/Footer.vue')['default']
     FormCol: typeof import('./components/layout/FormCol.vue')['default']
+    FYBgTaskCard: typeof import('./components/bg-task/FYBgTaskCard.vue')['default']
     FYForm: typeof import('./components/form/FYForm.vue')['default']
     FYOptionLocation: typeof import('./components/search-option/FYOptionLocation.vue')['default']
     FYOptionOnlineStatus: typeof import('./components/search-option/FYOptionOnlineStatus.vue')['default']
diff --git a/src/components/bg-task/FYBgTaskCard.vue b/src/components/bg-task/FYBgTaskCard.vue
new file mode 100644
index 0000000..877c4b7
--- /dev/null
+++ b/src/components/bg-task/FYBgTaskCard.vue
@@ -0,0 +1,52 @@
+<template>
+  <el-card class="bg-task-card" shadow="hover" :body-style="{ padding: '8px' }">
+    <!-- <template #header> -->
+    <el-row>
+      <el-space>
+        <el-tag>{{ nameToLabel(model.type) }}</el-tag>
+        <el-text tag="b" size="large" truncated>{{ model.name }}鍟婂疄鎵撳疄澶ц嫃鎵撳晩瀹炴墦瀹炲ぇ鑻忔墦闃垮ぇ鎾掑ぇ鎾�</el-text>
+      </el-space>
+    </el-row>
+
+    <!-- </template> -->
+    <el-text type="info" size="small">鐘舵�侊細{{ nameToLabel(model.status) }}</el-text>
+    <el-text type="info" size="small">寮�濮嬶細{{ model.startTime }}</el-text>
+    <el-text type="info" size="small">缁撴潫锛歿{ model.endTime }}</el-text>
+    <!-- <template #footer> -->
+    <el-button type="primary" size="small" :loading="false" @click="$emit('start', model)"
+      >寮�濮嬩换鍔�</el-button
+    >
+    <el-button type="danger" size="small" :loading="false" @click="$emit('shutDown', model)"
+      >寮哄埗缁撴潫</el-button
+    >
+    <el-button type="danger" size="small" :loading="false" @click="$emit('remove', model)"
+      >绉婚櫎浠诲姟</el-button
+    >
+    <el-button type="danger" size="small" :loading="false" @click="$emit('gotoResult', model)"
+      >鏌ョ湅缁撴灉</el-button
+    >
+    <el-text type="info" size="small">ID锛歿{ model.id }}</el-text>
+    <!-- </template> -->
+  </el-card>
+</template>
+<script>
+import { nTlBgTask } from '@/enum/bgTask';
+
+export default {
+  props: {
+    model: Object
+  },
+  emits: ['start', 'shutDown', 'remove', 'gotoResult'],
+  methods: {
+    nameToLabel(name) {
+      const t = nTlBgTask(name);
+      return t.label;
+    }
+  }
+};
+</script>
+<style scoped>
+.bg-task-card {
+  margin-bottom: 8px;
+}
+</style>
diff --git a/src/components/form/FYForm.vue b/src/components/form/FYForm.vue
index a305bde..f9f8297 100644
--- a/src/components/form/FYForm.vue
+++ b/src/components/form/FYForm.vue
@@ -136,7 +136,7 @@
   (nValue) => {
     formObj.value = nValue;
   },
-  { deep: true, immediate: true }
+  { deep: false, immediate: true }
 );
 
 //鐩戝惉琛ㄥ崟閲嶇疆鍔熻兘瑙﹀彂
diff --git a/src/composables/fetchData.js b/src/composables/fetchData.js
index 3598753..4b5458e 100644
--- a/src/composables/fetchData.js
+++ b/src/composables/fetchData.js
@@ -1,13 +1,13 @@
 // 鎺ュ彛鏁版嵁鐨勮幏鍙�
-import { onActivated, onDeactivated, ref, watch } from 'vue';
+import { ref, watch, computed } from 'vue';
 
-export function useFetchData(fetch) {
+export function useFetchData() {
   // 鍒嗛〉淇℃伅
-  const currentPage = ref(1);
-  const totalPage = ref(1);
+  const page = ref(1);
+  const pageNum = ref(1);
   const pageSize = ref(20);
   const total = ref(0);
-  watch(currentPage, (nValue, oValue) => {
+  watch(page, (nValue, oValue) => {
     if (nValue != oValue) {
       fetchData();
     }
@@ -21,14 +21,20 @@
   // 鍔犺浇鐘舵��, 0: 鍔犺浇瀹屾垚; 1: 鍔犺浇涓�; 2: 宸插叏閮ㄥ姞杞�; 3: 鍔犺浇澶辫触;
   const loadStatus = ref(0);
 
+  const loading = computed(() => {
+    return loadStatus.value == 1;
+  });
+
   // 鏁版嵁鑾峰彇
-  function fetchData() {
+  function fetchData(fetch) {
     loadStatus.value = 1;
-    fetch(currentPage.value, pageSize.value)
+    fetch(page.value, pageSize.value)
       .then((pageInfo) => {
-        currentPage.value = pageInfo.currentPage;
-        totalPage.value = pageInfo.totalPage;
-        total.value = pageInfo.total;
+        if (pageInfo) {
+          page.value = pageInfo.page ? pageInfo.page : 1;
+          pageNum.value = pageInfo.pageNum ? pageInfo.pageNum : 1;
+          total.value = pageInfo.total ? pageInfo.total : 0;
+        }
 
         loadStatus.value = 0;
       })
@@ -40,5 +46,5 @@
       });
   }
 
-  return {currentPage, totalPage, pageSize, total, loadStatus, fetchData}
+  return { page, pageNum, pageSize, total, loadStatus, loading, fetchData };
 }
diff --git a/src/composables/formConfirm.js b/src/composables/formConfirm.js
index fcd2828..0bb274c 100644
--- a/src/composables/formConfirm.js
+++ b/src/composables/formConfirm.js
@@ -26,8 +26,7 @@
   // });
 
   //琛ㄥ崟鍐呭
-  const formObj = reactive(defaultForm ? defaultForm : {});
-  // const formObj = reactive({});
+  const formObj = ref(defaultForm ? defaultForm : {});
   let formObjClone = useCloned(formObj, { manual: true });
   //琛ㄥ崟缁勪欢寮曠敤
   const formRef = ref(null);
@@ -97,15 +96,15 @@
     formRef.value.validate(async (valid) => {
       if (valid) {
         if (messageBox) {
-        useMessageBoxTip({
-          confirmMsg: submit.msg,
-          confirmTitle: submit.title,
-          onConfirm: async () => {
-            const res = await submit.do();
-            submited();
-            return res;
-          }
-        });
+          useMessageBoxTip({
+            confirmMsg: submit.msg,
+            confirmTitle: submit.title,
+            onConfirm: async () => {
+              const res = await submit.do();
+              submited();
+              return res;
+            }
+          });
         } else {
           await submit.do();
           submited();
diff --git a/src/enum/bgTask.js b/src/enum/bgTask.js
new file mode 100644
index 0000000..6e0c920
--- /dev/null
+++ b/src/enum/bgTask.js
@@ -0,0 +1,74 @@
+// 鑰楁椂浠诲姟鏋氫妇
+import { Enum } from './enum';
+
+const BG_TASK_TYPE = Enum({
+  TEST: {
+    name: 'TEST',
+    label: '娴嬭瘯浠诲姟',
+    value: '0'
+  },
+  AUTO_SCORE: {
+    name: 'AUTO_SCORE',
+    label: '鑷姩璇勪及浠诲姟',
+    value: '1'
+  }
+});
+
+const BG_TASK_STATUS = Enum({
+  WAITING: {
+    name: 'WAITING',
+    label: '绛夊緟',
+    value: '0'
+  },
+  RUNNING: {
+    name: 'RUNNING',
+    label: '杩愯涓�',
+    value: '1'
+  },
+  SUCCESS: {
+    name: 'SUCCESS',
+    label: '浠诲姟鎴愬姛',
+    value: '2'
+  },
+  FAIL: {
+    name: 'FAIL',
+    label: '浠诲姟鍑洪敊',
+    value: '3'
+  },
+  SHUTDOWN: {
+    name: 'SHUTDOWN',
+    label: '宸插叧闂�',
+    value: '4'
+  }
+});
+
+/**
+ * 閫氳繃鍚嶇О鏌ユ壘鏋氫妇绫�
+ * @param {String} name
+ * @returns
+ */
+function nTlBgTask(name) {
+  if (name in BG_TASK_TYPE) {
+    return BG_TASK_TYPE[name];
+  } else if (name in BG_TASK_STATUS) {
+    return BG_TASK_STATUS[name];
+  }
+}
+
+function enumBgTask(allOption = true) {
+  const l = _enumBgTask();
+  if (!allOption) {
+    l.shift();
+  }
+
+  return l;
+}
+
+function _enumBgTask() {
+  return Object.values(BG_TASK_TYPE).unshift({
+    label: '鍏ㄩ儴',
+    value: null
+  });
+}
+
+export { enumBgTask, BG_TASK_TYPE, BG_TASK_STATUS, nTlBgTask };
diff --git a/src/enum/enum.js b/src/enum/enum.js
new file mode 100644
index 0000000..12a03c3
--- /dev/null
+++ b/src/enum/enum.js
@@ -0,0 +1,19 @@
+const validator = {
+  get(target, name) {
+    // eslint-disable-next-line no-prototype-builtins
+    if (!target.hasOwnProperty(name)) {
+      throw new Error(`"${name}" value does not exist in the enum`);
+    } else if (typeof target[name] === 'object' && target[name] != null) {
+      return new Proxy(target[name], validator);
+    } else {
+      return target[name];
+    }
+  },
+  set(target, name, value) {
+    throw new Error('Cannot add a new value to the enum');
+  }
+};
+
+export function Enum(baseEnum) {
+  return new Proxy(baseEnum, validator);
+}
diff --git a/src/views/fysp/evaluation/DataSource.vue b/src/views/fysp/evaluation/DataSource.vue
index c680dec..0c16095 100644
--- a/src/views/fysp/evaluation/DataSource.vue
+++ b/src/views/fysp/evaluation/DataSource.vue
@@ -4,28 +4,17 @@
       <CompPreCheck></CompPreCheck>
     </el-col>
     <el-col :span="8">
-      <el-card shadow="never" class="radius">
-        <template #header>
-          <el-row justify="space-between">
-            <div>
-              <div><el-text tag="b" size="large">鑷姩璇勪及浠诲姟</el-text></div>
-              <el-text size="small" type="info">鏄剧ず褰撳墠姝e湪杩涜鐨勮嚜鍔ㄨ瘎浼颁换鍔$姸鎬�</el-text>
-            </div>
-            <el-button icon="Refresh" type="primary" size="default" :loading="loading" @click="submit"
-              >鍒锋柊浠诲姟</el-button
-            >
-          </el-row>
-        </template>
-      </el-card>
+      <CompEvaTask></CompEvaTask>
     </el-col>
   </el-row>
 </template>
 
 <script>
+import CompEvaTask from './components/CompEvaTask.vue';
 import CompPreCheck from './components/CompPreCheck.vue';
 export default {
   name: 'DataSource',
-  components: { CompPreCheck },
+  components: { CompPreCheck, CompEvaTask },
   data() {
     return {};
   }
diff --git a/src/views/fysp/evaluation/components/CompEvaTask.vue b/src/views/fysp/evaluation/components/CompEvaTask.vue
new file mode 100644
index 0000000..57299b1
--- /dev/null
+++ b/src/views/fysp/evaluation/components/CompEvaTask.vue
@@ -0,0 +1,125 @@
+<template>
+  <el-card shadow="never" :body-style="{ padding: 0 }">
+    <template #header>
+      <el-row justify="space-between">
+        <div>
+          <div><el-text tag="b" size="large">鑷姩璇勪及浠诲姟</el-text></div>
+          <el-text size="small" type="info">鏄剧ず褰撳墠姝e湪杩涜鐨勮嚜鍔ㄨ瘎浼颁换鍔$姸鎬�</el-text>
+        </div>
+        <el-button
+          icon="Refresh"
+          type="primary"
+          size="default"
+          :loading="loading"
+          @click="fetchTask"
+          >鍒锋柊浠诲姟</el-button
+        >
+      </el-row>
+      <el-row>
+        <el-button type="default" size="default" @click="newTestTask">鏂板娴嬭瘯浠诲姟</el-button>
+        <el-button type="default" size="default" @click="startNewTestTask"
+          >鏂板缓骞惰繍琛屼竴涓祴璇曚换鍔�</el-button
+        >
+        <el-button type="default" size="default" @click="shutDownTask"
+          >寮哄埗鍏抽棴鎵�鏈夋祴璇曚换鍔�</el-button
+        >
+      </el-row>
+    </template>
+    <el-scrollbar height="70vh" class="scrollbar">
+      <template v-for="(v, i) in taskList" :key="i">
+        <FYBgTaskCard
+          :model="v"
+          @start="startTask"
+          @shutDown="shutDownTask"
+          @remove="removeTask"
+          @gotoResult="gotoResult"
+        ></FYBgTaskCard>
+      </template>
+    </el-scrollbar>
+  </el-card>
+</template>
+<script>
+/**
+ * 鑷姩璇勪及浠诲姟绠$悊
+ */
+import { useFetchData } from '@/composables/fetchData';
+import bgtaskApi from '@/api/fysp/bgtaskApi';
+import { enumBgTask, BG_TASK_TYPE } from '@/enum/bgTask';
+
+export default {
+  setup() {
+    const { loading, fetchData } = useFetchData();
+    return { loading, fetchData };
+  },
+  data() {
+    return {
+      taskList: [],
+      taskIndex: 0
+    };
+  },
+  methods: {
+    _getParam(taskStatus) {
+      return {
+        type: taskStatus.type,
+        id: taskStatus.id
+      };
+    },
+    fetchTask() {
+      this.fetchData((page, pageSize) => {
+        return bgtaskApi
+          .fetchTaskStatus({
+            type: BG_TASK_TYPE.TEST.name
+          })
+          .then((res) => {
+            this.taskList = res.data;
+          });
+      });
+    },
+    startTask(taskStatus) {
+      this.fetchData((page, pageSize) => {
+        return bgtaskApi.startTask(this._getParam(taskStatus)).then((res) => {
+          this.taskList = this.taskList.concat(res.data);
+        });
+      });
+    },
+    newTestTask() {
+      this.fetchData((page, pageSize) => {
+        return bgtaskApi.newTestTask(`Test-Task-${++this.taskIndex}`).then((res) => {
+          this.taskList = this.taskList.concat(res.data);
+        });
+      });
+    },
+    startNewTestTask() {
+      this.fetchData((page, pageSize) => {
+        return bgtaskApi.startNewTestTask(`Test-Task-${++this.taskIndex}`).then((res) => {
+          this.taskList = this.taskList.concat(res.data);
+        });
+      });
+    },
+    shutDownTask(taskStatus) {
+      this.fetchData((page, pageSize) => {
+        return bgtaskApi.shutDownTask(this._getParam(taskStatus)).then((res) => {
+          res.data.forEach((e) => {
+            let v = this.taskList.find((value) => {
+              return value.id == e.id;
+            });
+            const i = this.taskList.indexOf(v);
+            this.taskList[i] = e;
+          });
+        });
+      });
+    },
+    removeTask(taskStatus){
+
+    },
+    gotoResult(taskStatus) {
+
+    }
+  },
+};
+</script>
+<style scoped>
+.scrollbar {
+  padding: 8px;
+}
+</style>
diff --git a/src/views/fysp/evaluation/components/CompHistoryRecord.vue b/src/views/fysp/evaluation/components/CompHistoryRecord.vue
deleted file mode 100644
index 95fda22..0000000
--- a/src/views/fysp/evaluation/components/CompHistoryRecord.vue
+++ /dev/null
@@ -1,10 +0,0 @@
-<template>
-  <div></div>
-</template>
-<script>
-export default {
-  methods:{
-
-  }
-}
-</script>
\ No newline at end of file
diff --git a/src/views/fytz/user/components/CompUserInfo.vue b/src/views/fytz/user/components/CompUserInfo.vue
index d782e78..423d624 100644
--- a/src/views/fytz/user/components/CompUserInfo.vue
+++ b/src/views/fytz/user/components/CompUserInfo.vue
@@ -92,10 +92,10 @@
 const props = defineProps({
   //鍩烘湰淇℃伅
   model: {
-    type: Object,
-    default: () => {
-      return { isenable: true };
-    }
+    type: Object
+    // default: () => {
+    //   return { isenable: true };
+    // }
   },
   create: {
     type: Boolean,
@@ -107,9 +107,14 @@
   }
 });
 
-const formInfo = computed(() => {
-  return parseUserInfo(props.model);
-});
+const formInfo = ref({ isenable: true });
+
+watch(
+  () => props.model,
+  (nValue) => {
+    formInfo.value = parseUserInfo(nValue);
+  }
+);
 
 const emit = defineEmits(['onSubmit', 'onCancel', 'updateEdit']);
 

--
Gitblit v1.9.3