Blame view

src/views/personal/setUp/student.vue 17.2 KB
77ebf04d   梁保满   个人版
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <template>
    <div>
      <back-box>
        <template slot="title">
          <span>学生管理</span>
        </template>
        <template slot="btns">
          <el-tooltip effect="dark" content="学生导入" placement="bottom">
            <el-button
              type="primary"
              icon="el-icon-upload2"
              size="mini"
              plain
              circle
              @click="diaUp = true"
            ></el-button>
          </el-tooltip>
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
18
19
20
21
22
23
24
25
26
27
          <el-tooltip effect="dark" content="学生导出" placement="bottom">
            <el-button
              type="primary"
              icon="el-icon-download"
              size="mini"
              plain
              circle
              @click="exportStudentExl"
            ></el-button>
          </el-tooltip>
77ebf04d   梁保满   个人版
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
          <el-tooltip effect="dark" content="添加班级" placement="bottom">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              plain
              circle
              @click="addClass"
            ></el-button>
          </el-tooltip>
        </template>
      </back-box>
  
      <div class="page-content">
        <div class="stu-box">
          <div class="stu-list">
            <p class="h-title">班级列表</p>
            <ul class="stu-ul">
              <li
                class="stu-item"
                v-for="item in classList"
                :key="item.id"
                :class="query.classId == item.id ? 'active' : ''"
                @click="classDetail(item)"
              >
                <i class="el-icon-edit-outline" @click.stop="setClass(item)"></i>
                {{ item.className }}({{ item.studentCount }})
              </li>
            </ul>
          </div>
          <div class="stu-detail">
            <p class="stu-head">
              {{ formStu.className }}所有学生({{ studentList.length }})
              <i
                v-if="query.classId"
                class="el-icon-circle-plus-outline"
                @click="openAddDia"
              ></i>
            </p>
            <ul class="s-ul" v-loading="loading">
              <li
                class="s-li"
                v-for="(item, index) in studentList"
                :key="item.id"
              >
                <el-popconfirm
                  title="确定删除吗?"
                  @confirm="removeStu(item, index)"
                >
                  <i class="el-icon-delete" slot="reference"></i>
                </el-popconfirm>
                <p class="name">{{ item.studentName }}</p>
                <p class="p1">答题器:{{ item.clickerSn || "--" }}</p>
                <p class="p1">长学号:{{ item.studentCode }}</p>
                <p class="p1">短学号:{{ item.shortNumber || "--" }}</p>
              </li>
            </ul>
            <el-empty
              :image-size="100"
              v-if="!studentList.length && loading == false"
              description="没有更多数据"
            ></el-empty>
          </div>
        </div>
      </div>
      <el-dialog title="添加学生" :visible.sync="diaStu" width="400">
        <el-form
          ref="formBox"
77ebf04d   梁保满   个人版
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
          :model="formStu"
          :rules="rulesStu"
          label-width="160px"
        >
          <el-form-item label="所在班级:">
            <span>{{ formStu.className }}</span>
          </el-form-item>
          <el-form-item label="学生姓名:" prop="studentName">
            <el-col :span="10">
              <el-input
                maxlength="30"
                placeholder="输入学生姓名"
                v-model.trim="formStu.studentName"
              />
            </el-col>
          </el-form-item>
          <el-form-item label="长学号:" prop="studentCode">
            <el-col :span="10">
              <el-input
                maxlength="12"
                placeholder="输入学生长学号"
                v-model.trim="formStu.studentCode"
              />
            </el-col>
          </el-form-item>
          <el-form-item label="短学号:">
            <el-col :span="10">
              <el-input maxlength="12" v-model.trim="formStu.shortNumber" />
            </el-col>
          </el-form-item>
          <el-form-item label="性别:">
            <el-radio-group v-model="formStu.sex">
              <el-radio :label="1">男</el-radio>
              <el-radio :label="2">女</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="答题器编码:">
            <el-col :span="10">
              <el-input v-model.trim="formStu.clickerSn" />
            </el-col>
          </el-form-item>
        </el-form>
        <div class="dialog-footer" slot="footer">
          <el-button @click="addStu">确 定</el-button>
          <el-button @click="diaStu = false">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog
        :title="formClass.classId ? '修改班级' : '添加班级'"
        :visible.sync="diaClass"
        width="400"
      >
        <el-form
          class="form-box"
          ref="formClass"
          :model="formClass"
          :rules="rulesClass"
          label-width="160px"
        >
          <el-form-item label="班级名称:" prop="className">
            <el-col :span="10">
              <el-input maxlength="30" v-model.trim="formClass.className" />
            </el-col>
          </el-form-item>
c2460294   梁保满   平台管理员接口联调
160
161
162
163
164
165
166
167
168
          <el-form-item label="科目:" prop="subjectNames">
            <div class="subject-box" :class="showAll ? 'active' : ''">
              <span class="showAll" @click="showAll = !showAll">{{
                showAll ? "收起" : "更多..."
              }}</span>
              <el-checkbox-group v-model="formClass.subjectNames">
                <el-checkbox
                  v-for="item in subjectList"
                  :label="item"
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
169
                  :key="item.id"
c2460294   梁保满   平台管理员接口联调
170
171
172
173
174
175
176
177
178
                  >{{ item }}</el-checkbox
                >
              </el-checkbox-group>
            </div>
            <el-col :span="8">
              <el-input
                placeholder="添加科目"
                v-model.trim="subjectName"
                maxlength="30"
77ebf04d   梁保满   个人版
179
              >
c2460294   梁保满   平台管理员接口联调
180
181
182
183
184
185
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-plus"
                  @click="addSubjectName"
                ></i>
              </el-input>
77ebf04d   梁保满   个人版
186
187
188
189
190
191
192
193
194
195
196
197
198
            </el-col>
          </el-form-item>
        </el-form>
        <div class="dialog-footer" slot="footer">
          <el-button @click="saveClass">确 定</el-button>
          <el-button @click="diaClass = false">取 消</el-button>
          <el-button v-if="formClass.classId" @click="removeClass"
            >删 除</el-button
          >
        </div>
      </el-dialog>
      <el-dialog title="学生导入" :visible.sync="diaUp" width="600">
        <up-load
77ebf04d   梁保满   个人版
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
          :url="url"
          @upSuccess="upSuccess"
          fileName="学生模板"
        >
          <p class="down-txt" slot="down">
            通过Excel名单导入学生模板,点击
            <el-link type="danger" @click="downExcel">模板下载</el-link> 。
          </p>
        </up-load>
        <div class="dialog-footer" slot="footer">
          <el-button @click="diaUp = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { downloadFile, getBlob } from "@/utils";
  export default {
    data() {
      return {
77ebf04d   梁保满   个人版
220
        loading: false,
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
221
222
223
224
        diaUp: false, //导入弹窗
        url: "/api_html/personal/importStudent",
        diaStu: false, //添加学生
        diaClass: false, //添加-修改班级
c2460294   梁保满   平台管理员接口联调
225
        showAll: false, //修改年级科目显示
77ebf04d   梁保满   个人版
226
227
228
        query: {
          classId: "",
        },
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
229
230
        formStu: {
          //添加学生信息
77ebf04d   梁保满   个人版
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
          className: "",
          studentName: "",
          studentCode: "",
          shortNumber: "",
          sex: 1,
          clickerSn: "",
        },
        rulesStu: {
          studentName: [
            { required: true, message: "请输入学生名称", trigger: "blur" },
          ],
          studentCode: [
            { required: true, message: "请输入学生长学号", trigger: "blur" },
          ],
        },
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
246
247
        formClass: {
          //添加班级信息
77ebf04d   梁保满   个人版
248
249
          classId: "",
          className: "",
c2460294   梁保满   平台管理员接口联调
250
          subjectNames: [],
77ebf04d   梁保满   个人版
251
252
253
254
255
        },
        rulesClass: {
          className: [
            { required: true, message: "请输入班级名称", trigger: "blur" },
          ],
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
256
257
258
          subjectNames: [
            { required: true, message: "请输入科目名称", trigger: "blur" },
          ],
77ebf04d   梁保满   个人版
259
        },
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
260
261
262
263
        classList: [], //班级列表
        studentList: [], //学生列表
        subjectList: [], //科目列表
        subjectName: "", //添加科目名称
77ebf04d   梁保满   个人版
264
265
266
      };
    },
    async created() {
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
267
268
269
      await this._QueryClass();
      this._QuerySubject();
      this._QueryData();
77ebf04d   梁保满   个人版
270
271
272
273
274
    },
    methods: {
      addClass() {
        this.formClass.classId = "";
        this.formClass.className = "";
c2460294   梁保满   平台管理员接口联调
275
        this.formClass.subjectNames = [];
77ebf04d   梁保满   个人版
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
        this.diaClass = true;
      },
      openAddDia() {
        this.formStu.studentName = "";
        this.formStu.studentCode = "";
        this.formStu.shortNumber = "";
        this.formStu.sex = 1;
        this.formStu.clickerSn = "";
        this.diaStu = true;
      },
      classDetail(obj) {
        this.query.classId = obj.id;
        this.formStu.className = obj.className;
        this._QueryData();
      },
      setClass(obj) {
        this.formClass.classId = obj.id;
        this.formClass.className = obj.className;
c2460294   梁保满   平台管理员接口联调
294
        this.formClass.subjectNames = obj.subjectNames;
77ebf04d   梁保满   个人版
295
296
        this.diaClass = true;
      },
c2460294   梁保满   平台管理员接口联调
297
298
299
300
301
302
303
304
305
306
307
308
      addSubjectName() {
        if (!this.subjectName) {
          this.$message.warning("请填写科目名称");
          return;
        } else if (this.subjectList.includes(this.subjectName)) {
          this.$message.warning("科目已存在,请重新填写~");
          return;
        }
        this.subjectList.push(this.subjectName);
        this.formClass.subjectNames.push(this.subjectName);
        this.subjectName = "";
      },
77ebf04d   梁保满   个人版
309
310
311
      saveClass() {
        this.$refs.formClass.validate(async (valid) => {
          if (valid) {
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
312
            const { data, status, info } = await this.$request.pSaveClass({
77ebf04d   梁保满   个人版
313
314
              classId: this.formClass.classId,
              className: this.formClass.className,
c2460294   梁保满   平台管理员接口联调
315
              subjectNames: this.formClass.subjectNames,
77ebf04d   梁保满   个人版
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
            });
            if (status === 0) {
              this.$message.success("修改成功");
              this.diaClass = false;
              this._QueryClass();
            } else {
              this.$message.error(info);
            }
          } else {
            this.$message.warning("输入有误请检查!");
            return false;
          }
        });
      },
      async removeClass() {
        let stuNum = 0;
        this.classList.map((item) => {
          if (item.classId == this.formClass.classId) {
            stuNum = item.studentCount;
          }
        });
        if (stuNum) {
          this.$message.warning("有学生的班级不能删除!");
          return;
        }
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
341
        const { data, status, info } = await this.$request.pDelClass({
77ebf04d   梁保满   个人版
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
          classId: this.formClass.classId,
        });
        if (status === 0) {
          this.$message.success("删除成功");
          this.diaClass = false;
          this._QueryClass();
        } else {
          this.$message.error(info);
        }
      },
      upSuccess(res) {
        this.$message.closeAll();
        this.$message({
          showClose: true,
          message: `成功(${res.data.success})`,
          type: "success",
          duration: 5000,
        });
        //导入成功
        this.diaUp = false;
        this._QueryData();
      },
c2460294   梁保满   平台管理员接口联调
364
365
366
367
368
369
370
371
      async _QuerySubject() {
        const { data, status, info } = await this.$request.pSubjectList();
        if (status === 0) {
          this.subjectList = [...data.subjectNames] || [];
        } else {
          this.$message.error(info);
        }
      },
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
372
  
77ebf04d   梁保满   个人版
373
      async removeStu(obj, index) {
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
374
        const { data, status, info } = await this.$request.pDelStudent({
77ebf04d   梁保满   个人版
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
          studentId: obj.id,
        });
        if (status === 0) {
          this.$message.success("删除成功");
          this.studentList.splice(index, 1);
          this._QueryClass();
        } else {
          this.$message.error(info);
        }
      },
      addStu() {
        let query = {};
        for (let key in this.formStu) {
          if (key != "className" && this.formStu[key]) {
            query[key] = this.formStu[key];
          }
        }
        this.loading = true;
        this.$refs.formBox.validate(async (valid) => {
          if (valid) {
            let hasName = this.studentList.find((item) => {
              return item.studentName == this.formStu.studentName;
            });
            console.log(hasName);
            if (hasName) {
              this.$message.warning("学生姓名已存在");
              return;
            }
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
403
            const { data, status, info } = await this.$request.pAddStudent({
77ebf04d   梁保满   个人版
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
              classId: this.query.classId,
              ...query,
            });
            this.loading = false;
            console.log(status);
            if (status === 0) {
              this.$message.success(info);
              this.diaStu = false;
              this._QueryClass();
              this._QueryData();
            } else {
              this.$message.error(info);
            }
          } else {
            this.$message.error("数据有误,请检查!");
          }
        });
      },
      async _QueryData() {
        this.loading = true;
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
424
        const { data, status, info } = await this.$request.pStudentList({
77ebf04d   梁保满   个人版
425
426
427
428
429
430
431
432
433
434
435
436
          ...this.query,
        });
        this.loading = false;
        console.log(status);
        if (status === 0) {
          this.studentList = data.list || [];
        } else {
          this.$message.error(info);
        }
      },
  
      async _QueryClass() {
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
437
438
439
        const { data, status, info } = await this.$request.pClassList({
          needStudentCount:1
        });
77ebf04d   梁保满   个人版
440
441
442
443
444
445
446
447
        if (status === 0) {
          this.classList = [...data.list] || [];
          this.query.classId = this.classList[0]?.id;
          this.formStu.className = this.classList[0]?.className;
        } else {
          this.$message.error(info);
        }
      },
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
      async downExcel() {
        this.loadingDown = true;
        let { data, info, status } = await this.$request.studentTemplateUrl();
        this.loadingDown = false;
        if (status == 0) {
          // getBlob(data.downloadUrl).then((res) => {
          //   downloadFile("学生模板", res);
          // });
          const a = document.createElement("a");
          a.href = data.downloadUrl;
          a.download = data.appName;
          document.body.appendChild(a);
          a.click();
          a.remove();
        } else {
          this.$message.error(info);
        }
      },
      async exportStudentExl() {
        this.loadingDown = true;
        let data = await this.$request.exportStudent();
        this.loadingDown = false;
        if (data) {
           let blob = new Blob([data], {
            type: "application/vnd.ms-excel;charset=utf-8",
          });
          downloadFile(`学生名单.xlsx`, blob);
        } else {
          this.$message.error("下载失败");
        }
      },
77ebf04d   梁保满   个人版
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .page-content {
    padding: 20px;
  }
  .stu-box {
    display: flex;
    background: #f8f8f8;
    border-radius: 10px;
    overflow: hidden;
    .stu-list {
      min-width: 200px;
      max-height: 80vh;
      .h-title {
        height: 40px;
        line-height: 40px;
        background: #eee;
      }
      .stu-item {
        font-size: 16px;
        color: #7f7f7f;
        line-height: 36px;
        cursor: pointer;
        padding-left: 12px;
        position: relative;
        .el-icon-edit-outline {
          position: absolute;
          top: 8px;
          right: 12px;
          font-size: 20px;
          display: none;
          &:hover {
            color: #667ffd;
          }
        }
        &:hover {
          background: #eee;
          .el-icon-edit-outline {
            display: block;
          }
        }
        &.active {
          color: #667ffd;
          background: #eee;
        }
      }
      .sel {
        width: 180px;
        :deep(.el-input__inner) {
          font-size: 16px;
          padding-left: 0;
          border: none;
          background: transparent;
        }
        :deep(.el-icon-arrow-up:before) {
          content: "\e78f";
        }
      }
    }
    .stu-detail {
      flex: 1;
      border-left: 0.5px solid #eee;
      .stu-head {
        padding: 12px 20px;
        color: #7f7f7f;
        position: relative;
        .el-icon-circle-plus-outline {
          position: absolute;
          top: 10px;
          right: 20px;
          font-size: 24px;
          color: #7f7f7f;
          cursor: pointer;
        }
      }
      .s-ul {
        display: flex;
        flex-wrap: wrap;
        padding-left: 20px;
        .s-li {
          width: 180px;
          height: 120px;
          box-shadow: 2px 2px 5px #7f7f7f;
          border-radius: 10px;
          margin: 0 20px 20px 0;
          padding: 0 12px 5px;
          position: relative;
          .el-icon-delete {
            position: absolute;
            top: 8px;
            right: 8px;
            font-size: 18px;
            padding: 2px;
            display: none;
            cursor: pointer;
            &:hover {
              color: #667ffd;
            }
          }
          &:hover {
            .el-icon-delete {
              display: block;
            }
          }
          .name {
            text-align: center;
            font-size: 16px;
            line-height: 18px;
            padding: 10px 0;
          }
          .p1 {
            color: #7f7f7f;
            line-height: 20px;
            padding-bottom: 5px;
          }
        }
      }
    }
  }
c2460294   梁保满   平台管理员接口联调
601
602
  .form-box {
    .subject-box {
d703d72c   梁保满   首页,个人信息,班级名单,部分备题...
603
      padding-right: 50px;
c2460294   梁保满   平台管理员接口联调
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
      max-height: 90px;
      overflow: hidden;
      position: relative;
      &.active {
        max-height: auto;
        overflow: auto;
      }
      .showAll {
        position: absolute;
        bottom: 0;
        right: 10px;
        font-size: 12px;
        color: #7f7f7f;
        cursor: pointer;
        padding: 2px;
        &:hover {
          color: #667ffd;
        }
      }
    }
    .el-icon-plus {
      cursor: pointer;
      &:hover {
        color: #667ffd;
      }
    }
  }
77ebf04d   梁保满   个人版
631
  </style>