diff --git a/zlt-web/src/main/frontend/config/proxy.ts b/zlt-web/src/main/frontend/config/proxy.ts index e44df51a..166ab746 100644 --- a/zlt-web/src/main/frontend/config/proxy.ts +++ b/zlt-web/src/main/frontend/config/proxy.ts @@ -8,32 +8,24 @@ */ export default { dev: { - // localhost:8000/api/** -> https://preview.pro.ant.design/api/** - '/api/': { - // 要代理的地址 - target: 'https://preview.pro.ant.design', - // 配置了这个可以从 http 代理到 https - // 依赖 origin 的功能可能需要这个,比如 cookie - changeOrigin: true, - }, '/api-uaa/': { - target: 'http://gateway.zlt2000.cn', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-user/': { - target: 'http://gateway.zlt2000.cn', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-log/': { - target: 'http://gateway.zlt2000.cn', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-search/': { - target: 'http://gateway.zlt2000.cn', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-generator/': { - target: 'http://gateway.zlt2000.cn', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, }, diff --git a/zlt-web/src/main/frontend/src/pages/system/App/index.tsx b/zlt-web/src/main/frontend/src/pages/system/App/index.tsx index 9b70a58b..1341f895 100644 --- a/zlt-web/src/main/frontend/src/pages/system/App/index.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/App/index.tsx @@ -1,14 +1,28 @@ -import { app } from '@/services/system/api'; -import type { ProColumns } from '@ant-design/pro-components'; +import { app, deleteApp } from '@/services/system/api'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components'; -import { Typography, message } from 'antd'; -import React, { useState } from 'react'; +import { Typography, message, Popconfirm } from 'antd'; +import React, { useRef, useState } from 'react'; const { Link } = Typography; +const handleDelete = async (data: SYSTEM.App) => { + const hide = message.loading('正在删除'); + try { + await deleteApp(data.id); + hide(); + message.success('删除应用成功'); + return true; + } catch (error) { + hide(); + message.error('删除应用失败'); + return false; + } +}; + const TableList: React.FC = () => { const [params, setParams] = useState>(); - + const actionRef = useRef(); const columns: ProColumns[] = [ { dataIndex: 'index', @@ -73,7 +87,19 @@ const TableList: React.FC = () => { key: 'action', fixed: 'right', width: 40, - render: () => message.info('演示环境不支持该功能')}>删除, + render: (_, entity) => { + const success = await handleDelete(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + , }, ]; return ( @@ -90,7 +116,8 @@ const TableList: React.FC = () => { rowKey="id" - headerTitle="Token管理" + headerTitle="应用管理" + actionRef={actionRef} request={app} columns={columns} search={false} diff --git a/zlt-web/src/main/frontend/src/pages/system/Menu/index.tsx b/zlt-web/src/main/frontend/src/pages/system/Menu/index.tsx index 1d477113..a87b7e82 100644 --- a/zlt-web/src/main/frontend/src/pages/system/Menu/index.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/Menu/index.tsx @@ -1,24 +1,26 @@ import { menu } from '@/services/system/api'; import { treeify } from '@/util/treeify'; -import { FolderOpenOutlined, MenuOutlined, ProfileOutlined } from '@ant-design/icons'; +import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined } from '@ant-design/icons'; import type { ProColumns } from '@ant-design/pro-components'; import { ProFormSelect } from '@ant-design/pro-components'; import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components'; -import { Space, Tag, Typography } from 'antd'; +import { Button, Space, Tag, Typography } from 'antd'; import React, { useEffect, useState } from 'react'; const { Link } = Typography; const Generator: React.FC = () => { const [data, setData] = useState(); - + const [keys, setKeys] = useState<(React.Key)[]>([]); + const [expandedRowKeys, setExpandedRowKeys] = useState<(React.Key)[]>([]); const query = async (params: Record) => { - const menus = (await menu(params)) ?? []; + const menus = await menu(params); const treeData = treeify(menus, {}); menus.forEach((node) => { if (node.children && node.children.length === 0) delete node.children; }); // debugger; + setKeys(menus.map(m=>m.id)); setData(treeData); }; @@ -30,7 +32,7 @@ const Generator: React.FC = () => { { title: '菜单名称', key: 'name', - width: 80, + width: 120, render(dom, entity) { if (entity.type === 1) { if (entity.url?.startsWith('javascript')) { @@ -136,6 +138,36 @@ const Generator: React.FC = () => { columns={columns} search={false} pagination={false} + expandable={{ + expandedRowKeys, + onExpandedRowsChange: (expandedRows) => setExpandedRowKeys([...expandedRows]), + }} + toolBarRender={() => [ + <> + + + + , + ]} /> ); diff --git a/zlt-web/src/main/frontend/src/pages/system/Role/components/AssignAuth.tsx b/zlt-web/src/main/frontend/src/pages/system/Role/components/AssignAuth.tsx index 6eb167eb..999d1d18 100644 --- a/zlt-web/src/main/frontend/src/pages/system/Role/components/AssignAuth.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/Role/components/AssignAuth.tsx @@ -1,11 +1,11 @@ -import { menuForAuth } from '@/services/system/api'; +import { assignMenu, menuForAuth } from '@/services/system/api'; import { treeify } from '@/util/treeify'; import type { TreeDataNode } from 'antd'; import { Modal, Tree, message } from 'antd'; import React, { useEffect, useState } from 'react'; type AssignAuthProps = { - roleId?: number; + roleId: number; tenantId?: string; onCancel: () => void; assignModalVisible: boolean; @@ -13,6 +13,25 @@ type AssignAuthProps = { type Key = string | number; +const handleAssign = async (roleId: number, menuIds: Key[]) => { + const hide = message.loading('正在添加'); + try { + const result = await assignMenu({ roleId, menuIds }); + hide(); + if (result.resp_code === 0) { + message.success('权限分配成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('权限分配失败'); + return false; + } +}; + const AssignAuth: React.FC = (props) => { const [treeData, setTreeData] = useState([]); const [checkedKeys, setCheckedKeys] = useState([]); @@ -39,9 +58,14 @@ const AssignAuth: React.FC = (props) => { // layout="horizontal" open={props.assignModalVisible} // initialValues={formData} - onOk={() => { - message.info('演示环境不支持该功能'); - props.onCancel(); + destroyOnClose + onOk={async () => { + const success = await handleAssign(roleId, checkedKeys); + if (success) { + setTreeData([]); + setCheckedKeys([]); + props.onCancel();; + } }} onCancel={() => { setTreeData([]); diff --git a/zlt-web/src/main/frontend/src/pages/system/Role/components/UpdateForm.tsx b/zlt-web/src/main/frontend/src/pages/system/Role/components/UpdateForm.tsx index d5930524..2fb64a0a 100644 --- a/zlt-web/src/main/frontend/src/pages/system/Role/components/UpdateForm.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/Role/components/UpdateForm.tsx @@ -9,10 +9,10 @@ import React, { useEffect } from 'react'; export type FormValueType = Partial; export type UpdateFormProps = { - onCancel: (flag?: boolean, formVals?: FormValueType) => void; + onVisibleChange: (flag: boolean) => void; onSubmit: (values: FormValueType) => Promise; updateModalVisible: boolean; - values: Partial; + values?: SYSTEM.Role; }; const UpdateForm: React.FC = (props) => { @@ -32,7 +32,7 @@ const UpdateForm: React.FC = (props) => { visible={props.updateModalVisible} // initialValues={formData} onFinish={props.onSubmit} - onVisibleChange={props.onCancel} + onVisibleChange={props.onVisibleChange} > { + const hide = message.loading('正在添加'); + try { + const result = await saveOrUpdateRole({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('添加角色成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('添加角色失败'); + return false; + } +}; + +const handleEdit = async (fields: SYSTEM.Role) => { + const hide = message.loading('正在更新'); + try { + const result = await saveOrUpdateRole({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('修改角色成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('修改角色失败'); + return false; + } +}; + +const handleDelete = async (data: SYSTEM.Role) => { + const hide = message.loading('正在删除'); + try { + const result = await deleteRole(data.id); + hide(); + if (result.resp_code === 0) { + message.success('删除角色成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('删除角色失败'); + return false; + } +}; + const TableList: React.FC = () => { const [params, setParams] = useState>({}); - + const actionRef = useRef(); const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); - const [currentRow, setCurrentRow] = useState(); + const [currentRow, setCurrentRow] = useState(); const [assignAuth, setAssignAuth] = useState({ assignModalVisible: false }); @@ -59,20 +116,32 @@ const TableList: React.FC = () => { { title: '操作', key: 'action', - render: (_, record) => ( + render: (_, entity) => ( { handleUpdateModalVisible(true); - setCurrentRow(record); + setCurrentRow(entity); }} > 修改 - message.info('演示环境不支持该功能')}>删除 + { + const success = await handleDelete(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + { - setAssignAuth({ roleId: record.id, assignModalVisible: true, tenantId: 'webApp' }); + setAssignAuth({ roleId: entity.id, assignModalVisible: true, tenantId: 'webApp' }); }} > 权限分配 @@ -112,6 +181,7 @@ const TableList: React.FC = () => { rowKey="id" headerTitle="角色管理" + actionRef={actionRef} request={pageRole} columns={columns} search={false} @@ -139,8 +209,15 @@ const TableList: React.FC = () => { width={500} visible={createModalVisible} onVisibleChange={handleModalVisible} - onFinish={async () => { - message.info('演示环境不支持该功能'); + modalProps={{ destroyOnClose: true }} + onFinish={async (values) => { + const success = await handleAdd(values as SYSTEM.Role); + if (success) { + handleModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } }} > @@ -171,17 +248,21 @@ const TableList: React.FC = () => { { - message.info('演示环境不支持该功能'); - handleUpdateModalVisible(false); - setCurrentRow(undefined); - }} - onCancel={(flag) => { - handleUpdateModalVisible(flag ?? true); - setCurrentRow(undefined); + onSubmit={async (values) => { + if (currentRow) { + const success = await handleEdit({ ...currentRow, ...values }); + if (success) { + handleUpdateModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } + setCurrentRow(undefined); + } }} + onVisibleChange={handleUpdateModalVisible} updateModalVisible={updateModalVisible} - values={currentRow || {}} + values={currentRow} /> setAssignAuth({ assignModalVisible: false })} /> diff --git a/zlt-web/src/main/frontend/src/pages/system/User/components/UpdateForm.tsx b/zlt-web/src/main/frontend/src/pages/system/User/components/UpdateForm.tsx index 20069c16..dcb8a428 100644 --- a/zlt-web/src/main/frontend/src/pages/system/User/components/UpdateForm.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/User/components/UpdateForm.tsx @@ -10,14 +10,14 @@ import { Form } from 'antd'; import React, { useEffect } from 'react'; export type FormValueType = { - roleCodes?: string[]; + roleIds?: number[]; } & Partial; export type UpdateFormProps = { - onCancel: (flag?: boolean, formVals?: FormValueType) => void; + onVisibleChange: (flag: boolean) => void; onSubmit: (values: FormValueType) => Promise; updateModalVisible: boolean; - values: Partial; + values?: SYSTEM.User; }; const UpdateForm: React.FC = (props) => { @@ -25,9 +25,9 @@ const UpdateForm: React.FC = (props) => { const { values } = props; useEffect(() => { - if (values.roles) { - const roleCodes = values.roles.map((r) => r.code); - const formData: FormValueType = { ...values, roleCodes }; + if (values?.roles) { + const roleIds = values.roles.map((r) => r.id); + const formData: FormValueType = { ...values, roleIds }; form.setFieldsValue(formData); } }, [form, values]); @@ -39,7 +39,7 @@ const UpdateForm: React.FC = (props) => { visible={props.updateModalVisible} // initialValues={formData} onFinish={props.onSubmit} - onVisibleChange={props.onCancel} + onVisibleChange={props.onVisibleChange} > = (props) => { /> { const roles = await role(); if (roles) return roles.map((r) => { - return { label: r.name, value: r.code }; + return { label: r.name, value: r.id }; }); return []; }} diff --git a/zlt-web/src/main/frontend/src/pages/system/User/index.tsx b/zlt-web/src/main/frontend/src/pages/system/User/index.tsx index 4468dee7..be59b379 100644 --- a/zlt-web/src/main/frontend/src/pages/system/User/index.tsx +++ b/zlt-web/src/main/frontend/src/pages/system/User/index.tsx @@ -1,6 +1,15 @@ -import { user, exportUser, role } from '@/services/system/api'; +import { + user, + saveOrUpdateUser, + exportUser, + role, + updateEnabled, + resetPassword, + deleteUser, + importUser, +} from '@/services/system/api'; import { ExportOutlined, ImportOutlined, PlusOutlined } from '@ant-design/icons'; -import type { ProColumns } from '@ant-design/pro-components'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { ProFormRadio, ProFormSelect, @@ -11,16 +20,131 @@ import { ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Space, Typography } from 'antd'; +import { Popconfirm, Space, Typography, Upload } from 'antd'; import { Button, Switch, message } from 'antd'; -import React, { useState } from 'react'; +import type { RcFile } from 'antd/lib/upload'; +import React, { useRef, useState } from 'react'; import UpdateForm from './components/UpdateForm'; const { Link } = Typography; +const handleAdd = async (fields: SYSTEM.User) => { + const hide = message.loading('正在添加'); + try { + const result = await saveOrUpdateUser({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('添加用户成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('添加用户失败'); + return false; + } +}; + +const handleEdit = async (fields: SYSTEM.User) => { + const hide = message.loading('正在更新'); + try { + const result = await saveOrUpdateUser({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('修改用户成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('修改用户失败'); + return false; + } +}; + +const swichUser = async (sysUser: SYSTEM.User) => { + const hide = message.loading('正在更新'); + try { + const result = await updateEnabled(sysUser.id, !sysUser.enabled); + hide(); + if (result.resp_code === 0) { + message.success('修改用户成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('修改用户失败'); + return false; + } +}; + +const handleResetPassword = async (sysUser: SYSTEM.User) => { + const hide = message.loading('正在更新'); + try { + const result = await resetPassword(sysUser.id); + hide(); + if (result.resp_code === 0) { + message.success('重置密码成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('重置密码失败'); + return false; + } +}; + +const handleDelete = async (sysUser: SYSTEM.User) => { + const hide = message.loading('正在删除'); + try { + const result = await deleteUser(sysUser.id); + hide(); + if (result.resp_code === 0) { + message.success('删除用户成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('删除用户失败'); + return false; + } +}; + +const handleImport = async (file: RcFile) => { + const hide = message.loading('正在导入'); + debugger + try { + const formData = new FormData(); + formData.append('file', file); + const result = await importUser(formData); + hide(); + if (result.resp_code === 0) { + message.success('导入用户成功'); + } else { + message.error(result.resp_msg); + } + } catch (error) { + hide(); + message.error('导入用户失败'); + } +}; + const TableList: React.FC = () => { const [params, setParams] = useState>({}); - + const actionRef = useRef(); const [createModalVisible, handleModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); @@ -65,25 +189,44 @@ const TableList: React.FC = () => { checkedChildren="正常" unCheckedChildren="锁定" checked={entity.enabled} - onClick={() => message.info('演示环境不支持该功能')} + onClick={async () => { + const success = await swichUser(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} /> ), }, { title: '操作', key: 'action', - render: (_, record) => ( + render: (_, entity) => ( { + setCurrentRow(entity); handleUpdateModalVisible(true); - setCurrentRow(record); }} > 修改 - message.info('演示环境不支持该功能')}>重置密码 - message.info('演示环境不支持该功能')}>删除 + await handleResetPassword(entity)}>重置密码 + { + const success = await handleDelete(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + ), }, @@ -112,6 +255,7 @@ const TableList: React.FC = () => { rowKey="id" headerTitle="用户管理" + actionRef={actionRef} request={user} columns={columns} search={false} @@ -129,13 +273,20 @@ const TableList: React.FC = () => { > 导出 - + + +