Spaces:
Sleeping
Sleeping
File size: 1,668 Bytes
f0953a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import { defineStore } from "pinia";
import type {
UserSettingStore,
GlobalSettingAttributes,
UserSettingAttributes,
} from "@/types/user";
import { settingApi } from "@/api/setting";
import { ElMessage } from "element-plus";
export const useUserSettingStore = defineStore("user", {
state: (): UserSettingStore => ({
globalSetting: null,
userSettings: {
cloud115Cookie: "",
quarkCookie: "",
},
displayStyle: (localStorage.getItem("display_style") as "table" | "card") || "card",
imagesSource: (localStorage.getItem("images_source") as "proxy" | "local") || "proxy",
}),
actions: {
async getSettings() {
const { data } = await settingApi.getSetting();
if (data) {
this.globalSetting = data.globalSetting;
this.userSettings = data.userSettings;
}
},
async saveSettings(settings: {
globalSetting?: GlobalSettingAttributes | null;
userSettings: UserSettingAttributes;
}) {
try {
await settingApi.saveSetting(settings);
await this.getSettings();
} catch (error) {
console.log(error);
throw error;
}
},
setDisplayStyle(style: "table" | "card") {
this.displayStyle = style;
localStorage.setItem("display_style", style);
ElMessage.success(`切换成功,当前为${style === "table" ? "列表" : "卡片"}模式`);
},
setImagesSource(source: "proxy" | "local") {
this.imagesSource = source;
localStorage.setItem("images_source", source);
ElMessage.success(`切换成功,图片模式当前为${source === "proxy" ? "代理" : "直连"}模式`);
},
},
});
|