monitor.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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: ['暂无班级'],
  24. classIndex: 0,
  25. provinceValue: '',//省份value
  26. regionValue: '',//地区value
  27. cityValue: '',
  28. schoolData: [{ 'id': '' }],
  29. schoolId: '',
  30. classData: [{ 'id': '' }],
  31. classId: '',
  32. initFirst: true,
  33. deviceId: '6f7aea71-3ed6-3919-ad36-8b94f768b8c1',
  34. //0=未上课 1=正在上课
  35. pageState: 0,
  36. //开始上课用到的数据
  37. //0是正常,1是error
  38. videostatus: 0
  39. },
  40. lifetimes: {
  41. attached: function () {
  42. // 在组件实例被从页面节点树添加时执行
  43. this.getMyInfo();
  44. },
  45. detached: function () {
  46. // 在组件实例被从页面节点树移除时执行
  47. },
  48. },
  49. methods: {
  50. getMyInfo: function () {
  51. if (ConstsData.AppData.myInfoData.id == 0) {
  52. //没有用户信息,请求接口
  53. httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then((res: any) => {
  54. ConstsData.AppData.myInfoData = res.data.data
  55. //获取地区和学校班级等信息
  56. this.changeOrganizeInfo()
  57. }).catch((res) => {
  58. console.log("获取我的信息失败:", res)
  59. })
  60. } else {
  61. //有用户信息,直接设置地区啥的
  62. this.changeOrganizeInfo()
  63. }
  64. },
  65. changeOrganizeInfo: function () {
  66. //设置名字
  67. this.setData({
  68. userName: ConstsData.AppData.myInfoData.name
  69. })
  70. //切换地区
  71. this.setData({
  72. regionOne: [],
  73. regionTwo: [],
  74. regionThree: []
  75. })
  76. ConstsData.AppData.organizeInfo.data.children.forEach((item, index) => {
  77. if (this.data.initFirst) {
  78. if (item.value == ConstsData.AppData.myInfoData.province) {
  79. //如果是当前的
  80. this.setData({
  81. regionOneIndex: index
  82. })
  83. }
  84. }
  85. this.data.regionOne.push(item.title)
  86. })
  87. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item, index) => {
  88. if (this.data.initFirst) {
  89. if (item.value == ConstsData.AppData.myInfoData.city) {
  90. this.setData({
  91. regionTwoIndex: index
  92. })
  93. }
  94. }
  95. this.data.regionTwo.push(item.title)
  96. })
  97. ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item, index) => {
  98. if (this.data.initFirst) {
  99. if (item.value == ConstsData.AppData.myInfoData.region) {
  100. this.setData({
  101. regionThreeIndex: index
  102. })
  103. }
  104. }
  105. this.data.regionThree.push(item.title)
  106. })
  107. this.setData({
  108. region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree],
  109. regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex],
  110. provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(),
  111. cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(),
  112. regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString(),
  113. initFirst: false
  114. })
  115. //切换学校
  116. this.changeSchool();
  117. },
  118. //查询学校
  119. changeSchool: function () {
  120. //查询学校
  121. let params = {
  122. city: this.data.cityValue,
  123. province: this.data.provinceValue,
  124. region: this.data.regionValue,
  125. type: 1,
  126. }
  127. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  128. this.setData({
  129. schoolArray: [],
  130. schoolIndex: 0,
  131. schoolData: res.data.data,
  132. schoolId: res.data.data[0].id
  133. })
  134. let newArray: string[] = [];
  135. res.data.data.forEach((element, index) => {
  136. if (ConstsData.AppData.myInfoData.schoolId == element.id) {
  137. this.setData({
  138. schoolIndex: index,
  139. schoolId: this.data.schoolData[index].id
  140. })
  141. }
  142. newArray.push(element.title)
  143. });
  144. this.data.schoolArray.push(newArray)
  145. this.setData({
  146. schoolArray: this.data.schoolArray
  147. })
  148. //切换班级
  149. this.changeClass()
  150. }).catch(res => {
  151. console.log("查询学校error:", res)
  152. this.setData({
  153. schoolArray: [['暂无学校']],
  154. schoolId: '',
  155. classArray: ['暂无班级'],
  156. classId: ''
  157. })
  158. })
  159. },
  160. //查询班级
  161. changeClass: function () {
  162. let params = {
  163. "city": this.data.cityValue,
  164. "father": this.data.schoolId,//学校ID
  165. "province": this.data.provinceValue,
  166. "region": this.data.regionValue,
  167. "type": 2,
  168. }
  169. httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => {
  170. this.setData({
  171. classArray: [],
  172. classIndex: 0
  173. })
  174. this.setData({
  175. classData: res.data.data,
  176. classId: res.data.data[0].id
  177. })
  178. console.log("classData:", this.data.classData)
  179. res.data.data.forEach((element: { id: number; title: string; }, index: number) => {
  180. if (element.id == ConstsData.AppData.myInfoData.classId) {
  181. this.setData({
  182. classIndex: index,
  183. classId: res.data.data[index].id
  184. })
  185. console.log("this.data.classIndex:", this.data.classIndex)
  186. }
  187. this.data.classArray.push(element.title)
  188. });
  189. this.setData({
  190. classArray: this.data.classArray,
  191. })
  192. }).catch(res => {
  193. console.log("查询班级error:", res)
  194. this.setData({
  195. classArray: ['暂无班级'],
  196. classId: ''
  197. })
  198. })
  199. },
  200. bindMultiPickerColumnChange: function (event: any) {
  201. //
  202. switch (Number(event.detail.column)) {
  203. case 0:
  204. //代表第一列
  205. this.setData({
  206. regionOneIndex: event.detail.value,
  207. })
  208. break;
  209. case 1:
  210. //代表第二列
  211. this.setData({
  212. regionTwoIndex: event.detail.value,
  213. })
  214. break;
  215. case 2:
  216. //代表第三列
  217. this.setData({
  218. regionThreeIndex: event.detail.value
  219. })
  220. break;
  221. }
  222. this.changeOrganizeInfo();
  223. },
  224. bindRegionChange: function (event: any) {
  225. this.setData({
  226. regionIndex: event.detail.value
  227. })
  228. },
  229. bindSchoolPicker: function (event: any) {
  230. this.setData({
  231. schoolIndex: event.detail.value,
  232. schoolId: this.data.schoolData[event.detail.value].id
  233. })
  234. this.changeClass();
  235. },
  236. bindClssPicker: function (event: any) {
  237. this.setData({
  238. classIndex: event.detail.value,
  239. classId: this.data.classData[event.detail.value].id
  240. })
  241. },
  242. //扫码界面(未处理回调)
  243. scanCode: function () {
  244. var that = this;
  245. wx.scanCode({ //扫描API
  246. success(res) { //扫描成功
  247. console.log(res) //输出回调信息
  248. that.setData({
  249. scanCodeMsg: res.result
  250. });
  251. wx.showToast({
  252. title: '扫码成功',
  253. icon: 'success',
  254. duration: 1000
  255. })
  256. },
  257. fail: (res: any) => {//接口调用失败的回调函数
  258. wx.showToast({
  259. title: '扫码失败',
  260. icon: 'success',
  261. duration: 1000
  262. })
  263. },
  264. })
  265. },
  266. //获取设备ID的输入
  267. bindDeviceInput(event: any) {
  268. this.setData({
  269. deviceId: event.detail.value
  270. })
  271. },
  272. //上课
  273. startMonitor: function () {
  274. if (!this.data.deviceId) {
  275. wx.showToast({
  276. title: '请输入设备ID',
  277. icon: 'none', //如果要纯文本,不要icon,将值设为'none'
  278. duration: 1000
  279. })
  280. return;
  281. }
  282. let params = {
  283. address: this.data.region[0] + "--" + this.data.region[1] + "--" + this.data.region[2],
  284. school: this.data.schoolArray[this.data.schoolIndex],
  285. class: this.data.classArray[this.data.classIndex],
  286. deviceId: this.data.deviceId
  287. }
  288. console.log("params:", params)
  289. httpUtil.wxGet(httpUtil.interfaces.getDeviceById + this.data.deviceId, null).then((res: any) => {
  290. console.log("根据ID获取设备信息成功:", res)
  291. if (res.data.success) {
  292. //开始上课
  293. this.setData({
  294. pageState: 1
  295. })
  296. }
  297. }).catch((res) => {
  298. console.log("根据ID获取设备信息失败:", res)
  299. })
  300. },
  301. //上课之后的方法
  302. //下课
  303. classOver: function () {
  304. //下课
  305. let that = this;
  306. wx.showModal({
  307. title: '',
  308. content: '确定下课么',
  309. success: function (res) {
  310. if (res.confirm) {
  311. console.log('点击确认回调')
  312. that.setData({
  313. pageState: 0
  314. })
  315. } else {
  316. console.log('点击取消回调')
  317. }
  318. }
  319. })
  320. }
  321. }
  322. })