Pārlūkot izejas kodu

feat(stores): 添加权限管理模块

- 创建 permissionStore 用于管理用户权限相关数据
- 实现 getUserPermission 方法以获取用户权限信息
- 使用 Pinia、Element Plus 等技术栈进行开发
nahida 9 mēneši atpakaļ
vecāks
revīzija
9d773ca7bf
1 mainītis faili ar 41 papildinājumiem un 0 dzēšanām
  1. 41 0
      src/stores/permissionStore.ts

+ 41 - 0
src/stores/permissionStore.ts

@@ -0,0 +1,41 @@
+import { defineStore } from 'pinia'
+import { clientPost } from '@/utils/request.ts'
+import { ElMessage } from 'element-plus'
+
+interface PermissionReponse extends BaseResponse {
+  data: {
+    success: boolean
+    code: number
+    data: {
+      personName: string
+      deptName: string
+      deptId: string
+      errorCode: number
+      personCode: string
+      userName: string
+      isBusinessAtt: boolean
+      message: string
+    }
+    message: string
+  }
+}
+
+export const usePermissionStore = defineStore('permission', () => {
+  const getUserPermission = async () => {
+    const res = await clientPost<null, PermissionReponse>('/userPermissions/queryUserPermissions')
+    if (res.code !== 200) {
+      ElMessage.error(res.msg)
+      return
+    }
+    if (res.data.code !== 200) {
+      ElMessage.error(res.data.message)
+      return
+    }
+    localStorage.setItem('userInfo', JSON.stringify(res.data.data))
+    return res.data
+  }
+
+  return {
+    getUserPermission,
+  }
+})