فهرست منبع

[修改]导出成绩 功能测试逻辑

soleil 7 سال پیش
والد
کامیت
46377b00ae

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 227 - 227
package-lock.json


+ 3 - 1
package.json

@@ -14,6 +14,7 @@
     "buefy": "^0.7.1",
     "chart.js": "^2.7.3",
     "dayjs": "^1.7.8",
+    "file-saver": "^2.0.1",
     "register-service-worker": "^1.5.2",
     "vue": "^2.5.17",
     "vue-chartjs": "^3.4.0",
@@ -22,7 +23,8 @@
     "vue-router": "^3.0.1",
     "vuelidate": "^0.7.4",
     "vuex": "^3.0.1",
-    "whatwg-fetch": "^3.0.0"
+    "whatwg-fetch": "^3.0.0",
+    "xlsx": "^0.14.1"
   },
   "devDependencies": {
     "@pollyjs/adapter-fetch": "^1.4.1",

+ 69 - 0
src/util/exportExcel.js

@@ -0,0 +1,69 @@
+import XLSX from "xlsx";
+import { saveAs } from "file-saver";
+
+/**
+ * fn 字符串转字符流
+ * @param s
+ * @returns {ArrayBuffer}
+ */
+function s2ab(s) {
+  let buf = new ArrayBuffer(s.length);
+  let view = new Uint8Array(buf);
+  for (let i = 0; i !== s.length; ++i) {
+    view[i] = s.charCodeAt(i) & 0xff;
+  }
+  return buf;
+}
+
+function data2ws(data) {
+  const ws = {};
+  const range = { s: { c: 10000000, r: 10000000 }, e: { c: 0, r: 0 } };
+  for (let R = 0; R !== data.length; ++R) {
+    for (let C = 0; C !== data[R].length; ++C) {
+      if (range.s.r > R) range.s.r = R;
+      if (range.s.c > C) range.s.c = C;
+      if (range.e.r < R) range.e.r = R;
+      if (range.e.c < C) range.e.c = C;
+      const cell = { v: data[R][C] };
+      if (cell.v == null) continue;
+      const cellRef = XLSX.utils.encode_cell({ c: C, r: R });
+      if (typeof cell.v === "number") cell.t = "n";
+      else if (typeof cell.v === "boolean") {
+        cell.t = "b";
+      } else {
+        cell.t = "s";
+      }
+      ws[cellRef] = cell;
+    }
+  }
+  if (range.s.c < 10000000) ws["!ref"] = XLSX.utils.encode_range(range);
+  return ws;
+}
+
+function Workbook() {
+  if (!(this instanceof Workbook)) {
+    return new Workbook();
+  }
+  this.SheetNames = [];
+  this.Sheets = {};
+}
+
+export const toExcel = ({ th, data, fileName, fileType, sheetName }) => {
+  data.unshift(th);
+  const wb = new Workbook();
+  const ws = data2ws(data);
+  sheetName = sheetName || "sheet1";
+  wb.SheetNames.push(sheetName);
+  wb.Sheets[sheetName] = ws;
+  fileType = fileType || "xlsx";
+  var wbout = XLSX.write(wb, {
+    bookType: fileType,
+    bookSST: false,
+    type: "binary"
+  });
+  fileName = fileName || "列表";
+  saveAs(
+    new Blob([s2ab(wbout)], { type: "application/octet-stream" }),
+    `${fileName}.${fileType}`
+  );
+};

+ 1 - 3
src/views/student/Code/ProjectDetail/Test/FunctionalTestDetail.vue

@@ -24,7 +24,7 @@
         <div class="tag">{{ displayUnixTime(testDetail.time) }}</div>
       </template>
     </page-header>
-    <div class="console-section">{{ testDetail.consoleOutput }}</div>
+    <!--<div class="console-section">{{ testDetail.consoleOutput }}</div>-->
     <page-body>
       <div v-if="testDetailLoading"><page-section-loading show /></div>
       <div v-else>
@@ -42,8 +42,6 @@
             </div>
             <div v-if="!item.pass" class="code-section">
               {{ item.message }} <br />
-              <br />
-              {{ item.trace }}
             </div>
           </div>
         </div>

+ 19 - 22
src/views/student/Code/ProjectDetail/TestDetail.vue

@@ -30,7 +30,7 @@
           <div
             :class="{ 'is-loading': testing }"
             @click="makeTest"
-            :disabled="!(functionTestList && functionTestList.length > 0)"
+            :disabled="!(projectDetail.latestDeploy && projectDetail.latestDeploy.status == 'SUCCESS')"
             class="button is-primary test-title__action"
           >
             触发测试
@@ -93,28 +93,25 @@ export default {
   mixins: [timeMixins],
   methods: {
     async makeTest() {
-      const { functionTestList } = this;
-      if (functionTestList && functionTestList.length > 0) {
-        this.testing = true;
-        const { deployId } = functionTestList[0];
-        const { homeworkId, projectId } = this.$route.params;
-        const { data } = await makeFunctionalTest({
-          homeworkId,
-          projectId,
-          deployId
+      this.testing = true;
+      const deployId = this.projectDetail.latestDeploy.id;
+      const { homeworkId, projectId } = this.$route.params;
+      const { data } = await makeFunctionalTest({
+        homeworkId,
+        projectId,
+        deployId
+      });
+      this.testing = false;
+      if (data.success) {
+        this.$toast.open({
+          message: `测试触发成功`,
+          type: "is-success"
+        });
+      } else {
+        this.$toast.open({
+          message: `测试触发失败`,
+          type: "is-danger"
         });
-        this.testing = false;
-        if (data.success) {
-          this.$toast.open({
-            message: `测试触发成功`,
-            type: "is-success"
-          });
-        } else {
-          this.$toast.open({
-            message: `测试触发失败`,
-            type: "is-danger"
-          });
-        }
       }
     },
     sortTestList(list) {

+ 0 - 150
src/views/teacher/Code/ProjectDetail/DeployDetail.vue

@@ -1,42 +1,6 @@
 <template>
   <div class="data-table">
     <section>
-      <!--<div class="mirror-subtitle" v-if="deployStatus != 'RUNNING'">-->
-      <!--选择镜像-->
-      <!--</div>-->
-      <!--<div class="select-mirror" v-if="deployStatus != 'RUNNING'">-->
-      <!--<div class="latest-build">-->
-      <!--<div class="test-item" :key="item.id" v-for="item in latestBuildList">-->
-      <!--<div>-->
-      <!--<b-radio v-model="radio" :native-value="`b${item.id}`"> </b-radio>-->
-      <!--<strong>构建ID: #</strong> {{ item.id }}-->
-      <!--<span style="padding-left: 10px">-->
-      <!--<strong>镜像ID: #</strong> {{ item.mirrorId }}-->
-      <!--</span>-->
-      <!--</div>-->
-      <!--</div>-->
-      <!--<div-->
-      <!--class="test-item"-->
-      <!--:key="item.id"-->
-      <!--v-for="item in latestDeployList"-->
-      <!--&gt;-->
-      <!--<div>-->
-      <!--<b-radio v-model="radio" :native-value="`d${item.id}`"> </b-radio>-->
-      <!--<strong>构建ID: #</strong> {{ item.id }}-->
-      <!--<span style="padding-left: 10px">-->
-      <!--<strong>镜像ID: #</strong> {{ item.mirrorId }}-->
-      <!--</span>-->
-      <!--</div>-->
-      <!--</div>-->
-      <!--</div>-->
-      <!--</div>-->
-      <!--<button-->
-      <!--:class="['button', 'block', 'is-link', { 'is-loading': isRunning }]"-->
-      <!--@click="startDeploy"-->
-      <!--style="margin-top: 20px;"-->
-      <!--&gt;-->
-      <!--开始部署-->
-      <!--</button>-->
       <b-message
         title="部署进行中..."
         :active.sync="isRunning"
@@ -93,10 +57,6 @@ export default {
       haveDeployRecord: false,
       deployLog: "",
       unfoldDeployLogInfo: false
-      // latestBuildList: [],
-      // latestDeployList: [],
-      // latestMirrorIdList: [],
-      // radio: -1
     };
   },
   props: {
@@ -116,14 +76,8 @@ export default {
       if (newVal.latestDeploy && newVal.latestDeploy.id) {
         this.haveDeployRecord = true;
         this.getLatestDeployInfo(newVal.latestDeploy.id);
-        // this.getLatestDeployInfo(17);
         this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
       }
-      // this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
-      // this.getLastNDeployInfoList(
-      //     this.projectDetail && this.projectDetail.id,
-      //     5
-      // );
     }
   },
   mounted() {
@@ -131,10 +85,6 @@ export default {
       this.getLatestDeployInfo(this.projectDetail.latestDeploy.id);
       this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
     }
-    // if (this.projectDetail.id) {
-    //     this.getLatestBuildInfo(this.projectDetail.id, 5);
-    //     this.getLastNDeployInfoList(this.projectDetail.id, 5);
-    // }
   },
   methods: {
     //获取最新一次部署详细信息
@@ -160,67 +110,6 @@ export default {
       }
       return time.replace("T", " ") + "ms";
     },
-    //开始部署
-    // startDeploy() {
-    //     if (this.radio == -1) {
-    //         this.$toast.open({
-    //             message: "请先选择镜像",
-    //             type: "is-danger"
-    //         });
-    //         return;
-    //     } else {
-    //         let mirrorId = this.getSelectedMirrorId();
-    //         //触发部署
-    //         makeDeploy({
-    //             projectId: this.projectDetail.id,
-    //             mirrorId: mirrorId,
-    //             replicas: 1
-    //         })
-    //             .then(res => {
-    //                 console.log(res);
-    //                 this.$toast.open({
-    //                     message: "开始部署",
-    //                     type: "is-success"
-    //                 });
-    //
-    //                 this.isRunning = true;
-    //             })
-    //             .then(e => {
-    //                 this.$toast.open({
-    //                     message: e.message || "服务器未知错误",
-    //                     type: "is-danger"
-    //                 });
-    //             });
-    //     }
-    // },
-    //获取最近n次部署成功记录
-    // getLastNDeployInfoList(projectId, limit) {
-    //     getLatestDeployInfoList(projectId, limit)
-    //         .then(res => {
-    //             this.latestDeployList = res.data;
-    //             // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
-    //         })
-    //         .catch(e => {
-    //             this.$toast.open({
-    //                 message: e.message || " 服务器未知错误",
-    //                 type: "is-danger"
-    //             });
-    //         });
-    // },
-    //获取最近n个构建的信息
-    // getLatestBuildInfo(projectId, limit) {
-    //     getLatestBuildInfoList(projectId, limit)
-    //         .then(res => {
-    //             this.latestBuildList = res.data;
-    //             // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
-    //         })
-    //         .catch(e => {
-    //             this.$toast.open({
-    //                 message: e.message || "服务器未知错误",
-    //                 type: "is-danger"
-    //             });
-    //         });
-    // },
     //获取部署日志
     getDeployLogInfo(deployId) {
       getDeployLogInfo(deployId)
@@ -246,50 +135,11 @@ export default {
         return "";
       }
     }
-    //选择镜像ID
-    // getSelectedMirrorId() {
-    //     let list =
-    //         this.radio[0] == "b" ? this.latestBuildList : this.latestDeployList;
-    //     let id = this.radio.substring(1);
-    //     for (let item of list) {
-    //         if (item.id == id) {
-    //             return item.mirrorId;
-    //         }
-    //     }
-    // }
   }
 };
 </script>
 <style lang="scss" scoped>
 @import "../../../../assets/scss/app";
-.mirror-subtitle {
-  font-size: 1.25rem;
-  width: 100%;
-  font-weight: bold;
-  padding-bottom: 10px;
-  border-bottom: 1px solid #dbdbdb;
-}
-.select-mirror {
-  width: 100%;
-  display: flex;
-  .latest-build {
-    width: 100%;
-  }
-}
-.test-item {
-  width: 100%;
-  padding: $default-margin $default-margin-between;
-  margin: 0 -#{$default-margin-between};
-  cursor: pointer;
-}
-/*.test-item:hover,*/
-/*.test-item:nth-child(even):hover {*/
-/*background-color: #dde3ef;*/
-/*}*/
-
-.test-item:nth-child(even) {
-  background-color: rgba(244, 247, 252, 0.6);
-}
 .deploy-list {
   margin-top: 1.5rem;
   .deploy-item {

+ 24 - 1
src/views/teacher/Result/index.vue

@@ -16,7 +16,7 @@
         <div class="form-group">
           <!--下拉框-->
           <b-field>
-            <a class="button is-link" :disabled="isNoResult">导出作业成绩</a>
+            <a class="button is-link" :disabled="isNoResult" @click="exportStudentResult">导出作业成绩</a>
           </b-field>
           <b-field>
             <a
@@ -168,6 +168,7 @@ import {
   setResultPercentList
 } from "@/api/resultstatistics";
 import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
+// import { toExcel } from "@/util/exportExcel";
 
 const RESULT_SECTION = [
   "0分",
@@ -215,6 +216,28 @@ export default {
     };
   },
   methods: {
+    //导出学生作业成绩
+    exportStudentResult() {
+      // const th = ['ID', '姓名', '文档作业成绩', '互评作业成绩', '代码作业成绩', '总评'];
+      // const filterVal = ['id', 'user', 'documents', 'reviews', 'codes', 'finalRes'];
+      // // const data = this.studentFinalResultList.map(v => filterVal.map(k => v[k]));
+      // // console.log(data);
+      // let data = [];
+      // for(let item of this.studentFinalResultList){
+      //     let docResString = "";
+      //     let reviewResString = "";
+      //     for(let docRes of item.documents){
+      //         docResString += `${docRes.name}:${docRes.score};`
+      //     }
+      //     for(let reviewRes of item.reviews){
+      //         reviewResString += `${reviewRes.name}:${reviewRes.score}`;
+      //     }
+      //     for(let codes)
+      //     let outPutInfo = [item.id,item.user.nickname,docResString,];
+      // }
+      // // const [fileName, fileType, sheetName] = ['学生成绩', 'xlsx', '成绩'];
+      // // toExcel({th, data, fileName, fileType, sheetName});
+    },
     //绘制成绩图表
     drawResultChart() {
       let myChart2 = new Chart(this.resultChart, {

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است