Bladeren bron

Merge remote-tracking branch 'origin/seec' into seec

yhd12345 4 jaren geleden
bovenliggende
commit
a381191f03
4 gewijzigde bestanden met toevoegingen van 113 en 115 verwijderingen
  1. 12 0
      src/api/course/course.js
  2. 0 10
      src/utils/oss.js
  3. 6 4
      src/views/AuthPage/components/AuthCard.vue
  4. 95 101
      src/views/ManagePage/ManagePage.vue

+ 12 - 0
src/api/course/course.js

@@ -71,6 +71,17 @@ function checkCourseCodeUnique(id, code) {
   });
 }
 
+function uploadCourseImage(name, image) {
+  let data = new FormData();
+  data.append("name", name);
+  data.append("file", image);
+  return axios.post(`${prefix}/uploadImage`, data, {
+    headers: {
+      "Content-Type": "multipart/form-data"
+    }
+  });
+}
+
 const courseAPIs = {
   createCourse,
   getAllCourses,
@@ -85,6 +96,7 @@ const courseAPIs = {
   checkCourseNameUnique,
   checkCourseCodeUnique,
   getCourseByEvalId,
+  uploadCourseImage,
 };
 
 export default courseAPIs;

+ 0 - 10
src/utils/oss.js

@@ -1,10 +0,0 @@
-let OSS = require("ali-oss");
-
-const client = new OSS({
-  region: "oss-cn-hangzhou",
-  accessKeyId: "LTAI5t8r92pu9SjG1vz9fCKT",
-  accessKeySecret: "NPGHba96kBK0PdL65QwQNyMBz0PCfq",
-  bucket: "mjh1"
-});
-
-export default client;

+ 6 - 4
src/views/AuthPage/components/AuthCard.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="auth-card-body">
     <h2 id="auth-card-title">{{ cardTitle }} </h2>
-    <el-form id="auth-card-form" ref="cardFormRef" :model="cardForm" :rules="cardFormRule" @keyup.enter="onSubmit">
+    <el-form id="auth-card-form" ref="cardFormRef"  :model="cardForm" :rules="cardFormRule" @keyup.enter="onSubmit">
 
       <el-form-item v-if="cardType==='login'" class="auth-card-form-item" prop="phone">
         <el-input v-model="cardForm.phone" autofocus clearable placeholder="请输入手机号">
@@ -92,7 +92,7 @@
       </div>
 
       <el-form-item v-if="cardType==='login'" class="auth-card-form-item">
-        <SlideVerifier id="auth-card-slide-verifier" is-lock @change="handleSlideVerifier"/>
+        <SlideVerifier id="auth-card-slide-verifier" ref="verifier" is-lock @change="handleSlideVerifier"/>
       </el-form-item>
 
       <el-form-item class="auth-card-form-item">
@@ -235,6 +235,7 @@ export default {
           }
         ]
       },
+      slideVerifierVisible: true,
     };
   },
 
@@ -355,9 +356,10 @@ export default {
                     this.$message({
                       showClose: true,
                       message: res.data.message,
-                      type: "warning"
+                      type: "error"
                     });
-                    location.reload();
+                    Object.assign(this.$data, this.$options.data());
+                    this.$refs.verifier.init();
                   }
                 })
                 .catch((e) => {

+ 95 - 101
src/views/ManagePage/ManagePage.vue

@@ -48,7 +48,8 @@
           </div>
         </template>
         <div class="course-card-list-container">
-          <CourseCard v-for="(item,index) in filterCourses" :key="index" :ref="'courseCard'+item.id" :courseVO="item" @delete="deleteCourse(item)" @update="beforeUpdateCourse(item)"/>
+          <CourseCard v-for="(item,index) in filterCourses" :key="index" :ref="'courseCard'+item.id" :courseVO="item"
+                      @delete="deleteCourse(item)" @update="beforeUpdateCourse(item)"/>
         </div>
       </el-card>
 
@@ -60,16 +61,16 @@
           <span style="font-weight: bold; font-size: larger">
             全部测试
           </span>
-<!--            <div class="course-type-selector">-->
-<!--              <el-select v-model="examType" class="m-2" placeholder="测试类型">-->
-<!--                <el-option-->
-<!--                  v-for="item in examTypeOptions"-->
-<!--                  :key="item.value"-->
-<!--                  :label="item.label"-->
-<!--                  :value="item.value"-->
-<!--                />-->
-<!--              </el-select>-->
-<!--            </div>-->
+            <!--            <div class="course-type-selector">-->
+            <!--              <el-select v-model="examType" class="m-2" placeholder="测试类型">-->
+            <!--                <el-option-->
+            <!--                  v-for="item in examTypeOptions"-->
+            <!--                  :key="item.value"-->
+            <!--                  :label="item.label"-->
+            <!--                  :value="item.value"-->
+            <!--                />-->
+            <!--              </el-select>-->
+            <!--            </div>-->
           </div>
         </template>
         <el-tabs v-model="activeTestPaneName">
@@ -176,9 +177,9 @@
 
 <script>
 import CourseCard from "@/components/CourseCard";
-import { ElMessage, ElMessageBox } from "element-plus";
-import client from "@/utils/oss";
-import { Back, Document } from "@element-plus/icons-vue";
+import {ElMessage, ElMessageBox} from "element-plus";
+// import client from "@/utils/oss";
+import {Back, Document} from "@element-plus/icons-vue";
 import TestCard from "@/components/TestCard";
 
 export default {
@@ -278,19 +279,19 @@ export default {
       myCourseList: [],
       courseType: "all",
       courseTypeOptions: [
-        { value: "all", label: "全部课程" },
-        { value: "pending", label: "未开始" },
-        { value: "start", label: "正在进行" },
-        { value: "end", label: "已结束" },
+        {value: "all", label: "全部课程"},
+        {value: "pending", label: "未开始"},
+        {value: "start", label: "正在进行"},
+        {value: "end", label: "已结束"},
       ],
       evalExamList: [],
       coderExamList: [],
       examType: "all",
       examTypeOptions: [
-        { value: "all", label: "全部测试" },
-        { value: "pending", label: "未开始" },
-        { value: "start", label: "正在进行" },
-        { value: "end", label: "已结束" },
+        {value: "all", label: "全部测试"},
+        {value: "pending", label: "未开始"},
+        {value: "start", label: "正在进行"},
+        {value: "end", label: "已结束"},
       ],
     };
   },
@@ -330,98 +331,91 @@ export default {
         this.$router.push("portal");
       }
       if (index === "1") {
-        document.getElementById("app").scrollIntoView({ behavior: "smooth" });
+        document.getElementById("app").scrollIntoView({behavior: "smooth"});
       }
       if (index === "2") {
-        document.querySelector("#manage-page-divider").scrollIntoView({ behavior: "smooth" });
+        document.querySelector("#manage-page-divider").scrollIntoView({behavior: "smooth"});
       }
       this.activeIndex = index;
     },
     handleFormConfirm() {
       const _this = this;
-      // 上传oss图片
-      this.$refs.formRef.validate((valid) => {
+      _this.form.imageUrl = null;
+      _this.$refs.formRef.validate((valid) => {
         if (valid) {
-          if (this.form.fileList.length === 0) {
-            this.form.imageUrl = null;
-            createOrUpdateCourse();
-          } else {
-            if (this.form.fileList[0].raw) {
-              client.put("/seecoder/image-" + this.form.name + ".jpg", this.form.fileList[0].raw)
-                .then(res => {
-                  this.form.imageUrl = res.res.requestUrls[0];
-                  createOrUpdateCourse();
-                })
-                .catch(err => {
-                  console.log(err);
-                  ElMessage.error(err);
-                });
-            } else {
-              createOrUpdateCourse();
-            }
-          }
-        }
-      });
-
-      function createOrUpdateCourse() {
-        console.log(_this.form);
-        if (_this.form.id === null) {
-          _this.$apis.createCourse({
-            name: _this.form.name,
-            teacher: {
-              id: _this.$store.state.user.id,
-            },
-            semester: _this.form.year + _this.form.season,
-            imageUrl: _this.form.imageUrl,
-            description: _this.form.description,
-            startTime: _this.form.courseTime[0],
-            endTime: _this.form.courseTime[1],
-            invitationCode: _this.form.invitationCode,
-            moocUrl: _this.form.moocUrl,
-            createdTime: new Date(),
-            price: Number(_this.form.price),
-            coderId: _this.form.coderLink ? -1 : null,
-            evalId: _this.form.evalLink ? -1 : null,
-          })
-            .then((res) => {
-              _this.myCourseList.push(res.data.data);
-              _this.dialogVisible = false;
-              _this.clearForm();
-              ElMessage.success("新建课程成功");
-            })
-            .catch(err => {
-              ElMessage.error(err);
+          if (_this.form.id === null) {
+            // 首先创建课程
+            // 之后上传课程图片
+            _this.$apis.createCourse({
+              name: _this.form.name,
+              teacher: {
+                id: _this.$store.state.user.id,
+              },
+              semester: _this.form.year + _this.form.season,
+              imageUrl: null,
+              description: _this.form.description,
+              startTime: _this.form.courseTime[0],
+              endTime: _this.form.courseTime[1],
+              invitationCode: _this.form.invitationCode,
+              moocUrl: _this.form.moocUrl,
+              createdTime: new Date(),
+              price: Number(_this.form.price),
+              coderId: _this.form.coderLink ? -1 : null,
+              evalId: _this.form.evalLink ? -1 : null,
+            }).then(async (res) => {
+              const createdCourse = res.data.data;
+              if (createdCourse) {
+                if (_this.form.fileList.length !== 0) {
+                  const imageUrl = (await _this.$apis.uploadCourseImage(createdCourse.name, this.form.fileList[0].raw)).data.data;
+                  if (imageUrl) {
+                    createdCourse.imageUrl = imageUrl;
+                  }
+                }
+                _this.myCourseList.push(createdCourse);
+                _this.dialogVisible = false;
+                _this.clearForm();
+                ElMessage.success("新建课程成功");
+              } else {
+                console.log(res);
+              }
             });
-        } else {
-          _this.$apis.updateCourse({
-            id: _this.form.id,
-            name: _this.form.name,
-            semester: _this.form.year + _this.form.season,
-            imageUrl: _this.form.imageUrl,
-            description: _this.form.description,
-            startTime: _this.form.courseTime[0],
-            endTime: _this.form.courseTime[1],
-            invitationCode: _this.form.invitationCode,
-            moocUrl: _this.form.moocUrl,
-            price: Number(_this.form.price),
-          })
-            .then((res) => {
-              for (let i = 0; i < _this.myCourseList.length; i++) {
-                if (_this.myCourseList[i].id === _this.form.id) {
-                  _this.myCourseList[i] = res.data.data;
+          } else {
+            // 首先更新课程
+            // 之后更新课程图片
+            _this.$apis.updateCourse({
+              id: _this.form.id,
+              name: _this.form.name,
+              semester: _this.form.year + _this.form.season,
+              imageUrl: _this.form.imageUrl,
+              description: _this.form.description,
+              startTime: _this.form.courseTime[0],
+              endTime: _this.form.courseTime[1],
+              invitationCode: _this.form.invitationCode,
+              moocUrl: _this.form.moocUrl,
+              price: Number(_this.form.price),
+            }).then(async (res) => {
+              const updatedCourse = res.data.data;
+              if (updatedCourse) {
+                if (_this.form.fileList.length !== 0) {
+                  const imageUrl = (await _this.$apis.uploadCourseImage(createdCourse.name, this.form.fileList[0].raw)).data.data;
+                  if (imageUrl) {
+                    updatedCourse.imageUrl = imageUrl;
+                  }
+                }
+                for (let i = 0; i < _this.myCourseList.length; i++) {
+                  if (_this.myCourseList[i].id === _this.form.id) {
+                    _this.myCourseList[i] = createdCourse;
+                  }
                 }
+                _this.$refs["courseCard" + _this.form.id][0].$props.courseVO = createdCourse;
+                _this.dialogVisible = false;
+                _this.clearForm();
+                ElMessage.success("更新课程成功");
               }
-              _this.$refs["courseCard" + _this.form.id][0].$props.courseVO = res.data.data;
-              _this.dialogVisible = false;
-              _this.clearForm();
-              ElMessage.success("更新课程成功");
-            })
-            .catch(err => {
-              console.log(err);
-              ElMessage.error(err);
             });
+          }
         }
-      }
+      });
     },
     handleFormCancel() {
       ElMessageBox.confirm("是否确认退出?退出后将不保存表格信息。", "提示", {