myClass.js 9.6 KB

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