answerAfterclass.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. this.data.chooseValue[this.data.index] = json;
  62. const items = this.data.questionList[this.data.index].QuestChoice
  63. for (let i = 0, len = items.length; i < len; ++i) {
  64. items[i].checked = items[i].value === e.detail.value
  65. }
  66. console.log( this.data.chooseValue,"尅额么");
  67. console.log(this.data.questionList);
  68. this.setData({
  69. questionList: this.data.questionList
  70. })
  71. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  72. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  73. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  74. },
  75. /*
  76. * 多选事件
  77. */
  78. checkboxChange: function (e) {
  79. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  80. let json = {};
  81. let aa = e.detail.value.join("||")
  82. json.currentAnswer = aa;
  83. json.questType = e.currentTarget.dataset.questtypes;
  84. json.id = e.currentTarget.dataset.idx;
  85. this.data.chooseValue[this.data.index] = json;
  86. const items = this.data.questionList[this.data.index].QuestChoice
  87. const values = e.detail.value
  88. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  89. items[i].checked = false
  90. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  91. if (items[i].value === values[j]) {
  92. items[i].checked = true
  93. break
  94. }
  95. }
  96. }
  97. this.setData({
  98. questionList: this.data.questionList
  99. })
  100. console.log(this.data.questionList, "7878787878");
  101. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  102. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  103. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  104. },
  105. /*
  106. * 解答事件
  107. */
  108. bindTextAreaBlur(e) {
  109. console.log(e.detail.value);
  110. let json = {};
  111. json.currentAnswer = e.detail.value;
  112. json.id = e.currentTarget.dataset.idx;
  113. json.questType = e.currentTarget.dataset.questtypes;
  114. this.data.chooseValue[this.data.index] = json;
  115. this.data.questionList[this.data.index].currentAnswer = e.detail.value;
  116. this.setData({
  117. questionList: this.data.questionList
  118. })
  119. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  120. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  121. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  122. },
  123. /*
  124. * 下一题/提交 按钮
  125. */
  126. nextSubmit: function () {
  127. // 判断是不是最后一题
  128. if (this.data.index < this.data.questionList.length - 1) {
  129. // 渲染下一题
  130. this.setData({
  131. index: this.data.index + 1
  132. })
  133. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  134. } else {
  135. console.log(this.data.chooseValue);
  136. if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
  137. this.setData({
  138. chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
  139. })
  140. }
  141. this.submitAll(this.data.chooseValue);
  142. }
  143. },
  144. upSubmit() {
  145. this.setData({
  146. index: this.data.index - 1
  147. })
  148. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  149. console.log(this.data.chooseValue, "88888888888888888888888888");
  150. console.log(this.data.chooseValue[this.data.index]);
  151. //this.data.chooseValue[this.data.index].currentAnswer
  152. },
  153. // onLoad: function (options) {
  154. // let a = [{
  155. // "QuestType": "3",
  156. // "QuestStem": "子类从父类那里继承什么方法和状态?",
  157. // "QuestAnswer": "",
  158. // "QuestChoice": "",
  159. // "Id": 39
  160. // },
  161. // {
  162. // "QuestType": "0",
  163. // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响\n     List l = new LinkedList();\n     l.add(new MyObject(\"A\"));\n    if(l.contains(new MyObject(\"A\"))){}",
  164. // "QuestAnswer": "equals ()",
  165. // "QuestChoice": "toString()||equals ()||hashCode()||clone()",
  166. // "Id": 36
  167. // },
  168. // {
  169. // "QuestType": "1",
  170. // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响(多选)   Map m = new HashMap;    m.add(new MyObject(\"A\"));    if(m.contains(new MyObject(\"A\"))){}",
  171. // "QuestAnswer": "equals ()||\nhashCode()||",
  172. // "QuestChoice": "toString()||\nequals ()||\nhashCode()||\nclone()||",
  173. // "Id": 38
  174. // },
  175. // {
  176. // "QuestType": "2",
  177. // "QuestStem": "1+1=2",
  178. // "QuestAnswer": "是",
  179. // "QuestChoice": "是||否",
  180. // "Id": 42
  181. // },
  182. // ];
  183. // let jsonArr = a.map(item => {
  184. // let json = {};
  185. // json.QuestType = item.QuestType;
  186. // json.id = item.Id;
  187. // json.QuestAnswer = item.QuestAnswer;
  188. // json.QuestStem = item.QuestStem;
  189. // if (item.QuestChoice) {
  190. // let arr = item.QuestChoice.split('||');
  191. // json.QuestChoice = arr;
  192. // }
  193. // return json;
  194. // })
  195. // this.setData({
  196. // questionList: jsonArr
  197. // })
  198. // }
  199. // onShow: function () {
  200. // console.log("show0000000000000000000000000000000000000000000000000000000000000000000000");
  201. // console.log(wx.getStorageSync('answersId'),"onshow 的 answeid");
  202. // // console.log(wx.getStorageSync('questionList'+((wx.getStorageSync('answersId'))),"78978978979877777");
  203. // if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
  204. // console.log("缓村了锕");
  205. // const questionList = wx.getStorageSync('questionList'+wx.getStorageSync('answersId'));
  206. // this.setData({
  207. // questionList: questionList,
  208. // index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
  209. // answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
  210. // chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
  211. // })
  212. // console.log(this.data.questionList,"show 缓存的数据");
  213. // }else{
  214. // this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  215. // console.log(this.data.questionList,"show 没有缓存");
  216. // }
  217. // },
  218. async onLoad(options) {
  219. // //const sessionKey = await tools.checkSessionAndLogin();
  220. // console.log("onload..................................");
  221. // wx.setStorageSync('answersId', options.answersId);
  222. // console.log(options.answersId,"传值的缓冲answersId");
  223. // console.log(wx.getStorageSync('answersId'),"1111111111111111111");
  224. // const sessionKey = 'yoa0rZTt2bAiTVDsiRjysw==';
  225. // this.setData({
  226. // sessionKey: sessionKey,
  227. // paperId:options.paperId,
  228. // answersId:options.answersId,
  229. // id:options.id,
  230. // })
  231. // console.log(wx.getStorageSync('answersId'),"onload中 的 answeid");
  232. // //....................
  233. // console.log(wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),"111111111111111111111");
  234. // if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
  235. // this.setData({
  236. // questionList: wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),
  237. // index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
  238. // answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
  239. // chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
  240. // })
  241. // console.log("onload 有缓存");
  242. // console.log(this.data.questionList,"onload 有缓存的数据");
  243. // } else {
  244. // console.log("onload 没有缓存");
  245. // this.allShi(options.id, options.paperId, sessionKey);
  246. // }
  247. // //....................
  248. const sessionKey = await tools.checkSessionAndLogin();
  249. //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
  250. console.log("onloading.....................");
  251. wx.setStorageSync('answersId', options.answersId);
  252. this.setData({
  253. sessionKey: sessionKey,
  254. paperId: options.paperId,
  255. answersId: options.answersId,
  256. id: options.id,
  257. })
  258. console.log(options.answersId, "00000000000000000000000000");
  259. console.log(wx.getStorageSync('answersId'), "1111111111111");
  260. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  261. console.log("缓村了锕");
  262. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  263. const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
  264. const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
  265. console.log(titleINDEX,"打印下看看");
  266. console.log(chooseValue,"choosevalue");
  267. this.setData({
  268. questionList: questionList,
  269. answersId: wx.getStorageSync('answersId'),
  270. chooseValue:chooseValue,
  271. index: titleINDEX
  272. })
  273. console.log(this.data.questionList, "show 缓存的数据");
  274. console.log(this.data.index, "indexindex");
  275. } else {
  276. console.log("无缓存");
  277. this.allShi(options.id, options.paperId, sessionKey);
  278. }
  279. },
  280. allShi(id, paperId, sessionKey) {
  281. wx.request({
  282. url: app.globalData.publicUrl + '/wx/paper/detail',
  283. method: "post",
  284. data: {
  285. sessionKey: sessionKey,
  286. id: id,
  287. paperId: paperId
  288. },
  289. success: (res) => {
  290. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  291. let json = {};
  292. json.QuestType = item.QuestType;
  293. json.id = item.Id;
  294. json.QuestAnswer = item.QuestAnswer;
  295. json.QuestStem = item.QuestStem;
  296. if (item.QuestChoice) {
  297. let arr = item.QuestChoice.split('||');
  298. json.QuestChoice = arr;
  299. }
  300. if (item.QuestType == '1') {
  301. let arr = item.QuestChoice.split('||');
  302. let arrJson = arr.map(item => {
  303. let json1 = {};
  304. json1.name = item;
  305. json1.value = item;
  306. json1.checked = false;
  307. return json1
  308. });
  309. json.QuestChoice = arrJson;
  310. }
  311. if (item.QuestType == '0') {
  312. let arr = item.QuestChoice.split('||');
  313. let arrJson = arr.map(item => {
  314. let json1 = {};
  315. json1.name = item;
  316. json1.value = item;
  317. json1.checked = false;
  318. return json1
  319. });
  320. json.QuestChoice = arrJson;
  321. }
  322. if (item.QuestType == '2') {
  323. let arr = item.QuestChoice.split('||');
  324. let arrJson = arr.map(item => {
  325. let json1 = {};
  326. json1.name = item;
  327. json1.value = item;
  328. json1.checked = false;
  329. return json1
  330. });
  331. json.QuestChoice = arrJson;
  332. }
  333. return json;
  334. })
  335. console.log(jsonArr);
  336. this.setData({
  337. questionList: jsonArr
  338. })
  339. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'),0);
  340. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'),[]),
  341. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  342. }
  343. })
  344. },
  345. submitAll(currentAnswerTemp) {
  346. console.log();
  347. wx.showLoading({
  348. mask: true,
  349. title: '加载中',
  350. })
  351. wx.request({
  352. url: app.globalData.publicUrl + '/wx/paper/commit',
  353. method: "post",
  354. data: {
  355. sessionKey: this.data.sessionKey,
  356. currentAnswerTemp: currentAnswerTemp,
  357. answersId: wx.getStorageSync('answersId')
  358. },
  359. success: (res) => {
  360. wx.hideLoading();
  361. if (res.data.code == 0) {
  362. wx.showModal({
  363. showCancel: false,
  364. content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  365. success() {
  366. wx.navigateBack({
  367. delta: 1
  368. })
  369. }
  370. })
  371. } else {
  372. wx.showModal({
  373. showCancel: false,
  374. content: res.data.msg,
  375. success() {
  376. wx.navigateBack({
  377. delta: 1
  378. })
  379. }
  380. })
  381. }
  382. }
  383. })
  384. }
  385. })