ev
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user