This commit is contained in:
2026-05-28 02:20:24 +08:00
parent 031c8c1cc7
commit 248aa0854a
8 changed files with 224 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
import { defineStore } from "pinia";
import api from "@/api";
import type { IHelperInfo } from "@/api/info/type";
export const useDnfHelperStore = defineStore("dnfHelperStore", () => {
const helperInfo = useLocalStorage<IHelperInfo | null>("dnfHelperInfo", null, {
serializer: {
read: (v) => (v ? JSON.parse(v) : null),
write: (v) => JSON.stringify(v),
},
});
const loading = ref(false);
const errorMessage = ref("");
const refleshHelperInfo = async (uid?: string) => {
if (!uid) return;
loading.value = true;
errorMessage.value = "";
try {
const data = await api.getHelperList(uid);
if (data) {
helperInfo.value = data;
}
} catch (error) {
errorMessage.value = error instanceof Error ? error.message : "同步助手数据失败";
throw error;
} finally {
loading.value = false;
}
};
const refreshHelperInfo = async (uid?: string) => {
await refleshHelperInfo(uid);
};
const logout = () => {
helperInfo.value = null;
errorMessage.value = "";
};
return {
helperInfo,
loading,
errorMessage,
refleshHelperInfo,
refreshHelperInfo,
logout,
};
});