monitor.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. // pages/teacher/monitor/monitor.ts
  2. import { ConstsData } from "../../../utils/const"
  3. import { httpUtil } from "../../../utils/restful";
  4. Component({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. regionOne: Array<String>(),
  10. regionTwo: Array<String>(),
  11. regionThree: Array<String>(),
  12. regionOneIndex: 0,
  13. regionTwoIndex: 0,
  14. regionThreeIndex: 0,
  15. region: [
  16. Array<String>(),
  17. Array<String>(),
  18. Array<String>()
  19. ],
  20. regionIndex: [0, 0, 0],
  21. schoolArray: [['中国']],
  22. schoolIndex: 0,
  23. classArray: ['一年级一班', '一年级2班', '一年级3班', '一年级4班'],
  24. classIndex: 0,
  25. provinceValue: '',//省份value
  26. regionValue: '',//地区value
  27. cityValue: '',
  28. schoolData: [{ 'id': '' }],
  29. schoolId: '',
  30. classData: [{ 'id': '' }],
  31. classId: '',
  32. deviceId: '',
  33. //0=未上课 1=正在上课
  34. pageState: 0,
  35. //开始上课用到的数据
  36. //0是正常,1是error
  37. videostatus: 0
  38. },
  39. lifetimes: {
  40. attached: function () {
  41. // 在组件实例被从页面节点树添加时执行
  42. this.changeOrganizeInfo()
  43. },
  44. detached: function () {
  45. // 在组件实例被从页面节点树移除时执行
  46. },
  47. },
  48. methods: {
  49. changeOrganizeInfo: function () {
  50. //切换地区
  51. this.setData({
  52. regionOne: [],
  53. regionTwo: [],
  54. regionThree: []
  55. })
  56. ConstsData.AppData.organizeInfo.data.children.forEach((item: { title: String; }) => {
  57. this.data.regionOne.push(item.title)
  58. })
  59. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item: { title: String; }) => {
  60. this.data.regionTwo.push(item.title)
  61. })
  62. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item: { title: String; }) => {
  63. this.data.regionThree.push(item.title)
  64. })
  65. this.setData({
  66. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  67. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  68. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  69. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  70. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString()
  71. })
  72. //切换学校
  73. this.changeSchool();
  74. //切换班级
  75. },
  76. //查询学校
  77. changeSchool: function () {
  78. //查询学校
  79. let params = {
  80. city: this.data.cityValue,
  81. province: this.data.provinceValue,
  82. region: this.data.regionValue,
  83. type: 1,
  84. }
  85. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  86. this.setData({
  87. schoolArray: [],
  88. schoolIndex: 0,
  89. schoolData: res.data.data,
  90. schoolId: res.data.data[0].id
  91. })
  92. let newArray: string[] = [];
  93. res.data.data.forEach((element: { title: string; }) => {
  94. newArray.push(element.title)
  95. });
  96. this.data.schoolArray.push(newArray)
  97. this.setData({
  98. schoolArray: this.data.schoolArray
  99. })
  100. this.changeClass()
  101. }).catch(res => {
  102. console.log("查询学校error:", res)
  103. })
  104. },
  105. //查询班级
  106. changeClass: function () {
  107. let params = {
  108. "city": this.data.cityValue,
  109. "father": this.data.schoolId,//学校ID
  110. "province": this.data.provinceValue,
  111. "region": this.data.regionValue,
  112. "type": 2,
  113. }
  114. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  115. this.setData({
  116. classArray: [],
  117. classIndex: 0
  118. })
  119. this.setData({
  120. classData: res.data.data,
  121. classId: res.data.data[0].id
  122. })
  123. res.data.data.forEach((element: { title: string; }) => {
  124. this.data.classArray.push(element.title)
  125. });
  126. this.setData({
  127. classArray: this.data.classArray,
  128. })
  129. }).catch(res => {
  130. console.log("查询班级error:", res)
  131. })
  132. },
  133. bindMultiPickerColumnChange: function (event: any) {
  134. //
  135. switch (Number(event.detail.column)) {
  136. case 0:
  137. //代表第一列
  138. this.setData({
  139. regionOneIndex: event.detail.value,
  140. })
  141. break;
  142. case 1:
  143. //代表第二列
  144. this.setData({
  145. regionTwoIndex: event.detail.value,
  146. })
  147. break;
  148. case 2:
  149. //代表第三列
  150. this.setData({
  151. regionThreeIndex: event.detail.value
  152. })
  153. break;
  154. }
  155. this.changeOrganizeInfo();
  156. },
  157. bindRegionChange: function (event: any) {
  158. this.setData({
  159. regionIndex: event.detail.value
  160. })
  161. },
  162. bindSchoolPicker: function (event: any) {
  163. this.setData({
  164. schoolIndex: event.detail.value,
  165. schoolId: this.data.schoolData[event.detail.value].id
  166. })
  167. this.changeClass();
  168. },
  169. bindClssPicker: function (event: any) {
  170. this.setData({
  171. classIndex: event.detail.value
  172. })
  173. },
  174. //扫码界面(未处理回调)
  175. scanCode: function () {
  176. var that = this;
  177. wx.scanCode({ //扫描API
  178. success(res) { //扫描成功
  179. console.log(res) //输出回调信息
  180. that.setData({
  181. scanCodeMsg: res.result
  182. });
  183. wx.showToast({
  184. title: '扫码成功',
  185. icon: 'success',
  186. duration: 1000
  187. })
  188. },
  189. fail: (res: any) => {//接口调用失败的回调函数
  190. wx.showToast({
  191. title: '扫码失败',
  192. icon: 'success',
  193. duration: 1000
  194. })
  195. },
  196. })
  197. },
  198. //获取设备ID的输入
  199. bindDeviceInput(event: any) {
  200. this.setData({
  201. deviceId: event.detail.value
  202. })
  203. },
  204. //上课
  205. startMonitor: function () {
  206. if (!this.data.deviceId) {
  207. wx.showToast({
  208. title: '请输入设备ID',
  209. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  210. duration: 1000
  211. })
  212. return;
  213. }
  214. let params = {
  215. address: this.data.region[0] + "--" + this.data.region[1] + "--" + this.data.region[2],
  216. school: this.data.schoolArray[this.data.schoolIndex],
  217. class: this.data.classArray[this.data.classIndex],
  218. deviceId: this.data.deviceId
  219. }
  220. console.log("params:", params)
  221. //开始上课
  222. this.setData({
  223. pageState: 1
  224. })
  225. },
  226. //上课之后的方法
  227. //下课
  228. classOver: function () {
  229. //下课
  230. let that = this;
  231. wx.showModal({
  232. title: '',
  233. content: '确定下课么',
  234. success: function (res) {
  235. if (res.confirm) {
  236. console.log('点击确认回调')
  237. that.setData({
  238. pageState: 0
  239. })
  240. } else {
  241. console.log('点击取消回调')
  242. }
  243. }
  244. })
  245. }
  246. }
  247. })