index.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { defineStore } from "pinia";
  2. import router from "@/router";
  3. interface RecogFillSetType {
  4. fillColor: string;
  5. fillShow: boolean;
  6. unfillColor: string;
  7. unfillShow: boolean;
  8. borderWidth: number;
  9. }
  10. export const useUserStore = defineStore<
  11. "user",
  12. {
  13. curExam: Exam | null;
  14. imageCheckLoopTime: number;
  15. userInfo: any;
  16. recogFillSet: RecogFillSetType;
  17. },
  18. any,
  19. any
  20. >("user", {
  21. persist: [
  22. {
  23. storage: sessionStorage,
  24. paths: ["userInfo"],
  25. },
  26. {
  27. storage: localStorage,
  28. paths: ["curExam", "imageCheckLoopTime", "recogFillSet"],
  29. },
  30. ],
  31. state: () => ({
  32. userInfo: null,
  33. curExam: null,
  34. imageCheckLoopTime: 0,
  35. recogFillSet: {
  36. fillColor: "#f53f3f ",
  37. fillShow: true,
  38. unfillColor: "#165DFF",
  39. unfillShow: false,
  40. borderWidth: 2,
  41. },
  42. }),
  43. actions: {
  44. setUserInfo(info: any) {
  45. this.userInfo = info;
  46. },
  47. setCurExam(exam: Exam) {
  48. this.curExam = exam;
  49. },
  50. setImageCheckLoopTime(imageCheckLoopTime: number) {
  51. this.imageCheckLoopTime = imageCheckLoopTime;
  52. },
  53. setRecogFillSet(recogFillSet: RecogFillSetType) {
  54. this.recogFillSet = recogFillSet;
  55. },
  56. setState(data: any) {
  57. this.$patch(data);
  58. },
  59. resetUserInfo() {
  60. this.$reset();
  61. },
  62. async logout() {
  63. //todo 退出登录接口
  64. // await logout();
  65. this.setUserInfo(null);
  66. router.push({ name: "Login" });
  67. window.electronApi?.changeWinSize("small");
  68. },
  69. },
  70. });