myMission.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. const app = require('../../utils/util.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. showewm: false,
  8. showzs: false,
  9. kcArr: []
  10. },
  11. selectBtn0() {
  12. this.setData({
  13. select: 0
  14. });
  15. },
  16. selectBtn1() {
  17. this.setData({
  18. select: 1
  19. });
  20. },
  21. gokhAnswer() {
  22. wx.navigateTo({
  23. url: '../answerAfterclass/answerAfterclass'
  24. })
  25. },
  26. gopjClass() {
  27. wx.navigateTo({
  28. url: '../evaluationCourse/evaluationCourse'
  29. })
  30. },
  31. startAnswer() {
  32. wx.navigateTo({
  33. url: '/pages/answerAfterclass/answerAfterclass',
  34. })
  35. },
  36. goWrite() {
  37. wx.navigateTo({
  38. url: '../studentRegistration/studentRegistration'
  39. })
  40. },
  41. goWrite2() {
  42. wx.navigateTo({
  43. url: '../feedBack/feedBack'
  44. })
  45. },
  46. lq() {
  47. this.setData({
  48. showzs: true
  49. });
  50. // wx.showToast({
  51. // title: '领取成功'
  52. // })
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. getMycourse(sessionKey) {
  58. var _this = this;
  59. wx.request({
  60. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  61. method: "post",
  62. data: {
  63. sessionKey: sessionKey
  64. },
  65. success: function (res) {
  66. console.log(res)
  67. _this.setData({
  68. kcArr: res.data.list
  69. });
  70. }
  71. })
  72. },
  73. isClass(sessionKey) {
  74. var _this = this;
  75. wx.request({
  76. url: app.globalData.publicUrl2 + '/wx/student/selAllClas',
  77. method: "post",
  78. data: {
  79. sessionKey: sessionKey
  80. },
  81. success: function (res) {
  82. console.log(res.data, "我是返回的班级列表")
  83. var filterArr = res.data.data.claList.filter(o => o.isActive == 5)
  84. console.log(filterArr, "我是筛选出来的数组")
  85. if (filterArr.length == 0) {
  86. wx.showModal({
  87. title: '您还未加入班级',
  88. content: '跳转至身份认证',
  89. success: function (res) {
  90. if (res.confirm) {
  91. wx.redirectTo({
  92. url: '../Identity/Identity'
  93. })
  94. } else {
  95. wx.switchTab({
  96. url: '../index/index'
  97. })
  98. }
  99. }
  100. })
  101. return false;
  102. }
  103. }
  104. })
  105. },
  106. // onShow: function () {
  107. // var _this = this;
  108. // wx.checkSession({
  109. // success: () => {
  110. // console.log("我有缓存")
  111. // var sessionKey = wx.getStorageSync('sessionKey');
  112. // if (sessionKey == "") {
  113. // wx.login({
  114. // success(res) {
  115. // console.log(res);
  116. // var code = res.code
  117. // wx.request({
  118. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  119. // method: "get",
  120. // data: {
  121. // code
  122. // },
  123. // success: function (res) {
  124. // sessionKey = res.data.sessionKey;
  125. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  126. // }
  127. // })
  128. // }
  129. // })
  130. // } else {
  131. // _this.getMycourse(sessionKey);
  132. // }
  133. // },
  134. // fail() {
  135. // console.log("我没有缓存并去登录请求")
  136. // wx.login({
  137. // success(res) {
  138. // console.log(res);
  139. // var code = res.code
  140. // wx.request({
  141. // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  142. // method: "get",
  143. // data: {
  144. // code
  145. // },
  146. // success: function (res) {
  147. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  148. // var sessionKey = res.data.sessionKey;
  149. // _this.getMycourse(sessionKey);
  150. // }
  151. // })
  152. // }
  153. // })
  154. // }
  155. // })
  156. // },
  157. showEwm() {
  158. var sessionKey = "";
  159. var _this = this;
  160. wx.checkSession({
  161. success: () => {
  162. console.log("我有缓存")
  163. sessionKey = wx.getStorageSync('sessionKey');
  164. console.log(sessionKey)
  165. wx.request({
  166. url: app.globalData.publicUrl2 + '/wx/student/wxGroup',
  167. method: "post",
  168. data: {
  169. sessionKey: sessionKey
  170. },
  171. success: function (res) {
  172. console.log(res)
  173. _this.setData({
  174. showewm: true
  175. })
  176. }
  177. })
  178. },
  179. fail() {
  180. console.log("我没有缓存并去登录请求")
  181. wx.login({
  182. success(res) {
  183. console.log(res);
  184. var code = res.code
  185. wx.request({
  186. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  187. method: "get",
  188. data: {
  189. code
  190. },
  191. success: function (res) {
  192. sessionKey = res.data.sessionKey;
  193. wx.setStorageSync('sessionKey', res.data.sessionKey);
  194. wx.request({
  195. url: app.globalData.publicUrl2 + '/wx/student/wxGroup',
  196. method: "post",
  197. data: {
  198. sessionKey: sessionKey
  199. },
  200. success: function (res) {
  201. console.log(res)
  202. _this.setData({
  203. showewm: true
  204. })
  205. }
  206. })
  207. }
  208. })
  209. }
  210. })
  211. }
  212. })
  213. // this.setData({
  214. // showewm: true
  215. // });
  216. },
  217. // showzs(){
  218. // },
  219. onShow() {
  220. var _this = this;
  221. wx.checkSession({
  222. success: () => {
  223. console.log("我有缓存")
  224. var sessionKey = wx.getStorageSync('sessionKey');
  225. console.log(sessionKey, "我有缓存")
  226. if (sessionKey == "") {
  227. wx.login({
  228. success(res) {
  229. console.log(res);
  230. var code = res.code
  231. wx.request({
  232. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  233. method: "get",
  234. data: {
  235. code
  236. },
  237. success: function (res) {
  238. sessionKey = res.data.sessionKey;
  239. wx.setStorageSync('sessionKey', res.data.sessionKey);
  240. _this.isClass(sessionKey);
  241. _this.getMycourse(sessionKey);
  242. }
  243. })
  244. }
  245. })
  246. } else {
  247. _this.isClass(sessionKey);
  248. _this.getMycourse(sessionKey);
  249. }
  250. },
  251. fail() {
  252. console.log("我没有缓存并去登录请求")
  253. wx.login({
  254. success(res) {
  255. console.log(res);
  256. var code = res.code
  257. wx.request({
  258. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  259. method: "get",
  260. data: {
  261. code
  262. },
  263. success: function (res) {
  264. wx.setStorageSync('sessionKey', res.data.sessionKey);
  265. var sessionKey = res.data.sessionKey;
  266. _this.isClass(sessionKey);
  267. _this.getMycourse(sessionKey);
  268. }
  269. })
  270. }
  271. })
  272. }
  273. })
  274. },
  275. onClose() {
  276. wx.hideLoading()
  277. this.setData({
  278. showewm: false
  279. });
  280. },
  281. onClose1() {
  282. this.setData({
  283. showzs: false
  284. });
  285. },
  286. /**
  287. * 生命周期函数--监听页面初次渲染完成
  288. */
  289. saveImg() {
  290. wx.getSetting({
  291. success(res) {
  292. if (!res.authSetting['scope.writePhotosAlbum']) {
  293. wx.authorize({
  294. scope: 'scope.writePhotosAlbum',
  295. success() {
  296. console.log(res, "我点击同意啦")
  297. wx.showLoading({
  298. title: '保存中...'
  299. })
  300. var imgSrc = "http://yijiao.oss-cn-qingdao.aliyuncs.com/images/http://tmp/wx1b4e5e756cd48af1.o6zAJsws4grEQvYrWTjBigy-6QaU.0llhudiKSF2V955a1c48350d9328ef064b4d36d12746.jpg"
  301. wx.downloadFile({
  302. url: imgSrc,
  303. success: function (res) {
  304. console.log(res, '我下载完成啦');
  305. //图片保存到本地
  306. wx.saveImageToPhotosAlbum({
  307. filePath: res.tempFilePath,
  308. success: function (data) {
  309. console.log(data, '我保存成功啦')
  310. wx.hideLoading();
  311. wx.showToast({
  312. title: '保存成功',
  313. icon: 'success',
  314. duration: 2000
  315. })
  316. },
  317. fail: function (err) {
  318. console.log(err, '我保存失败啦')
  319. wx.hideLoading();
  320. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  321. console.log("当初用户拒绝,再次发起授权")
  322. wx.openSetting({
  323. success(settingdata) {
  324. console.log(settingdata)
  325. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  326. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  327. } else {
  328. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  329. }
  330. }
  331. })
  332. }
  333. },
  334. complete(res) {
  335. console.log(res);
  336. }
  337. })
  338. }
  339. })
  340. console.log('授权成功')
  341. }
  342. })
  343. } else {
  344. var imgSrc = "http://yijiao.oss-cn-qingdao.aliyuncs.com/images/http://tmp/wx1b4e5e756cd48af1.o6zAJsws4grEQvYrWTjBigy-6QaU.0llhudiKSF2V955a1c48350d9328ef064b4d36d12746.jpg"
  345. wx.downloadFile({
  346. url: imgSrc,
  347. success: function (res) {
  348. console.log(res, '我下载完成啦');
  349. wx.hideLoading();
  350. //图片保存到本地
  351. wx.saveImageToPhotosAlbum({
  352. filePath: res.tempFilePath,
  353. success: function (data) {
  354. console.log(data, '我保存成功啦')
  355. wx.hideLoading();
  356. wx.showToast({
  357. title: '保存成功',
  358. icon: 'success',
  359. duration: 2000
  360. })
  361. },
  362. fail: function (err) {
  363. console.log(err, '我保存失败啦')
  364. wx.hideLoading();
  365. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  366. console.log("当初用户拒绝,再次发起授权")
  367. wx.openSetting({
  368. success(settingdata) {
  369. console.log(settingdata)
  370. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  371. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  372. } else {
  373. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  374. }
  375. }
  376. })
  377. }
  378. },
  379. complete(res) {
  380. console.log(res);
  381. }
  382. })
  383. }
  384. })
  385. }
  386. }
  387. })
  388. },
  389. onReady: function () {
  390. },
  391. /**
  392. * 生命周期函数--监听页面显示
  393. */
  394. // onShow: function () {
  395. // },
  396. /**
  397. * 生命周期函数--监听页面隐藏
  398. */
  399. onHide: function () {
  400. },
  401. /**
  402. * 生命周期函数--监听页面卸载
  403. */
  404. onUnload: function () {
  405. },
  406. /**
  407. * 页面相关事件处理函数--监听用户下拉动作
  408. */
  409. onPullDownRefresh: function () {
  410. },
  411. /**
  412. * 页面上拉触底事件的处理函数
  413. */
  414. onReachBottom: function () {
  415. },
  416. /**
  417. * 用户点击右上角分享
  418. */
  419. onShareAppMessage: function () {
  420. }
  421. })