Ver código fonte

Merge commit 'refs/pull/358/head' of https://gitee.com/zuohuaijun/Admin.NET into next

zuohuaijun 3 anos atrás
pai
commit
2a57a972f8

+ 2 - 2
Admin.NET/Admin.NET.Core/Entity/SysLogOp.cs

@@ -28,8 +28,8 @@ public class SysLogOp : EntityBase
     /// <summary>
     /// 地址
     /// </summary>
-    [SugarColumn(ColumnDescription = "地址", Length = 100)]
-    [MaxLength(100)]
+    [SugarColumn(ColumnDescription = "地址", Length = 300)]
+    [MaxLength(300)]
     public string Location { get; set; }
 
     /// <summary>

+ 3 - 1
Admin.NET/Admin.NET.Core/Service/Auth/AuthService.cs

@@ -41,7 +41,7 @@ public class AuthService : IDynamicApiController, ITransient
     /// 登录系统
     /// </summary>
     /// <param name="input"></param>
-    /// <remarks>用户名/密码:admin/123456</remarks>
+    /// <remarks>用户名/密码:vben/123456</remarks>
     /// <returns></returns>
     [HttpPost("/login")]
     [AllowAnonymous]
@@ -124,6 +124,8 @@ public class AuthService : IDynamicApiController, ITransient
             RealName = user.RealName,
             Avatar = user.Avatar,
             Desc = user.Introduction,
+            OrgId = user.OrgId,
+            OrgName = user.SysOrg != null ? user.SysOrg.Name : "",
             Roles = roles.Select(u => new LoginRole
             {
                 RoleName = u.Name,

+ 10 - 0
Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginUserInfoOutput.cs

@@ -30,6 +30,16 @@ public class LoginUserInfoOutput
     /// </summary>
     public string Desc { get; set; }
 
+    /// <summary>
+    /// 机构Id
+    /// </summary>
+    public long OrgId { get; set; }
+
+    /// <summary>
+    /// 机构名称
+    /// </summary>
+    public string OrgName { get; set; }
+
     /// <summary>
     /// 角色集合
     /// </summary>

+ 14 - 0
Admin.NET/Admin.NET.Core/Service/Dict/Dto/DictDataInput.cs

@@ -110,4 +110,18 @@ public class ChageStatusDictDataInput : BaseIdInput
     /// 状态
     /// </summary>
     public int Status { get; set; }
+}
+
+public class QueryDictDataInput
+{
+    /// <summary>
+    /// 编码
+    /// </summary>
+    [Required(ErrorMessage = "字典唯一编码不能为空")]
+    public string Code { get; set; }
+
+    /// <summary>
+    /// 状态
+    /// </summary>
+    public int? Status { get; set; }
 }

+ 19 - 0
Admin.NET/Admin.NET.Core/Service/Dict/SysDictDataService.cs

@@ -151,4 +151,23 @@ public class SysDictDataService : IDynamicApiController, ITransient
                 Value = b.Code
             }).ToListAsync();
     }
+
+    /// <summary>
+    /// 根据条件查询字典获取下拉框集合
+    /// </summary>
+    /// <param name="input">查询参数</param>
+    /// <returns></returns>
+    [HttpGet("/sysDictData/queryDictDataDropdown")]
+    public async Task<dynamic> QueryDictDataDropdown([FromQuery] QueryDictDataInput input)
+    {
+        return await _sysDictDataRep.Context.Queryable<SysDictType, SysDictData>((a, b) =>
+            new JoinQueryInfos(JoinType.Left, a.Id == b.DictTypeId))
+            .Where((a, b) => a.Code == input.Code)
+            .WhereIF(input.Status.HasValue, (a, b) => b.Status == (StatusEnum)input.Status.Value)
+            .Select((a, b) => new
+            {
+                Label = b.Value,
+                Value = b.Code
+            }).ToListAsync();
+    }
 }

+ 12 - 0
Admin.NET/Admin.NET.Core/Service/Org/SysOrgService.cs

@@ -31,6 +31,18 @@ public class SysOrgService : IDynamicApiController, ITransient
         _sysEmpExtOrgPosService = sysEmpExtOrgPosService;
     }
 
+    /// <summary>
+    /// 获取用户拥有机构信息列表
+    /// </summary>
+    /// <param name="userId">用户id</param>
+    /// <returns></returns>
+    [HttpGet("/sysOrg/userOwnOrgInfo/{userId}")]
+    public async Task<List<SysOrg>> GetUserOrgList(long userId)
+    {
+        List<long> orgList = await _sysUserOrgService.GetUserOrgIdList(userId);
+        return await _sysOrgRep.AsQueryable().Where(t => orgList.Contains(t.Id)).ToListAsync();
+    }
+
     /// <summary>
     /// 获取机构列表
     /// </summary>

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/User/UserManager.cs

@@ -35,7 +35,7 @@ public class UserManager : IUserManager, IScoped
 
     public SysUser User
     {
-        get => _sysUserRep.GetFirst(u => u.Id == UserId);
+        get => _sysUserRep.AsQueryable().Includes(t => t.SysOrg).First(u => u.Id == UserId);
     }
 
     public UserManager(SqlSugarRepository<SysUser> sysUserRep,

+ 8 - 0
Vben2/src/api/sys/admin.ts

@@ -41,6 +41,7 @@ enum Api {
   AddOrg = '/sysOrg/add',
   DeleteOrg = '/sysOrg/delete',
   UpdateOrg = '/sysOrg/update',
+  UserOwnOrgInfoList = '/sysOrg/userOwnOrgInfo',
 
   // 职位接口
   PosList = '/sysPos/list',
@@ -94,6 +95,7 @@ enum Api {
   UpdateDictData = '/sysDictData/update',
   DeleteDictData = '/sysDictData/delete',
   GetDictDataDropdown = '/sysDictData/DictDataDropdown',
+  QueryDictDataDropdown = '/sysDictData/queryDictDataDropdown',
 
   // 数据库接口
   GetColumnInfoList = '/dataBase/columnInfoList',
@@ -219,6 +221,9 @@ export const addOrg = (params: any) => defHttp.post({ url: Api.AddOrg, params })
 export const deleteOrg = (id: number) => defHttp.post({ url: Api.DeleteOrg, params: { id } });
 // 更新机构
 export const updateOrg = (params: any) => defHttp.post({ url: Api.UpdateOrg, params });
+// 获取用户拥有机构信息列表
+export const userOwnOrgInfoList = (params: any) =>
+  defHttp.get<any>({ url: Api.UserOwnOrgInfoList + '/' + params });
 
 ////////// 职位管理接口 //////////
 // 获取职位列表
@@ -321,6 +326,9 @@ export const getDictDataList = (params?: any) =>
 // 从字典中值,下拉框控件使用
 export const getDictDataDropdown = (params: any) =>
   defHttp.get<any>({ url: Api.GetDictDataDropdown + '/' + params });
+// 根据条件,从字典中值,下拉框控件使用
+export const queryDictDataDropdown = (params: any) =>
+  defHttp.get<any>({ url: Api.QueryDictDataDropdown, params });
 // 增加典类型
 export const addDictData = (params: any) => defHttp.post({ url: Api.AddDictData, params });
 // 删除字典类型

+ 4 - 0
Vben2/src/api/sys/model/userModel.ts

@@ -35,4 +35,8 @@ export interface GetUserInfoModel {
   avatar: string;
   // 介绍
   desc?: string;
+  // 机构id
+  orgId: string | number;
+  //机构名称
+  orgName: string;
 }

+ 5 - 0
Vben2/src/router/guard/permissionGuard.ts

@@ -29,6 +29,11 @@ export function createPermissionGuard(router: Router) {
       return;
     }
 
+    //缓存当前用户部门信息
+    if (userStore.orgInfo.length === 0 && userStore.userInfo) {
+      const userid = Number(userStore.getUserInfo.userId);
+      await userStore.getOrgInfoAction(userid);
+    }
     //缓存所有常量数据
     if (userStore.constSelectorWithOptions.length === 0) {
       await userStore.getAllConstSelectorWithOptionsAction();

+ 24 - 2
Vben2/src/store/modules/user.ts

@@ -1,4 +1,4 @@
-import type { UserInfo } from '/#/store';
+import type { UserInfo, OrgInfo } from '/#/store';
 import type { ErrorMessageMode } from '/#/axios';
 import { defineStore } from 'pinia';
 import { store } from '/@/store';
@@ -8,7 +8,7 @@ import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY } from '/@/enums/cacheEnum';
 import { getAuthCache, setAuthCache } from '/@/utils/auth';
 import { GetUserInfoModel, LoginParams } from '/@/api/sys/model/userModel';
 import { doLogout, getUserInfo, loginApi } from '/@/api/sys/user';
-import { getAllConstSelectorWithOptions } from '/@/api/sys/admin';
+import { getAllConstSelectorWithOptions, userOwnOrgInfoList } from '/@/api/sys/admin';
 import { useI18n } from '/@/hooks/web/useI18n';
 import { useMessage } from '/@/hooks/web/useMessage';
 import { router } from '/@/router';
@@ -20,6 +20,7 @@ import { h } from 'vue';
 
 interface UserState {
   userInfo: Nullable<UserInfo>;
+  orgInfo: OrgInfo[];
   token?: string;
   roleList: RoleEnum[];
   sessionTimeout?: boolean;
@@ -32,6 +33,8 @@ export const useUserStore = defineStore({
   state: (): UserState => ({
     // user info
     userInfo: null,
+    // org info
+    orgInfo: [],
     // token
     token: undefined,
     // roleList
@@ -62,6 +65,9 @@ export const useUserStore = defineStore({
     getAllConstSelectorWithOptions(): any[] {
       return this.constSelectorWithOptions || getAllConstSelectorWithOptions();
     },
+    getOrgInfo(): OrgInfo[] {
+      return this.orgInfo || [];
+    },
   },
   actions: {
     setToken(info: string | undefined) {
@@ -180,6 +186,22 @@ export const useUserStore = defineStore({
       this.constSelectorWithOptions = data;
       // setAuthCache(USER_INFO_KEY, data);
     },
+    async getOrgInfoAction(userid: number) {
+      const data = await userOwnOrgInfoList(userid);
+
+      let obj: OrgInfo;
+      const list: OrgInfo[] = [];
+      for (let i = 0; i < data.length; i++) {
+        obj = {
+          orgId: data[i].id,
+          code: data[i].code,
+          name: data[i].name,
+          status: data[i].status,
+        };
+        list.push(obj);
+      }
+      this.orgInfo = list;
+    },
   },
 });
 

+ 9 - 0
Vben2/types/store.d.ts

@@ -37,6 +37,8 @@ export interface UserInfo {
   avatar: string;
   desc?: string;
   homePath?: string;
+  orgId: string | number;
+  orgName: string;
   roles: RoleInfo[];
 }
 
@@ -46,3 +48,10 @@ export interface BeforeMiniState {
   menuMode?: MenuModeEnum;
   menuType?: MenuTypeEnum;
 }
+
+export interface OrgInfo {
+  orgId: string | number;
+  code: string;
+  name: string;
+  status: string | number;
+}