Преглед на файлове

feat: 创建作业防抖/美化

XiaoYu преди 1 година
родител
ревизия
8df481c12e
променени са 2 файла, в които са добавени 39 реда и са изтрити 2 реда
  1. 22 2
      src/views/CourseDetailPage/tabs/HomeworkTab.vue
  2. 17 0
      src/views/CoursePage/CoursePage.vue

+ 22 - 2
src/views/CourseDetailPage/tabs/HomeworkTab.vue

@@ -1,6 +1,7 @@
 <script>
 import {ElMessage, ElMessageBox} from "element-plus";
 import {Close, UploadFilled} from "@element-plus/icons-vue";
+import debounce from "lodash-es/debounce";
 
 export default {
   name: "HomeworkTab",
@@ -241,6 +242,13 @@ export default {
         }
       });
     },
+    createWritingHomeworkDebounce: debounce(function () {
+      this.createHomework();
+    }, 1000, { leading: true, trailing: false }),
+
+    createSpeakingHomeworkDebounce: debounce(function () {
+      this.createSpeakingHomework();
+    }, 1000, { leading: true, trailing: false }),
     handleClose(){
       ElMessageBox.confirm("确认吗?你的修改将不会保存。",{
         confirmButtonText:"确认",
@@ -647,7 +655,7 @@ export default {
     <template #footer>
       <div class="dialog-footer">
         <el-button @click="createHomeworkCancel">取消</el-button>
-        <el-button type="primary" @click="createHomework">
+        <el-button type="primary" @click="createWritingHomeworkDebounce">
           创建
         </el-button>
       </div>
@@ -852,7 +860,7 @@ export default {
     <template #footer>
       <div class="dialog-footer">
         <el-button @click="createHomeworkCancel">取消</el-button>
-        <el-button type="primary" @click="createSpeakingHomework">
+        <el-button type="primary" @click="createSpeakingHomeworkDebounce">
           创建
         </el-button>
       </div>
@@ -890,6 +898,12 @@ export default {
   width: 100%;
   max-width: 100%;
   height: auto;
+
+}
+.homework-form-item textarea {
+  word-break: normal; /* 允许在单词之间换行 */
+  overflow-wrap: break-word; /* 防止长单词溢出,必要时才打断 */
+  hyphens: none; /* 禁止浏览器自动断字(连字符) */
 }
 .form-input{
   width: 100%;
@@ -905,4 +919,10 @@ export default {
 .list-leave-to {
   opacity: 0;
 }
+/* 统一字体 */
+.el-input__inner,
+.el-textarea__inner {
+  font-family: inherit;
+  font-size: 14px;
+}
 </style>

+ 17 - 0
src/views/CoursePage/CoursePage.vue

@@ -66,6 +66,7 @@ export default {
       activeIndex: "1",
       courses_all: [],
       courses_my: [],
+      hasAutoJumped: false, // 用于判断是否已经自动跳转
     };
   },
   computed: {
@@ -85,6 +86,9 @@ export default {
     isLogin() {
       return this.$store.getters.isLogin;
     },
+    shouldJumpToManage(){
+      return this.isTeacher && this.activeIndex === "2" && !this.hasAutoJumped;
+    },
   },
 
   async created() {
@@ -103,9 +107,22 @@ export default {
       if (index === "0") {
         this.$router.push("portal");
       }
+      if (index === "2" && this.isTeacher) {
+      // 教师一点“我的课程”直接进管理页
+      this.$router.push("/manage");
+      return;
+    }
       this.activeIndex = index;
     },
   },
+  watch:{
+    shouldJumpToManage(val){
+      if(val){
+        this.hasAutoJumped = true; // 设置标志位,防止重复跳转
+        this.$router.push("/manage");
+      }
+    }
+  }
 };
 </script>