发布小练

本文介绍了一个使用Angular框架实现的小练发布功能,包括从本地存储读取模板ID,查询班级信息,以及根据用户选择发布小练到指定班级的具体实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import { Component, OnInit } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Router } from '@angular/router';
import { InterceptorService } from 'src/app/shared/providers/interceptor.service';
import { url } from 'inspector';

@Component({
  selector: 'app-release-question',
  templateUrl: './release-question.page.html',
  styleUrls: ['./release-question.page.scss'],
})
export class ReleaseQuestionPage implements OnInit {

/*---------------------------------变量声明区------------------------------------- */
  // 班级信息
  classLabel = [];
  // 模板ID
  templateId = '';
  // 上课班ID集合
  classIdList = [];
  // 复选框是否选中
  checkList = [];
  // 未选中的复选框个数
  checkOutSum = 0;
  // 考试名称
  examineeName = '';
/*---------------------------------变量声明区------------------------------------- */

  constructor(
    public router: Router,
    public http: InterceptorService,
    public storage: Storage
    ) { }

/*---------------------------------方法区------------------------------------- */

  ngOnInit() {
    this.queryClass();
  }

  /**
   * 查询班级信息
   * @author 郭满亮
   * @since 2019年1月30日19:59:48
   */
  queryClass() {
    this.templateId = localStorage.getItem('templateId');
    this.storage.get('userId').then((val) => {
      const classUrl = 'exam-web/teacherTeachClass/findByTeacherId/' + val + '/' + this.templateId;
      this.http.get(classUrl).subscribe(
        res => {
          if (res.json().code === '0000') {
            this.classLabel = res.json().data;
          }
        });
    });
  }

  /**
   * 获取班级ID
   * @author 郭满亮
   * @since 2019年1月30日20:00:13
   */
  getClass(classId: string, index: number) {
    if (this.checkList[index] === true) {
      this.classIdList[index] = classId;
    } else {
      this.classIdList[index] = '';
    }
  }

  /**
   * 发布小练
   * @author 郭满亮
   * @since 2019年1月30日20:33:19
   */
  okRelease() {
    for (let j = 0 ; j < this.checkList.length ; j++) {
      if (this.checkList[j] === false) {
        this.checkOutSum += 1;
      }
    }
    // 考试名称 上课班id 模板id
    for (let i = 0; i < this.classIdList.length; i++) {
      if (this.classIdList[i] !== '' && this.classIdList[i] !== null && this.classIdList[i] !== undefined) {
        const releaseUrl = 'exam-web/studentTeachClass/savePractice/'
        + this.examineeName + '/' + this.classIdList[i] + '/' + localStorage.getItem('templateId');
        this.http.post(releaseUrl).subscribe(
        res => {
          if (res.json().code === '0000') {
            alert('发布小练成功');
            this.router.navigateByUrl('tabs/home/teacher-main/released-practice');
          }
        });
      }
    }

    // 若所有班级都发布,则修改模版状态
    if (this.checkOutSum === 0) {
      const urlState = '';
      this.http.post(urlState).subscribe();
    }

  }
/*---------------------------------方法区------------------------------------- */

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值