index.ts 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { defineStore, createPinia } from 'pinia'
  2. import { GlobalState } from './interface/index'
  3. import { User_Dept_List, User_Post_List } from '@/api/user/index'
  4. export const GlobalStore = defineStore({
  5. id: 'GlobalState',
  6. state: (): GlobalState => ({
  7. loading: false,
  8. UserDeptList: [],
  9. UserPostList: [],
  10. User_tokey: localStorage.getItem('User_tokey') || ''
  11. }),
  12. getters: {
  13. GET_User_tokey: state => state.User_tokey,
  14. GET_Dept_List: state => state.UserDeptList
  15. },
  16. actions: {
  17. SET_User_Tokey(payload: string) {
  18. if (typeof payload === 'string') {
  19. this.User_tokey = payload
  20. }
  21. },
  22. async SET_User_Dept_List() {
  23. const res: any = await User_Dept_List()
  24. this.UserDeptList = res.Data
  25. },
  26. async SET_User_Post_List() {
  27. const res = await User_Post_List()
  28. console.log(res)
  29. }
  30. }
  31. })
  32. const pinia = createPinia()
  33. export default pinia