From b46f098e2949a18228158151b4eba043ca23b0de Mon Sep 17 00:00:00 2001 From: hutanglong Date: Sun, 24 Sep 2023 00:50:43 +0800 Subject: [PATCH] edit logmanage --- .../src/config/theme/default-algnorithm.ts | 12 +- .../console-new/src/page/log/detail.tsx | 33 ++++++ threadpool/console-new/src/page/log/index.tsx | 108 +++++++++--------- .../console-new/src/page/log/service.ts | 65 +---------- .../console-new/src/page/tenant/index.tsx | 30 ++--- .../console-new/src/page/tenant/service.ts | 6 - .../console-new/src/utils/common/index.ts | 12 +- .../console-new/src/utils/request/index.ts | 9 +- 8 files changed, 132 insertions(+), 143 deletions(-) create mode 100644 threadpool/console-new/src/page/log/detail.tsx diff --git a/threadpool/console-new/src/config/theme/default-algnorithm.ts b/threadpool/console-new/src/config/theme/default-algnorithm.ts index b22cbcaf..bcb8e6b9 100644 --- a/threadpool/console-new/src/config/theme/default-algnorithm.ts +++ b/threadpool/console-new/src/config/theme/default-algnorithm.ts @@ -25,12 +25,12 @@ export const defaultAlgorithm = { // paddingContentVerticalLG: 4, }, Modal: { - borderRadiusLG: 2, - borderRadiusSM: 2, - colorText: lightDefaultTheme.fontColor.fc3, - borderRadius: 2, - paddingContentHorizontalLG: 0, - paddingMD: 0, + // borderRadiusLG: 2, + // borderRadiusSM: 2, + // colorText: lightDefaultTheme.fontColor.fc3, + // borderRadius: 2, + // paddingContentHorizontalLG: 0, + // paddingMD: 0, }, Menu: { itemBg: lightDefaultTheme.backgroundColor.bg1, diff --git a/threadpool/console-new/src/page/log/detail.tsx b/threadpool/console-new/src/page/log/detail.tsx new file mode 100644 index 00000000..fd753f20 --- /dev/null +++ b/threadpool/console-new/src/page/log/detail.tsx @@ -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 ( + + + + {data.category} + + + {data.bizNo} + + + {data.operator} + + + {data.createTime} + + + {data.action} + + + + ); +}; + +export default LogDetail; diff --git a/threadpool/console-new/src/page/log/index.tsx b/threadpool/console-new/src/page/log/index.tsx index a7c0b23f..0bcfcde4 100644 --- a/threadpool/console-new/src/page/log/index.tsx +++ b/threadpool/console-new/src/page/log/index.tsx @@ -1,85 +1,90 @@ import { useAntdTable } from 'ahooks'; -import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; -import { SearchOutlined, EditOutlined } from '@ant-design/icons'; +import { Button, Form, Input, Row, Space, Table, Col } from 'antd'; +import { SearchOutlined, RedoOutlined } from '@ant-design/icons'; import React, { useState } from 'react'; -import { fetchTenantList } from './service'; +import { fetchLogList } from './service'; import { useUrlSet } from '@/hooks/useUrlSet'; import style from './index.module.less'; +import LogDetail from './detail'; const baseColumns = [ { title: '序号', dataIndex: 'id', + width: 100, + // fixed: 'left', }, { - title: '租户', - dataIndex: 'tenantId', + title: '业务类型', + dataIndex: 'category', + width: 200, }, { - title: '租户名称', - dataIndex: 'tenantName', + title: '业务标识', + dataIndex: 'bizNo', + width: 380, }, { - title: '负责人', - dataIndex: 'owner', + title: '日志内容', + dataIndex: 'action', + width: 380, }, { - title: '修改时间', - dataIndex: 'gmtModified', + title: '操作人', + dataIndex: 'operator', + width: 100, + }, + { + title: '操作时间', + dataIndex: 'createTime', + width: 200, }, ]; const Tenant: React.FC = () => { - const [editVisible, setEditVisible] = useState(false); - const [type, setType] = useState('add'); + const [visible, setVisible] = useState(false); const [form] = Form.useForm(); const { setUrl } = useUrlSet({ form }); - const { tableProps, search } = useAntdTable(fetchTenantList, { form }); - // const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); - 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 { tableProps, search } = useAntdTable(fetchLogList, { form }); + const [curItems, setCurItems] = useState({}); const handleSearch = () => { setUrl(); search.submit(); }; - // const handleDelete = (item: any) => { - // Modal.confirm({ - // title: `此操作将删除${item.tenantName}, 是否继续?`, - // onOk: () => { - // search.submit(); - // }, - // }); - // }; + const handleDetail = (item: any) => { + setVisible(!visible); + setCurItems(item); + }; + const handleClose = () => { + setVisible(false); + }; return (
- - - + + + - + + + + + + + + + + + - @@ -93,26 +98,25 @@ const Tenant: React.FC = () => { {...tableProps} bordered rowKey="id" + scroll={{ x: 1000 }} columns={[ ...baseColumns, { + fixed: 'right', + width: 100, title: '操作', key: 'action', render: (text: string, record: any) => { return ( - - - - + ); }, }, ]} /> +
); }; diff --git a/threadpool/console-new/src/page/log/service.ts b/threadpool/console-new/src/page/log/service.ts index 2fab1ef7..d135380c 100644 --- a/threadpool/console-new/src/page/log/service.ts +++ b/threadpool/console-new/src/page/log/service.ts @@ -1,79 +1,24 @@ import request from '@/utils'; -const fetchTenantList = async ( +const fetchLogList = async ( pageProps: { current: number; pageSize: number }, - formData: { tencent: string | number } + formData: { category: string | number; bizNo: string; operator: string } ): Promise<{ total: number; list: Array }> => { - const res: any = await request('/hippo4j/v1/cs/tenant/query/page', { + const res: any = await request('/hippo4j/v1/cs/log/query/page', { method: 'POST', - headers: { - Authorization: - 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ', - cookie: - 'Admin-Token=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ; userName=baoxinyi_admin', - }, body: { ...formData, current: pageProps.current, size: pageProps.pageSize, - desc: true, }, }); if (res && res.success) { return { 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 || '服务器开小差啦~'); }; -const fetchAddTenant = async (id: string) => { - 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 }; +export { fetchLogList }; diff --git a/threadpool/console-new/src/page/tenant/index.tsx b/threadpool/console-new/src/page/tenant/index.tsx index 0d80beff..71e93db1 100644 --- a/threadpool/console-new/src/page/tenant/index.tsx +++ b/threadpool/console-new/src/page/tenant/index.tsx @@ -4,7 +4,6 @@ import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { useUrlSet } from '@/hooks/useUrlSet'; import { fetchTenantList } from './service'; - import style from './index.module.less'; const baseColumns = [ @@ -37,6 +36,19 @@ const Tenant: React.FC = () => { const { setUrl } = useUrlSet({ form }); const { tableProps, search } = useAntdTable(fetchTenantList, { form }); // 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) => { switch (type) { case 'add': @@ -46,24 +58,12 @@ const Tenant: React.FC = () => { setEditVisible(true); break; case 'delete': - // handleDelete(); + handleDelete(item); break; default: break; } }; - const handleSearch = () => { - setUrl(); - search.submit(); - }; - // const handleDelete = (item: any) => { - // Modal.confirm({ - // title: `此操作将删除${item.tenantName}, 是否继续?`, - // onOk: () => { - // search.submit(); - // }, - // }); - // }; return (
@@ -105,7 +105,7 @@ const Tenant: React.FC = () => { - diff --git a/threadpool/console-new/src/page/tenant/service.ts b/threadpool/console-new/src/page/tenant/service.ts index 2fab1ef7..181163e4 100644 --- a/threadpool/console-new/src/page/tenant/service.ts +++ b/threadpool/console-new/src/page/tenant/service.ts @@ -6,12 +6,6 @@ const fetchTenantList = async ( ): Promise<{ total: number; list: Array }> => { const res: any = await request('/hippo4j/v1/cs/tenant/query/page', { method: 'POST', - headers: { - Authorization: - 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ', - cookie: - 'Admin-Token=Bearer%20eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3LGJhb3hpbnlpX2FkbWluIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTUzOTg4NDksImlhdCI6MTY5NDc5NDA0OSwicm9sIjoiUk9MRV9BRE1JTiJ9.syRDshKpd-xETsSdeMPRtk956f4BJkPt4utVsUl4smgH71Woj8SUq4w2RX1YtGTC4aTZRJYdKOfkTqwK0g_dHQ; userName=baoxinyi_admin', - }, body: { ...formData, current: pageProps.current, diff --git a/threadpool/console-new/src/utils/common/index.ts b/threadpool/console-new/src/utils/common/index.ts index 8ae65582..a087d7f4 100644 --- a/threadpool/console-new/src/utils/common/index.ts +++ b/threadpool/console-new/src/utils/common/index.ts @@ -49,9 +49,19 @@ const isPlainObject = (obj: { [key: string]: any }): boolean => { }; const setToken = (token: string) => { + localStorage.setItem(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 为空的元素 * @param obj @@ -79,4 +89,4 @@ const isEmpty = (value: any) => { return typeof value === 'object' ? _.isEmpty(value) : isNilValue(value); }; -export { isPlainObject, isEmpty, filterEmptyField, setToken }; +export { isPlainObject, isEmpty, filterEmptyField, setToken, removeToken, getToken }; diff --git a/threadpool/console-new/src/utils/request/index.ts b/threadpool/console-new/src/utils/request/index.ts index 7a537a87..6186d547 100644 --- a/threadpool/console-new/src/utils/request/index.ts +++ b/threadpool/console-new/src/utils/request/index.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from '../common'; +import { getToken, isPlainObject } from '../common'; import { notification, message } from 'antd'; import Qs from 'qs'; @@ -40,8 +40,6 @@ const inital: RequestOptions = { body: null, headers: { 'Content-Type': 'application/json', - Authorization: - 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMCxiYW94aW55aV91c2VyIiwiaXNzIjoiYWRtaW4iLCJleHAiOjE2OTU3MzAwNzYsImlhdCI6MTY5NTEyNTI3Niwicm9sIjoiUk9MRV9VU0VSIn0.4cWyhllP7u-aoRAIHs3nMggsgl4-LUCVBas8WE0FJYIe-YNS0wGf1_0RJq3TUGw00KmSaSRPKdoPgRTFqEphZA', }, credentials: true, responseType: 'JSON', @@ -85,6 +83,11 @@ function request(url: string, config: RequestOptions): Promise> { } if (config.headers && isPlainObject(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; if (typeof url !== 'string') throw new TypeError('url is not an string');