store.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { reactive } from "vue";
  2. type IUser = {
  3. username?: string;
  4. nickname?: string;
  5. /** 真实姓名 */
  6. realName?: string;
  7. tenantId?: number;
  8. /** 声部名称 */
  9. subjectId?: any;
  10. subjectNames?: string;
  11. subjectName?: string;
  12. /** 头像 */
  13. avatar?: string;
  14. memberRankSettingId?: number;
  15. id?: string | number;
  16. clientType?: "BACKEND" | "SCHOOL" | "TEACHER" | "STUDENT";
  17. phone?: string;
  18. schoolInfos?: any[];
  19. // 当前用户 绑定 的乐器
  20. instrumentId?: string;
  21. // 如果学生的声部是打击乐,打击乐可能会有多个乐器id,
  22. specialInstrumentIds?: any[];
  23. // 性别
  24. gender?: 1|0;
  25. // vip类型 VIP:会员 SVIP:SVIP,PERMANENT_SVIP:永久SVIP,NOT_VIP:不是vip
  26. vipType?: string;
  27. };
  28. type IStatus = "init" | "login" | "logout" | "error";
  29. type IPlatformType = "STUDENT" | "TEACHER" | "WEB" | "";
  30. type IPlatformApi = "/api-student" | "/api-teacher" | "/api-web" | "/api-backend" | "/edu-app" | "/cbs-app";
  31. type IProxy = "" | "/gym" | "/colexiu" | "/orchestra" | "/instrument";
  32. export interface IStoreData {
  33. platformType: IPlatformType;
  34. platformApi: IPlatformApi;
  35. proxy: IProxy;
  36. isApp: boolean;
  37. isTeacher: boolean;
  38. }
  39. export const storeData = reactive({
  40. status: "init" as IStatus,
  41. /** 用户信息 */
  42. user: {} as IUser,
  43. /** 端口 */
  44. platformType: "STUDENT" as IPlatformType,
  45. /** api地址前缀 */
  46. platformApi: "/api-student" as IPlatformApi,
  47. /** 开发模式api前缀 */
  48. proxy: "" as IProxy,
  49. /** 是否在APP中 */
  50. isApp: false,
  51. /** 是否是老师端 */
  52. isTeacher: false,
  53. });
  54. /** 初始化 */
  55. export const setStoreData = (data: IStoreData) => {
  56. Object.assign(storeData, data);
  57. };
  58. /** 设置用户信息 */
  59. export const setUserInfo = (user: IUser) => {
  60. storeData.status = "login";
  61. storeData.user = user || {};
  62. };
  63. export const setLogout = () => {
  64. storeData.status = "logout";
  65. storeData.user = {};
  66. };
  67. export const setLoginError = () => {
  68. storeData.status = "error";
  69. storeData.user = {};
  70. };