You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
59 lines
1.4 KiB
|
|
|
|
import {defineStore} from 'pinia';
|
|
import carStore from './car.js'
|
|
import { deleteWrongOrCol } from '@/config/api.js'
|
|
|
|
let carObj = carStore()
|
|
|
|
|
|
const questionStore = defineStore(
|
|
'wrong',
|
|
{
|
|
state: () => ({
|
|
wrongList: [],
|
|
frequency: uni.getStorageSync('frequency')?uni.getStorageSync('frequency'):0
|
|
}),
|
|
actions: {
|
|
setFrequency(value) {
|
|
uni.setStorageSync('frequency', value)
|
|
this.frequency = value
|
|
},
|
|
setList(value) {
|
|
// 类型只选一个
|
|
let obj = {num: 0, id: value, }
|
|
let index = this.wrongList.findIndex(item=>item.id==value)
|
|
if(index!=-1) {
|
|
this.wrongList.splice(index, 1)
|
|
}
|
|
this.wrongList.push(obj)
|
|
},
|
|
// 查看在不在错题里
|
|
lookList(value) {
|
|
let index = this.wrongList.findIndex(item=>item.id==value)
|
|
if(index!=-1) {
|
|
let item = this.wrongList[index]
|
|
console.log('找到之前的错题了')
|
|
item.num = item.num + 1
|
|
if(this.frequency&&item.num>=this.frequency ) {
|
|
// 删除题
|
|
this.deleteWrongOrColFn(value)
|
|
this.wrongList.splice(index, 1)
|
|
}
|
|
}
|
|
},
|
|
async deleteWrongOrColFn(value) {
|
|
let index = this.wrongList.findIndex(item=>item.id==value)
|
|
if(index!=-1) this.wrongList.splice(index, 1)
|
|
let obj = {
|
|
"carType": carObj.carInfo.carType,
|
|
"questionId": value,
|
|
"stepType": carObj.carInfo.stepType,
|
|
"type": 1
|
|
}
|
|
await deleteWrongOrCol(obj)
|
|
}
|
|
}
|
|
})
|
|
|
|
export default questionStore
|