You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
830 B
33 lines
830 B
import { defineStore } from "pinia";
|
|
import { ref, watch } from "vue";
|
|
import { cache } from "@/utils/cache";
|
|
|
|
export const useUserStore = defineStore("user", () => {
|
|
const userInfo = ref(cache('USERINFO_KEY') ? JSON.parse(cache('USERINFO_KEY')) : {
|
|
username: "",
|
|
});
|
|
|
|
const adressInfo = ref(cache('ADRESS_KEY') ? JSON.parse(cache('ADRESS_KEY')) : {
|
|
latitude: "",
|
|
longitude: "",
|
|
adress: "",
|
|
});
|
|
|
|
watch(userInfo, (newValue) => cache('USERINFO_KEY', newValue ? JSON.stringify(newValue) : null));
|
|
watch(adressInfo, (newValue) => cache('ADRESS_KEY', newValue ? JSON.stringify(newValue) : null));
|
|
|
|
function setUserInfo(payload) {
|
|
userInfo.value = payload;
|
|
}
|
|
function setAdressInfo(payload) {
|
|
adressInfo.value = payload;
|
|
}
|
|
|
|
return {
|
|
userInfo,
|
|
setUserInfo,
|
|
adressInfo,
|
|
setAdressInfo
|
|
};
|
|
});
|