monitor.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // pages/teacher/monitor/monitor.ts
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. region: ['北京市', '北京市', '海淀区'],
  8. schoolArray: ['中国', '美国', '巴西', '日本'],
  9. schoolIndex: 0,
  10. classArray: ['一年级一班', '一年级2班', '一年级3班', '一年级4班'],
  11. classIndex: 0,
  12. deviceId: '',
  13. //0=未上课 1=正在上课
  14. pageState: 0,
  15. //开始上课用到的数据
  16. //0是正常,1是error
  17. videostatus: 0
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad() {
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady() {
  28. },
  29. //选择地区回调
  30. bindRegionChange: function (event: any) {
  31. this.setData({
  32. region: event.detail.value
  33. })
  34. },
  35. //选择学校回调
  36. bindSchoolPicker: function (event: any) {
  37. let newArray;
  38. switch (Number(event.detail.value)) {
  39. case 0:
  40. newArray = ["一", "二", "三"];
  41. this.setData({
  42. classArray: newArray,
  43. classIndex: 0
  44. })
  45. break;
  46. case 1:
  47. newArray = ["4", "5", "6"];
  48. this.setData({
  49. classArray: newArray,
  50. classIndex: 0
  51. })
  52. break;
  53. case 2:
  54. newArray = ["as", "ad", "af"];
  55. this.setData({
  56. classArray: newArray,
  57. classIndex: 0
  58. })
  59. break;
  60. case 3:
  61. newArray = ["b1", "b2", "b3"];
  62. this.setData({
  63. classArray: newArray,
  64. classIndex: 0
  65. })
  66. break;
  67. }
  68. this.setData({
  69. schoolIndex: event.detail.value
  70. })
  71. },
  72. //选择班级回调
  73. bindClssPicker: function (event: any) {
  74. this.setData({
  75. classIndex: event.detail.value
  76. })
  77. },
  78. //扫码界面(未处理回调)
  79. scanCode: function () {
  80. var that = this;
  81. wx.scanCode({ //扫描API
  82. success(res) { //扫描成功
  83. console.log(res) //输出回调信息
  84. that.setData({
  85. scanCodeMsg: res.result
  86. });
  87. wx.showToast({
  88. title: '扫码成功',
  89. icon: 'success',
  90. duration: 1000
  91. })
  92. },
  93. fail: (res: any) => {//接口调用失败的回调函数
  94. wx.showToast({
  95. title: '扫码失败',
  96. icon: 'success',
  97. duration: 1000
  98. })
  99. },
  100. })
  101. },
  102. //获取设备ID的输入
  103. bindDeviceInput(event: any) {
  104. this.setData({
  105. deviceId: event.detail.value
  106. })
  107. },
  108. //上课
  109. startMonitor: function () {
  110. if (!this.data.deviceId) {
  111. wx.showToast({
  112. title: '请输入设备ID',
  113. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  114. duration: 1000
  115. })
  116. return;
  117. }
  118. let params = {
  119. address: this.data.region[0] + "--" + this.data.region[1] + "--" + this.data.region[2],
  120. school: this.data.schoolArray[this.data.schoolIndex],
  121. class: this.data.classArray[this.data.classIndex],
  122. deviceId: this.data.deviceId
  123. }
  124. console.log("params:", params)
  125. //开始上课
  126. this.setData({
  127. pageState: 1
  128. })
  129. },
  130. //上课之后的方法
  131. //下课
  132. classOver: function () {
  133. //下课
  134. let that = this;
  135. wx.showModal({
  136. title: '',
  137. content: '确定下课么',
  138. success: function (res) {
  139. if (res.confirm) {
  140. console.log('点击确认回调')
  141. that.setData({
  142. pageState: 0
  143. })
  144. } else {
  145. console.log('点击取消回调')
  146. }
  147. }
  148. })
  149. }
  150. })