123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- const app = require('../../utils/util.js');
- const tools = require('../../utils/tools.js');
- Page({
- data: {
- index: 0, // 题目序列
- chooseValue: [], // 选择的答案序列
- questionList: [
- // {
- // id: 10,
- // "QuestStem": "以下属于传统协同办公应用开发的典型问题的是?",
- // 'QuestChoice': [{
- // name: 'a',
- // value: 'aaaaaaa',
- // checked: false
- // },
- // {
- // name: 'aa',
- // value: 'sdsdsd',
- // checked: false
- // },
- // {
- // name: 'a3',
- // value: 'ewewewe',
- // checked: false
- // },
- // ],
- // "QuestType": 1,
- // "checked": false
- // },
- // {
- // id: 12,
- // "QuestStem": "企业微信建立开放办公应用生态的主要策略是000?",
- // "QuestChoice": ['A', 'B'],
- // "QuestType": 2,
- // "scores": 10,
- // "checked": false
- // },
- // {
- // id: 123,
- // "QuestStem": "企业微信建立开放办公应用生态的主要策略是?",
- // "QuestType": 3,
- // "scores": 10,
- // "checked": false
- // },
- ],
- totalScore: 0,
- id: '', //考试主键id(可取list接口中id)
- paperId: '', //试卷id(可取list接口中paperId)
- answersId: '', // 提交答案
- sessionKey: '',
- },
- /*
- * 单选事件
- */
- radioChange: function (e) {
- console.log('checkbox发生change事件,携带value值为:', e.detail.value)
- let json = {};
- json.currentAnswer = e.detail.value;
- json.id = e.currentTarget.dataset.idx;
- json.questType = e.currentTarget.dataset.questtypes;
- console.log("题目", this.data.questionList)
- this.data.chooseValue[this.data.index] = json;
- this.data.questionList[this.data.index].checked = e.detail.value;
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- }, radioChange: function (e) {
- console.log('checkbox发生change事件,携带value值为:', e.detail.value)
- let json = {};
- json.currentAnswer = e.detail.value;
- json.id = e.currentTarget.dataset.idx;
- json.questType = e.currentTarget.dataset.questtypes;
- this.data.chooseValue[this.data.index] = json;
- const items = this.data.questionList[this.data.index].QuestChoice
- for (let i = 0, len = items.length; i < len; ++i) {
- items[i].checked = items[i].value === e.detail.value
- }
- console.log( this.data.chooseValue,"尅额么");
- console.log(this.data.questionList);
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 多选事件
- */
- checkboxChange: function (e) {
- console.log('checkbox发生change事件,携带value值为:', e.detail.value)
- let json = {};
- let aa = e.detail.value.join("||")
- json.currentAnswer = aa;
- json.questType = e.currentTarget.dataset.questtypes;
- json.id = e.currentTarget.dataset.idx;
- this.data.chooseValue[this.data.index] = json;
- const items = this.data.questionList[this.data.index].QuestChoice
- const values = e.detail.value
- for (let i = 0, lenI = items.length; i < lenI; ++i) {
- items[i].checked = false
- for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
- if (items[i].value === values[j]) {
- items[i].checked = true
- break
- }
- }
- }
- this.setData({
- questionList: this.data.questionList
- })
- console.log(this.data.questionList, "7878787878");
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 解答事件
- */
- bindTextAreaBlur(e) {
- console.log(e.detail.value);
- let json = {};
- json.currentAnswer = e.detail.value;
- json.id = e.currentTarget.dataset.idx;
- json.questType = e.currentTarget.dataset.questtypes;
- this.data.chooseValue[this.data.index] = json;
- this.data.questionList[this.data.index].currentAnswer = e.detail.value;
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 下一题/提交 按钮
- */
- nextSubmit: function () {
- // 判断是不是最后一题
- if (this.data.index < this.data.questionList.length - 1) {
- // 渲染下一题
- this.setData({
- index: this.data.index + 1
- })
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- } else {
- console.log(this.data.chooseValue);
- if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
- this.setData({
- chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
- })
- }
- this.submitAll(this.data.chooseValue);
- }
- },
- upSubmit() {
- this.setData({
- index: this.data.index - 1
- })
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- console.log(this.data.chooseValue, "88888888888888888888888888");
- console.log(this.data.chooseValue[this.data.index]);
- //this.data.chooseValue[this.data.index].currentAnswer
- },
- // onLoad: function (options) {
- // let a = [{
- // "QuestType": "3",
- // "QuestStem": "子类从父类那里继承什么方法和状态?",
- // "QuestAnswer": "",
- // "QuestChoice": "",
- // "Id": 39
- // },
- // {
- // "QuestType": "0",
- // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响\n List l = new LinkedList();\n l.add(new MyObject(\"A\"));\n if(l.contains(new MyObject(\"A\"))){}",
- // "QuestAnswer": "equals ()",
- // "QuestChoice": "toString()||equals ()||hashCode()||clone()",
- // "Id": 36
- // },
- // {
- // "QuestType": "1",
- // "QuestStem": "MyObject 的什么方法会对if表达式的正确性产生影响(多选) Map m = new HashMap; m.add(new MyObject(\"A\")); if(m.contains(new MyObject(\"A\"))){}",
- // "QuestAnswer": "equals ()||\nhashCode()||",
- // "QuestChoice": "toString()||\nequals ()||\nhashCode()||\nclone()||",
- // "Id": 38
- // },
- // {
- // "QuestType": "2",
- // "QuestStem": "1+1=2",
- // "QuestAnswer": "是",
- // "QuestChoice": "是||否",
- // "Id": 42
- // },
- // ];
- // let jsonArr = a.map(item => {
- // let json = {};
- // json.QuestType = item.QuestType;
- // json.id = item.Id;
- // json.QuestAnswer = item.QuestAnswer;
- // json.QuestStem = item.QuestStem;
- // if (item.QuestChoice) {
- // let arr = item.QuestChoice.split('||');
- // json.QuestChoice = arr;
- // }
- // return json;
- // })
- // this.setData({
- // questionList: jsonArr
- // })
- // }
- onShow: function () {
- console.log("show0000000000000000000000000000000000000000000000000000000000000000000000");
- console.log(wx.getStorageSync('answersId'),"onshow 的 answeid");
- // console.log(wx.getStorageSync('questionList'+((wx.getStorageSync('answersId'))),"78978978979877777");
- if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
- console.log("缓村了锕");
- const questionList = wx.getStorageSync('questionList'+wx.getStorageSync('answersId'));
- this.setData({
- questionList: questionList,
- index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
- answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
- chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
- })
- console.log(this.data.questionList,"show 缓存的数据");
- }else{
- this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
- console.log(this.data.questionList,"show 没有缓存");
- }
- },
- async onLoad(options) {
- // //const sessionKey = await tools.checkSessionAndLogin();
- // console.log("onload..................................");
- // wx.setStorageSync('answersId', options.answersId);
- // console.log(options.answersId,"传值的缓冲answersId");
- // console.log(wx.getStorageSync('answersId'),"1111111111111111111");
- // const sessionKey = 'yoa0rZTt2bAiTVDsiRjysw==';
- // this.setData({
- // sessionKey: sessionKey,
- // paperId:options.paperId,
- // answersId:options.answersId,
- // id:options.id,
- // })
- // console.log(wx.getStorageSync('answersId'),"onload中 的 answeid");
- // //....................
- // console.log(wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),"111111111111111111111");
- // if (wx.getStorageSync('questionList'+wx.getStorageSync('answersId'))) {
- // this.setData({
- // questionList: wx.getStorageSync('questionList'+wx.getStorageSync('answersId')),
- // index: wx.getStorageSync('titleINDEX'+wx.getStorageSync('answersId')),
- // answersId: wx.getStorageSync('answersId'+wx.getStorageSync('answersId')),
- // chooseValue:wx.getStorageSync('chooseValue'+wx.getStorageSync('answersId')),
- // })
- // console.log("onload 有缓存");
- // console.log(this.data.questionList,"onload 有缓存的数据");
- // } else {
- // console.log("onload 没有缓存");
- // this.allShi(options.id, options.paperId, sessionKey);
- // }
- // //....................
- const sessionKey = await tools.checkSessionAndLogin();
- //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
- console.log("onloading.....................");
- wx.setStorageSync('answersId', options.answersId);
- this.setData({
- sessionKey: sessionKey,
- paperId: options.paperId,
- answersId: options.answersId,
- id: options.id,
- })
- console.log(options.answersId, "00000000000000000000000000");
- console.log(wx.getStorageSync('answersId'), "1111111111111");
- if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
- console.log("缓村了锕");
- const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
- const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
- const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
- console.log(titleINDEX,"打印下看看");
- console.log(chooseValue,"choosevalue");
- this.setData({
- questionList: questionList,
- answersId: wx.getStorageSync('answersId'),
- chooseValue:chooseValue,
- index: titleINDEX
- })
-
- console.log(this.data.questionList, "show 缓存的数据");
- console.log(this.data.index, "indexindex");
- } else {
- console.log("无缓存");
- this.allShi(options.id, options.paperId, sessionKey);
- }
- },
- allShi(id, paperId, sessionKey) {
- wx.request({
- url: app.globalData.publicUrl + '/wx/paper/detail',
- method: "post",
- data: {
- sessionKey: sessionKey,
- id: id,
- paperId: paperId
- },
- success: (res) => {
- let jsonArr = JSON.parse(res.data.paperContent).map(item => {
- let json = {};
- json.QuestType = item.QuestType;
- json.id = item.Id;
- json.QuestAnswer = item.QuestAnswer;
- json.QuestStem = item.QuestStem;
- if (item.QuestChoice) {
- let arr = item.QuestChoice.split('||');
- json.QuestChoice = arr;
- }
- if (item.QuestType == '1') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- if (item.QuestType == '0') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- if (item.QuestType == '2') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- return json;
- })
- this.setData({
- questionList: jsonArr
- })
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'),0);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'),[]),
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- }
- })
- },
- submitAll(currentAnswerTemp) {
- console.log();
- wx.request({
- url: app.globalData.publicUrl + '/wx/paper/commit',
- method: "post",
- data: {
- sessionKey: this.data.sessionKey,
- currentAnswerTemp: currentAnswerTemp,
- answersId: wx.getStorageSync('answersId')
- },
- success: (res) => {
- console.log(res);
- // if (res.data.msg == '请勿重复提交') {
- // wx.showModal({
- // showCancel: false,
- // content: '当前老师批阅中,' + res.data.msg,
- // success(res) {}
- // })
- // } else {
- if (res.data.code == 0) {
- console.log(res, "为我么我们微妙"); // 提交答案是后
- // this.setData({
- // answersId: res.data.answersId
- // })
- // this.allShi(id, paperId, sessionKey);
- wx.showModal({
- showCancel: false,
- content: '恭喜您,提交答案成功,请耐心等待老师判卷',
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- // wx.switchTab({
- // url: '/pages/testAnswer/testAnswer',
- // })
- } else {
- wx.showModal({
- showCancel: false,
- content: res.data.msg,
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- }
- }
- })
- }
- })
|