// pages/teacher/monitor/monitor.ts import { ConstsData } from "../../../utils/const" import { httpUtil } from "../../../utils/restful"; Component({ /** * 页面的初始数据 */ data: { regionOne: Array(), regionTwo: Array(), regionThree: Array(), regionOneIndex: 0, regionTwoIndex: 0, regionThreeIndex: 0, region: [ Array(), Array(), Array() ], regionIndex: [0, 0, 0], schoolArray: [['暂无学校']], schoolIndex: 0, classArray: ['暂无班级'], classIndex: 0, provinceValue: '',//省份value regionValue: '',//地区value cityValue: '', schoolData: [{ 'id': '' }], schoolId: '', classData: [{ 'id': '' }], classId: '', initFirst: true, deviceId: '', //0=未上课 1=正在上课 pageState: 0, //#region 开始上课用到的数据 //0是正常,1是error videostatus: 0, videoUrl: '', lessId: '', hasGetFile: false, imgList: [], //#endregion }, lifetimes: { attached: function () { // 在组件实例被从页面节点树添加时执行 this.getMyInfo(); }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, methods: { getMyInfo: function () { if (ConstsData.AppData.myInfoData.id == 0) { //没有用户信息,请求接口 httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then((res: any) => { ConstsData.AppData.myInfoData = res.data.data //获取地区和学校班级等信息 this.changeOrganizeInfo() }).catch((res) => { console.log("获取我的信息失败:", res) }) } else { //有用户信息,直接设置地区啥的 this.changeOrganizeInfo() } }, changeOrganizeInfo: function () { //设置名字 this.setData({ userName: ConstsData.AppData.myInfoData.name }) //切换地区 this.setData({ regionOne: [], regionTwo: [], regionThree: [] }) ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => { if (this.data.initFirst) { if (item.value == ConstsData.AppData.myInfoData.province) { //如果是当前的 this.setData({ regionOneIndex: index }) } } this.data.regionOne.push(item.title) }) ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => { if (this.data.initFirst) { if (item.value == ConstsData.AppData.myInfoData.city) { this.setData({ regionTwoIndex: index }) } } this.data.regionTwo.push(item.title) }) ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => { if (this.data.initFirst) { if (item.value == ConstsData.AppData.myInfoData.region) { this.setData({ regionThreeIndex: index }) } } 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(), initFirst: false }) //切换学校 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, index) => { if (ConstsData.AppData.myInfoData.schoolId == element.id) { this.setData({ schoolIndex: index, schoolId: this.data.schoolData[index].id }) } newArray.push(element.title) }); this.data.schoolArray.push(newArray) this.setData({ schoolArray: this.data.schoolArray }) //切换班级 this.changeClass() }).catch(res => { console.log("查询学校error:", res) this.setData({ schoolArray: [['暂无学校']], schoolId: '', classArray: ['暂无班级'], classId: '' }) }) }, //查询班级 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 }) console.log("classData:", this.data.classData) res.data.data.forEach((element: { id: number; title: string; }, index: number) => { if (element.id == ConstsData.AppData.myInfoData.classId) { this.setData({ classIndex: index, classId: res.data.data[index].id }) console.log("this.data.classIndex:", this.data.classIndex) } this.data.classArray.push(element.title) }); this.setData({ classArray: this.data.classArray, }) }).catch(res => { console.log("查询班级error:", res) this.setData({ classArray: ['暂无班级'], classId: '' }) }) }, //根据地区,学校,班级获取deviceId getDeviceByRSC: function () { let params = { city: this.data.cityValue, classId: this.data.classId, province: this.data.provinceValue,//省份 region: this.data.regionValue,//地区 schoolId: this.data.schoolId, } httpUtil.wxGet(httpUtil.interfaces.getDevideIdByRSC, params).then((res: any) => { console.log("根据省市学校班级获取deviceId成功:", res) if (res.data.success) { this.setData({ deviceId: res.data.data.deviceId }) } else { this.setData({ deviceId: '' }) } }).catch((res) => { console.log("根据省市学校班级获取deviceId失败:", res) this.setData({ deviceId: '暂无设备' }) }) }, 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, classId: this.data.classData[event.detail.value].id }) this.getDeviceByRSC() }, //扫码界面(未处理回调) 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 = { deviceId: this.data.deviceId, teacherId: httpUtil.httpData.userId, // title: '' } console.log("params:", params) httpUtil.wxPost(httpUtil.interfaces.createLess, params).then((res: any) => { console.log("创建文件成功(开始上课):", res) //开始上课 if (res.data.success) { this.setData({ pageState: 1, videoUrl: res.data.data.liveUrl, lessId: res.data.data.id, hasGetFile: true }) this.triggerEvent('canChangeIndex', { canChange: false }) this.getDocumentFile() } }).catch((res) => { console.log("创建文件失败(开始上课):", res) }) }, //#region 上课之后的方法 //下课 classOver: function () { //下课 let that = this; wx.showModal({ title: '', content: '确定下课么', success: function (res) { if (res.confirm) { console.log('点击确认回调') that.setData({ pageState: 0, hasGetFile: false }) that.triggerEvent('canChangeIndex', { canChange: true }) } else { console.log('点击取消回调') } } }) }, //心跳获取文件库所有文件 getDocumentFile: function () { let that = this; let params = { lessId: that.data.lessId, deviceId: that.data.deviceId, userId: httpUtil.httpData.userId, pageNo: 1, pageSize: 100000, } httpUtil.wxGet(httpUtil.interfaces.getDocumentFile, params).then((res: any) => { console.log("获取所有文件成功:", res) that.setData({ imgList: res.data.data.list }) let getfile = setInterval(function () { if (that.data.hasGetFile) { httpUtil.wxGet(httpUtil.interfaces.getDocumentFile, params).then((res: any) => { console.log("获取所有文件成功:", res) that.setData({ imgList: res.data.data.list }) }).catch((res) => { console.log("获取所有文件失败:", res) }) } else { clearInterval(getfile) } }, 5000) }).catch((res) => { console.log("获取所有文件失败:", res) }) } ////#endregion } })