From 1671b2dbee506aef3d8d3f0e55e25af670d65fbb Mon Sep 17 00:00:00 2001 From: hutanglong Date: Sun, 24 Sep 2023 21:50:00 +0800 Subject: [PATCH] update user tenant log user --- .../console-new/src/page/item/create.tsx | 10 +- .../console-new/src/page/item/index.tsx | 14 +-- .../console-new/src/page/tenant/create.tsx | 96 +++++++++++++++ .../console-new/src/page/tenant/index.tsx | 46 +++++-- .../console-new/src/page/tenant/service.ts | 57 ++++----- .../console-new/src/page/user/create.tsx | 115 ++++++++++++++++++ .../console-new/src/page/user/index.tsx | 70 ++++++++--- .../console-new/src/page/user/service.ts | 72 ++++++----- 8 files changed, 373 insertions(+), 107 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/page/item/create.tsx b/threadpool/console-new/src/page/item/create.tsx index a776a039..f04fa140 100644 --- a/threadpool/console-new/src/page/item/create.tsx +++ b/threadpool/console-new/src/page/item/create.tsx @@ -83,22 +83,22 @@ const ItemCreate: React.FC = props => { + - + - + - + diff --git a/threadpool/console-new/src/page/item/index.tsx b/threadpool/console-new/src/page/item/index.tsx index cf64f5ca..b64a1167 100644 --- a/threadpool/console-new/src/page/item/index.tsx +++ b/threadpool/console-new/src/page/item/index.tsx @@ -1,5 +1,5 @@ import { useAntdTable, useRequest } from 'ahooks'; -import { Button, Form, Input, Row, Space, Table, Col, Modal, notification } from 'antd'; +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 { fetchDeleteItem, fetchItemList } from './service'; @@ -15,22 +15,18 @@ const baseColumns = [ { title: '租户', dataIndex: 'tenantId', - // with: 200, }, { title: '项目', dataIndex: 'itemId', - // with: 200, }, { title: '项目名称', dataIndex: 'itemName', - with: 200, }, { title: '负责人', dataIndex: 'owner', - with: 200, }, { title: '修改时间', @@ -54,7 +50,7 @@ const Tenant: React.FC = () => { const handleDelete = (item: any) => { Modal.confirm({ title: '提示', - content: `此操作将删除${item.itemName}, 是否继续?`, + content: `此操作将删除 ${item.itemId}, 是否继续?`, onOk: async () => { try { const res = await deleteRequest.runAsync(item.itemId); @@ -62,8 +58,8 @@ const Tenant: React.FC = () => { notification.success({ message: '删除成功' }); search.reset(); } - } catch (e) { - notification.error({ message: '删除失败' }); + } catch (e: any) { + message.error(e.message || '服务器开小差啦~'); } }, }); @@ -96,7 +92,7 @@ const Tenant: React.FC = () => { - + 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 b271d0e2..31dfc940 100644 --- a/threadpool/console-new/src/page/tenant/service.ts +++ b/threadpool/console-new/src/page/tenant/service.ts @@ -11,9 +11,9 @@ const fetchTenantOptions = async (tencent: string) => { }, }); if (res && res.success) { - return res.data && res.data.records.map((item: any) => ({ value: item.tenantId, label: item.tenantName })); + return res.data && res.data.records.map((item: any) => ({ value: item.tenantId, label: item.tenantId })); } - throw new Error(res.msg || '服务器开小差啦~'); + throw new Error(res.message || '服务器开小差啦~'); }; const fetchTenantList = async ( @@ -32,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 }, + body: { ...params }, }); - - 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 || '服务器开小差啦~'); + 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 { fetchTenantOptions, 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 };