answerAfterclass.js 13 KB

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