123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- // pages/teacher/monitor/monitor.ts
- import { ConstsData } from "../../../utils/const"
- import { httpUtil } from "../../../utils/restful";
- Component({
- /**
- * 页面的初始数据
- */
- data: {
- regionOne: Array<String>(),
- regionTwo: Array<String>(),
- regionThree: Array<String>(),
- regionOneIndex: 0,
- regionTwoIndex: 0,
- regionThreeIndex: 0,
- region: [
- Array<String>(),
- Array<String>(),
- Array<String>()
- ],
- regionIndex: [0, 0, 0],
- schoolArray: [['中国']],
- schoolIndex: 0,
- classArray: ['一年级一班', '一年级2班', '一年级3班', '一年级4班'],
- classIndex: 0,
- provinceValue: '',//省份value
- regionValue: '',//地区value
- cityValue: '',
- schoolData: [{ 'id': '' }],
- schoolId: '',
- classData: [{ 'id': '' }],
- classId: '',
- deviceId: '',
- //0=未上课 1=正在上课
- pageState: 0,
- //开始上课用到的数据
- //0是正常,1是error
- videostatus: 0
- },
- lifetimes: {
- attached: function () {
- // 在组件实例被从页面节点树添加时执行
- this.changeOrganizeInfo()
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- },
- methods: {
- changeOrganizeInfo: function () {
- //切换地区
- this.setData({
- regionOne: [],
- regionTwo: [],
- regionThree: []
- })
- ConstsData.AppData.organizeInfo.data.children.forEach((item: { title: String; }) => {
- this.data.regionOne.push(item.title)
- })
- ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item: { title: String; }) => {
- this.data.regionTwo.push(item.title)
- })
- ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item: { title: String; }) => {
- this.data.regionThree.push(item.title)
- })
- this.setData({
- region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
- regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
- provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
- cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
- regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString()
- })
- //切换学校
- this.changeSchool();
- //切换班级
- },
- //查询学校
- changeSchool: function () {
- //查询学校
- let params = {
- city: this.data.cityValue,
- province: this.data.provinceValue,
- region: this.data.regionValue,
- type: 1,
- }
- httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
- this.setData({
- schoolArray: [],
- schoolIndex: 0,
- schoolData: res.data.data,
- schoolId: res.data.data[0].id
- })
- let newArray: string[] = [];
- res.data.data.forEach((element: { title: string; }) => {
- newArray.push(element.title)
- });
- this.data.schoolArray.push(newArray)
- this.setData({
- schoolArray: this.data.schoolArray
- })
- this.changeClass()
- }).catch(res => {
- console.log("查询学校error:", res)
- })
- },
- //查询班级
- changeClass: function () {
- let params = {
- "city": this.data.cityValue,
- "father": this.data.schoolId,//学校ID
- "province": this.data.provinceValue,
- "region": this.data.regionValue,
- "type": 2,
- }
- httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
- this.setData({
- classArray: [],
- classIndex: 0
- })
- this.setData({
- classData: res.data.data,
- classId: res.data.data[0].id
- })
- res.data.data.forEach((element: { title: string; }) => {
- this.data.classArray.push(element.title)
- });
- this.setData({
- classArray: this.data.classArray,
- })
- }).catch(res => {
- console.log("查询班级error:", res)
- })
- },
- bindMultiPickerColumnChange: function (event: any) {
- //
- switch (Number(event.detail.column)) {
- case 0:
- //代表第一列
- this.setData({
- regionOneIndex: event.detail.value,
- })
- break;
- case 1:
- //代表第二列
- this.setData({
- regionTwoIndex: event.detail.value,
- })
- break;
- case 2:
- //代表第三列
- this.setData({
- regionThreeIndex: event.detail.value
- })
- break;
- }
- this.changeOrganizeInfo();
- },
- bindRegionChange: function (event: any) {
- this.setData({
- regionIndex: event.detail.value
- })
- },
- bindSchoolPicker: function (event: any) {
- this.setData({
- schoolIndex: event.detail.value,
- schoolId: this.data.schoolData[event.detail.value].id
- })
- this.changeClass();
- },
- bindClssPicker: function (event: any) {
- this.setData({
- classIndex: event.detail.value
- })
- },
- //扫码界面(未处理回调)
- scanCode: function () {
- var that = this;
- wx.scanCode({ //扫描API
- success(res) { //扫描成功
- console.log(res) //输出回调信息
- that.setData({
- scanCodeMsg: res.result
- });
- wx.showToast({
- title: '扫码成功',
- icon: 'success',
- duration: 1000
- })
- },
- fail: (res: any) => {//接口调用失败的回调函数
- wx.showToast({
- title: '扫码失败',
- icon: 'success',
- duration: 1000
- })
- },
- })
- },
- //获取设备ID的输入
- bindDeviceInput(event: any) {
- this.setData({
- deviceId: event.detail.value
- })
- },
- //上课
- startMonitor: function () {
- if (!this.data.deviceId) {
- wx.showToast({
- title: '请输入设备ID',
- icon: 'none', //如果要纯文本,不要icon,将值设为'none'
- duration: 1000
- })
- return;
- }
- let params = {
- address: this.data.region[0] + "--" + this.data.region[1] + "--" + this.data.region[2],
- school: this.data.schoolArray[this.data.schoolIndex],
- class: this.data.classArray[this.data.classIndex],
- deviceId: this.data.deviceId
- }
- console.log("params:", params)
- //开始上课
- this.setData({
- pageState: 1
- })
- },
- //上课之后的方法
- //下课
- classOver: function () {
- //下课
- let that = this;
- wx.showModal({
- title: '',
- content: '确定下课么',
- success: function (res) {
- if (res.confirm) {
- console.log('点击确认回调')
- that.setData({
- pageState: 0
- })
- } else {
- console.log('点击取消回调')
- }
- }
- })
- }
- }
- })
|