Michael Wang 3 سال پیش
والد
کامیت
0d8cbac357
1فایلهای تغییر یافته به همراه107 افزوده شده و 6 حذف شده
  1. 107 6
      src/features/projectDataManagement/ProjectDataManagement.vue

+ 107 - 6
src/features/projectDataManagement/ProjectDataManagement.vue

@@ -26,7 +26,12 @@
     </div>
 
     <div class="tw-bg-white tw-p-5 tw-rounded-xl">
-      <a-form>
+      <a-radio-group
+        :options="[...plainOptions]"
+        v-model:value="dataSourceChannel"
+      />
+      <div class="tw-mb-5"></div>
+      <a-form v-if="dataSourceChannel === '数据上传'">
         <a-form-item label="文件地址">
           <input id="file-input" :multiple="false" type="file" />
         </a-form-item>
@@ -37,6 +42,26 @@
         </a-form-item>
         <a-button type="primary" @click="handleImport">保存</a-button>
       </a-form>
+      <a-form v-else>
+        <a-form-item label="系统域名">
+          <a-input v-model:value="domain" placeholder="http://192.168.10.100" />
+        </a-form-item>
+        <a-form-item label="考试标识">
+          <a-select v-model:value="examId" placeholder="请选择考试">
+            <a-select-option
+              v-for="(item, index) in exams"
+              :key="index"
+              :value="item.id"
+            >
+              {{ item.name }}({{ item.id }})
+            </a-select-option>
+          </a-select>
+        </a-form-item>
+        <div class="tw-flex tw-gap-2">
+          <a-button type="primary" @click="handleTestServer">测试</a-button>
+          <a-button type="primary" @click="handleSync">保存</a-button>
+        </div>
+      </a-form>
     </div>
   </div>
 </template>
@@ -46,11 +71,14 @@ import {
   getProjectList,
   importProjectDataSource,
 } from "@/api/projectManagementPage";
+import { httpApp } from "@/plugins/axiosApp";
 import { useMainStore } from "@/store";
 import { Project } from "@/types";
 import { downloadFileURL, goBack } from "@/utils/utils";
 import { message } from "ant-design-vue";
-import { onMounted, computed } from "vue";
+import { debounce } from "lodash-es";
+import QueryString from "qs";
+import { onMounted, computed, watch } from "vue";
 import { useRoute } from "vue-router";
 
 const store = useMainStore();
@@ -98,8 +126,81 @@ async function handleImport() {
   void message.success({ content: "导入成功" });
 }
 
-// async function handleLogsOfProject() {
-//   await logsOfProject(projectId);
-//   void message.success({ content: "操作成功" });
-// }
+const plainOptions = ["数据上传", "资料同步"] as const;
+let dataSourceChannel: typeof plainOptions[number] = $ref("数据上传");
+
+const domain = $ref("");
+
+async function handleTestServer() {
+  if (!domain) {
+    void message.warn({ content: "请先填写域名" });
+    return;
+  }
+  try {
+    const res = await httpApp.post(
+      "/api/ess/task/sync/test",
+      QueryString.stringify({
+        domain,
+        projectId,
+      })
+    );
+    // console.log(res);
+    void message.info(res.data);
+  } catch (error) {
+    console.log(error);
+    void message.info("网络失败,请检查网络或联系管理员!");
+  }
+}
+
+interface Exam {
+  id: number;
+  name: string;
+}
+
+let exams: Exam[] = $ref([]);
+async function fetchExamsFromOtherServer() {
+  if (!domain) {
+    return;
+  }
+  try {
+    const res = await httpApp.post<any, { data: Exam[] }>(
+      "/api/ess/task/exams",
+      QueryString.stringify({
+        domain,
+        projectId,
+      }),
+      { noErrorMessage: true }
+    );
+    // console.log(res);
+    // void message.info(res.data);
+    exams = res.data;
+  } catch (error) {
+    console.log(error);
+    // void message.info("网络失败,请检查网络或联系管理员!");
+  }
+}
+
+const deboundcedFunc = debounce(fetchExamsFromOtherServer, 5000);
+watch(
+  () => [domain],
+  () => {
+    deboundcedFunc();
+  }
+);
+
+let examId: string = $ref(null as unknown as string);
+
+async function handleSync() {
+  if (typeof examId !== "number") {
+    void message.warn("请先选择考试");
+    return;
+  }
+  await httpApp.post("/api/ess/task/sync", {
+    domain,
+    examId,
+    projectId,
+  });
+
+  void message.warn("正在同步中...");
+}
 </script>