myClass.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. const app = require('../../utils/util.js');
  2. Page({
  3. data: {
  4. showMore: false, //更多
  5. showzs: false,
  6. show: false,
  7. SessionKey: "",
  8. notice: "暂无未读通知",
  9. className: '',
  10. logoImg: '',
  11. kcArr: [],
  12. sfmArr: []
  13. },
  14. // 更多
  15. listToggle: function () {
  16. this.setData({
  17. showMore: !this.data.showMore
  18. })
  19. },
  20. hidePopup() {
  21. var _this = this;
  22. _this.setData({
  23. show: false
  24. });
  25. var sessionKey = "";
  26. wx.checkSession({
  27. success: () => {
  28. sessionKey = wx.getStorageSync('sessionKey');
  29. wx.request({
  30. url: app.globalData.publicUrl2 + '/wx/student/verification',
  31. method: "post",
  32. data: {
  33. sessionKey: sessionKey
  34. },
  35. success: function (res) {
  36. console.log(res, "我成功了")
  37. }
  38. })
  39. },
  40. fail() {
  41. console.log("我没有缓存并去登录请求")
  42. wx.login({
  43. success(res) {
  44. console.log(res);
  45. var code = res.code
  46. wx.request({
  47. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  48. method: "get",
  49. data: {
  50. code
  51. },
  52. success: function (res) {
  53. sessionKey = res.data.sessionKey;
  54. wx.setStorageSync('sessionKey', res.data.sessionKey);
  55. wx.request({
  56. url: app.globalData.publicUrl2 + '/wx/student/verification',
  57. method: "post",
  58. data: {
  59. sessionKey: sessionKey
  60. },
  61. success: function (res) {
  62. console.log(res, "我成功了")
  63. }
  64. })
  65. }
  66. })
  67. }
  68. })
  69. }
  70. })
  71. },
  72. myactiveMore() {
  73. wx.navigateTo({
  74. url: '../myActive/myActive'
  75. })
  76. },
  77. gokhAnswer() {
  78. wx.navigateTo({
  79. url: '../answerAfterclass/answerAfterclass'
  80. })
  81. },
  82. gopjClass() {
  83. wx.navigateTo({
  84. url: '../evaluationCourse/evaluationCourse'
  85. })
  86. },
  87. goMyPoints() {
  88. // wx.showModal({
  89. // showCancel: false,
  90. // content: "敬请期待",
  91. // success(res) {}
  92. // })
  93. wx.navigateTo({
  94. url: '../myPoints/myPoints'
  95. })
  96. },
  97. goactiveDetails() {
  98. wx.navigateTo({
  99. url: '../myactiveDetails/myactiveDetails'
  100. })
  101. },
  102. lq() {
  103. // wx.showModal({
  104. // showCancel: false,
  105. // content: "此功能暂时还未开放哦",
  106. // success(res) {}
  107. // })
  108. this.setData({
  109. showzs: true
  110. });
  111. },
  112. onClose1() {
  113. this.setData({
  114. showzs: false
  115. });
  116. },
  117. goQmks() {
  118. wx.showModal({
  119. showCancel: false,
  120. content: "此功能暂时还未开放哦",
  121. success(res) {}
  122. })
  123. },
  124. goWrite() {
  125. // wx.showModal({
  126. // showCancel: false,
  127. // content: "敬请期待",
  128. // success(res) {}
  129. // })
  130. wx.navigateTo({
  131. url: '../studentRegistration/studentRegistration'
  132. })
  133. },
  134. goWrite2() {
  135. // wx.showModal({
  136. // showCancel: false,
  137. // content: "敬请期待",
  138. // success(res) {}
  139. // })
  140. wx.navigateTo({
  141. url: '../feedBack/feedBack'
  142. })
  143. },
  144. // 跳转直播点播页面
  145. goStudy(e) {
  146. let id = e.currentTarget.dataset.item.id
  147. if (e.currentTarget.dataset.item.isLive == 1) {
  148. if (e.currentTarget.dataset.item.isActive == 1) {
  149. wx.navigateTo({
  150. url: '../zbDetails/zbDetails?id=' + id
  151. })
  152. } else {
  153. wx.showModal({
  154. showCancel: false,
  155. content: "直播还未开始哦",
  156. success(res) {}
  157. })
  158. }
  159. } else {
  160. wx.navigateTo({
  161. url: '../dbDetails/dbDetails?id=' + id
  162. })
  163. }
  164. },
  165. // 查询我是否有班&&班级名字
  166. isClass(sessionKey) {
  167. var _this = this;
  168. wx.request({
  169. url: app.globalData.publicUrl2 + '/wx/student/selMyClas',
  170. method: "post",
  171. data: {
  172. sessionKey: sessionKey
  173. },
  174. success: function (res) {
  175. console.log(res, "我是返回是否有班级")
  176. if (res.data.code == 0) {
  177. _this.setData({
  178. className: res.data.data.clasName,
  179. logoImg: res.data.data.logoImg
  180. })
  181. } else {
  182. wx.showModal({
  183. content: "您当前还没有开放的班级!",
  184. showCancel: false,
  185. success(res) {
  186. if (res.confirm) {
  187. wx.switchTab({
  188. url: '../index/index'
  189. })
  190. }
  191. }
  192. })
  193. return false;
  194. }
  195. }
  196. })
  197. },
  198. // 协议是否已同意
  199. isAgree(sessionKey) {
  200. var _this = this;
  201. wx.request({
  202. url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKey',
  203. method: "post",
  204. data: {
  205. sessionKey: sessionKey
  206. },
  207. success: function (res) {
  208. console.log(res.data, "wwwwww")
  209. if (res.data.data) {
  210. if (res.data.data.isAgree == 0) {
  211. _this.setData({
  212. show: true
  213. });
  214. } else {
  215. _this.setData({
  216. show: false
  217. });
  218. }
  219. }
  220. }
  221. })
  222. },
  223. // 我的通知
  224. getMynotice(sessionKey) {
  225. var _this = this;
  226. wx.request({
  227. url: app.globalData.publicUrl3 + '/wx/eduNoticeSee/list',
  228. method: "post",
  229. data: {
  230. sessionKey: sessionKey,
  231. isSee: 1,
  232. isNotice: 0
  233. },
  234. success: function (res) {
  235. console.log(res, "333333333")
  236. if (res.data.code == 0) {
  237. if (res.data.list && res.data.list.length !== 0)
  238. _this.setData({
  239. notice: res.data.list[0].noticeContent
  240. });
  241. }
  242. }
  243. })
  244. },
  245. gomyNotice() {
  246. // if (this.data.notice !== "暂无未读通知") {
  247. wx.navigateTo({
  248. url: '../myNotice/myNotice'
  249. })
  250. // }
  251. },
  252. // // 我的课程
  253. getMycourse(sessionKey) {
  254. var _this = this;
  255. wx.request({
  256. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  257. method: "post",
  258. data: {
  259. sessionKey: sessionKey
  260. },
  261. success: function (res) {
  262. console.log(res, "kckckc")
  263. _this.setData({
  264. kcArr: res.data.list
  265. });
  266. let result = [];
  267. if (res.data.list)
  268. for (var i = 0; i < res.data.list.length; i++) {
  269. result.push({
  270. courseTime: res.data.list[i].courseTime
  271. });
  272. }
  273. const timesArr = result.map((item) => {
  274. return item.courseTime;
  275. });
  276. let sfmArr = [];
  277. for (let i = 0; i < timesArr.length; i++) {
  278. let value = timesArr[i];
  279. const resultValue = _this.handler(value);
  280. sfmArr.push({
  281. courseTime: resultValue
  282. })
  283. _this.setData({
  284. sfmArr: sfmArr
  285. })
  286. }
  287. }
  288. })
  289. },
  290. handler(value) {
  291. //换算为秒 进制1000
  292. const second = Math.floor(value / 1000); //判断是否够1秒
  293. if (second < 1) {
  294. return "0秒";
  295. }
  296. const secondValue = second % 60; // 秒
  297. const minutes = Math.floor(second / 60); //判断是否够1分钟
  298. if (minutes < 1) {
  299. return `${secondValue}秒`;
  300. }
  301. const minutesValue = minutes % 60; //分
  302. const hours = Math.floor(minutes / 60); //判断是否够1小时
  303. if (hours < 1) {
  304. return `${minutesValue}分${secondValue}秒`;
  305. }
  306. const hoursValue = hours % 60; //小时
  307. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  308. },
  309. onShow() {
  310. var _this = this;
  311. wx.checkSession({
  312. success: () => {
  313. console.log("我有缓存")
  314. var sessionKey = wx.getStorageSync('sessionKey');
  315. console.log(sessionKey, "我有缓存")
  316. if (sessionKey == "") {
  317. wx.login({
  318. success(res) {
  319. console.log(res);
  320. var code = res.code
  321. wx.request({
  322. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  323. method: "get",
  324. data: {
  325. code
  326. },
  327. success: function (res) {
  328. sessionKey = res.data.sessionKey;
  329. wx.setStorageSync('sessionKey', res.data.sessionKey);
  330. _this.isClass(sessionKey);
  331. // _this.getClassName(sessionKey);
  332. _this.getMycourse(sessionKey);
  333. _this.getMynotice(sessionKey);
  334. }
  335. })
  336. }
  337. })
  338. } else {
  339. _this.isClass(sessionKey);
  340. _this.getMycourse(sessionKey);
  341. // _this.getClassName(sessionKey);
  342. _this.getMynotice(sessionKey);
  343. }
  344. },
  345. fail() {
  346. console.log("我没有缓存并去登录请求")
  347. wx.login({
  348. success(res) {
  349. console.log(res);
  350. var code = res.code
  351. wx.request({
  352. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  353. method: "get",
  354. data: {
  355. code
  356. },
  357. success: function (res) {
  358. wx.setStorageSync('sessionKey', res.data.sessionKey);
  359. var sessionKey = res.data.sessionKey;
  360. _this.isClass(sessionKey);
  361. _this.getMycourse(sessionKey);
  362. // _this.getClassName(sessionKey);
  363. _this.getMynotice(sessionKey);
  364. }
  365. })
  366. }
  367. })
  368. }
  369. })
  370. }
  371. })