answerAfterclasses.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. index: 0, // 题目序列
  6. chooseValue: [], // 选择的答案序列
  7. questionList: [
  8. // {
  9. // id: 10,
  10. // "QuestStem": "以下属于传统协同办公应用开发的典型问题的是?",
  11. // 'QuestChoice': [{
  12. // name: 'a',
  13. // value: 'aaaaaaa',
  14. // checked: false
  15. // },
  16. // {
  17. // name: 'aa',
  18. // value: 'sdsdsd',
  19. // checked: false
  20. // },
  21. // {
  22. // name: 'a3',
  23. // value: 'ewewewe',
  24. // checked: false
  25. // },
  26. // ],
  27. // "QuestType": 1,
  28. // "checked": false
  29. // },
  30. // {
  31. // id: 12,
  32. // "QuestStem": "企业微信建立开放办公应用生态的主要策略是000?",
  33. // "QuestChoice": ['A', 'B'],
  34. // "QuestType": 2,
  35. // "scores": 10,
  36. // "checked": false
  37. // },
  38. // {
  39. // id: 123,
  40. // "QuestStem": "企业微信建立开放办公应用生态的主要策略是?",
  41. // "QuestType": 3,
  42. // "scores": 10,
  43. // "checked": false
  44. // },
  45. ],
  46. totalScore: 0,
  47. id: '', //考试主键id(可取list接口中id)
  48. paperId: '', //试卷id(可取list接口中paperId)
  49. answersId: '', // 提交答案
  50. sessionKey: '',
  51. },
  52. /*
  53. * 单选事件
  54. */
  55. radioChange: function (e) {
  56. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  57. let json = {};
  58. json.currentAnswer = e.detail.value;
  59. json.id = e.currentTarget.dataset.idx;
  60. json.questType = e.currentTarget.dataset.questtypes;
  61. console.log("题目", this.data.questionList)
  62. this.data.chooseValue[this.data.index] = json;
  63. this.data.questionList[this.data.index].checked = e.detail.value;
  64. this.setData({
  65. questionList: this.data.questionList
  66. })
  67. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  68. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  69. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  70. }, radioChange: function (e) {
  71. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  72. let json = {};
  73. json.currentAnswer = e.detail.value;
  74. json.id = e.currentTarget.dataset.idx;
  75. json.questType = e.currentTarget.dataset.questtypes;
  76. this.data.chooseValue[this.data.index] = json;
  77. const items = this.data.questionList[this.data.index].QuestChoice
  78. for (let i = 0, len = items.length; i < len; ++i) {
  79. items[i].checked = items[i].value === e.detail.value
  80. }
  81. console.log( this.data.chooseValue,"尅额么");
  82. console.log(this.data.questionList);
  83. this.setData({
  84. questionList: this.data.questionList
  85. })
  86. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  87. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  88. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  89. },
  90. /*
  91. * 多选事件
  92. */
  93. checkboxChange: function (e) {
  94. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  95. let json = {};
  96. let aa = e.detail.value.join("||")
  97. json.currentAnswer = aa;
  98. json.questType = e.currentTarget.dataset.questtypes;
  99. json.id = e.currentTarget.dataset.idx;
  100. this.data.chooseValue[this.data.index] = json;
  101. const items = this.data.questionList[this.data.index].QuestChoice
  102. const values = e.detail.value
  103. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  104. items[i].checked = false
  105. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  106. if (items[i].value === values[j]) {
  107. items[i].checked = true
  108. break
  109. }
  110. }
  111. }
  112. this.setData({
  113. questionList: this.data.questionList
  114. })
  115. console.log(this.data.questionList, "7878787878");
  116. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  117. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  118. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  119. },
  120. /*
  121. * 解答事件
  122. */
  123. bindTextAreaBlur(e) {
  124. console.log(e.detail.value);
  125. let json = {};
  126. json.currentAnswer = e.detail.value;
  127. json.id = e.currentTarget.dataset.idx;
  128. json.questType = e.currentTarget.dataset.questtypes;
  129. this.data.chooseValue[this.data.index] = json;
  130. this.data.questionList[this.data.index].currentAnswer = e.detail.value;
  131. this.setData({
  132. questionList: this.data.questionList
  133. })
  134. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  135. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  136. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  137. },
  138. /*
  139. * 下一题/提交 按钮
  140. */
  141. nextSubmit: function () {
  142. // 判断是不是最后一题
  143. if (this.data.index < this.data.questionList.length - 1) {
  144. // 渲染下一题
  145. this.setData({
  146. index: this.data.index + 1
  147. })
  148. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  149. } else {
  150. console.log(this.data.chooseValue);
  151. if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
  152. this.setData({
  153. chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
  154. })
  155. }
  156. this.submitAll(this.data.chooseValue);
  157. }
  158. },
  159. upSubmit() {
  160. this.setData({
  161. index: this.data.index - 1
  162. })
  163. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  164. console.log(this.data.chooseValue, "88888888888888888888888888");
  165. console.log(this.data.chooseValue[this.data.index]);
  166. //this.data.chooseValue[this.data.index].currentAnswer
  167. },
  168. // onLoad: function (options) {
  169. // let a = [{
  170. // "QuestType": "3",
  171. // "QuestStem": "子类从父类那里继承什么方法和状态?",
  172. // "QuestAnswer": "",
  173. // "QuestChoice": "",
  174. // "Id": 39
  175. // },
  176. // {
  177. // "QuestType": "0",
  178. // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响\n     List l = new LinkedList();\n     l.add(new MyObject(\"A\"));\n    if(l.contains(new MyObject(\"A\"))){}",
  179. // "QuestAnswer": "equals ()",
  180. // "QuestChoice": "toString()||equals ()||hashCode()||clone()",
  181. // "Id": 36
  182. // },
  183. // {
  184. // "QuestType": "1",
  185. // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响(多选)   Map m = new HashMap;    m.add(new MyObject(\"A\"));    if(m.contains(new MyObject(\"A\"))){}",
  186. // "QuestAnswer": "equals ()||\nhashCode()||",
  187. // "QuestChoice": "toString()||\nequals ()||\nhashCode()||\nclone()||",
  188. // "Id": 38
  189. // },
  190. // {
  191. // "QuestType": "2",
  192. // "QuestStem": "1+1=2",
  193. // "QuestAnswer": "是",
  194. // "QuestChoice": "是||否",
  195. // "Id": 42
  196. // },
  197. // ];
  198. // let jsonArr = a.map(item => {
  199. // let json = {};
  200. // json.QuestType = item.QuestType;
  201. // json.id = item.Id;
  202. // json.QuestAnswer = item.QuestAnswer;
  203. // json.QuestStem = item.QuestStem;
  204. // if (item.QuestChoice) {
  205. // let arr = item.QuestChoice.split('||');
  206. // json.QuestChoice = arr;
  207. // }
  208. // return json;
  209. // })
  210. // this.setData({
  211. // questionList: jsonArr
  212. // })
  213. // }
  214. onShow: function () {
  215. console.log("show0000000000000000000000000000000000000000000000000000000000000000000000");
  216. console.log(wx.getStorageSync('answersId'),"onshow 的 answeid");
  217. // console.log(wx.getStorageSync('questionList'+((wx.getStorageSync('answersId'))),"78978978979877777");
  218. if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
  219. console.log("缓村了锕");
  220. const questionList = wx.getStorageSync('questionList'+wx.getStorageSync('answersId'));
  221. this.setData({
  222. questionList: questionList,
  223. index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
  224. answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
  225. chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
  226. })
  227. console.log(this.data.questionList,"show 缓存的数据");
  228. }else{
  229. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  230. console.log(this.data.questionList,"show 没有缓存");
  231. }
  232. },
  233. async onLoad(options) {
  234. // //const sessionKey = await tools.checkSessionAndLogin();
  235. // console.log("onload..................................");
  236. // wx.setStorageSync('answersId', options.answersId);
  237. // console.log(options.answersId,"传值的缓冲answersId");
  238. // console.log(wx.getStorageSync('answersId'),"1111111111111111111");
  239. // const sessionKey = 'yoa0rZTt2bAiTVDsiRjysw==';
  240. // this.setData({
  241. // sessionKey: sessionKey,
  242. // paperId:options.paperId,
  243. // answersId:options.answersId,
  244. // id:options.id,
  245. // })
  246. // console.log(wx.getStorageSync('answersId'),"onload中 的 answeid");
  247. // //....................
  248. // console.log(wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),"111111111111111111111");
  249. // if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
  250. // this.setData({
  251. // questionList: wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),
  252. // index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
  253. // answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
  254. // chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
  255. // })
  256. // console.log("onload 有缓存");
  257. // console.log(this.data.questionList,"onload 有缓存的数据");
  258. // } else {
  259. // console.log("onload 没有缓存");
  260. // this.allShi(options.id, options.paperId, sessionKey);
  261. // }
  262. // //....................
  263. const sessionKey = await tools.checkSessionAndLogin();
  264. //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
  265. console.log("onloading.....................");
  266. wx.setStorageSync('answersId', options.answersId);
  267. this.setData({
  268. sessionKey: sessionKey,
  269. paperId: options.paperId,
  270. answersId: options.answersId,
  271. id: options.id,
  272. })
  273. console.log(options.answersId, "00000000000000000000000000");
  274. console.log(wx.getStorageSync('answersId'), "1111111111111");
  275. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  276. console.log("缓村了锕");
  277. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  278. const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
  279. const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
  280. console.log(titleINDEX,"打印下看看");
  281. console.log(chooseValue,"choosevalue");
  282. this.setData({
  283. questionList: questionList,
  284. answersId: wx.getStorageSync('answersId'),
  285. chooseValue:chooseValue,
  286. index: titleINDEX
  287. })
  288. console.log(this.data.questionList, "show 缓存的数据");
  289. console.log(this.data.index, "indexindex");
  290. } else {
  291. console.log("无缓存");
  292. this.allShi(options.id, options.paperId, sessionKey);
  293. }
  294. },
  295. allShi(id, paperId, sessionKey) {
  296. wx.request({
  297. url: app.globalData.publicUrl + '/wx/paper/detail',
  298. method: "post",
  299. data: {
  300. sessionKey: sessionKey,
  301. id: id,
  302. paperId: paperId
  303. },
  304. success: (res) => {
  305. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  306. let json = {};
  307. json.QuestType = item.QuestType;
  308. json.id = item.Id;
  309. json.QuestAnswer = item.QuestAnswer;
  310. json.QuestStem = item.QuestStem;
  311. if (item.QuestChoice) {
  312. let arr = item.QuestChoice.split('||');
  313. json.QuestChoice = arr;
  314. }
  315. if (item.QuestType == '1') {
  316. let arr = item.QuestChoice.split('||');
  317. let arrJson = arr.map(item => {
  318. let json1 = {};
  319. json1.name = item;
  320. json1.value = item;
  321. json1.checked = false;
  322. return json1
  323. });
  324. json.QuestChoice = arrJson;
  325. }
  326. if (item.QuestType == '0') {
  327. let arr = item.QuestChoice.split('||');
  328. let arrJson = arr.map(item => {
  329. let json1 = {};
  330. json1.name = item;
  331. json1.value = item;
  332. json1.checked = false;
  333. return json1
  334. });
  335. json.QuestChoice = arrJson;
  336. }
  337. if (item.QuestType == '2') {
  338. let arr = item.QuestChoice.split('||');
  339. let arrJson = arr.map(item => {
  340. let json1 = {};
  341. json1.name = item;
  342. json1.value = item;
  343. json1.checked = false;
  344. return json1
  345. });
  346. json.QuestChoice = arrJson;
  347. }
  348. return json;
  349. })
  350. this.setData({
  351. questionList: jsonArr
  352. })
  353. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'),0);
  354. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'),[]),
  355. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  356. }
  357. })
  358. },
  359. submitAll(currentAnswerTemp) {
  360. console.log();
  361. wx.request({
  362. url: app.globalData.publicUrl + '/wx/paper/commit',
  363. method: "post",
  364. data: {
  365. sessionKey: this.data.sessionKey,
  366. currentAnswerTemp: currentAnswerTemp,
  367. answersId: wx.getStorageSync('answersId')
  368. },
  369. success: (res) => {
  370. console.log(res);
  371. // if (res.data.msg == '请勿重复提交') {
  372. // wx.showModal({
  373. // showCancel: false,
  374. // content: '当前老师批阅中,' + res.data.msg,
  375. // success(res) {}
  376. // })
  377. // } else {
  378. if (res.data.code == 0) {
  379. console.log(res, "为我么我们微妙"); // 提交答案是后
  380. // this.setData({
  381. // answersId: res.data.answersId
  382. // })
  383. // this.allShi(id, paperId, sessionKey);
  384. wx.showModal({
  385. showCancel: false,
  386. content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  387. success() {
  388. wx.navigateBack({
  389. delta: 1
  390. })
  391. }
  392. })
  393. // wx.switchTab({
  394. // url: '/pages/testAnswer/testAnswer',
  395. // })
  396. } else {
  397. wx.showModal({
  398. showCancel: false,
  399. content: res.data.msg,
  400. success() {
  401. wx.navigateBack({
  402. delta: 1
  403. })
  404. }
  405. })
  406. }
  407. }
  408. })
  409. }
  410. })