systemStore.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { defineStore } from "pinia";
  2. import { getSTSInfo } from "@/api/path/system.api";
  3. export const useSystemStore = defineStore("useSystemStore", {
  4. state: () => ({
  5. local_loading: false,
  6. routeSate: "",
  7. token: "",
  8. ISCREATE: false,
  9. stsClientInfo: {},
  10. Administrator: {},
  11. DAPP_CACHE_KEY:[],
  12. AddressList:[],
  13. DeviceId:'',
  14. USERID:"",
  15. ImsessionList:[],
  16. needRefreshIm:false,
  17. userUuid:'',
  18. messageList: {},//消息缓存
  19. // FirendList:[]
  20. }),
  21. persist: true,
  22. getters: {
  23. getLocalLoading() {
  24. return this.local_loading;
  25. },
  26. getToken() {
  27. if (this.token) return this.token;
  28. this.token = window.localStorage?.token || "";
  29. return this.token;
  30. },
  31. // getSTSClient() {
  32. // const stsFn = async () => {
  33. // const windowVar = window;
  34. // let longTime = 0;
  35. // if (
  36. // windowVar.stsOSSClient &&
  37. // windowVar.stsOSSClient.stsTokenFreshTime
  38. // ) {
  39. // const oldTime = windowVar.stsOSSClient.stsTokenFreshTime.getTime();
  40. // const newTime = new Date().getTime();
  41. // longTime = newTime - oldTime;
  42. // }
  43. // // STS信息
  44. // if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
  45. // const res = await getSTSInfo({});
  46. // const info = res.data;
  47. // const systemStore = useSystemStore();
  48. // const getInfoData = (info) => {
  49. // const infoData = {
  50. // endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
  51. // region: "oss-cn-hongkong",
  52. // accessKeyId: info.AccessKeyId,
  53. // accessKeySecret: info.AccessKeySecret,
  54. // stsToken: info.SecurityToken,
  55. // bucket: "flexi",
  56. // cname: true,
  57. // };
  58. // this.stsClientInfo = infoData;
  59. // systemStore.setStateValue("stsClientInfo", infoData);
  60. // return infoData;
  61. // };
  62. // getInfoData(info);
  63. // const client = new windowVar.OSS({
  64. // ...this.stsClientInfo,
  65. // refreshSTSToken: async () => {
  66. // const res = await getSTSInfo({});
  67. // getInfoData(res.data);
  68. // return {
  69. // accessKeyId: info.AccessKeyId,
  70. // accessKeySecret: info.AccessKeySecret,
  71. // stsToken: info.SecurityToken,
  72. // };
  73. // },
  74. // refreshSTSTokenInterval: 30 * 60 * 1000,
  75. // });
  76. // client.putObject = async (data) => {
  77. // const putRes = await client.put(data.key, data.body);
  78. // putRes.statusCode = 200;
  79. // return putRes;
  80. // };
  81. // windowVar.stsOSSClient = client;
  82. // return client;
  83. // }
  84. // return windowVar.stsOSSClient;
  85. // };
  86. // return stsFn;
  87. // },
  88. },
  89. actions: {
  90. localLoading(value = false) {
  91. this.local_loading = value;
  92. },
  93. // 储存
  94. // setStateValue(res) {
  95. // this[res.key] = res.value;
  96. // const value =
  97. // typeof res.value === "string" ? res.value : JSON.stringify(res.value);
  98. // if (res.localStorage) {
  99. // // 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
  100. // window.localStorage.setItem(res.key, value);
  101. // }
  102. // },
  103. },
  104. });