guhongwei 4 lat temu
rodzic
commit
b5da11d95c

+ 20 - 0
src/router/index.js

@@ -549,6 +549,26 @@ const routes = [
         meta: { title: '新人才报' },
         component: () => import('@/views/newspaper/index.vue'),
       },
+      // 10-17
+      // 作业管理
+      {
+        path: '/task/index',
+        name: 'task_index',
+        meta: { title: '作业管理' },
+        component: () => import('@/views/task/index.vue'),
+      },
+      {
+        path: '/task/taskList',
+        name: 'task_taskList',
+        meta: { title: '学生作业列表' },
+        component: () => import('@/views/task/taskList.vue'),
+      },
+      {
+        path: '/task/taskDetail',
+        name: 'task_taskDetail',
+        meta: { title: '学生作业详情' },
+        component: () => import('@/views/task/taskDetail.vue'),
+      },
     ],
   },
   {

+ 127 - 0
src/views/task/index.vue

@@ -0,0 +1,127 @@
+<template>
+  <div id="index">
+    <list-frame :title="pageTitle" @query="search" :total="total" :needFilter="false" :needAdd="false">
+      <el-form size="small" :inline="true">
+        <el-form-item label="班级">
+          <el-select v-model="searchInfo.classid" placeholder="请选择班级">
+            <el-option v-for="(c, index) in classList" :key="index" :label="`${c.name.includes('班') ? c.name : `${c.name}班`}`" :value="c._id"></el-option>
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <data-table :fields="fields" :data="tableData" :opera="opera" @view="toTaskList"></data-table>
+    </list-frame>
+  </div>
+</template>
+
+<script>
+import listFrame from '@frame/layout/admin/list-frame';
+import dataTable from '@frame/components/data-table';
+import _ from 'lodash';
+import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: lesson } = createNamespacedHelpers('lesson');
+const { mapActions: util } = createNamespacedHelpers('util');
+const { mapActions: classes } = createNamespacedHelpers('classes');
+export default {
+  name: 'index',
+  props: {},
+  components: { listFrame, dataTable },
+  data: () => ({
+    opera: [
+      {
+        label: '查看学生作业',
+        icon: 'el-icon-view',
+        method: 'view',
+      },
+    ],
+    fields: [
+      { label: '课程日期', prop: 'date' },
+      { label: '课程名称', prop: 'subname' },
+    ],
+    tableData: [],
+    total: 0,
+    // 选择班级
+    searchInfo: {},
+    // 班级列表
+    classList: [],
+  }),
+  created() {
+    this.getOtherList();
+    if (this.id) {
+      this.search();
+    }
+  },
+  computed: {
+    ...mapState(['user', 'defaultOption']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  methods: {
+    ...classes({ getClass: 'query' }),
+    ...lesson({ lessionInfo: 'fetch', lessionList: 'query' }),
+    ...util({ modelFetch: 'fetch' }),
+    async search({ skip, limit, ...info } = {}) {
+      const lesson = await this.modelFetch({ model: 'lesson', ...this.searchInfo });
+      let lessons = _.get(lesson.data, 'lessons', []);
+      // lesson排序,只去时间最早的作为作业的上传lessonid,需要和学生作业列表处相同处理
+      let r = lessons.filter(f => f.subid);
+      r = r.map(r => {
+        let time = r.time.split('-');
+        r.start = `${r.date} ${time[0]}`;
+        return r;
+      });
+      r = Object.values(_.groupBy(r, 'subid'));
+      r = r.map(a => {
+        let na = _.orderBy(a, ['start'], ['asc']);
+        return _.head(na);
+      });
+      this.$set(this, `tableData`, r);
+      this.$set(this, `total`, r.length);
+    },
+    toTaskList(item) {
+      this.$router.push({ path: '/task/taskList', query: { lessonid: item.data._id, classid: this.searchInfo.classid } });
+    },
+    // 查询班级列表
+    async getOtherList() {
+      const { termid } = this.defaultOption;
+      if (!termid) return;
+      const res = await this.getClass({ termid });
+      if (this.$checkRes(res)) {
+        let duplicate = _.cloneDeep(res.data);
+        duplicate = duplicate.map(i => {
+          if (parseInt(i.name)) {
+            i.order = parseInt(i.name);
+          } else {
+            // i.order = i.name;
+          }
+          return i;
+        });
+        duplicate = _.orderBy(duplicate, ['order'], ['asc']);
+        this.$set(this, `classList`, duplicate);
+      }
+    },
+  },
+  watch: {
+    defaultOption: {
+      deep: true,
+      handler(val, oval) {
+        this.getOtherList();
+      },
+    },
+    searchInfo: {
+      deep: true,
+      handler(val) {
+        if (val) {
+          const keys = Object.keys(val);
+          if (keys.length > 0) this.search();
+        }
+      },
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 154 - 0
src/views/task/taskDetail.vue

@@ -0,0 +1,154 @@
+<template>
+  <div id="taskDetail">
+    <detail-frame title="作业详情" :returns="toreturn">
+      <el-row style="text-align:center">
+        <el-col :span="24">
+          <el-row type="flex" :gutter="20">
+            <el-col :span="getSpan('task')" v-if="task && task.question">
+              <el-card header="在线作业">
+                <el-table :data="task.question" size="mini" border stripe>
+                  <el-table-column align="center" type="expand">
+                    <template v-slot="{ row }">
+                      <el-row class="task_list">
+                        <el-col :span="24">
+                          {{ row.topic }}
+                        </el-col>
+                        <el-col :span="24" v-for="(o, oi) in row.option" :key="`${index}-${oi}`"> {{ o.number }} - {{ o.opname }} </el-col>
+                        <el-col :span="24">学生答案:{{ row.answers }}</el-col>
+                      </el-row>
+                    </template>
+                  </el-table-column>
+                  <el-table-column align="center" label="题目" prop="topic"></el-table-column>
+                  <el-table-column align="center" label="题目类型">
+                    <template v-slot="{ row }">
+                      <span>{{ row.type == '0' ? '单选' : row.type == '1' ? '多选' : row.type == '2' ? '问答' : '暂无' }}</span>
+                    </template>
+                  </el-table-column>
+                  <el-table-column align="center" label="答案" prop="answers"></el-table-column>
+                </el-table>
+              </el-card>
+            </el-col>
+            <el-col :span="getSpan('picurl')" v-if="taskAnswer && taskAnswer.picurl">
+              <el-card header="上传作业">
+                <el-col :span="24" v-if="taskAnswer">
+                  <p style="padding: 0 0 15px 0;font-size: 23px;">作业成绩:{{ taskAnswer.score }}</p>
+                </el-col>
+                <!-- <el-alert title="点击查看大图" type="success" style="margin:10px" center></el-alert> -->
+                <el-image v-for="(i, index) in taskAnswer.picurl" :key="index" :src="i" :preview-src-list="taskAnswer.picurl"></el-image>
+              </el-card>
+            </el-col>
+          </el-row>
+        </el-col>
+        <!-- <el-col :span="24">
+          <el-input class="score" v-model="taskAnswer.score" type="number" label="作业成绩:" placeholder="请输入学生成绩" />
+          <el-button round @click="onSubmit">提交成绩</el-button>
+        </el-col> -->
+      </el-row>
+    </detail-frame>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+import detailFrame from '@frame/layout/admin/detail-frame';
+import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
+const { mapActions: task } = createNamespacedHelpers('task');
+const { mapActions: util } = createNamespacedHelpers('util');
+export default {
+  name: 'taskDetail',
+  props: {},
+  components: { detailFrame },
+  data: () => ({
+    task: null,
+    active: '',
+    picurl: '',
+    score: '',
+    taskAnswer: null,
+  }),
+  created() {
+    this.search();
+  },
+  computed: {
+    uploadtaskid() {
+      return this.$route.query.uploadtaskid;
+    },
+  },
+  methods: {
+    ...util({ modelFetch: 'fetch' }),
+    ...task({ taskInfo: 'fetch' }),
+    ...uploadtask(['fetch', 'query', 'update']),
+    async search() {
+      const taskAnswer = await this.fetch(this.uploadtaskid);
+      let item = taskAnswer.data;
+      if (!_.isArray(item.picurl)) item.picurl = [item.picurl];
+      this.$set(this, `taskAnswer`, item);
+      if (item.taskid) {
+        let task = await this.taskInfo(item.taskid);
+        if (task.errcode == '0') {
+          const { answers } = item;
+          let { question } = task.data;
+          question = question.map(i => {
+            const r = answers.find(f => f.questionid == i._id);
+            if (r) i.answers = r.answer;
+            return i;
+          });
+          task.data.question = question;
+        }
+        console.log(task.data);
+        this.$set(this, `task`, task.data);
+      }
+    },
+    async onSubmit() {
+      const res = await this.update(this.taskAnswer);
+      if (res.errcode === 0) {
+        this.$message({
+          message: '提交学生成绩成功',
+          type: 'success',
+        });
+        this.toreturn();
+      }
+    },
+    toreturn() {
+      window.history.go(-1);
+    },
+    getSpan(type) {
+      let span = 0;
+      if (type == 'task') {
+        if (this.task) span = 12;
+        if (!_.get(this.taskAnswer, 'picurl')) span = 24;
+      } else {
+        if (_.get(this.taskAnswer, 'picurl')) span = 12;
+        if (!this.task) span = 24;
+      }
+      return span;
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.task_list {
+  .el-col {
+    padding: 5px 0;
+  }
+}
+.overflow {
+  overflow: hidden;
+  white-space: nowrap;
+  text-overflow: ellipsis;
+  -o-text-overflow: ellipsis;
+}
+.title {
+  text-align: center;
+  font-weight: bold;
+  font-size: 20px;
+}
+.question {
+  margin: 10px;
+}
+.score {
+  width: 50%;
+  margin-right: 20px;
+}
+</style>

+ 134 - 0
src/views/task/taskList.vue

@@ -0,0 +1,134 @@
+<template>
+  <div id="taskList">
+    <list-frame :title="pageTitle" returns="/task/index" @query="search" :needFilter="false" :needAdd="false" :needPag="false">
+      <el-row class="total">
+        <el-col :span="24">
+          <p>
+            班级人数:<span>{{ stuTotal }}</span> 作业人数:<span>{{ total }}</span>
+          </p>
+        </el-col>
+        <el-col :span="24" style="font-size:18px;color:#ff0000">没交作业的学生:{{ getNoTask() }}</el-col>
+      </el-row>
+      <data-table :fields="fields" :data="tableData" :opera="opera" @view="toTaskDetail">
+        <template #custom="{item, row}">
+          <template v-if="item.prop === 'picurl'">
+            <template v-for="(i, index) in row.picurl">
+              <el-image :key="index" :src="i" style="width:100px;height:100px;margin-right: 10px;" @click="btnpicurl(i)"></el-image>
+            </template>
+          </template>
+        </template>
+      </data-table>
+    </list-frame>
+    <el-dialog title="查看" :visible.sync="dialog" center :append-to-body="true">
+      <el-image :src="image" style="width: 100%;"></el-image>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+import listFrame from '@frame/layout/admin/list-frame';
+import dataTable from '@frame/components/data-table';
+import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
+const { mapActions: task } = createNamespacedHelpers('task');
+const { mapActions: student } = createNamespacedHelpers('student');
+export default {
+  name: 'taskList',
+  props: {},
+  components: { listFrame, dataTable },
+  data: () => ({
+    opera: [
+      {
+        label: '查看作业详情',
+        icon: 'el-icon-view',
+        method: 'view',
+      },
+    ],
+    fields: [
+      { label: '学生名称', prop: 'stuname' },
+      { label: '作业得分', prop: 'score' },
+      { label: '上传作业(单击放大)', prop: 'picurl', custom: true },
+    ],
+    tableData: [],
+    stuTotal: 0,
+    total: 0,
+    options: undefined,
+    image: require('@/assets/logo.png'),
+    dialog: false,
+    stuList: [],
+  }),
+  created() {
+    this.search();
+    this.searchstu();
+  },
+  computed: {
+    ...mapState(['user', 'defaultOption']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+    id() {
+      return this.$route.query.classid;
+    },
+    lessonid() {
+      return this.$route.query.lessonid;
+    },
+  },
+  methods: {
+    ...uploadtask(['fetch', 'query', 'update']),
+    ...student({ stuQuery: 'query' }),
+    async search({ skip, limit, ...info } = {}) {
+      const stutasks = await this.query({ skip, limit, lessonid: this.lessonid, classid: this.id });
+      let tableData = _.uniqBy(stutasks.data, 'studentid');
+      tableData = tableData.map(i => {
+        if (!_.isArray(i.picurl)) i.picurl = [i.picurl];
+        return i;
+      });
+      this.$set(this, `tableData`, tableData);
+      this.$set(this, `total`, tableData.length);
+    },
+    toTaskDetail(item) {
+      console.log(item);
+      this.$router.push({ path: '/task/taskDetail', query: { uploadtaskid: item.data._id } });
+    },
+    // 查班级学生
+    async searchstu() {
+      let res = await this.stuQuery({ classid: this.id });
+      if (res.errcode == 0) {
+        this.$set(this, `stuTotal`, res.total);
+        this.$set(this, `stuList`, res.data);
+      }
+    },
+    // 放大图片
+    btnpicurl(url) {
+      this.$set(this, `image`, url);
+      this.dialog = true;
+    },
+    // 获取没有交作业的学生名单
+    getNoTask() {
+      const hasTaskList = this.tableData.map(i => i.studentid);
+      const list = this.stuList.filter(f => !hasTaskList.includes(f._id));
+      let namelist = list.map(i => i.name);
+      namelist = namelist.join(';');
+      // let word = '';
+      // for (const stu of list) {
+      //   word = `${word} ${stu.name}`;
+      // }
+      return namelist;
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.total {
+  padding: 0 0 15px 0;
+  p {
+    font-size: 18px;
+    span {
+      color: #ff0000;
+      font-weight: bold;
+    }
+  }
+}
+</style>