|
@@ -1,17 +1,18 @@
|
|
|
import { defineStore } from "pinia";
|
|
|
import { getSTSInfo } from "@/api/path/system.api";
|
|
|
-import { setLocalStorage, getLocalStorage } from "@/utils";
|
|
|
|
|
|
export const useSystemStore = defineStore("useSystemStore", {
|
|
|
state: () => ({
|
|
|
local_loading: false,
|
|
|
routeSate: "",
|
|
|
- user_login_information: "",
|
|
|
- token: getLocalStorage("token") || "",
|
|
|
+ avatar: "",
|
|
|
+ nickname: "",
|
|
|
+ token: "",
|
|
|
+ ISCREATE: false,
|
|
|
stsClientInfo: {},
|
|
|
- Administrator:{}
|
|
|
+ Administrator: {},
|
|
|
}),
|
|
|
- persist: ["stsClientInfo"],
|
|
|
+ persist: true,
|
|
|
getters: {
|
|
|
getLocalLoading() {
|
|
|
return this.local_loading;
|
|
@@ -21,91 +22,83 @@ export const useSystemStore = defineStore("useSystemStore", {
|
|
|
this.token = window.localStorage?.token || "";
|
|
|
return this.token;
|
|
|
},
|
|
|
- getRouteSate() {
|
|
|
- return this.routeSate || getLocalStorage("routeSate");
|
|
|
- },
|
|
|
- getSTSClient() {
|
|
|
- const stsFn = async () => {
|
|
|
- const windowVar = window;
|
|
|
- let longTime = 0;
|
|
|
- if (
|
|
|
- windowVar.stsOSSClient &&
|
|
|
- windowVar.stsOSSClient.stsTokenFreshTime
|
|
|
- ) {
|
|
|
- const oldTime = windowVar.stsOSSClient.stsTokenFreshTime.getTime();
|
|
|
- const newTime = new Date().getTime();
|
|
|
- longTime = newTime - oldTime;
|
|
|
- }
|
|
|
|
|
|
- // STS信息
|
|
|
- if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
|
|
|
- const res = await getSTSInfo({});
|
|
|
+ // getSTSClient() {
|
|
|
+ // const stsFn = async () => {
|
|
|
+ // const windowVar = window;
|
|
|
+ // let longTime = 0;
|
|
|
+ // if (
|
|
|
+ // windowVar.stsOSSClient &&
|
|
|
+ // windowVar.stsOSSClient.stsTokenFreshTime
|
|
|
+ // ) {
|
|
|
+ // const oldTime = windowVar.stsOSSClient.stsTokenFreshTime.getTime();
|
|
|
+ // const newTime = new Date().getTime();
|
|
|
+ // longTime = newTime - oldTime;
|
|
|
+ // }
|
|
|
|
|
|
- const info = res.data;
|
|
|
- const systemStore = useSystemStore();
|
|
|
- const getInfoData = (info) => {
|
|
|
- const infoData = {
|
|
|
- endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
|
|
|
- region: "oss-cn-hongkong",
|
|
|
- accessKeyId: info.AccessKeyId,
|
|
|
- accessKeySecret: info.AccessKeySecret,
|
|
|
- stsToken: info.SecurityToken,
|
|
|
- bucket: "flexi",
|
|
|
- cname: true,
|
|
|
- };
|
|
|
- this.stsClientInfo = infoData;
|
|
|
- systemStore.setStateValue("stsClientInfo", infoData);
|
|
|
- return infoData;
|
|
|
- };
|
|
|
- getInfoData(info);
|
|
|
+ // // STS信息
|
|
|
+ // if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
|
|
|
+ // const res = await getSTSInfo({});
|
|
|
|
|
|
- const client = new windowVar.OSS({
|
|
|
- ...this.stsClientInfo,
|
|
|
- refreshSTSToken: async () => {
|
|
|
- const res = await getSTSInfo({});
|
|
|
- getInfoData(res.data);
|
|
|
- return {
|
|
|
- accessKeyId: info.AccessKeyId,
|
|
|
- accessKeySecret: info.AccessKeySecret,
|
|
|
- stsToken: info.SecurityToken,
|
|
|
- };
|
|
|
- },
|
|
|
- refreshSTSTokenInterval: 30 * 60 * 1000,
|
|
|
- });
|
|
|
+ // const info = res.data;
|
|
|
+ // const systemStore = useSystemStore();
|
|
|
+ // const getInfoData = (info) => {
|
|
|
+ // const infoData = {
|
|
|
+ // endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
|
|
|
+ // region: "oss-cn-hongkong",
|
|
|
+ // accessKeyId: info.AccessKeyId,
|
|
|
+ // accessKeySecret: info.AccessKeySecret,
|
|
|
+ // stsToken: info.SecurityToken,
|
|
|
+ // bucket: "flexi",
|
|
|
+ // cname: true,
|
|
|
+ // };
|
|
|
+ // this.stsClientInfo = infoData;
|
|
|
+ // systemStore.setStateValue("stsClientInfo", infoData);
|
|
|
+ // return infoData;
|
|
|
+ // };
|
|
|
+ // getInfoData(info);
|
|
|
|
|
|
- client.putObject = async (data) => {
|
|
|
- const putRes = await client.put(data.key, data.body);
|
|
|
- putRes.statusCode = 200;
|
|
|
- return putRes;
|
|
|
- };
|
|
|
- windowVar.stsOSSClient = client;
|
|
|
+ // const client = new windowVar.OSS({
|
|
|
+ // ...this.stsClientInfo,
|
|
|
+ // refreshSTSToken: async () => {
|
|
|
+ // const res = await getSTSInfo({});
|
|
|
+ // getInfoData(res.data);
|
|
|
+ // return {
|
|
|
+ // accessKeyId: info.AccessKeyId,
|
|
|
+ // accessKeySecret: info.AccessKeySecret,
|
|
|
+ // stsToken: info.SecurityToken,
|
|
|
+ // };
|
|
|
+ // },
|
|
|
+ // refreshSTSTokenInterval: 30 * 60 * 1000,
|
|
|
+ // });
|
|
|
|
|
|
- return client;
|
|
|
- }
|
|
|
- return windowVar.stsOSSClient;
|
|
|
- };
|
|
|
- return stsFn;
|
|
|
- },
|
|
|
- getISCREATE() {
|
|
|
- return this.ISCREATE || getLocalStorage("ISCREATE");
|
|
|
- },
|
|
|
- getUserInfo() {
|
|
|
- return this.user_login_information || getLocalStorage("user_login_information");
|
|
|
- },
|
|
|
+ // client.putObject = async (data) => {
|
|
|
+ // const putRes = await client.put(data.key, data.body);
|
|
|
+ // putRes.statusCode = 200;
|
|
|
+ // return putRes;
|
|
|
+ // };
|
|
|
+ // windowVar.stsOSSClient = client;
|
|
|
+
|
|
|
+ // return client;
|
|
|
+ // }
|
|
|
+ // return windowVar.stsOSSClient;
|
|
|
+ // };
|
|
|
+ // return stsFn;
|
|
|
+ // },
|
|
|
},
|
|
|
actions: {
|
|
|
localLoading(value = false) {
|
|
|
this.local_loading = value;
|
|
|
},
|
|
|
// 储存
|
|
|
- setStateValue(res) {
|
|
|
- this[res.key] = res.value;
|
|
|
- const value =
|
|
|
- typeof res.value === "string" ? res.value : JSON.stringify(res.value);
|
|
|
- if (res.localStorage) {
|
|
|
- // 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
|
|
|
- window.localStorage.setItem(res.key, value);
|
|
|
- }
|
|
|
- },
|
|
|
+ // setStateValue(res) {
|
|
|
+ // this[res.key] = res.value;
|
|
|
+ // const value =
|
|
|
+ // typeof res.value === "string" ? res.value : JSON.stringify(res.value);
|
|
|
+ // if (res.localStorage) {
|
|
|
+ // // 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
|
|
|
+ // window.localStorage.setItem(res.key, value);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
},
|
|
|
});
|