初始化3.0.0版本

This commit is contained in:
zengqiao
2022-08-18 17:04:05 +08:00
parent 462303fca0
commit 51832385b1
2446 changed files with 93177 additions and 127211 deletions

View File

@@ -0,0 +1,105 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
import { notification, Utils } from 'knowdesign';
const goLogin = () => {
// notification.error({ message: '当前未登录,将自动跳转到登录页' });
window.history.replaceState({}, '', `/login?redirect=${window.location.href.slice(window.location.origin.length)}`);
};
const serviceInstance = Utils.service;
// 清除 axios 实例默认的响应拦截
serviceInstance.interceptors.response.handlers = [];
// 请求拦截
serviceInstance.interceptors.request.use(
(config: any) => {
const user = Utils.getCookie('X-SSO-USER');
const id = Utils.getCookie('X-SSO-USER-ID');
if ((!user || !id) && !window.location.pathname.toLowerCase().startsWith('/login')) {
goLogin();
} else {
config.headers['X-SSO-USER'] = user; // 请求携带token
config.headers['X-SSO-USER-ID'] = id;
return config;
}
},
(err: any) => {
return err;
}
);
// 响应拦截
serviceInstance.interceptors.response.use(
(config: any) => {
return config.data;
},
(err: any) => {
const config = err.config;
if (!config || !config.retryTimes) return dealResponse(err, config.customNotification);
const { __retryCount = 0, retryDelay = 300, retryTimes } = config;
config.__retryCount = __retryCount;
if (__retryCount >= retryTimes) {
return dealResponse(err);
}
config.__retryCount++;
const delay = new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, retryDelay);
});
// 重新发起请求
return delay.then(function () {
return serviceInstance(config);
});
}
);
const dealResponse = (error: any) => {
if (error?.response) {
switch (error.response.status) {
case 401:
goLogin();
break;
case 403:
location.href = '/403';
break;
case 405:
notification.error({
message: '错误',
duration: 3,
description: `${error.response.data.message || '请求方式错误'}`,
});
break;
case 500:
notification.error({
message: '错误',
duration: 3,
description: '服务错误,请重试!',
});
break;
case 502:
notification.error({
message: '错误',
duration: 3,
description: '网络错误,请重试!',
});
break;
default:
notification.error({
message: '连接出错',
duration: 3,
description: `${error.response.status}`,
});
}
} else {
notification.error({
description: '请重试或检查服务',
message: '连接超时! ',
duration: 3,
});
}
return Promise.reject(error);
};

View File

@@ -0,0 +1,34 @@
export const defaultPagination = {
current: 1,
pageSize: 10,
total: 0,
};
export const defaultPaginationConfig = {
showQuickJumper: true,
showSizeChanger: true,
pageSizeOptions: ['10', '20', '50', '100', '200', '500'],
showTotal: (total: number) => `${total}`,
};
export const cellStyle = {
overflow: 'hidden',
whiteSpace: 'nowrap' as any,
textOverflow: 'ellipsis',
cursor: 'pointer',
maxWidth: 150,
};
export const systemCipherKey = 'Szjx2022@666666$';
export const oneDayMillims = 24 * 60 * 60 * 1000;
export const classNamePrefix = 'bdp';
export const timeFormat = 'YYYY-MM-DD HH:mm:ss';
export const dateFormat = 'YYYY-MM-DD';
export const SMALL_DRAWER_WIDTH = 480;
export const MIDDLE_DRAWER_WIDTH = 728;
export const LARGE_DRAWER_WIDTH = 1080;

View File

@@ -0,0 +1,37 @@
const pkgJson = require('../../package');
export const systemKey = pkgJson.ident;
export const leftMenus = {
name: `${systemKey}`,
path: '',
icon: '#icon-kafka',
children: [
{
name: 'setting',
path: 'setting',
icon: 'icon-Cluster',
},
{
name: 'user',
path: 'user',
icon: 'icon-Brokers',
},
{
name: 'operationLog',
path: 'operation-log',
icon: 'icon-Topics',
},
],
};
// key值需要与locale zh 中key值一致
export const permissionPoints = {
[`menu.${systemKey}.home`]: true,
};
export const ROUTER_CACHE_KEYS = {
home: `menu.${systemKey}.home`,
dev: `menu.${systemKey}.dev`,
devDetail: `menu.${systemKey}.dev.detail`,
devTable: `menu.${systemKey}.dev.table`,
};