Explorar el Código

feat: 用户添加角色

wanggaokun hace 3 semanas
padre
commit
ab23a35857

+ 1 - 0
.eslintrc-auto-import.json

@@ -6,6 +6,7 @@
     "DirectiveBinding": true,
     "EffectScope": true,
     "ElMessage": true,
+    "ElMessageBox": true,
     "ExtractDefaultPropTypes": true,
     "ExtractPropTypes": true,
     "ExtractPublicPropTypes": true,

+ 9 - 1
src/api/interface/system/user.ts

@@ -68,7 +68,7 @@ export interface UserBO {
  */
 export interface UserRoleBO {
   userId: string
-  roleId: string
+  roleIds: string[]
 }
 /**
  * 接收已有角色
@@ -77,3 +77,11 @@ export interface UserRoleVO {
   allRoles: RoleVO[]
   hasRoles: string[]
 }
+
+/**
+ * 传入新旧密码
+ */
+export interface PasswordBO {
+  oldPassword: string
+  password: string
+}

+ 18 - 1
src/api/module/system/user.ts

@@ -1,5 +1,5 @@
 import http from '@/axios'
-import { UserBO, UserInfo, UserQuery, UserRoleVO, UserVO } from '@/api/interface/system/user'
+import { PasswordBO, UserBO, UserInfo, UserQuery, UserRoleBO, UserRoleVO, UserVO } from '@/api/interface/system/user'
 
 class UserApi {
   static getInfo = (): Promise<ResultData<any>> => {
@@ -38,6 +38,14 @@ class UserApi {
     return http.put({ url: '/system/user/edit', data })
   }
 
+  /**
+   * @name 修改密码
+   * @returns returns
+   */
+  static modifyPassword = (data: PasswordBO): Promise<ResultData<any>> => {
+    return http.put({ url: '/system/user/password/modify', data })
+  }
+
   /**
    * @name 重置密码
    * @returns returns
@@ -53,6 +61,7 @@ class UserApi {
   static delete = (data: string[]): Promise<ResultData<any>> => {
     return http.delete({ url: '/system/user/delete', data })
   }
+
   /**
    * @name 查询已有角色
    * @returns returns
@@ -60,5 +69,13 @@ class UserApi {
   static getRole = (params: string): Promise<ResultData<any>> => {
     return http.get<UserRoleVO>({ url: `/system/user/role/${params}` })
   }
+
+  /**
+   * @name 用户添加角色
+   * @returns returns
+   */
+  static addRole = (data: UserRoleBO): Promise<ResultData<any>> => {
+    return http.put<UserRoleVO>({ url: `/system/user/role/add`, data })
+  }
 }
 export default UserApi

+ 3 - 1
src/axios/config.ts

@@ -28,7 +28,9 @@ const defaultResponseInterceptors = (response: AxiosResponse) => {
   } else if (code === ResultEnum.OVERDUE) {
     userStore.clear()
     authStore.clear()
-    router.replace(LOGIN_URL)
+    if (router.currentRoute.value.path !== LOGIN_URL) {
+      router.replace(LOGIN_URL)
+    }
     ElMessage.warning('认证失效,请重新登录!')
   } else {
     console.error(msg)

+ 3 - 0
src/types/auto-components.d.ts

@@ -19,6 +19,7 @@ declare module 'vue' {
     AppTransverse: typeof import('./../layouts/container/AppTransverse/index.vue')['default']
     ColSetting: typeof import('./../components/ProTable/ColSetting.vue')['default']
     ConfigDrawer: typeof import('./../views/system/config/components/ConfigDrawer.vue')['default']
+    copy: typeof import('./../views/system/user/components/AddRoleDialog copy.vue')['default']
     DictDrawer: typeof import('./../views/system/dict/components/DictDrawer.vue')['default']
     EcoDialog: typeof import('./../components/EcoDialog/index.vue')['default']
     EcoDialogForm: typeof import('./../components/EcoDialogForm/index.vue')['default']
@@ -75,6 +76,8 @@ declare module 'vue' {
     LoginForm: typeof import('./../views/login/components/LoginForm.vue')['default']
     MenuDrawer: typeof import('./../views/system/menu/components/MenuDrawer.vue')['default']
     MenuItem: typeof import('./../layouts/components/AppMenu/MenuItem.vue')['default']
+    ModifyPassword: typeof import('./../views/system/user/components/ModifyPassword.vue')['default']
+    ModifyPasswordDialog: typeof import('./../views/system/user/components/ModifyPasswordDialog.vue')['default']
     MoreButton: typeof import('./../layouts/components/AppTabs/MoreButton.vue')['default']
     OrgDrawer: typeof import('./../views/system/org/components/OrgDrawer.vue')['default']
     OrgForm: typeof import('./../views/system/org/components/orgForm.vue')['default']

+ 1 - 0
src/types/auto-imports.d.ts

@@ -339,6 +339,7 @@ declare module 'vue' {
   interface ComponentCustomProperties {
     readonly EffectScope: UnwrapRef<(typeof import('vue'))['EffectScope']>
     readonly ElMessage: UnwrapRef<(typeof import('element-plus/es'))['ElMessage']>
+    readonly ElMessageBox: UnwrapRef<(typeof import('element-plus/es'))['ElMessageBox']>
     readonly acceptHMRUpdate: UnwrapRef<(typeof import('pinia'))['acceptHMRUpdate']>
     readonly asyncComputed: UnwrapRef<(typeof import('@vueuse/core'))['asyncComputed']>
     readonly autoResetRef: UnwrapRef<(typeof import('@vueuse/core'))['autoResetRef']>

+ 1 - 1
src/views/login/index.vue

@@ -59,7 +59,7 @@ const submitForm = (formEl: FormInstance | undefined) => {
           await initDynamicRouter()
           const { path, queryParams } = parseRedirect()
           router.push({ path: path, query: queryParams })
-          ElMessage.success({ message: '提交成功', duration: 1000 })
+          ElMessage.success({ message: '登录成功', duration: 1000 })
         }
       })
     } else {

+ 2 - 6
src/views/system/user/components/AddRoleDialog.vue

@@ -21,16 +21,12 @@
   </el-dialog>
 </template>
 
-<script setup lang="ts">
+<script setup lang="ts" name="AddRoleDialog">
 import { RoleVO } from '@/api/interface/system/role'
 import { UserBO, UserRoleBO } from '@/api/interface/system/user'
 import UserApi from '@/api/module/system/user'
 import { ResultEnum } from '@/enums/HttpEnum'
 
-defineOptions({
-  name: 'UserPermissions'
-})
-
 interface EcoDialogProps {
   api?: (params: any) => Promise<any> // 调用接口
   title: string // 顶部标题
@@ -85,7 +81,7 @@ const getRole = (userId: string) => {
 
 const handleSubmit = async () => {
   try {
-    const { code } = await paramsProps.value.api!(paramsProps.value.row)
+    const { code } = await paramsProps.value.api!({ userId: paramsProps.value.row.userId, roleIds: hasRoles.value })
     if (code == ResultEnum.SUCCESS) {
       ElMessage.success({ message: `${paramsProps.value.title}成功!` })
       paramsProps.value.getTableList!()

+ 2 - 3
src/views/system/user/index.vue

@@ -145,9 +145,8 @@ const dialogRef = ref<InstanceType<typeof AddRoleDialog> | null>(null)
 const openDialog = (title: string, row: Partial<UserBO> = {}) => {
   const params = {
     title,
-    row: title === '新增' ? { orgId: selectTreeId.value } : { ...row },
-    isView: title === '查看',
-    api: title === '新增' ? UserApi.add : title === '编辑' ? UserApi.edit : undefined,
+    row: { ...row },
+    api: UserApi.addRole,
     getTableList: proTableRef.value?.getTableList
   }
   dialogRef.value?.acceptParams(params)