feat: package api
This commit is contained in:
23
src/app.tsx
23
src/app.tsx
@@ -248,9 +248,9 @@ export function patchClientRoutes({ routes }: { routes: any }) {
|
||||
const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
return menus.flatMap((item) => {
|
||||
let Component: React.ComponentType<any> | null = null;
|
||||
console.log(findFirstLeafRoute(item), "item");
|
||||
if (item.component && item.component.length > 0) {
|
||||
// 防止配置了路由,但本地暂未添加对应的页面,产生的错误
|
||||
console.log(item.component);
|
||||
Component = React.lazy(() => {
|
||||
const importComponent = () => import(`@/pages/${item.component}`);
|
||||
const import404 = () => import("@/pages/404");
|
||||
@@ -265,6 +265,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
icon: item.icon,
|
||||
id: item.id,
|
||||
parentId: pId,
|
||||
|
||||
children: [
|
||||
{
|
||||
path: item.url,
|
||||
@@ -275,6 +276,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
},
|
||||
];
|
||||
} else {
|
||||
// console.log(findFirstLeafRoute(newItem));
|
||||
return [
|
||||
{
|
||||
path: item.path,
|
||||
@@ -282,6 +284,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
icon: item.icon,
|
||||
id: item.menuID,
|
||||
parentId: pId,
|
||||
redirect: "/system/tenant/list",
|
||||
element: (
|
||||
<React.Suspense
|
||||
fallback={<Spin style={{ width: "100%", height: "100%" }} />}
|
||||
@@ -295,3 +298,21 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const findFirstLeafRoute = (menuItem: any, parent = "/"): string | null => {
|
||||
// 如果没有子菜单,返回当前路径
|
||||
|
||||
if (!menuItem.children || menuItem.children.length === 0) {
|
||||
return parent + menuItem.path;
|
||||
}
|
||||
|
||||
// 递归查找第一个叶子节点
|
||||
for (const child of menuItem.children) {
|
||||
const leafRoute = findFirstLeafRoute(child, menuItem.path + "/");
|
||||
if (leafRoute) {
|
||||
return leafRoute;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type TenantVO, deleteTenant } from "@/services/system/tenant/list";
|
||||
import { ProColumns } from "@ant-design/pro-components";
|
||||
import { ProColumns, ProFormColumnsType } from "@ant-design/pro-components";
|
||||
import { DatePicker, Modal, Popconfirm } from "antd";
|
||||
import { FormInstance } from "antd/lib";
|
||||
import dayjs from "dayjs";
|
||||
@@ -80,7 +80,7 @@ export const baseTenantColumns: ProColumns<TenantVO>[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const formColumns: any = [
|
||||
export const formColumns = (type: string): ProFormColumnsType[] => [
|
||||
{
|
||||
title: "租户名",
|
||||
dataIndex: "name",
|
||||
@@ -140,7 +140,7 @@ export const formColumns: any = [
|
||||
{
|
||||
title: "用户名称",
|
||||
dataIndex: "username",
|
||||
hideInForm: true,
|
||||
hideInForm: type === "update",
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
@@ -159,7 +159,7 @@ export const formColumns: any = [
|
||||
title: "用户密码",
|
||||
dataIndex: "password",
|
||||
valueType: "password",
|
||||
hideInForm: true,
|
||||
hideInForm: type === "update",
|
||||
fieldProps: {
|
||||
placeholder: "请输入用户密码",
|
||||
autoComplete: "new-password",
|
||||
|
||||
@@ -130,7 +130,7 @@ const TenantList = () => {
|
||||
<ConfigurableDrawerForm
|
||||
ref={configurableDrawerRef}
|
||||
title={formStatusType[type]}
|
||||
columns={formColumns}
|
||||
columns={formColumns(type)}
|
||||
onSubmit={handleSubmit}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -26,6 +26,24 @@ interface ResponseStructure {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
}
|
||||
const ignoreMsgs = [
|
||||
"无效的刷新令牌", // 刷新令牌被删除时,不用提示
|
||||
"刷新令牌已过期", // 使用刷新令牌,刷新获取新的访问令牌时,结果因为过期失败,此时需要忽略。否则,会导致继续 401,无法跳转到登出界面
|
||||
];
|
||||
const errorCode: { [key: string]: string } = {
|
||||
"400": "请求参数不正确",
|
||||
"401": "账号未登录",
|
||||
"403": "当前操作没有权限",
|
||||
"404": "访问资源不存在",
|
||||
"405": "请求方法不正确",
|
||||
"423": "请求失败,请稍后重试",
|
||||
"429": "请求失败,请稍后重试",
|
||||
"500": "系统异常",
|
||||
"501": "功能未实现/未开启",
|
||||
"502": "错误的配置项",
|
||||
"900": "重复请求,请稍后重试",
|
||||
default: "系统未知错误,请反馈给管理员",
|
||||
};
|
||||
|
||||
/**
|
||||
* @name 错误处理
|
||||
@@ -118,11 +136,33 @@ export const errorConfig: RequestConfig = {
|
||||
// 响应拦截器
|
||||
responseInterceptors: [
|
||||
async (response) => {
|
||||
const { data } = response as unknown as ResponseStructure;
|
||||
let { data } = response as unknown as ResponseStructure;
|
||||
const config = response.config;
|
||||
const { code } = data;
|
||||
if (!data) {
|
||||
// 返回“[HTTP]请求没有返回值”;
|
||||
throw new Error();
|
||||
}
|
||||
// 未设置状态码则默认成功状态
|
||||
// 二进制数据则直接返回,例如说 Excel 导出
|
||||
if (
|
||||
response.request.responseType === "blob" ||
|
||||
response.request.responseType === "arraybuffer"
|
||||
) {
|
||||
// 注意:如果导出的响应为 json,说明可能失败了,不直接返回进行下载
|
||||
// if (response.data.type !== "application/json") {
|
||||
// return response.data;
|
||||
// }
|
||||
data = await new Response(data).json();
|
||||
}
|
||||
// 获取错误信息
|
||||
const msg = data.msg || errorCode[code] || errorCode["default"];
|
||||
if (ignoreMsgs.indexOf(msg) !== -1) {
|
||||
// 如果是忽略的错误码,直接返回 msg 异常
|
||||
return Promise.reject(msg);
|
||||
}
|
||||
// 发送请求时出了点问题
|
||||
if (code === 401) {
|
||||
else if (code === 401) {
|
||||
if (!isRefreshToken) {
|
||||
isRefreshToken = true;
|
||||
// 1. 如果获取不到刷新令牌,则只能执行登出操作
|
||||
@@ -153,7 +193,7 @@ export const errorConfig: RequestConfig = {
|
||||
requestList = [];
|
||||
isRefreshToken = false;
|
||||
}
|
||||
return;
|
||||
return request(config.url!, config);
|
||||
} else {
|
||||
console.log("刷新令牌失败");
|
||||
//添加到队列,等待刷新获取到新的令牌
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { request } from "@umijs/max";
|
||||
|
||||
export interface TenantPackageVO {
|
||||
id: number;
|
||||
name: string;
|
||||
status: number;
|
||||
remark: string;
|
||||
creator: string;
|
||||
updater: string;
|
||||
updateTime: string;
|
||||
menuIds: number[];
|
||||
createTime: Date;
|
||||
}
|
||||
|
||||
// 查询租户套餐列表
|
||||
// export const getTenantPackagePage = (params: PageParam) => {
|
||||
// return request.get({ url: '/system/tenant-package/page', params })
|
||||
// }
|
||||
|
||||
// 获得租户
|
||||
// export const getTenantPackage = (id: number) => {
|
||||
// return request.get({ url: '/system/tenant-package/get?id=' + id })
|
||||
// }
|
||||
export async function getTenantPackage(id: number) {
|
||||
return request("/system/tenant-package", {
|
||||
method: "GET",
|
||||
params: { id },
|
||||
});
|
||||
}
|
||||
// 新增租户套餐
|
||||
// export const createTenantPackage = (data: TenantPackageVO) => {
|
||||
// return request.post({ url: '/system/tenant-package/create', data })
|
||||
// }
|
||||
export async function createTenantPackage(data: TenantPackageVO) {
|
||||
return request("/system/tenant-package/create", {
|
||||
method: "POST",
|
||||
data,
|
||||
});
|
||||
}
|
||||
// 修改租户套餐
|
||||
// export const updateTenantPackage = (data: TenantPackageVO) => {
|
||||
// return request.put({ url: "/system/tenant-package/update", data });
|
||||
// };
|
||||
export async function updateTenantPackage(data: TenantPackageVO) {
|
||||
return request("/system/tenant-package/update", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data,
|
||||
});
|
||||
}
|
||||
// 删除租户套餐
|
||||
// export const deleteTenantPackage = (id: number) => {
|
||||
// return request.delete({ url: '/system/tenant-package/delete?id=' + id })
|
||||
// }
|
||||
export async function deleteTenantPackage(id: number) {
|
||||
return request("/system/tenant-package/delete", {
|
||||
method: "DELETE",
|
||||
params: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 获取租户套餐精简信息列表
|
||||
// export const getTenantPackageList = () => {
|
||||
// return request.get({ url: '/system/tenant-package/simple-list' })
|
||||
// }
|
||||
|
||||
export async function getTenantPackageList() {
|
||||
return request("/system/tenant-package/simple-list", {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user