Преглед изворни кода

feat:修改教师批改作业的权限问题,并修复一些教师名称显示问题

白白 пре 2 година
родитељ
комит
609e02915e

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

@@ -1,7 +1,7 @@
 import axios from "axios";
 
 // const BASEURL = 'http://47.111.23.171:8081'
-const BASEURL = '/api'
+const BASEURL = 'http://localhost:8080'
 // const BASEURL = 'http://8.130.126.86:8080'
 
 const axiosInstance = axios.create({
@@ -19,8 +19,7 @@ axiosInstance.interceptors.request.use(
         if(sessionStorage.getItem('user-storage')){
             token = JSON.parse(sessionStorage.getItem('user-storage') as string).token
         }
-        
-        console.log(token, "axios.configs")
+
         // 如果存在token,则每次请求前加入到请求头中
         if (token) config.headers["Authorization"] = token
         return config

+ 3 - 1
src/components/WordEditor/WordEditor.vue

@@ -62,7 +62,9 @@
     },
     editorConfig: {
       lang: 'zh-CN',
-      callbackUrl: 'http://139.196.252.184:8081/api/onlyoffice/callback',
+      //不要用localhost和127.0.0.1访问,用局域网IP访问
+      //TODO:项目部署要改
+      callbackUrl: 'http://192.168.137.1:8080/api/onlyoffice/callback',
       customization: {
         autosave: false,
         comments: false,

+ 4 - 3
src/types/vo.ts

@@ -75,8 +75,8 @@ export interface AssignmentVO {
 
 export interface IAssignmentTableColumn {
     title: string;
-    dataIndex: 'desc' | 'publisher' | 'startDate' | 'endDate' | 'details' | 'writing' | 'assignmentId';
-    key: 'desc' | 'publisher' | 'startDate' | 'endDate' | 'details' | 'writing' | 'assignmentId';
+    dataIndex: 'desc' | 'publisher' | 'startDate' | 'endDate' | 'details' | 'writing' | 'assignmentId' | 'teacherId';
+    key: 'desc' | 'publisher' | 'startDate' | 'endDate' | 'details' | 'writing' | 'assignmentId' | 'teacherId';
 }
 
 export interface IAssignmentTableItem {
@@ -85,7 +85,8 @@ export interface IAssignmentTableItem {
     startDate: string;
     endDate: string;
     assignmentId: number;
-    descriptionFile?: string
+    descriptionFile?: string;
+    teacherId: string
 }
 
 

+ 2 - 1
src/views/CorrectPage/AssignmentPage.vue

@@ -104,7 +104,8 @@
   let courseInfo = reactive<CourseVO>({} as CourseVO)
 
   let query = reactive<AssignmentQuery>({
-    courseId: +route.query.courseId
+    courseId: +route.query.courseId,
+    teacherId: store.user.id
   } as AssignmentQuery)
 
   const fetchCourseInfo = () => {

+ 7 - 1
src/views/CourseSquare/component/CourseDetails/component/CourseHomeworkTable.vue

@@ -23,7 +23,7 @@
         </el-table-column>
         <el-table-column :label="role == 'teachers'? '编辑':'写作'">
           <template #default="scope">
-            <el-button color="#888" circle @click="handleFunctionButton(scope.row.assignmentId)" :disabled="props.disabled"/>
+            <el-button color="#888" circle @click="handleFunctionButton(scope.row.assignmentId)" :disabled="props.disabled || isDisabled(scope.row.teacherId)"/>
           </template>
         </el-table-column>
       </el-table>
@@ -76,6 +76,7 @@ import {defineProps, inject, onMounted, reactive, ref} from 'vue';
   import {useFormatDate} from "@/hooks/useFormatDate";
   import assignment from "@/apis/assignment";
 import ViewsWordEditor from "@/components/ViewsWordEditor/ViewsWordEditor.vue";
+import {useStore} from "@/store";
 
   const props = defineProps<{
     tableData: IAssignmentTableItem[],
@@ -87,6 +88,7 @@ import ViewsWordEditor from "@/components/ViewsWordEditor/ViewsWordEditor.vue";
   }>()
 
   const apis = useApis()
+  const store = useStore()
   const doRefresh:Function = inject("reload")
   const {formatDate} = useFormatDate()
 
@@ -252,6 +254,10 @@ const openEditor = (url: string, title: string) => {
     doRefresh();
   }
 
+  const isDisabled = (teacherId:string) => {
+    return props.role == 'teachers' && +teacherId != store.user.id;
+  }
+
   onMounted(() => {
     console.log(props)
   })

+ 38 - 15
src/views/CourseSquare/component/CourseDetails/index.vue

@@ -173,12 +173,28 @@ const columns = ref<IAssignmentTableColumn[]>([
 // 用于展示课程所含的作业
 let homeworkList = ref<IAssignmentTableItem[]>([]);
 
+/*
+  用于显示教师姓名
+   */
+const processCourses = () => {
+  for(let i = 0; i < dataForm.teacherIds.length; i++){
+    apis.findUserById(dataForm.teacherIds[i])
+        .then((res:any) => {
+          dataForm.teacherIds[i] = res.data.data.records[0].name
+        })
+        .catch((err:any) => {
+          console.log("错误信息",err)
+        })
+  }
+}
+
 const getCourse = () => {
   // 获取课程信息
   apis.getCourseByCourseId(courseId)
       .then((res: any) => {
         let data = res.data.data.records[0]
         Object.assign(dataForm, {...data})
+        processCourses()
         getNewCourseInfo(dataForm)
       })
       .catch((err: any) => {
@@ -206,10 +222,11 @@ const getHomeworkList = () => {
         let data = res.data.data.records
         homeworkList.value = convertHomeworkList(data)
         // TODO
-        for(let i = 0; i < data.length; i++){
-          apis.findUserById(data[i].teacherId)
+        console.log(homeworkList.value)
+        for(let i = 0; i < homeworkList.value.length; i++){
+          apis.findUserById(+homeworkList.value[i].publisher)
               .then((res: any) => {
-                data[i].teacherId = res.data.data.records[0].name
+                homeworkList.value[i].publisher = res.data.data.records[0].name
               })
         }
       })
@@ -274,18 +291,23 @@ const enroll = () => {
 const isShowEdit = () => {
   apis.getCourseByTeacherId(store.user.id)
       .then((res: any) => {
-        let data = res.data.data.records
-        for(let i = 0 ; i < data.length; i++){
-          if(data[i].courseId == courseId){
-            showEdit.value = true;
-            break;
-          }
-        }
+        let total = res.data.data.total
+        apis.getCourseByTeacherId(store.user.id, 1, total)
+            .then((res: any) => {
+              let data = res.data.data.records
+              for(let i = 0 ; i < data.length; i++){
+                if(data[i].courseId == courseId){
+                  showEdit.value = true;
+                  break;
+                }
+              }
+            })
+            .catch((err: any) => {
+              console.error(err);
+            })
+            .finally(() => {});
       })
-      .catch((err: any) => {
-        console.error(err);
-      })
-      .finally(() => {});
+
 }
 
 /*
@@ -300,7 +322,8 @@ const convertHomeworkList = (data:IAssignment[]) => {
       startDate: formatDate(data[i].startTime),
       endDate: formatDate(data[i].endTime),
       assignmentId: data[i].assignmentId,
-      descriptionFile: data[i].descriptionFile != null ? data[i].descriptionFile: null
+      descriptionFile: data[i].descriptionFile != null ? data[i].descriptionFile: null,
+      teacherId: data[i].teacherId.toString(),
     }
     newHomeworkList.push(item)
   }

+ 10 - 5
src/views/HomeworkPage/component/HomeworkDetail.vue

@@ -86,11 +86,16 @@ async function getEngagement(){
         console.log(_res)
         //还未参加作业,则先加入作业
         if(_res.data.data == null){
-          apis.engageAssignment(assignmentId);
-          ElMessage({
-            message: '参加作业成功',
-            type: 'success',
-          })
+          apis.engageAssignment(assignmentId)
+              .then((res:any) => {
+                ElMessage({
+                  message: '参加作业成功',
+                  type: 'success',
+                })
+              })
+              .catch((_err:any) => {
+                console.log("参加做业的错误",_err)
+              })
         }
       }).catch((_err:any) => {
         console.log(_err)

+ 5 - 20
vite.config.ts

@@ -3,26 +3,8 @@ import { fileURLToPath, URL } from 'node:url'
 import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 
-//vite.config.ts 和 axios.config.ts和baiqi的版本有些许出入,若保留其版本无法正常登陆
-//目前用的还是xiaoyu的版本
-
 // https://vitejs.dev/config/
 export default defineConfig({
-
-    //配置代理,解决跨域问题。详见EAI问题文档
-    server: {
-      host: '127.0.0.1',
-      port: 4000,
-      proxy: {
-        '/api': {  
-          target: 'http://localhost:8080',
-          changeOrigin: true,
-          rewrite: (path) => path.replace(/^\/api/, ''),
-        },
-      },
-    },
-  
-
   plugins: [
     vue(),
   ],
@@ -31,5 +13,8 @@ export default defineConfig({
       '@': fileURLToPath(new URL('./src', import.meta.url))
     }
   },
- 
-})
+  server: {
+    host: 'localhost',
+    port: 3000
+  }
+})