Skip to content

Commit

Permalink
Merge pull request #238 from sj-distributor/role-permission-function-…
Browse files Browse the repository at this point in the history
…development

Role permission function development
  • Loading branch information
wuxin666789 authored Mar 4, 2024
2 parents 03cdddd + dd7d563 commit 49415af
Show file tree
Hide file tree
Showing 60 changed files with 4,777 additions and 1,157 deletions.
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
"material-icons": "^1.13.11",
"moment": "^2.29.4",
"node-sass": "^8.0.0",
"notistack": "^3.0.1",
"ramda": "^0.28.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-mentions": "^4.4.7",
"react-router-dom": "^6.5.0",
"react-scripts": "5.0.1",
"react-scripts": "^5.0.1",
"react-virtualized": "^9.22.5",
"react-virtualized-tree": "^3.4.1",
"react-window": "^1.8.9",
Expand Down
4 changes: 0 additions & 4 deletions web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
56 changes: 12 additions & 44 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
import { Route, Routes, Navigate } from "react-router-dom"
import { routerArray } from "./router/elementRoute"
import Login from "./pages/login"
import Main from "./pages/main"
import useAction from "./AppHook"
import { RouteItem } from "./dtos/route-type"
import IsAuthUser from "./pages/auth"
import { Router } from "./router/elementRoute";
import TokenProvider from "./hooks/authProvider";
import useAction from "./AppHook";

const App = () => {
const { isLoaded } = useAction()

const getSubRoute = (list: RouteItem[]) => {
return list.map((item, index) => {
return (
<Route
key={index}
path={item.path}
element={<IsAuthUser>{item.element}</IsAuthUser>}
>
<Route path="" element={<Navigate to="/home/enterprise" />} />

{item.children?.map((childrenItem, childrenIndex) => {
return (
<Route
key={childrenIndex}
path={childrenItem.path}
element={childrenItem.elementChild}
/>
)
})}
</Route>
)
})
}
const { isLoaded } = useAction();

return (
<>
{isLoaded && (
<div className="App">
<Routes>
<Route path="/login" element={<Login />} />
<Route element={<Main />}>
<Route path="" element={<Navigate to={"/home"} />} />
{getSubRoute(routerArray)}
</Route>
</Routes>
</div>
<TokenProvider>
<div className="App">
<Router />
</div>
</TokenProvider>
)}
</>
)
}
);
};

export default App
export default App;
8 changes: 4 additions & 4 deletions web/src/api/email/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IEmailResonponse } from "../../dtos/email"
import { Get, Post } from "../http-client"
import { IEmailResonponse } from "../../dtos/email";
import { Get } from "../http-client";

export const GetEmailData = async () => {
return await Get<IEmailResonponse[]>("/api/Email/server/accounts")
}
return await Get<IEmailResonponse[]>("/api/Email/server/accounts");
};
29 changes: 16 additions & 13 deletions web/src/api/http-client.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AppSettings } from "../appsettings"
import { AppSettings } from "../appsettings";

export async function Get<T>(url: string) {
return base<T>(url, "get")
return base<T>(url, "get");
}

export async function Post<T>(url: string, data?: object | FormData) {
return base<T>(url, "post", data)
return base<T>(url, "post", data);
}

export interface IResponse<T> {
code: ResponseCode
msg: string
data: T
code: ResponseCode;
msg: string;
data: T;
}

export enum ResponseCode {
Expand All @@ -25,17 +25,17 @@ export async function base<T>(
method: "get" | "post",
data?: object | FormData
) {
const settings = (window as any).appSettings as AppSettings
const settings = (window as any).appSettings as AppSettings;
const headers: { Authorization: string; "Content-Type"?: string } = {
Authorization:
"Bearer " +
(localStorage.getItem("token")
? (localStorage.getItem("token") as string)
: ""),
}
const isFormData = data instanceof FormData
if (!isFormData) headers["Content-Type"] = "application/json"
const body = isFormData ? data : JSON.stringify(data)
};
const isFormData = data instanceof FormData;
if (!isFormData) headers["Content-Type"] = "application/json";
const body = isFormData ? data : JSON.stringify(data);

return await fetch(`${settings.serverUrl}${url}`, {
method: method,
Expand All @@ -45,9 +45,12 @@ export async function base<T>(
.then((res) => res.json())
.then((res: IResponse<T>) => {
if (res.code === ResponseCode.Ok) {
return res.data
return res.data;
} else {
throw new Error(res.msg)
throw new Error(res.msg);
}
})
.catch((error) => {
throw new Error(error.message);
});
}
2 changes: 1 addition & 1 deletion web/src/api/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ILoginRequest } from "../../dtos/login";
import { Get, Post } from "../http-client";
import { Post } from "../http-client";

export const AuthAccont = async (data: ILoginRequest) => {
return await Post<string>("/auth/login", data);
Expand Down
91 changes: 91 additions & 0 deletions web/src/api/role-user-permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
IAddRoleUsersDto,
IDeleteRole,
IDeleteRoleUserRequest,
IFoundationTreeDto,
IPageDto,
IPermissionsDto,
IRolePermission,
IRolePermissionDto,
IRoleUserItemDto,
IRoleUserPageDto,
IRoleUserResponse,
} from "../../dtos/role-user-permissions";
import { Get, Post } from "../http-client";

export const GetCurrentRolesByPermissions = async () => {
return await Get<IRolePermissionDto>(`/api/Security/mine/roles`);
};

// 获取用户list
export const GetRoleUser = async (data: IRoleUserPageDto) => {
return await Get<IRoleUserResponse>(
`/api/Security/role/users?PageIndex=${data.PageIndex + 1}&PageSize=${
data.PageSize
}&RoleId=${data.RoleId}&Keyword=${data.Keyword}`
);
};

// 移除用户
export const DeleteRoleUser = async (data: IDeleteRoleUserRequest) => {
return await Post("/api/Security/role/users/delete", data);
};

// 添加用户
export const AddRoleUser = async (data: IAddRoleUsersDto) => {
return await Post<IRoleUserItemDto>("/api/Security/role/users/create", data);
};

//人员层级tree
export const GetTreeList = async () => {
return await Get<IFoundationTreeDto>(
"/api/Foundation/department/staff/hierarchy/tree"
);
};

//获取全部角色用户列表
export const GetRoleUserList = async () => {
return await Get<IRoleUserResponse>(`/api/Security/role/users`);
};

// 获取功能权限
export const GetPermissions = async () => {
return await Get<IPermissionsDto>("/api/Security/permissions");
};

// 查询角色
export const GetRolePermission = async (roleId: string) => {
return await Get<IRolePermission>(`/api/Security/role/${roleId}/permissions`);
};

// 添加角色
export const AddRolePermission = async (data: IRolePermission) => {
return await Post<IRolePermission>(
"/api/Security/role/permissions/assign",
data
);
};

// 更新角色
export const UpdateRolePermission = async (data: IRolePermission) => {
return await Post<IRolePermission>(
"/api/Security/role/permissions/edit",
data
);
};

// 获取角色list
export const GetRolesByPermissions = async (data: IPageDto) => {
return await Get<IRolePermissionDto>(
`/api/Security/roles/by/permissions?PageIndex=${
data.pageIndex + 1
}&PageSize=${data.pageSize}${
data.keyword ? "&Keyword=" + data.keyword : ""
}`
);
};

//删除角色
export const DeleteRoles = async (data: IDeleteRole) => {
return await Post("/api/Security/roles/delete", data);
};
34 changes: 20 additions & 14 deletions web/src/api/user-management/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import { ILoginRequest } from "../../dtos/login"
import { ILoginRequest } from "../../dtos/login";
import {
IGetAllUserDto,
IUserAllResponse,
IUserApikeyAddData,
IUserApikeysResponse,
IUserResponse,
} from "../../dtos/user-management"
import { Get, Post } from "../http-client"
} from "../../dtos/user-management";
import { Get, Post } from "../http-client";

export const GetAuthUser = async () => {
return await Get<IUserResponse>("/auth/user")
}
return await Get<IUserResponse>("/auth/user");
};

export const PostAuthRegister = async (data: ILoginRequest) => {
return await Post("/auth/register", data)
}
return await Post("/auth/register", data);
};

export const GetAllUsers = async () => {
return await Get<IUserResponse[]>("/auth/allUsers")
}
export const GetAllUsers = async (data: IGetAllUserDto) => {
return await Get<IUserAllResponse>(
`/auth/allUsers?PageIndex=${data.Page}&PageSize=${data.PageSize}${
data.UserName ? "&UserName=" + data.UserName : ""
}`
);
};

export const GetUserApikeys = async (userId: string) => {
return await Get<IUserApikeysResponse[]>(
`/auth/user/apikeys?UserId=${userId}`
)
}
);
};

export const PostUserApikeysAdd = async (data: IUserApikeyAddData) => {
return await Post("/auth/user/apikey/add", data)
}
return await Post("/auth/user/apikey/add", data);
};
6 changes: 3 additions & 3 deletions web/src/appsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const settings = (window as any).appSettings;
export async function InitialAppSetting() {
if ((window as any).appSettings) return (window as any).appSettings;

await fetch("../appsetting.json", {
await fetch(`${process.env.PUBLIC_URL}/appsetting.json`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json"
}
Accept: "application/json",
},
})
.then((res) => res.json())
.then((res: AppSettings) => {
Expand Down
Loading

0 comments on commit 49415af

Please sign in to comment.