permissionStore.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 // 获取"?=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. // appId: '0bc14fd11d27ac047f1a15114314367d',
  31. // appToken: 'b87ed71f0594243c44bb6b85a190eebd4c32e06a6c540b06ac5974babef32a0e51a4dedeba15a92ab9b1bf97adeda823',
  32. },
  33. },
  34. )
  35. // console.log(11111,res)
  36. if (res.code !== 200) {
  37. ElMessage.error(res.msg)
  38. return
  39. }
  40. if (res.data.errorCode !== 2000) {
  41. ElMessage.error(res.data.message)
  42. return
  43. }
  44. localStorage.setItem('userInfo', JSON.stringify(res.data))
  45. return res.data
  46. }
  47. return {
  48. getUserPermission,
  49. }
  50. })