|
@@ -17,15 +17,24 @@
|
|
|
<div class="part-box">
|
|
|
<a-tabs v-model:activeKey="dataSourceChannel" type="card">
|
|
|
<a-tab-pane key="资料同步" tab="资料同步">
|
|
|
- <a-form :labelCol="{ style: { width: '72px' } }" style="width: 400px">
|
|
|
- <a-form-item label="系统域名">
|
|
|
+ <a-form
|
|
|
+ ref="formRef"
|
|
|
+ :labelCol="{ style: { width: '85px' } }"
|
|
|
+ :model="formData"
|
|
|
+ :rules="rules"
|
|
|
+ style="width: 400px"
|
|
|
+ >
|
|
|
+ <a-form-item label="系统域名" name="domain">
|
|
|
<a-input
|
|
|
- v-model:value="domain"
|
|
|
+ v-model:value="formData.domain"
|
|
|
placeholder="http://192.168.10.100"
|
|
|
/>
|
|
|
</a-form-item>
|
|
|
- <a-form-item label="考试标识">
|
|
|
- <a-select v-model:value="examId" placeholder="请选择考试">
|
|
|
+ <a-form-item label="考试标识" name="examId">
|
|
|
+ <a-select
|
|
|
+ v-model:value="formData.examId"
|
|
|
+ placeholder="请选择考试"
|
|
|
+ >
|
|
|
<a-select-option
|
|
|
v-for="(item, index) in exams"
|
|
|
:key="index"
|
|
@@ -36,10 +45,18 @@
|
|
|
</a-select>
|
|
|
</a-form-item>
|
|
|
<div>
|
|
|
- <a-button type="primary" @click="handleTestServer"
|
|
|
+ <a-button
|
|
|
+ type="success"
|
|
|
+ :loading="testLoading"
|
|
|
+ @click="handleTestServer"
|
|
|
>接口检测</a-button
|
|
|
>
|
|
|
- <a-button type="primary" @click="handleSync">数据计算</a-button>
|
|
|
+ <a-button
|
|
|
+ type="primary"
|
|
|
+ :loading="submitLoading"
|
|
|
+ @click="handleSync"
|
|
|
+ >数据计算</a-button
|
|
|
+ >
|
|
|
</div>
|
|
|
</a-form>
|
|
|
</a-tab-pane>
|
|
@@ -96,10 +113,11 @@ import { downloadFileURL, goBack } from "@/utils/utils";
|
|
|
import { message } from "ant-design-vue";
|
|
|
import { debounce } from "lodash-es";
|
|
|
import QueryString from "qs";
|
|
|
-import { onMounted, computed, watch } from "vue";
|
|
|
+import { onMounted, computed, watch, reactive, ref } from "vue";
|
|
|
import { useRoute } from "vue-router";
|
|
|
import useLoading from "@/hooks/loading";
|
|
|
import type { UploadProps } from "ant-design-vue";
|
|
|
+import type { Rule, FormInstance } from "ant-design-vue/es/form";
|
|
|
|
|
|
const store = useMainStore();
|
|
|
store.currentLocation = "项目列表 / 数据管理";
|
|
@@ -129,6 +147,10 @@ onMounted(async () => {
|
|
|
await search();
|
|
|
});
|
|
|
|
|
|
+const plainOptions = ["数据上传", "资料同步"] as const;
|
|
|
+let dataSourceChannel: (typeof plainOptions)[number] = $ref("资料同步");
|
|
|
+
|
|
|
+/** 数据上传 */
|
|
|
const { loading: downLoading, setLoading: setDownLoading } = useLoading();
|
|
|
async function downloadTpl() {
|
|
|
if (downLoading.value) return;
|
|
@@ -167,48 +189,44 @@ async function handleImport() {
|
|
|
|
|
|
void message.success({ content: "导入成功" });
|
|
|
}
|
|
|
+/** 数据上传 ---end */
|
|
|
|
|
|
-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<any, { data: string }>(
|
|
|
- "/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("网络失败,请检查网络或联系管理员!");
|
|
|
- }
|
|
|
-}
|
|
|
+/** 资料同步 */
|
|
|
+const defaultFormData = {
|
|
|
+ domain: "",
|
|
|
+ examId: "",
|
|
|
+};
|
|
|
+type FormDataType = typeof defaultFormData;
|
|
|
+const formRef = ref<FormInstance>();
|
|
|
+const formData = reactive<FormDataType>({ ...defaultFormData });
|
|
|
+const rules: Record<keyof FormDataType, Rule[]> = {
|
|
|
+ domain: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请输入系统域名",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ examId: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请选择考试",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+};
|
|
|
|
|
|
interface Exam {
|
|
|
id: number;
|
|
|
name: string;
|
|
|
}
|
|
|
-
|
|
|
let exams: Exam[] = $ref([]);
|
|
|
async function fetchExamsFromOtherServer() {
|
|
|
- if (!domain) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!formData.domain) return;
|
|
|
+
|
|
|
try {
|
|
|
const res = await httpApp.post<any, { data: Exam[] }>(
|
|
|
"/api/ess/task/exams",
|
|
|
QueryString.stringify({
|
|
|
- domain,
|
|
|
+ domain: formData.domain,
|
|
|
projectId,
|
|
|
}),
|
|
|
{ noErrorMessage: true }
|
|
@@ -224,25 +242,56 @@ async function fetchExamsFromOtherServer() {
|
|
|
|
|
|
const deboundcedFunc = debounce(fetchExamsFromOtherServer, 5000);
|
|
|
watch(
|
|
|
- () => [domain],
|
|
|
+ () => formData.domain,
|
|
|
() => {
|
|
|
void deboundcedFunc();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
-let examId: string = $ref(null as unknown as string);
|
|
|
+const { loading: testLoading, setLoading: setTestLoading } = useLoading();
|
|
|
+async function handleTestServer() {
|
|
|
+ const valid = await formRef.value?.validateFields("domain").catch(() => {});
|
|
|
+ if (!valid) return;
|
|
|
|
|
|
-async function handleSync() {
|
|
|
- if (typeof examId !== "number") {
|
|
|
- void message.warn("请先选择考试");
|
|
|
- return;
|
|
|
+ if (testLoading.value) return;
|
|
|
+ setTestLoading(true);
|
|
|
+ try {
|
|
|
+ const res = await httpApp.post<any, { data: string }>(
|
|
|
+ "/api/ess/task/sync/test",
|
|
|
+ QueryString.stringify({
|
|
|
+ domain: formData.domain,
|
|
|
+ projectId,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ // console.log(res);
|
|
|
+ void message.info(res.data);
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ void message.info("网络失败,请检查网络或联系管理员!");
|
|
|
}
|
|
|
- await httpApp.post("/api/ess/task/sync", {
|
|
|
- domain,
|
|
|
- examId,
|
|
|
- projectId,
|
|
|
- });
|
|
|
+ setTestLoading(false);
|
|
|
+}
|
|
|
+
|
|
|
+const { loading: submitLoading, setLoading: setSubmitLoading } = useLoading();
|
|
|
+async function handleSync() {
|
|
|
+ const valid = await formRef.value?.validate().catch(() => {});
|
|
|
+ if (!valid) return;
|
|
|
|
|
|
- void message.warn("正在同步中...");
|
|
|
+ if (submitLoading.value) return;
|
|
|
+ setSubmitLoading(true);
|
|
|
+ let err = false;
|
|
|
+ await httpApp
|
|
|
+ .post("/api/ess/task/sync", {
|
|
|
+ domain: formData.domain,
|
|
|
+ examId: formData.examId,
|
|
|
+ projectId,
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ err = true;
|
|
|
+ });
|
|
|
+ setSubmitLoading(false);
|
|
|
+
|
|
|
+ if (err) return;
|
|
|
+ void message.warn("操作成功,正在同步中...");
|
|
|
}
|
|
|
</script>
|