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

2 weeks ago
  1. import {defineStore} from 'pinia';
  2. import carStore from './car.js'
  3. import { deleteWrongOrCol } from '@/config/api.js'
  4. let carObj = carStore()
  5. const questionStore = defineStore(
  6. 'wrong',
  7. {
  8. state: () => ({
  9. wrongList: [],
  10. frequency: uni.getStorageSync('frequency')?uni.getStorageSync('frequency'):0
  11. }),
  12. actions: {
  13. setFrequency(value) {
  14. uni.setStorageSync('frequency', value)
  15. this.frequency = value
  16. },
  17. setList(value) {
  18. // 类型只选一个
  19. let obj = {num: 0, id: value, }
  20. let index = this.wrongList.findIndex(item=>item.id==value)
  21. if(index!=-1) {
  22. this.wrongList.splice(index, 1)
  23. }
  24. this.wrongList.push(obj)
  25. },
  26. // 查看在不在错题里
  27. lookList(value) {
  28. let index = this.wrongList.findIndex(item=>item.id==value)
  29. if(index!=-1) {
  30. let item = this.wrongList[index]
  31. console.log('找到之前的错题了')
  32. item.num = item.num + 1
  33. if(this.frequency&&item.num>=this.frequency ) {
  34. // 删除题
  35. this.deleteWrongOrColFn(value)
  36. this.wrongList.splice(index, 1)
  37. }
  38. }
  39. },
  40. async deleteWrongOrColFn(value) {
  41. let index = this.wrongList.findIndex(item=>item.id==value)
  42. if(index!=-1) this.wrongList.splice(index, 1)
  43. let obj = {
  44. "carType": carObj.carInfo.carType,
  45. "questionId": value,
  46. "stepType": carObj.carInfo.stepType,
  47. "type": 1
  48. }
  49. await deleteWrongOrCol(obj)
  50. }
  51. }
  52. })
  53. export default questionStore