#2 优化学生写作作业提交逻辑和暂存逻辑

Закрыто
ZhuChenXi хочет смерджить 1 коммит(ов) из FanYanPeng/zcx-7-14 в FanYanPeng/host-nju
3 измененных файлов с 50 добавлено и 49 удалено
  1. 2 2
      src/apis/axios.config.ts
  2. 15 15
      src/router/index.ts
  3. 33 32
      src/views/Home/component/Edit/index.vue

+ 2 - 2
src/apis/axios.config.ts

@@ -1,9 +1,9 @@
 import axios from "axios";
 
 // const BASEURL = 'http://47.111.23.171:8081'
-// const BASEURL = 'http://localhost:8082'
+const BASEURL = 'http://localhost:8082'
 // const BASEURL = 'http://8.130.126.86:8080'
-const BASEURL = 'https://air-nju.seec.seecoder.cn/'
+// const BASEURL = 'https://air-nju.seec.seecoder.cn/'
 
 const axiosInstance = axios.create({
     baseURL: BASEURL,

+ 15 - 15
src/router/index.ts

@@ -16,24 +16,24 @@ const router = createRouter({
     },
 
     // 登录与注册
-    {
-      path: "/",
-      redirect: () => {
-        window.location.href = "https://p-nju.seec.seecoder.cn/login?from=https://air-nju.seec.seecoder.cn";
-        // window.location.href = "http://localhost:8000/login?from=http://localhost:4000";
-        // {本地门户首页地址}?from={本地eai首页地址}
-        return "/"; // 占位返回值,实际不会执行
-    },
-    },
     // {
     //   path: "/",
-    //   redirect: "/login"
+    //   redirect: () => {
+    //     window.location.href = "https://p-nju.seec.seecoder.cn/login?from=https://air-nju.seec.seecoder.cn";
+    //     // window.location.href = "http://localhost:8000/login?from=http://localhost:4000";
+    //     // {本地门户首页地址}?from={本地eai首页地址}
+    //     return "/"; // 占位返回值,实际不会执行
     // },
-    // {
-    //   path: '/login',
-    //   name: 'login',
-    //   component: () => import('../views/LoginPage/LoginPage.vue')
     // },
+    {
+      path: "/",
+      redirect: "/login"
+    },
+    {
+      path: '/login',
+      name: 'login',
+      component: () => import('../views/LoginPage/LoginPage.vue')
+    },
     {
       path: '/register',
       name: 'register',
@@ -195,7 +195,7 @@ const router = createRouter({
  */
   router.beforeEach(async (to) => {
     const store = useStore();
-    const publicPaths = [ '/register', '/passwordChange', '/admin/login'];
+    const publicPaths = [ '/register', '/passwordChange', '/admin/login', '/login'];
     // 1. 检查URL中的token
     const urlToken = new URLSearchParams(window.location.search).get('token');
     if (urlToken) {

+ 33 - 32
src/views/Home/component/Edit/index.vue

@@ -81,48 +81,49 @@
   };
 
   // 提交操作
-  const handleSubmit = () => {
-    // 内容已保存,则可以点击提交
-    if (hasStage.value == true) {
-      const endTime = dayjs(data.assignment.endTime); // 假设截止时间在 assignment 的 endTime 属性中
-      const currentTime = dayjs();
-      if (currentTime.isAfter(endTime)) {
-        ElMessage.error('作业已截止,无法提交!');
-        return;
-      }
-      hasStage.value = false
-      apis.engagementSubmit(store.user.id, props.engagement.assignmentId, )
-          .then((_res: any) => {
-            success(_res.data.data);
-            router.push("/home/myHomework")
-          })
-          .catch((error: any) => {
-            console.error('提交失败', error);
-            error('提交失败');
-          });
-    } else {
-      ElMessage.error('编辑内容未保存,请保存后提交!');
+  const handleSubmit = async () => {
+    // 先自动暂存
+    try {
+      await handleStage();
+    } catch (e) {
+      ElMessage.error('暂存失败,无法提交!');
+      return;
     }
+    const endTime = dayjs(data.assignment.endTime); // 假设截止时间在 assignment 的 endTime 属性中
+    const currentTime = dayjs();
+    if (currentTime.isAfter(endTime)) {
+      ElMessage.error('作业已截止,无法提交!');
+      return;
+    }
+    apis.engagementSubmit(store.user.id, props.engagement.assignmentId, )
+    .then((_res: any) => {
+      success(_res.data.data);
+      router.push("/home/myHomework")
+    })
+    .catch((error: any) => {
+      console.error('提交失败', error);
+      error('提交失败');
+    });
   };
 
   // 暂存操作
-  const handleStage = () => {
+  const handleStage = async () => {
     const endTime = dayjs(data.assignment.endTime); // 假设截止时间在 assignment 的 endTime 属性中
     const currentTime = dayjs();
     if (currentTime.isAfter(endTime)) {
       ElMessage.error('作业已截止,无法暂存!');
       return;
     }
-    apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value)
-        .then((_res: any) => {
-          // 存储行为数据
-          emitter.emit('click-stage')
-          success(_res.data.data);
-        })
-        .catch((error: any) => {
-          console.error('暂存失败', error);
-          error('暂存失败');
-        });
+    try {
+      const _res = await apis.engagementStage(store.user.id, props.engagement.assignmentId, JSON.stringify(getQuillContent), getText.value, getHTML.value);
+      emitter.emit('click-stage');
+      success(_res.data.data);
+      return _res;
+    } catch (error) {
+      console.error('暂存失败', error);
+      error('暂存失败');
+      throw error;
+    }
   };
 
   // window.onbeforeunload = function(event) {