|
@@ -4,20 +4,22 @@ import { setLocalStorage, getLocalStorage } from "@/utils";
|
|
|
|
|
|
const INITIALIZE = {
|
|
const INITIALIZE = {
|
|
local_loading: false,
|
|
local_loading: false,
|
|
- layout: "menu",
|
|
|
|
- menus: "",
|
|
|
|
routeSate: "",
|
|
routeSate: "",
|
|
user_login_information: "",
|
|
user_login_information: "",
|
|
stsClientInfo: {},
|
|
stsClientInfo: {},
|
|
|
|
+ wallet: {
|
|
|
|
+ address: "",
|
|
|
|
+ privateKey: "",
|
|
|
|
+ },
|
|
};
|
|
};
|
|
try {
|
|
try {
|
|
- const SYSTEM_STORE = getLocalStorage("SYSTEM_STORE")
|
|
|
|
|
|
+ const SYSTEM_STORE = getLocalStorage("SYSTEM_STORE");
|
|
for (const key in SYSTEM_STORE) {
|
|
for (const key in SYSTEM_STORE) {
|
|
- const value = getLocalStorage(key)
|
|
|
|
- if (value) INITIALIZE[key] = value
|
|
|
|
|
|
+ const value = getLocalStorage(key);
|
|
|
|
+ if (value) INITIALIZE[key] = value;
|
|
}
|
|
}
|
|
} catch (err) {
|
|
} catch (err) {
|
|
- window.console.log('无存储数据', err)
|
|
|
|
|
|
+ window.console.log("无存储数据", err);
|
|
}
|
|
}
|
|
|
|
|
|
export const useSystemStore = defineStore("useSystemStore", {
|
|
export const useSystemStore = defineStore("useSystemStore", {
|
|
@@ -26,87 +28,87 @@ export const useSystemStore = defineStore("useSystemStore", {
|
|
}),
|
|
}),
|
|
getters: {
|
|
getters: {
|
|
getLocalLoading() {
|
|
getLocalLoading() {
|
|
- return this.local_loading
|
|
|
|
|
|
+ return this.local_loading;
|
|
},
|
|
},
|
|
getToken() {
|
|
getToken() {
|
|
if (this.token) return this.token;
|
|
if (this.token) return this.token;
|
|
this.token = window.localStorage?.token || "";
|
|
this.token = window.localStorage?.token || "";
|
|
return this.token;
|
|
return this.token;
|
|
},
|
|
},
|
|
- getLayout() {
|
|
|
|
- return this.layout;
|
|
|
|
|
|
+ getWallet() {
|
|
|
|
+ if (this.wallet.address) return this.wallet;
|
|
|
|
+ this.wallet = window.localStorage?.wallet || "";
|
|
|
|
+ return this.wallet;
|
|
},
|
|
},
|
|
getRouteSate() {
|
|
getRouteSate() {
|
|
- return this.routeSate || getLocalStorage("routeSate")
|
|
|
|
- },
|
|
|
|
- getMenus() {
|
|
|
|
- if (this.menus) return this.menus;
|
|
|
|
- this.menus = window.localStorage?.menus || "";
|
|
|
|
- return this.menus;
|
|
|
|
|
|
+ return this.routeSate || getLocalStorage("routeSate");
|
|
},
|
|
},
|
|
getSTSClient() {
|
|
getSTSClient() {
|
|
const stsFn = async () => {
|
|
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 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信息
|
|
// STS信息
|
|
if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
|
|
if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
|
|
- const res = await getSTSInfo({})
|
|
|
|
|
|
+ const res = await getSTSInfo({});
|
|
|
|
|
|
- const info = res.data
|
|
|
|
- const systemStore = useSystemStore()
|
|
|
|
- const getInfoData = info => {
|
|
|
|
|
|
+ const info = res.data;
|
|
|
|
+ const systemStore = useSystemStore();
|
|
|
|
+ const getInfoData = (info) => {
|
|
const infoData = {
|
|
const infoData = {
|
|
- endpoint: 'https://flexi.oss-cn-hongkong.aliyuncs.com',
|
|
|
|
- region: 'oss-cn-hongkong',
|
|
|
|
|
|
+ endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
|
|
|
|
+ region: "oss-cn-hongkong",
|
|
accessKeyId: info.AccessKeyId,
|
|
accessKeyId: info.AccessKeyId,
|
|
accessKeySecret: info.AccessKeySecret,
|
|
accessKeySecret: info.AccessKeySecret,
|
|
stsToken: info.SecurityToken,
|
|
stsToken: info.SecurityToken,
|
|
- bucket: 'flexi',
|
|
|
|
- cname: true
|
|
|
|
- }
|
|
|
|
- this.stsClientInfo = infoData
|
|
|
|
- systemStore.setStateValue('stsClientInfo', infoData)
|
|
|
|
- return infoData
|
|
|
|
- }
|
|
|
|
- getInfoData(info)
|
|
|
|
|
|
+ bucket: "flexi",
|
|
|
|
+ cname: true,
|
|
|
|
+ };
|
|
|
|
+ this.stsClientInfo = infoData;
|
|
|
|
+ systemStore.setStateValue("stsClientInfo", infoData);
|
|
|
|
+ return infoData;
|
|
|
|
+ };
|
|
|
|
+ getInfoData(info);
|
|
|
|
|
|
const client = new windowVar.OSS({
|
|
const client = new windowVar.OSS({
|
|
...this.stsClientInfo,
|
|
...this.stsClientInfo,
|
|
refreshSTSToken: async () => {
|
|
refreshSTSToken: async () => {
|
|
- const res = await getSTSInfo({})
|
|
|
|
- getInfoData(res.data)
|
|
|
|
|
|
+ const res = await getSTSInfo({});
|
|
|
|
+ getInfoData(res.data);
|
|
return {
|
|
return {
|
|
accessKeyId: info.AccessKeyId,
|
|
accessKeyId: info.AccessKeyId,
|
|
accessKeySecret: info.AccessKeySecret,
|
|
accessKeySecret: info.AccessKeySecret,
|
|
- stsToken: info.SecurityToken
|
|
|
|
- }
|
|
|
|
|
|
+ stsToken: info.SecurityToken,
|
|
|
|
+ };
|
|
},
|
|
},
|
|
- refreshSTSTokenInterval: 30 * 60 * 1000
|
|
|
|
- })
|
|
|
|
|
|
+ refreshSTSTokenInterval: 30 * 60 * 1000,
|
|
|
|
+ });
|
|
|
|
|
|
- client.putObject = async data => {
|
|
|
|
- const putRes = await client.put(data.key, data.body)
|
|
|
|
- putRes.statusCode = 200
|
|
|
|
- return putRes
|
|
|
|
- }
|
|
|
|
- windowVar.stsOSSClient = client
|
|
|
|
|
|
+ client.putObject = async (data) => {
|
|
|
|
+ const putRes = await client.put(data.key, data.body);
|
|
|
|
+ putRes.statusCode = 200;
|
|
|
|
+ return putRes;
|
|
|
|
+ };
|
|
|
|
+ windowVar.stsOSSClient = client;
|
|
|
|
|
|
- return client
|
|
|
|
|
|
+ return client;
|
|
}
|
|
}
|
|
- return windowVar.stsOSSClient
|
|
|
|
|
|
+ return windowVar.stsOSSClient;
|
|
};
|
|
};
|
|
- return stsFn
|
|
|
|
- }
|
|
|
|
|
|
+ return stsFn;
|
|
|
|
+ },
|
|
},
|
|
},
|
|
actions: {
|
|
actions: {
|
|
localLoading(value = false) {
|
|
localLoading(value = false) {
|
|
- this.local_loading = value
|
|
|
|
|
|
+ this.local_loading = value;
|
|
},
|
|
},
|
|
// 储存
|
|
// 储存
|
|
setStateValue(res) {
|
|
setStateValue(res) {
|
|
@@ -117,6 +119,6 @@ export const useSystemStore = defineStore("useSystemStore", {
|
|
// 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
|
|
// 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
|
|
window.localStorage.setItem(res.key, value);
|
|
window.localStorage.setItem(res.key, value);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
},
|
|
},
|
|
});
|
|
});
|