From 159fd9cbad2888c677637666bb4f674a7660f30d Mon Sep 17 00:00:00 2001 From: baiJinjin <66710700+baiJinjin@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:03:25 +0800 Subject: [PATCH] perfect the user log tenant and project modules (#1478) * Add user log item Manage * edit Item Management * merge from develop * add router * add router * edit logmanage * edit tenant * update item * update user tenant log user * edit userName --- .../console-new/src/config/i18n/locales/zh.ts | 2 +- .../console-new/src/page/item/create.tsx | 107 +++++++++++++--- .../console-new/src/page/item/index.tsx | 42 +++++-- .../console-new/src/page/item/service.ts | 40 +++--- .../console-new/src/page/tenant/create.tsx | 96 +++++++++++++++ .../console-new/src/page/tenant/index.tsx | 46 +++++-- .../console-new/src/page/tenant/service.ts | 69 ++++++----- .../console-new/src/page/user/create.tsx | 115 ++++++++++++++++++ .../console-new/src/page/user/index.tsx | 70 ++++++++--- .../console-new/src/page/user/service.ts | 72 ++++++----- 10 files changed, 525 insertions(+), 134 deletions(-) create mode 100644 threadpool/console-new/src/page/tenant/create.tsx create mode 100644 threadpool/console-new/src/page/user/create.tsx diff --git a/threadpool/console-new/src/config/i18n/locales/zh.ts b/threadpool/console-new/src/config/i18n/locales/zh.ts index 301d4a4b..0d3bdaf3 100644 --- a/threadpool/console-new/src/config/i18n/locales/zh.ts +++ b/threadpool/console-new/src/config/i18n/locales/zh.ts @@ -21,7 +21,7 @@ const zhTranslationMap: { [key: string]: string } = { [STR_MAP.EDIT]: '操作', [STR_MAP.TENANT_MANAGE]: '租户管理', [STR_MAP.PROJECT_MANAGE]: '项目管理', - [STR_MAP.USER_MANAGE]: '用户管理', + [STR_MAP.USER_MANAGE]: '用户权限', [STR_MAP.LOG_MANAGE]: '日志管理', }; diff --git a/threadpool/console-new/src/page/item/create.tsx b/threadpool/console-new/src/page/item/create.tsx index 860aef60..f04fa140 100644 --- a/threadpool/console-new/src/page/item/create.tsx +++ b/threadpool/console-new/src/page/item/create.tsx @@ -1,29 +1,104 @@ import { useRequest } from 'ahooks'; -import { Form, Modal, Input, Select } from 'antd'; -import React from 'react'; -import { fetchTenantList } from '../tenant/service'; +import { Form, Modal, Input, Select, notification } from 'antd'; +import React, { useEffect } from 'react'; +import { fetchTenantOptions } from '../tenant/service'; +import { fetchAddItem, fetchUpdateItem } from './service'; -const ItemCreate: React.FC<{ +interface IProps { type: string; data: any; visible: boolean; onClose: () => void; -}> = props => { - const { visible, onClose, data, type } = props; - const { data: tenant } = useRequest(fetchTenantList); - console.log('tenant', tenant); + reset: () => void; +} + +const ItemCreate: React.FC = props => { + const { visible, onClose, data, type, reset } = props; + const [form] = Form.useForm(); + const tenantRequest = useRequest(fetchTenantOptions, { + ready: !!type, + }); + const updateRequest = useRequest(fetchUpdateItem, { + manual: true, + onSuccess: () => { + notification.success({ message: '更新成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + notification.error({ message: err.message }); + }, + }); + const addRequest = useRequest(fetchAddItem, { + manual: true, + onSuccess: () => { + notification.success({ message: '创建成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + notification.error({ message: err.message }); + }, + }); + const onSave = () => { + form + .validateFields() + .then(values => { + addRequest.run({ ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + const onUpdate = () => { + form + .validateFields() + .then(values => { + updateRequest.run({ id: data.id, ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + useEffect(() => { + if (type === 'edit') { + form.setFieldsValue({ + ...data, + }); + } + }, [type, data, form]); return ( - -
- - {/* */} + + + + + + + - - + + - - + + diff --git a/threadpool/console-new/src/page/item/index.tsx b/threadpool/console-new/src/page/item/index.tsx index ea506206..55cfc618 100644 --- a/threadpool/console-new/src/page/item/index.tsx +++ b/threadpool/console-new/src/page/item/index.tsx @@ -1,8 +1,8 @@ -import { useAntdTable } from 'ahooks'; -import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; +import { useAntdTable, useRequest } from 'ahooks'; +import { Button, Form, Input, Row, Space, Table, Col, Modal, notification, message } from 'antd'; import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import React, { useState } from 'react'; -import { fetchItemList } from './service'; +import { fetchDeleteItem, fetchItemList } from './service'; import { useUrlSet } from '@/hooks/useUrlSet'; import style from './index.module.less'; import ItemCreate from './create'; @@ -23,6 +23,10 @@ const baseColumns = [ dataIndex: 'itemId', with: 200, }, + { + title: '项目', + dataIndex: 'itemId', + }, { title: '项目名称', dataIndex: 'itemName', @@ -46,16 +50,26 @@ const Tenant: React.FC = () => { const [form] = Form.useForm(); const { setUrl } = useUrlSet({ form }); const { tableProps, search } = useAntdTable(fetchItemList, { form }); - // const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); + const deleteRequest = useRequest(fetchDeleteItem, { manual: true }); + const handleSearch = () => { setUrl(); search.submit(); }; const handleDelete = (item: any) => { Modal.confirm({ - title: `此操作将删除${item.itemName}, 是否继续?`, - onOk: () => { - search.submit(); + title: '提示', + content: `此操作将删除 ${item.itemId}, 是否继续?`, + onOk: async () => { + try { + const res = await deleteRequest.runAsync(item.itemId); + if (res && res.success) { + notification.success({ message: '删除成功' }); + search.reset(); + } + } catch (e: any) { + message.error(e.message || '服务器开小差啦~'); + } }, }); }; @@ -87,7 +101,7 @@ const Tenant: React.FC = () => { - + @@ -95,7 +109,7 @@ const Tenant: React.FC = () => { - @@ -131,7 +145,15 @@ const Tenant: React.FC = () => { }, ]} /> - + {editVisible && ( + search.reset()} + /> + )} ); }; diff --git a/threadpool/console-new/src/page/item/service.ts b/threadpool/console-new/src/page/item/service.ts index babf4216..0e8bbdf9 100644 --- a/threadpool/console-new/src/page/item/service.ts +++ b/threadpool/console-new/src/page/item/service.ts @@ -19,10 +19,10 @@ const fetchItemList = async ( list: res.data.records.map((item: any, index: number) => ({ index: index + 1, ...item })), }; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchAddTenant = async (params: { +const fetchAddItem = async (params: { itemDesc: string; // 项目简介 itemId: string; // 项目 itemName: string; // 项目名称 @@ -31,39 +31,47 @@ const fetchAddTenant = async (params: { tenantDesc?: string; tenantName?: string; }) => { - const res = await request('/hippo4j/v1/cs/tenant/save', { + const res = await request('/hippo4j/v1/cs/item/save', { method: 'POST', body: { ...params }, }); - if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchDeleteItem = async (id: string) => { - const url = 'hippo4j/v1/cs/item/delete/prescription/' + id; - const res = await request(url, { - method: 'DELETE', +const fetchUpdateItem = async (params: { + id: string; + itemDesc: string; // 项目简介 + itemId: string; // 项目 + itemName: string; // 项目名称 + owner: string; // 负责人 + tenantId: string; // 租户 + tenantDesc?: string; + tenantName?: string; +}) => { + const res = await request('/hippo4j/v1/cs/item/update', { + method: 'POST', + body: { ...params }, }); if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchUpdateItem = async (id: string) => { - const res = await request('/hippo4j/v1/cs/item/update', { - method: 'POST', - params: { id }, +const fetchDeleteItem = async (id: string) => { + const url = 'hippo4j/v1/cs/item/delete/prescription/' + id; + const res = await request(url, { + method: 'DELETE', }); if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -export { fetchItemList, fetchAddTenant, fetchDeleteItem, fetchUpdateItem }; +export { fetchItemList, fetchAddItem, fetchDeleteItem, fetchUpdateItem }; diff --git a/threadpool/console-new/src/page/tenant/create.tsx b/threadpool/console-new/src/page/tenant/create.tsx new file mode 100644 index 00000000..ee4c065e --- /dev/null +++ b/threadpool/console-new/src/page/tenant/create.tsx @@ -0,0 +1,96 @@ +import { useRequest } from 'ahooks'; +import { Form, Modal, Input, notification } from 'antd'; +import React, { useEffect } from 'react'; +import { fetchAddTenant, fetchUpdateTenant } from './service'; + +interface IProps { + type: string; + data: any; + visible: boolean; + onClose: () => void; + reset: () => void; +} + +const TenantCreate: React.FC = props => { + const { visible, onClose, data, type, reset } = props; + const [form] = Form.useForm(); + const updateRequest = useRequest(fetchUpdateTenant, { + manual: true, + onSuccess: () => { + notification.success({ message: '更新成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + notification.error({ message: err.message }); + }, + }); + const addRequest = useRequest(fetchAddTenant, { + manual: true, + onSuccess: () => { + notification.success({ message: '创建成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + notification.error({ message: err.message }); + }, + }); + const onSave = () => { + form + .validateFields() + .then(values => { + addRequest.run({ ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + const onUpdate = () => { + form + .validateFields() + .then(values => { + updateRequest.run({ id: data.id, ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + useEffect(() => { + if (type === 'edit') { + form.setFieldsValue({ + ...data, + }); + } + }, [type, data, form]); + + return ( + +
+ + + + + + + + + + + + +
+
+ ); +}; + +export default TenantCreate; diff --git a/threadpool/console-new/src/page/tenant/index.tsx b/threadpool/console-new/src/page/tenant/index.tsx index 71e93db1..5af8ac52 100644 --- a/threadpool/console-new/src/page/tenant/index.tsx +++ b/threadpool/console-new/src/page/tenant/index.tsx @@ -1,15 +1,16 @@ import React, { useState } from 'react'; -import { useAntdTable } from 'ahooks'; -import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; +import { useAntdTable, useRequest } from 'ahooks'; +import { Button, Form, Input, Row, Space, Table, Col, Modal, notification, message } from 'antd'; import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { useUrlSet } from '@/hooks/useUrlSet'; -import { fetchTenantList } from './service'; +import { fetchDeleteTenant, fetchTenantList } from './service'; import style from './index.module.less'; +import TenantCreate from './create'; const baseColumns = [ { title: '序号', - dataIndex: 'id', + dataIndex: 'index', }, { title: '租户', @@ -31,11 +32,13 @@ const baseColumns = [ const Tenant: React.FC = () => { const [editVisible, setEditVisible] = useState(false); + const [curItem, setCurItem] = useState({}); const [type, setType] = useState('add'); const [form] = Form.useForm(); const { setUrl } = useUrlSet({ form }); const { tableProps, search } = useAntdTable(fetchTenantList, { form }); - // const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); + const deleteRequest = useRequest(fetchDeleteTenant, { manual: true }); + const handleSearch = () => { setUrl(); search.submit(); @@ -43,18 +46,29 @@ const Tenant: React.FC = () => { const handleDelete = (item: any) => { Modal.confirm({ title: '提示', - content: `此操作将删除${item.tenantName},是否继续?`, - onOk: () => { - search.submit(); + content: `此操作将删除 ${item.tenantId},是否继续?`, + onOk: async () => { + try { + const res = await deleteRequest.runAsync(item.tenantId); + if (res && res.success) { + notification.success({ message: '删除成功' }); + search.reset(); + } + } catch (e: any) { + message.error(e.message || '服务器开小差啦~'); + } }, }); }; const actions = (type: string, item?: any) => { switch (type) { case 'add': + setType('add'); setEditVisible(true); break; case 'edit': + setType('edit'); + setCurItem(item); setEditVisible(true); break; case 'delete': @@ -64,6 +78,9 @@ const Tenant: React.FC = () => { break; } }; + const handleClose = () => { + setEditVisible(false); + }; return (
@@ -71,7 +88,7 @@ const Tenant: React.FC = () => { - + @@ -79,7 +96,7 @@ const Tenant: React.FC = () => { - @@ -114,6 +131,15 @@ const Tenant: React.FC = () => { }, ]} /> + {editVisible && ( + search.reset()} + /> + )}
); }; diff --git a/threadpool/console-new/src/page/tenant/service.ts b/threadpool/console-new/src/page/tenant/service.ts index 181163e4..31dfc940 100644 --- a/threadpool/console-new/src/page/tenant/service.ts +++ b/threadpool/console-new/src/page/tenant/service.ts @@ -1,5 +1,21 @@ import request from '@/utils'; +const fetchTenantOptions = async (tencent: string) => { + const res: any = await request('/hippo4j/v1/cs/tenant/query/page', { + method: 'POST', + body: { + tencent, + current: 1, + size: 10, + desc: true, + }, + }); + if (res && res.success) { + return res.data && res.data.records.map((item: any) => ({ value: item.tenantId, label: item.tenantId })); + } + throw new Error(res.message || '服务器开小差啦~'); +}; + const fetchTenantList = async ( pageProps: { current: number; pageSize: number }, formData: { tencent: string | number } @@ -16,58 +32,53 @@ const fetchTenantList = async ( if (res && res.success) { return { total: res.data.total, - list: res.data.records, + list: res.data.records.map((item: any, index: number) => ({ index: index + 1, ...item })), }; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchAddTenant = async (id: string) => { +const fetchAddTenant = async (params: { + tenantDesc: string; // 项目简介 + tenantId: string; // 项目 + tenantName: string; // 项目名称 + owner: 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 }, + body: { ...params }, }); - if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchUpdateTenant = async (id: string) => { +const fetchUpdateTenant = async (params: { + tenantDesc: string; // 项目简介 + tenantId: string; // 项目 + tenantName: string; // 项目名称 + owner: string; // 负责人 +}) => { const res = await request('hippo4j/v1/cs/tenant/update', { method: 'POST', - params: { id }, + body: { ...params }, }); - if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchTenantDetail = async (id: string) => { - const res = await request('/tenants', { - method: 'POST', - params: { id }, +const fetchDeleteTenant = async (id: string) => { + const url = 'hippo4j/v1/cs/item/delete/prescription/' + id; + const res = await request(url, { + method: 'DELETE', }); - if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -export { fetchTenantList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant, fetchTenantDetail }; +export { fetchTenantOptions, fetchTenantList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant }; diff --git a/threadpool/console-new/src/page/user/create.tsx b/threadpool/console-new/src/page/user/create.tsx new file mode 100644 index 00000000..6a397a3b --- /dev/null +++ b/threadpool/console-new/src/page/user/create.tsx @@ -0,0 +1,115 @@ +import { useRequest } from 'ahooks'; +import { Form, Modal, Input, notification, Select, Checkbox, message } from 'antd'; +import React, { useEffect } from 'react'; +import { fetchAddUser, fetchUpdateUser } from './service'; +import { fetchTenantOptions } from '../tenant/service'; + +interface IProps { + type: string; + data: any; + visible: boolean; + onClose: () => void; + reset: () => void; +} + +const ROLE_OPTIONS = [ + { + label: 'ROLE_USER', + value: 'ROLE_USER', + }, + { + label: 'ROLE_ADMIN', + value: 'ROLE_ADMIN', + }, + { + label: 'ROLE_MANAGE', + value: 'ROLE_MANAGE', + }, +]; + +const UserCreate: React.FC = props => { + const { visible, onClose, data, type, reset } = props; + const [form] = Form.useForm(); + const tenantRequest = useRequest(fetchTenantOptions, { + ready: !!type, + }); + const updateRequest = useRequest(fetchUpdateUser, { + manual: true, + onSuccess: () => { + notification.success({ message: '更新成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + message.error(err.message); + }, + }); + const addRequest = useRequest(fetchAddUser, { + manual: true, + onSuccess: () => { + notification.success({ message: '创建成功' }); + form.resetFields(); + onClose(); + reset(); + }, + onError: err => { + message.error(err.message); + }, + }); + const onSave = () => { + form + .validateFields() + .then(values => { + addRequest.run({ ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + const onUpdate = () => { + form + .validateFields() + .then(values => { + updateRequest.run({ id: data.id, ...values }); + }) + .catch(info => { + console.log('Validate Failed:', info); + }); + }; + useEffect(() => { + if (type === 'edit') { + form.setFieldsValue({ + ...data, + }); + } + }, [type, data, form]); + + return ( + +
+ + + + + + + + + @@ -78,7 +96,7 @@ const Tenant: React.FC = () => { - @@ -104,7 +122,12 @@ const Tenant: React.FC = () => { - @@ -113,6 +136,15 @@ const Tenant: React.FC = () => { }, ]} /> + {editVisible && ( + search.reset()} + /> + )} ); }; diff --git a/threadpool/console-new/src/page/user/service.ts b/threadpool/console-new/src/page/user/service.ts index 51e68bff..6c9c5e33 100644 --- a/threadpool/console-new/src/page/user/service.ts +++ b/threadpool/console-new/src/page/user/service.ts @@ -6,12 +6,6 @@ const fetchUserList = async ( ): Promise<{ total: number; list: Array }> => { const res: any = await request('/hippo4j/v1/cs/auth/users/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, @@ -24,55 +18,67 @@ const fetchUserList = async ( list: res.data.records.map((item: any, index: number) => ({ index: index + 1, ...item })), }; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchAddTenant = async (id: string) => { - const res = await request('/hippo4j/v1/cs/tenant/save', { +const fetchAddUser = async (params: { + password?: string; + permission?: string; + role: string; + userName: string; + tempResources: Array; + tenant: Array; + resources?: Array<{ resource: string; action: 'rw' }>; +}) => { + const { tempResources = [] } = params; + const res = await request('/hippo4j/v1/cs/auth/users/add', { method: 'POST', - params: { id }, + body: { + ...params, + tempResources: tempResources.length > 0 ? true : false, + resources: tempResources.map(item => ({ resource: item, action: 'rw' })), + }, }); if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchDeleteTenant = async (id: string) => { - const res = await request('/tenants', { - method: 'POST', - params: { id }, - }); - - if (res && res.success) { - return res; +const fetchUpdateUser = async (params: { + password?: string; + permission?: string; + role: string; + userName: string; + tempResources: Array; + resources?: Array<{ resource: string; action: 'rw' }>; +}) => { + const { tempResources = [] } = params; + if (tempResources.length > 0) { + params.resources = tempResources.map(item => ({ resource: item, action: 'rw' })); } - throw new Error(res.msg || '服务器开小差啦~'); -}; - -const fetchUpdateTenant = async (id: string) => { - const res = await request('hippo4j/v1/cs/tenant/update', { - method: 'POST', - params: { id }, + const res = await request('/hippo4j/v1/cs/auth/users/update', { + method: 'PUT', + body: { ...params }, }); if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -const fetchTenantDetail = async (id: string) => { - const res = await request('/tenants', { - method: 'POST', - params: { id }, +const fetchDeleteUser = async (id: string) => { + const url = '/hippo4j/v1/cs/auth/users/remove/' + id; + const res = await request(url, { + method: 'DELETE', }); if (res && res.success) { return res; } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; -export { fetchUserList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant, fetchTenantDetail }; +export { fetchUserList, fetchAddUser, fetchDeleteUser, fetchUpdateUser };