index.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { reactive, toRefs } from 'vue';
  2. import { LoginaccountModel, MarketrunModal, SelectedAccountModel, UserAccountModel, UserInfoModel } from './initDataModel/account';
  3. import { NeedClearSourceDataType, NoClearSourceDataType } from './interface';
  4. /**
  5. * 需要清空数据中心
  6. */
  7. const needClearSourceData: NeedClearSourceDataType = {
  8. systemDate: '',
  9. externalexchange: [],
  10. goodsgroups: [], // 商品组
  11. loginAccount: new LoginaccountModel(),
  12. markets: [],
  13. systemParams: [], // 系统参数
  14. userAccount: new UserAccountModel(), // 用户账号信息
  15. userInfo: new UserInfoModel(), // 用户信息
  16. username: '',
  17. menus: [],
  18. tableHead: [],
  19. areaRoles: [],// 所属角色信息
  20. Goods: [],
  21. DeliveryGoodsList: [],
  22. marketRun: new MarketrunModal(), // 市场运行信息
  23. // checkTokenTimeDiff: Math.floor(Math.random() * 6 + 5) * 60 * 1000,
  24. checkTokenTimeDiff: 1 * 60 * 1000,
  25. accountList: [],
  26. selectedAccount: new SelectedAccountModel(),
  27. quoteDayInfo: [],
  28. RootUser: [],
  29. };
  30. /**
  31. * 不需要清空的数据
  32. */
  33. const noClearSourceData: NoClearSourceDataType = {
  34. touristToken: 'c886a057f3d820d4dbc41473686c7c2d',
  35. };
  36. class DataCenter {
  37. private data = toRefs<NeedClearSourceDataType>(reactive(Object.assign({}, needClearSourceData)));
  38. private noClearData = toRefs<NoClearSourceDataType>(reactive(Object.assign({}, noClearSourceData)));
  39. /** 重置所有数据 */
  40. public reset(): void {
  41. this.data = toRefs<NeedClearSourceDataType>(reactive(Object.assign({}, needClearSourceData)));
  42. }
  43. /** 设置键对应的值 */
  44. public setOneOf(props: keyof (NeedClearSourceDataType & NoClearSourceDataType), value: any) {
  45. if (Reflect.has(noClearSourceData, props)) {
  46. this.noClearData[props as keyof NoClearSourceDataType].value = value;
  47. } else if (Reflect.has(needClearSourceData, props)) {
  48. this.data[props as keyof NeedClearSourceDataType].value = value;
  49. }
  50. }
  51. /** 获取其中之一 */
  52. public getOneOf(props: keyof (NeedClearSourceDataType & NoClearSourceDataType)): any {
  53. if (Reflect.has(noClearSourceData, props)) {
  54. return this.noClearData[props as keyof NoClearSourceDataType];
  55. } else if (Reflect.has(needClearSourceData, props)) {
  56. return this.data[props as keyof NeedClearSourceDataType];
  57. }
  58. }
  59. /** 获取全部数据 */
  60. // public getAll() {
  61. // return this.data;
  62. // }
  63. }
  64. export default DataCenter;