paper.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. export default {
  2. namespaced: true,
  3. state: {
  4. paperInfo: null,
  5. fromSchoolId: null, // 归属学校id // 该参数通过二维码链接获取
  6. studentId: null,
  7. studentQuestionAnserList: [],
  8. examParams: null // 缓存考试页面试题及答案参数
  9. // userFormData: null // 缓存用户信息表单参数
  10. },
  11. getters: {
  12. getStudentQuestionAnserList: state => {
  13. if (state.studentQuestionAnserList.length > 0) {
  14. return state.studentQuestionAnserList
  15. }
  16. let studentQuestionAnserList = uni.getStorageSync('studentQuestionAnserList')
  17. if (studentQuestionAnserList) {
  18. return JSON.parse(studentQuestionAnserList)
  19. }
  20. return null
  21. },
  22. getExamParams: state => {
  23. if (state.examParams) {
  24. return state.examParams
  25. }
  26. let examParams = uni.getStorageSync('examParams')
  27. if (examParams) {
  28. return JSON.parse(examParams)
  29. }
  30. return null
  31. },
  32. getPaperInfo: state => {
  33. if (state.paperInfo) {
  34. return state.paperInfo
  35. }
  36. let paperInfo = uni.getStorageSync('paperInfo')
  37. if (paperInfo) {
  38. return JSON.parse(paperInfo)
  39. }
  40. return null
  41. },
  42. getStudentId: state => {
  43. if (state.studentId) {
  44. return state.studentId
  45. }
  46. let studentId = uni.getStorageSync('studentId')
  47. if (studentId) {
  48. return parseInt(JSON.parse(studentId))
  49. }
  50. return null
  51. },
  52. getFromSchoolId: state => {
  53. if (state.fromSchoolId) {
  54. return state.fromSchoolId
  55. }
  56. let fromSchoolId = uni.getStorageSync('fromSchoolId')
  57. if (fromSchoolId) {
  58. return parseInt(JSON.parse(fromSchoolId))
  59. }
  60. return null
  61. }
  62. },
  63. mutations: {
  64. updateStudentQuestionAnserList (state, data) {
  65. state.studentQuestionAnserList = data
  66. uni.setStorage({
  67. key: 'studentQuestionAnserList',
  68. data: JSON.stringify(studentQuestionAnserList)
  69. })
  70. },
  71. updatePaperInfo (state, data) {
  72. state.paperInfo = data
  73. uni.setStorage({
  74. key: 'paperInfo',
  75. data: JSON.stringify(data)
  76. })
  77. },
  78. updateStudentId (state, data) {
  79. state.studentId = data
  80. uni.setStorage({
  81. key: 'studentId',
  82. data: JSON.stringify(data)
  83. })
  84. },
  85. updateExamParams (state, data) {
  86. state.examParams = data
  87. uni.setStorage({
  88. key: 'examParams',
  89. data: JSON.stringify(data)
  90. })
  91. },
  92. updateFromSchoolId (state, data) {
  93. state.fromSchoolId = data
  94. uni.setStorage({
  95. key: 'fromSchoolId',
  96. data: JSON.stringify(data)
  97. })
  98. }
  99. }
  100. }