add router and edit request (#1477)

* Add user log item Manage

* edit Item Management

* merge from develop

* add router

* add router

* edit logmanage

* edit tenant
pull/1482/head
baiJinjin 9 months ago committed by GitHub
parent d645c49450
commit d543979a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,4 @@
// import { Suspense } from 'react';
import LayoutCom from './components/layout-com'; import LayoutCom from './components/layout-com';
import { Routes, Route, Link } from 'react-router-dom'; import { Routes, Route, Link } from 'react-router-dom';
import routeList from './route'; import routeList from './route';
@ -18,6 +19,26 @@ const App = () => {
{ label: <Link to={'/thread-poll/index'}>{useTran(STR_MAP.THREAD_POOL)}</Link>, key: '/thread-poll/index' }, { label: <Link to={'/thread-poll/index'}>{useTran(STR_MAP.THREAD_POOL)}</Link>, key: '/thread-poll/index' },
], ],
}, },
{
label: <Link to={'/tenant'}>{useTran(STR_MAP.TENANT_MANAGE)}</Link>,
key: STR_MAP.TENANT_MANAGE,
icon: <IconFont type="icon-hot-for-ux"></IconFont>,
},
{
label: <Link to={'/item'}>{useTran(STR_MAP.PROJECT_MANAGE)}</Link>,
key: STR_MAP.PROJECT_MANAGE,
icon: <IconFont type="icon-hot-for-ux"></IconFont>,
},
{
label: <Link to={'/user'}>{useTran(STR_MAP.USER_MANAGE)}</Link>,
key: STR_MAP.USER_MANAGE,
icon: <IconFont type="icon-hot-for-ux"></IconFont>,
},
{
label: <Link to={'/log'}>{useTran(STR_MAP.LOG_MANAGE)}</Link>,
key: STR_MAP.LOG_MANAGE,
icon: <IconFont type="icon-hot-for-ux"></IconFont>,
},
]; ];
return ( return (

@ -17,4 +17,8 @@ export enum STR_MAP {
CREATION_TIME = 'creationTime', CREATION_TIME = 'creationTime',
UPDATE_TIME = 'update time', UPDATE_TIME = 'update time',
EDIT = 'edit', EDIT = 'edit',
TENANT_MANAGE = 'tenantManage',
LOG_MANAGE = 'logManage',
PROJECT_MANAGE = 'projectManage',
USER_MANAGE = 'userManage',
} }

@ -19,6 +19,10 @@ const enTranslationMap: { [key: string]: string } = {
[STR_MAP.CREATION_TIME]: 'creation time', [STR_MAP.CREATION_TIME]: 'creation time',
[STR_MAP.UPDATE_TIME]: 'update time', [STR_MAP.UPDATE_TIME]: 'update time',
[STR_MAP.EDIT]: 'edit', [STR_MAP.EDIT]: 'edit',
[STR_MAP.TENANT_MANAGE]: 'tenant management',
[STR_MAP.PROJECT_MANAGE]: 'project management',
[STR_MAP.USER_MANAGE]: 'user management',
[STR_MAP.LOG_MANAGE]: 'log management',
}; };
export default enTranslationMap; export default enTranslationMap;

@ -19,6 +19,10 @@ const zhTranslationMap: { [key: string]: string } = {
[STR_MAP.CREATION_TIME]: '创建时间', [STR_MAP.CREATION_TIME]: '创建时间',
[STR_MAP.UPDATE_TIME]: '更新时间', [STR_MAP.UPDATE_TIME]: '更新时间',
[STR_MAP.EDIT]: '操作', [STR_MAP.EDIT]: '操作',
[STR_MAP.TENANT_MANAGE]: '租户管理',
[STR_MAP.PROJECT_MANAGE]: '项目管理',
[STR_MAP.USER_MANAGE]: '用户管理',
[STR_MAP.LOG_MANAGE]: '日志管理',
}; };
export default zhTranslationMap; export default zhTranslationMap;

@ -25,12 +25,12 @@ export const defaultAlgorithm = {
// paddingContentVerticalLG: 4, // paddingContentVerticalLG: 4,
}, },
Modal: { Modal: {
borderRadiusLG: 2, // borderRadiusLG: 2,
borderRadiusSM: 2, // borderRadiusSM: 2,
colorText: lightDefaultTheme.fontColor.fc3, // colorText: lightDefaultTheme.fontColor.fc3,
borderRadius: 2, // borderRadius: 2,
paddingContentHorizontalLG: 0, // paddingContentHorizontalLG: 0,
paddingMD: 0, // paddingMD: 0,
}, },
Menu: { Menu: {
itemBg: lightDefaultTheme.backgroundColor.bg1, itemBg: lightDefaultTheme.backgroundColor.bg1,

@ -1,10 +1,11 @@
import React from 'react'; import React, { Suspense } from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import App from './App'; import App from './App';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { MyStore } from './context'; import { MyStore } from './context';
import './config/i18n'; import './config/i18n';
import 'antd/dist/reset.css'; import 'antd/dist/reset.css';
import { Spin } from 'antd';
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
@ -14,7 +15,9 @@ root.render(
{/* theme context */} {/* theme context */}
<MyStore> <MyStore>
{/* theme config context */} {/* theme config context */}
<App /> <Suspense fallback={<Spin />}>
<App />
</Suspense>
</MyStore> </MyStore>
</BrowserRouter> </BrowserRouter>
</React.StrictMode> </React.StrictMode>

@ -0,0 +1,33 @@
import { useRequest } from 'ahooks';
import { Form, Modal, Input, Select } from 'antd';
import React from 'react';
import { fetchTenantList } from '../tenant/service';
const ItemCreate: React.FC<{
type: string;
data: any;
visible: boolean;
onClose: () => void;
}> = props => {
const { visible, onClose, data, type } = props;
const { data: tenant } = useRequest(fetchTenantList);
console.log('tenant', tenant);
return (
<Modal open={visible} onCancel={onClose} footer={null} width={600} title={type === 'edit' ? '编辑' : '创建'}>
<Form>
<Form.Item label="租户" name="">
{/* <Select options={tenant}></Select> */}
</Form.Item>
<Form.Item label="项目" name="">
<Input />
</Form.Item>
<Form.Item label="负责人" name="">
<Input />
</Form.Item>
</Form>
</Modal>
);
};
export default ItemCreate;

@ -1,27 +1,37 @@
import { useAntdTable } from 'ahooks'; import { useAntdTable } from 'ahooks';
import { Button, Form, Input, Row, Space, Table, Col } from 'antd'; import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd';
import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { SearchOutlined, EditOutlined } from '@ant-design/icons';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { fetchItemList } from './service'; import { fetchItemList } from './service';
import { useUrlSet } from '@/hooks/useUrlSet'; import { useUrlSet } from '@/hooks/useUrlSet';
import style from './index.module.less'; import style from './index.module.less';
import ItemCreate from './create';
const baseColumns = [ const baseColumns = [
{ {
title: '序号', title: '序号',
dataIndex: 'index', dataIndex: 'index',
with: 200,
}, },
{ {
title: '租户', title: '租户',
dataIndex: 'tenantId', dataIndex: 'tenantId',
with: 200,
},
{
title: '项目',
dataIndex: 'itemId',
with: 200,
}, },
{ {
title: '项目名称', title: '项目名称',
dataIndex: 'itemName', dataIndex: 'itemName',
with: 200,
}, },
{ {
title: '负责人', title: '负责人',
dataIndex: 'owner', dataIndex: 'owner',
with: 200,
}, },
{ {
title: '修改时间', title: '修改时间',
@ -32,37 +42,44 @@ const baseColumns = [
const Tenant: React.FC = () => { const Tenant: React.FC = () => {
const [editVisible, setEditVisible] = useState(false); const [editVisible, setEditVisible] = useState(false);
const [type, setType] = useState('add'); const [type, setType] = useState('add');
const [curItem, setCurItem] = useState({});
const [form] = Form.useForm(); const [form] = Form.useForm();
const { setUrl } = useUrlSet({ form }); const { setUrl } = useUrlSet({ form });
const { tableProps, search } = useAntdTable(fetchItemList, { form }); const { tableProps, search } = useAntdTable(fetchItemList, { form });
// const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); // const {run: delete} = useRequest(fetchDeleteTenant, { manual: true });
const handleSearch = () => {
setUrl();
search.submit();
};
const handleDelete = (item: any) => {
Modal.confirm({
title: `此操作将删除${item.itemName}, 是否继续?`,
onOk: () => {
search.submit();
},
});
};
const actions = (type: string, item?: any) => { const actions = (type: string, item?: any) => {
switch (type) { switch (type) {
case 'add': case 'add':
setType('add');
setEditVisible(true); setEditVisible(true);
break; break;
case 'edit': case 'edit':
setType('edit');
setCurItem(item);
setEditVisible(true); setEditVisible(true);
break; break;
case 'delete': case 'delete':
// handleDelete(); handleDelete(item);
break; break;
default: default:
break; break;
} }
}; };
const handleSearch = () => { const handleClose = () => {
setUrl(); setEditVisible(false);
search.submit();
}; };
// const handleDelete = (item: any) => {
// Modal.confirm({
// title: `此操作将删除${item.tenantName}, 是否继续?`,
// onOk: () => {
// search.submit();
// },
// });
// };
return ( return (
<div className={style.tenant_wrapper}> <div className={style.tenant_wrapper}>
@ -93,6 +110,7 @@ const Tenant: React.FC = () => {
{...tableProps} {...tableProps}
bordered bordered
rowKey="index" rowKey="index"
scroll={{ x: 1000 }}
columns={[ columns={[
...baseColumns, ...baseColumns,
{ {
@ -104,7 +122,7 @@ const Tenant: React.FC = () => {
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}> <Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}>
</Button> </Button>
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}> <Button onClick={() => actions('delete', record)} type="link" className={style.opreate_btn}>
</Button> </Button>
</Space> </Space>
@ -113,6 +131,7 @@ const Tenant: React.FC = () => {
}, },
]} ]}
/> />
<ItemCreate data={curItem} onClose={handleClose} visible={editVisible} type={type} />
</div> </div>
); );
}; };

@ -6,12 +6,6 @@ const fetchItemList = async (
): Promise<{ total: number; list: Array<any> }> => { ): Promise<{ total: number; list: Array<any> }> => {
const res: any = await request('/hippo4j/v1/cs/item/query/page', { const res: any = await request('/hippo4j/v1/cs/item/query/page', {
method: 'POST', method: 'POST',
headers: {
Authorization:
'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ',
cookie:
'Admin-Token=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ; userName=baoxinyi_admin',
},
body: { body: {
...formData, ...formData,
current: pageProps.current, current: pageProps.current,

@ -0,0 +1,33 @@
import { Descriptions, Modal } from 'antd';
import React from 'react';
const LogDetail: React.FC<{
data: any;
visible: boolean;
onClose: () => void;
}> = props => {
const { visible, onClose, data } = props;
return (
<Modal open={visible} onCancel={onClose} footer={null} width={600}>
<Descriptions title={'详情'} column={1}>
<Descriptions.Item span={1} label="业务类型">
{data.category}
</Descriptions.Item>
<Descriptions.Item span={1} label="业务标识">
{data.bizNo}
</Descriptions.Item>
<Descriptions.Item span={1} label="操作人">
{data.operator}
</Descriptions.Item>
<Descriptions.Item span={1} label="创建时间">
{data.createTime}
</Descriptions.Item>
<Descriptions.Item span={1} label="日志内容">
{data.action}
</Descriptions.Item>
</Descriptions>
</Modal>
);
};
export default LogDetail;

@ -1,85 +1,90 @@
import { useAntdTable } from 'ahooks'; import { useAntdTable } from 'ahooks';
import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; import { Button, Form, Input, Row, Space, Table, Col } from 'antd';
import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { SearchOutlined, RedoOutlined } from '@ant-design/icons';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { fetchTenantList } from './service'; import { fetchLogList } from './service';
import { useUrlSet } from '@/hooks/useUrlSet'; import { useUrlSet } from '@/hooks/useUrlSet';
import style from './index.module.less'; import style from './index.module.less';
import LogDetail from './detail';
const baseColumns = [ const baseColumns = [
{ {
title: '序号', title: '序号',
dataIndex: 'id', dataIndex: 'id',
width: 100,
// fixed: 'left',
}, },
{ {
title: '租户', title: '业务类型',
dataIndex: 'tenantId', dataIndex: 'category',
width: 200,
}, },
{ {
title: '租户名称', title: '业务标识',
dataIndex: 'tenantName', dataIndex: 'bizNo',
width: 380,
}, },
{ {
title: '负责人', title: '日志内容',
dataIndex: 'owner', dataIndex: 'action',
width: 380,
}, },
{ {
title: '修改时间', title: '操作人',
dataIndex: 'gmtModified', dataIndex: 'operator',
width: 100,
},
{
title: '操作时间',
dataIndex: 'createTime',
width: 200,
}, },
]; ];
const Tenant: React.FC = () => { const Tenant: React.FC = () => {
const [editVisible, setEditVisible] = useState(false); const [visible, setVisible] = useState(false);
const [type, setType] = useState('add');
const [form] = Form.useForm(); const [form] = Form.useForm();
const { setUrl } = useUrlSet({ form }); const { setUrl } = useUrlSet({ form });
const { tableProps, search } = useAntdTable(fetchTenantList, { form }); const { tableProps, search } = useAntdTable(fetchLogList, { form });
// const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); const [curItems, setCurItems] = useState({});
const actions = (type: string, item?: any) => {
switch (type) {
case 'add':
setEditVisible(true);
break;
case 'edit':
setEditVisible(true);
break;
case 'delete':
// handleDelete();
break;
default:
break;
}
};
const handleSearch = () => { const handleSearch = () => {
setUrl(); setUrl();
search.submit(); search.submit();
}; };
// const handleDelete = (item: any) => { const handleDetail = (item: any) => {
// Modal.confirm({ setVisible(!visible);
// title: `此操作将删除${item.tenantName}, 是否继续?`, setCurItems(item);
// onOk: () => { };
// search.submit(); const handleClose = () => {
// }, setVisible(false);
// }); };
// };
return ( return (
<div className={style.tenant_wrapper}> <div className={style.tenant_wrapper}>
<Form form={form} wrapperCol={{ span: 23 }}> <Form form={form} wrapperCol={{ span: 23 }}>
<Row> <Row>
<Col span={6}> <Col span={5}>
<Form.Item name="note"> <Form.Item name="category">
<Input placeholder="租户" /> <Input placeholder="业务类型" allowClear />
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={18}> <Col span={5}>
<Form.Item name="bizNo">
<Input placeholder="业务标识" allowClear />
</Form.Item>
</Col>
<Col span={5}>
<Form.Item name="operator">
<Input placeholder="操作人" allowClear />
</Form.Item>
</Col>
<Col span={6}>
<Space> <Space>
<Button onClick={() => handleSearch()} type="primary" icon={<SearchOutlined />}> <Button onClick={() => handleSearch()} type="primary" icon={<SearchOutlined />}>
</Button> </Button>
<Button onClick={() => setEditVisible(true)} type="primary" icon={<EditOutlined />}> <Button onClick={() => search.reset()} type="primary" icon={<RedoOutlined />}>
</Button> </Button>
</Space> </Space>
</Col> </Col>
@ -93,26 +98,25 @@ const Tenant: React.FC = () => {
{...tableProps} {...tableProps}
bordered bordered
rowKey="id" rowKey="id"
scroll={{ x: 1000 }}
columns={[ columns={[
...baseColumns, ...baseColumns,
{ {
fixed: 'right',
width: 100,
title: '操作', title: '操作',
key: 'action', key: 'action',
render: (text: string, record: any) => { render: (text: string, record: any) => {
return ( return (
<Space> <Button onClick={() => handleDetail(record)} type="link" className={style.opreate_btn}>
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}>
</Button>
</Button>
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}>
</Button>
</Space>
); );
}, },
}, },
]} ]}
/> />
<LogDetail visible={visible} onClose={handleClose} data={curItems} />
</div> </div>
); );
}; };

@ -1,79 +1,24 @@
import request from '@/utils'; import request from '@/utils';
const fetchTenantList = async ( const fetchLogList = async (
pageProps: { current: number; pageSize: number }, pageProps: { current: number; pageSize: number },
formData: { tencent: string | number } formData: { category: string | number; bizNo: string; operator: string }
): Promise<{ total: number; list: Array<any> }> => { ): Promise<{ total: number; list: Array<any> }> => {
const res: any = await request('/hippo4j/v1/cs/tenant/query/page', { const res: any = await request('/hippo4j/v1/cs/log/query/page', {
method: 'POST', method: 'POST',
headers: {
Authorization:
'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ',
cookie:
'Admin-Token=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ; userName=baoxinyi_admin',
},
body: { body: {
...formData, ...formData,
current: pageProps.current, current: pageProps.current,
size: pageProps.pageSize, size: pageProps.pageSize,
desc: true,
}, },
}); });
if (res && res.success) { if (res && res.success) {
return { return {
total: res.data.total, total: res.data.total,
list: res.data.records, list: res.data.records.map((item: any, index: number) => ({ id: index + 1, ...item })),
}; };
} }
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.msg || '服务器开小差啦~');
}; };
const fetchAddTenant = async (id: string) => { export { fetchLogList };
const res = await request('/hippo4j/v1/cs/tenant/save', {
method: 'POST',
params: { id },
});
if (res && res.success) {
return res;
}
throw new Error(res.msg || '服务器开小差啦~');
};
const fetchDeleteTenant = async (id: string) => {
const res = await request('/tenants', {
method: 'POST',
params: { id },
});
if (res && res.success) {
return res;
}
throw new Error(res.msg || '服务器开小差啦~');
};
const fetchUpdateTenant = async (id: string) => {
const res = await request('hippo4j/v1/cs/tenant/update', {
method: 'POST',
params: { id },
});
if (res && res.success) {
return res;
}
throw new Error(res.msg || '服务器开小差啦~');
};
const fetchTenantDetail = async (id: string) => {
const res = await request('/tenants', {
method: 'POST',
params: { id },
});
if (res && res.success) {
return res;
}
throw new Error(res.msg || '服务器开小差啦~');
};
export { fetchTenantList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant, fetchTenantDetail };

@ -4,7 +4,6 @@ import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd';
import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { SearchOutlined, EditOutlined } from '@ant-design/icons';
import { useUrlSet } from '@/hooks/useUrlSet'; import { useUrlSet } from '@/hooks/useUrlSet';
import { fetchTenantList } from './service'; import { fetchTenantList } from './service';
import style from './index.module.less'; import style from './index.module.less';
const baseColumns = [ const baseColumns = [
@ -37,6 +36,19 @@ const Tenant: React.FC = () => {
const { setUrl } = useUrlSet({ form }); const { setUrl } = useUrlSet({ form });
const { tableProps, search } = useAntdTable(fetchTenantList, { form }); const { tableProps, search } = useAntdTable(fetchTenantList, { form });
// const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); // const {run: delete} = useRequest(fetchDeleteTenant, { manual: true });
const handleSearch = () => {
setUrl();
search.submit();
};
const handleDelete = (item: any) => {
Modal.confirm({
title: '提示',
content: `此操作将删除${item.tenantName},是否继续?`,
onOk: () => {
search.submit();
},
});
};
const actions = (type: string, item?: any) => { const actions = (type: string, item?: any) => {
switch (type) { switch (type) {
case 'add': case 'add':
@ -46,24 +58,12 @@ const Tenant: React.FC = () => {
setEditVisible(true); setEditVisible(true);
break; break;
case 'delete': case 'delete':
// handleDelete(); handleDelete(item);
break; break;
default: default:
break; break;
} }
}; };
const handleSearch = () => {
setUrl();
search.submit();
};
// const handleDelete = (item: any) => {
// Modal.confirm({
// title: `此操作将删除${item.tenantName}, 是否继续?`,
// onOk: () => {
// search.submit();
// },
// });
// };
return ( return (
<div className={style.tenant_wrapper}> <div className={style.tenant_wrapper}>
@ -105,7 +105,7 @@ const Tenant: React.FC = () => {
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}> <Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}>
</Button> </Button>
<Button onClick={() => actions('edit', record)} type="link" className={style.opreate_btn}> <Button onClick={() => actions('delete', record)} type="link" className={style.opreate_btn}>
</Button> </Button>
</Space> </Space>

@ -6,12 +6,6 @@ const fetchTenantList = async (
): Promise<{ total: number; list: Array<any> }> => { ): Promise<{ total: number; list: Array<any> }> => {
const res: any = await request('/hippo4j/v1/cs/tenant/query/page', { const res: any = await request('/hippo4j/v1/cs/tenant/query/page', {
method: 'POST', method: 'POST',
headers: {
Authorization:
'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ',
cookie:
'Admin-Token=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ; userName=baoxinyi_admin',
},
body: { body: {
...formData, ...formData,
current: pageProps.current, current: pageProps.current,

@ -4,9 +4,18 @@ import aboutRouter from '@/page/about/router';
import ThreadPoolRouter from '@/page/thread-pool/router'; import ThreadPoolRouter from '@/page/thread-pool/router';
import tenantRouter from '@/page/tenant/router'; import tenantRouter from '@/page/tenant/router';
import LoginRouter from '@/page/login/router'; import LoginRouter from '@/page/login/router';
// import itemRouter from '@/page/item/router'; import itemRouter from '@/page/item/router';
// import userRouter from '@/page/user/router'; import userRouter from '@/page/user/router';
// import logRouter from '@/page/log/router'; import logRouter from '@/page/log/router';
const routerList: IRouterList[] = [...homeRouter, ...aboutRouter, ...tenantRouter, ...ThreadPoolRouter, ...LoginRouter]; const routerList: IRouterList[] = [
...homeRouter,
...aboutRouter,
...tenantRouter,
...ThreadPoolRouter,
...LoginRouter,
...itemRouter,
...userRouter,
...logRouter,
];
export default routerList; export default routerList;

@ -49,9 +49,19 @@ const isPlainObject = (obj: { [key: string]: any }): boolean => {
}; };
const setToken = (token: string) => { const setToken = (token: string) => {
localStorage.setItem(TokenKey, token);
Cookie.set(TokenKey, token); Cookie.set(TokenKey, token);
}; };
const removeToken = () => {
localStorage.removeItem(TokenKey);
Cookie.remove(TokenKey);
};
const getToken = () => {
return localStorage.getItem(TokenKey) || Cookie.get(TokenKey);
};
/** /**
* @description object value * @description object value
* @param obj * @param obj
@ -79,4 +89,4 @@ const isEmpty = (value: any) => {
return typeof value === 'object' ? _.isEmpty(value) : isNilValue(value); return typeof value === 'object' ? _.isEmpty(value) : isNilValue(value);
}; };
export { isPlainObject, isEmpty, filterEmptyField, setToken }; export { isPlainObject, isEmpty, filterEmptyField, setToken, removeToken, getToken };

@ -1,4 +1,4 @@
import { isPlainObject } from '../common'; import { getToken, isPlainObject } from '../common';
import { notification, message } from 'antd'; import { notification, message } from 'antd';
import Qs from 'qs'; import Qs from 'qs';
@ -40,8 +40,6 @@ const inital: RequestOptions = {
body: null, body: null,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization:
'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMCxiYW94aW55aV91c2VyIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTU3MzAwNzYsImlhdCI6MTY5NTEyNTI3Niwicm9sIjoiUk9MRV9VU0VSIn0.4cWyhllP7u-aoRAIHs3nMggsgl4-LUCVBas8WE0FJYIe-YNS0wGf1_0RJq3TUGw00KmSaSRPKdoPgRTFqEphZA',
}, },
credentials: true, credentials: true,
responseType: 'JSON', responseType: 'JSON',
@ -85,6 +83,11 @@ function request<T>(url: string, config: RequestOptions): Promise<Response<T>> {
} }
if (config.headers && isPlainObject(config.headers)) { if (config.headers && isPlainObject(config.headers)) {
config.headers = Object.assign({}, inital.headers, config.headers); config.headers = Object.assign({}, inital.headers, config.headers);
if (!config.headers?.Authorization) {
config.headers.Authorization = getToken();
}
} else {
config.headers = { Authorization: getToken(), 'Content-Type': 'application/json' };
} }
let { method, params, body, headers, credentials, responseType } = Object.assign({}, inital, config) as any; let { method, params, body, headers, credentials, responseType } = Object.assign({}, inital, config) as any;
if (typeof url !== 'string') throw new TypeError('url is not an string'); if (typeof url !== 'string') throw new TypeError('url is not an string');

Loading…
Cancel
Save