permissionStore.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { defineStore } from 'pinia'
  2. import { clientPost } from '@/utils/request.ts'
  3. import { ElMessage } from 'element-plus'
  4. interface PermissionReponse extends BaseResponse {
  5. data: {
  6. personName: string
  7. deptName: string
  8. deptId: string
  9. errorCode: number
  10. personCode: string
  11. userName: string
  12. isBusinessAtt: boolean
  13. message: string
  14. }
  15. }
  16. export const usePermissionStore = defineStore('permission', () => {
  17. const search = window.location.search // 获取"?appToken=xxx&appId=xxx"
  18. const params = new URLSearchParams(search)
  19. const getUserPermission = async () => {
  20. // if (!params.get('appId') || !params.get('appToken')) {
  21. // return
  22. // }
  23. const res = await clientPost<null, PermissionReponse>(
  24. '/userPermissions/queryUserPermissions',
  25. null,
  26. {
  27. params: {
  28. appId: params.get('appId'),
  29. appToken: params.get('appToken'),
  30. },
  31. },
  32. )
  33. console.log(11111,res)
  34. if (res.code !== 200) {
  35. ElMessage.error(res.msg)
  36. return
  37. }
  38. if (res.data.errorCode !== 2000) {
  39. ElMessage.error(res.data.message)
  40. return
  41. }
  42. localStorage.setItem('userInfo', JSON.stringify(res.data))
  43. return res.data
  44. }
  45. return {
  46. getUserPermission,
  47. }
  48. })