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.
45 lines
895 B
45 lines
895 B
import { defineStore } from 'pinia'; |
|
import { store } from '/@/store'; |
|
import fetchApi from '/@/api/home'; |
|
import { ResInfoList } from '/@/api/home/model'; |
|
|
|
interface HomeState { |
|
info: Nullable<ResInfoList>; |
|
} |
|
|
|
export const useHomeStore = defineStore({ |
|
id: 'app-home', |
|
state: (): HomeState => ({ |
|
// info |
|
info: null, |
|
}), |
|
getters: { |
|
getInfo(): Nullable<ResInfoList> { |
|
return this.info || null; |
|
}, |
|
}, |
|
actions: { |
|
setInfo(info: Nullable<ResInfoList>) { |
|
this.info = info; |
|
}, |
|
resetState() { |
|
this.info = null; |
|
}, |
|
/** |
|
* @description: login |
|
*/ |
|
async fetchInfo() { |
|
const res = await fetchApi.info(); |
|
if (res) { |
|
// save token |
|
this.setInfo(res); |
|
} |
|
return res; |
|
}, |
|
}, |
|
}); |
|
|
|
// Need to be used outside the setup |
|
export function useHomeStoreWithOut() { |
|
return useHomeStore(store); |
|
}
|
|
|