|
|
|
@ -1,13 +1,8 @@ |
|
|
|
|
import { |
|
|
|
|
defineStore |
|
|
|
|
} from 'pinia'; |
|
|
|
|
import { defineStore } from 'pinia'; |
|
|
|
|
import http from '@/jtools/request/index'; |
|
|
|
|
import { |
|
|
|
|
queryQuestion, |
|
|
|
|
getVersion, |
|
|
|
|
querySysConfig |
|
|
|
|
} from '@/jtools/api/question'; |
|
|
|
|
import { queryQuestion, getVersion, querySysConfig } from '@/jtools/api/question'; |
|
|
|
|
import storage from '@/jtools/storage'; |
|
|
|
|
let JSON_SPLIT_LENGTH = 10; |
|
|
|
|
|
|
|
|
|
const question = defineStore({ |
|
|
|
|
id: 'question', |
|
|
|
@ -26,37 +21,36 @@ const question = defineStore({ |
|
|
|
|
|
|
|
|
|
actions: { |
|
|
|
|
resetStorage() { |
|
|
|
|
this.currentIndex_subject1=0 |
|
|
|
|
this.currentIndex_subject4=0 |
|
|
|
|
this.curSubject=0 |
|
|
|
|
storage.remove('curSubject') |
|
|
|
|
storage.remove('wrongList_subject1') |
|
|
|
|
storage.remove('wrongList_subject4') |
|
|
|
|
storage.remove('rightList_subject1') |
|
|
|
|
storage.remove('rightList_subject4') |
|
|
|
|
this.getAllQuestion() |
|
|
|
|
this.currentIndex_subject1 = 0; |
|
|
|
|
this.currentIndex_subject4 = 0; |
|
|
|
|
this.curSubject = 0; |
|
|
|
|
storage.remove('curSubject'); |
|
|
|
|
storage.remove('wrongList_subject1'); |
|
|
|
|
storage.remove('wrongList_subject4'); |
|
|
|
|
storage.remove('rightList_subject1'); |
|
|
|
|
storage.remove('rightList_subject4'); |
|
|
|
|
// this.getAllQuestion()
|
|
|
|
|
}, |
|
|
|
|
getAllQuestion() { |
|
|
|
|
this.currentCartype = storage.get('carType') || '1001' |
|
|
|
|
this.currentCartype = storage.get('carType') || '1001'; |
|
|
|
|
getVersion(this.currentCartype).then(resp => { |
|
|
|
|
if (resp.code === '0000') { |
|
|
|
|
querySysConfig(this.currentCartype, 'QuestionBank').then(res => { |
|
|
|
|
const urlList = JSON.parse(res.data.configJson) |
|
|
|
|
const urlOne = urlList.find(item => item.subject == '1').url |
|
|
|
|
const urlFour = urlList.find(item => item.subject == '4').url |
|
|
|
|
const urlList = JSON.parse(res.data.configJson); |
|
|
|
|
const urlOne = urlList.find(item => item.subject == '1').url; |
|
|
|
|
const urlFour = urlList.find(item => item.subject == '4').url; |
|
|
|
|
if (this.version != resp.data) { |
|
|
|
|
this.version = resp.data |
|
|
|
|
storage.set('version', resp.data) |
|
|
|
|
this.getOrderQuestion_sub1(true, urlOne) |
|
|
|
|
this.getOrderQuestion_sub4(true, urlFour) |
|
|
|
|
this.version = resp.data; |
|
|
|
|
storage.set('version', resp.data); |
|
|
|
|
this.getOrderQuestion_sub1(true, urlOne); |
|
|
|
|
this.getOrderQuestion_sub4(true, urlFour); |
|
|
|
|
} else { |
|
|
|
|
this.getOrderQuestion_sub1(false, urlOne) |
|
|
|
|
this.getOrderQuestion_sub4(false, urlOne) |
|
|
|
|
this.getOrderQuestion_sub1(false, urlOne); |
|
|
|
|
this.getOrderQuestion_sub4(false, urlOne); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
divideArray(array, numChunks) { |
|
|
|
|
var chunkSize = Math.ceil(array.length / numChunks); |
|
|
|
@ -69,168 +63,94 @@ const question = defineStore({ |
|
|
|
|
|
|
|
|
|
//改变当前科目
|
|
|
|
|
changeSubject(val) { |
|
|
|
|
this.curSubject = val |
|
|
|
|
storage.set('curSubject', val) |
|
|
|
|
this.curSubject = val; |
|
|
|
|
storage.set('curSubject', val); |
|
|
|
|
}, |
|
|
|
|
// 获取顺序做题科目1
|
|
|
|
|
getOrderQuestion_sub1(isUpdate, url) { |
|
|
|
|
if (isUpdate) { |
|
|
|
|
this.loading_subject1 = true |
|
|
|
|
const that = this |
|
|
|
|
uni.request({ |
|
|
|
|
url: url, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.data) { |
|
|
|
|
that.orderQuestion_subject1 = resp.data.data |
|
|
|
|
const diveList = that.divideArray(that.orderQuestion_subject1, 5) |
|
|
|
|
that.loading_subject1 = false |
|
|
|
|
uni.setStorageSync('questionOneSub1', diveList[0]) |
|
|
|
|
uni.setStorageSync('questionOneSub2', diveList[1]) |
|
|
|
|
uni.setStorageSync('questionOneSub3', diveList[2]) |
|
|
|
|
uni.setStorageSync('questionOneSub4', diveList[3]) |
|
|
|
|
uni.setStorageSync('questionOneSub5', diveList[4]) |
|
|
|
|
const falseList = storage.get('wrongList_subject1') || [] |
|
|
|
|
const trueList = storage.get('rightList_subject1') || [] |
|
|
|
|
const falseArr = [] |
|
|
|
|
const rightArr = [] |
|
|
|
|
that.orderQuestion_subject1.forEach(item => { |
|
|
|
|
if (falseList.includes(item.questionId)) { |
|
|
|
|
falseArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
if (trueList.includes(item.questionId)) { |
|
|
|
|
rightArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
storage.set('wrongList_subject1', falseArr) |
|
|
|
|
storage.set('rightList_subject1', rightArr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
this.loading_subject1 = true; |
|
|
|
|
this.loadAllQuestion(url, 1); |
|
|
|
|
} else { |
|
|
|
|
const list1 = uni.getStorageSync('questionOneSub1') || [] |
|
|
|
|
const list2 = uni.getStorageSync('questionOneSub2') || [] |
|
|
|
|
const list3 = uni.getStorageSync('questionOneSub3') || [] |
|
|
|
|
const list4 = uni.getStorageSync('questionOneSub4') || [] |
|
|
|
|
const list5 = uni.getStorageSync('questionOneSub5') || [] |
|
|
|
|
this.orderQuestion_subject1 = [...list1, ...list2, ...list3, ...list4, ...list5] |
|
|
|
|
this.orderQuestion_subject4 = []; |
|
|
|
|
for (let i = 0; i < JSON_SPLIT_LENGTH; i++) { |
|
|
|
|
const arr = uni.getStorageSync(`question4Sub${i + 1}`) || []; |
|
|
|
|
this.orderQuestion_subject4 = [...this.orderQuestion_subject4, ...arr]; |
|
|
|
|
} |
|
|
|
|
if (this.orderQuestion_subject1 && this.orderQuestion_subject1.length) { |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this.loading_subject1 = true |
|
|
|
|
const that = this |
|
|
|
|
uni.request({ |
|
|
|
|
url: url, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.data) { |
|
|
|
|
that.orderQuestion_subject1 = resp.data.data |
|
|
|
|
const diveList = that.divideArray(that.orderQuestion_subject1, 5) |
|
|
|
|
that.loading_subject1 = false |
|
|
|
|
uni.setStorageSync('questionOneSub1', diveList[0]) |
|
|
|
|
uni.setStorageSync('questionOneSub2', diveList[1]) |
|
|
|
|
uni.setStorageSync('questionOneSub3', diveList[2]) |
|
|
|
|
uni.setStorageSync('questionOneSub4', diveList[3]) |
|
|
|
|
uni.setStorageSync('questionOneSub5', diveList[4]) |
|
|
|
|
const falseList = storage.get('wrongList_subject1') || [] |
|
|
|
|
const trueList = storage.get('rightList_subject1') || [] |
|
|
|
|
const falseArr = [] |
|
|
|
|
const rightArr = [] |
|
|
|
|
that.orderQuestion_subject1.forEach(item => { |
|
|
|
|
if (falseList.includes(item.questionId)) { |
|
|
|
|
falseArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
if (trueList.includes(item.questionId)) { |
|
|
|
|
rightArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
storage.set('wrongList_subject1', falseArr) |
|
|
|
|
storage.set('rightList_subject1', rightArr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
this.loading_subject1 = true; |
|
|
|
|
this.loadAllQuestion(url, 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 获取顺序做题科目4
|
|
|
|
|
getOrderQuestion_sub4(isUpdate, url) { |
|
|
|
|
if (isUpdate) { |
|
|
|
|
this.loading_subject4 = true |
|
|
|
|
const that = this |
|
|
|
|
uni.request({ |
|
|
|
|
url: url, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.data) { |
|
|
|
|
that.orderQuestion_subject4 = resp.data.data |
|
|
|
|
const diveList = that.divideArray(that.orderQuestion_subject4, 5) |
|
|
|
|
that.loading_subject4 = false |
|
|
|
|
uni.setStorageSync('questionFourSub1', diveList[0]) |
|
|
|
|
uni.setStorageSync('questionFourSub2', diveList[1]) |
|
|
|
|
uni.setStorageSync('questionFourSub3', diveList[2]) |
|
|
|
|
uni.setStorageSync('questionFourSub4', diveList[3]) |
|
|
|
|
uni.setStorageSync('questionFourSub5', diveList[4]) |
|
|
|
|
const falseList = storage.get('wrongList_subject4') || [] |
|
|
|
|
const trueList = storage.get('rightList_subject4') || [] |
|
|
|
|
const falseArr = [] |
|
|
|
|
const rightArr = [] |
|
|
|
|
that.orderQuestion_subject4.forEach(item => { |
|
|
|
|
if (falseList.includes(item.questionId)) { |
|
|
|
|
falseArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
if (trueList.includes(item.questionId)) { |
|
|
|
|
rightArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
storage.set('wrongList_subject4', falseArr) |
|
|
|
|
storage.set('rightList_subject4', rightArr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
this.loading_subject4 = true; |
|
|
|
|
this.loadAllQuestion(url, 4); |
|
|
|
|
} else { |
|
|
|
|
const list1 = uni.getStorageSync('questionFourSub1') || [] |
|
|
|
|
const list2 = uni.getStorageSync('questionFourSub2') || [] |
|
|
|
|
const list3 = uni.getStorageSync('questionFourSub3') || [] |
|
|
|
|
const list4 = uni.getStorageSync('questionFourSub4') || [] |
|
|
|
|
const list5 = uni.getStorageSync('questionFourSub5') || [] |
|
|
|
|
this.orderQuestion_subject4 = [...list1, ...list2, ...list3, ...list4, ...list5] |
|
|
|
|
this.orderQuestion_subject4 = []; |
|
|
|
|
for (let i = 0; i < JSON_SPLIT_LENGTH; i++) { |
|
|
|
|
const arr = uni.getStorageSync(`question1Sub${i + 1}`) || []; |
|
|
|
|
this.orderQuestion_subject4 = [...this.orderQuestion_subject4, ...arr]; |
|
|
|
|
} |
|
|
|
|
if (this.orderQuestion_subject4 && this.orderQuestion_subject4.length) { |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this.loading_subject4 = true |
|
|
|
|
const that = this |
|
|
|
|
this.loading_subject4 = true; |
|
|
|
|
this.loadAllQuestion(url, 4); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 加载线上题目
|
|
|
|
|
loadAllQuestion(url, course) { |
|
|
|
|
const that = this; |
|
|
|
|
uni.request({ |
|
|
|
|
url: url, |
|
|
|
|
success(resp) { |
|
|
|
|
if (resp.data) { |
|
|
|
|
that.orderQuestion_subject4 = resp.data.data |
|
|
|
|
const diveList = that.divideArray(that.orderQuestion_subject4, 5) |
|
|
|
|
that.loading_subject4 = false |
|
|
|
|
uni.setStorageSync('questionFourSub1', diveList[0]) |
|
|
|
|
uni.setStorageSync('questionFourSub2', diveList[1]) |
|
|
|
|
uni.setStorageSync('questionFourSub3', diveList[2]) |
|
|
|
|
uni.setStorageSync('questionFourSub4', diveList[3]) |
|
|
|
|
uni.setStorageSync('questionFourSub5', diveList[4]) |
|
|
|
|
const falseList = storage.get('wrongList_subject4') || [] |
|
|
|
|
const trueList = storage.get('rightList_subject4') || [] |
|
|
|
|
const falseArr = [] |
|
|
|
|
const rightArr = [] |
|
|
|
|
that.orderQuestion_subject4.forEach(item => { |
|
|
|
|
if (resp?.data) { |
|
|
|
|
try { |
|
|
|
|
for (let i = 0; i < JSON_SPLIT_LENGTH; i++) { |
|
|
|
|
storage.remove(`question${course}Sub${i + 1}`); |
|
|
|
|
} |
|
|
|
|
that[`orderQuestion_subject${course}`] = resp.data?.data || []; |
|
|
|
|
const diveList = that.divideArray(that.orderQuestion_subject4, JSON_SPLIT_LENGTH); |
|
|
|
|
that[`loading_subject${course}`] = false; |
|
|
|
|
for (let i = 0; i < JSON_SPLIT_LENGTH; i++) { |
|
|
|
|
uni.setStorageSync(`question${course}Sub${i + 1}`, diveList[i]); |
|
|
|
|
} |
|
|
|
|
const falseList = storage.get(`wrongList_subject${course}`) || []; |
|
|
|
|
const trueList = storage.get(`rightList_subject${course}`) || []; |
|
|
|
|
const falseArr = []; |
|
|
|
|
const rightArr = []; |
|
|
|
|
that[`orderQuestion_subject${course}`].forEach(item => { |
|
|
|
|
if (falseList.includes(item.questionId)) { |
|
|
|
|
falseArr.push(item.questionId) |
|
|
|
|
falseArr.push(item.questionId); |
|
|
|
|
} |
|
|
|
|
if (trueList.includes(item.questionId)) { |
|
|
|
|
rightArr.push(item.questionId) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
storage.set('wrongList_subject4', falseArr) |
|
|
|
|
storage.set('rightList_subject4', rightArr) |
|
|
|
|
rightArr.push(item.questionId); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
storage.set(`wrongList_subject${course}`, falseArr); |
|
|
|
|
storage.set(`rightList_subject${course}`, rightArr); |
|
|
|
|
} catch () { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '题库下载异常,请稍后再试', |
|
|
|
|
icon: 'none' |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '加载题目失败,请稍后再试', |
|
|
|
|
icon: 'none' |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
//获取索引
|
|
|
|
|
getCurrentIndex(index, val) { |
|
|
|
|
this[`currentIndex_subject${val}`] = index |
|
|
|
|
this[`currentIndex_subject${val}`] = index; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|