新增应用管理新增、修改功能

This commit is contained in:
Gao Shan
2022-10-19 02:00:37 +08:00
committed by Gao Shan
parent 36f9b6c1e9
commit fcccb31717
12 changed files with 702 additions and 102 deletions
@@ -17,6 +17,11 @@ body,
left: unset; left: unset;
} }
.hightligh{
background-color: @yellow-2 !important;
}
canvas { canvas {
display: block; display: block;
} }
@@ -1,7 +1,6 @@
import { deleteFile, file } from '@/services/files/api'; import { deleteFile, file } from '@/services/files/api';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { import {
ProFormSelect,
PageContainer, PageContainer,
ProFormText, ProFormText,
ProTable, ProTable,
@@ -12,10 +11,10 @@ import React, { useRef, useState } from 'react';
const { Link } = Typography; const { Link } = Typography;
const handleDelete = async (file: FILES.File) => { const handleDelete = async (deletefile: FILES.File) => {
const hide = message.loading('正在删除'); const hide = message.loading('正在删除');
try { try {
const result = await deleteFile(file.id); const result = await deleteFile(deletefile.id);
hide(); hide();
if (result.resp_code === 0) { if (result.resp_code === 0) {
message.success('删除File成功'); message.success('删除File成功');
@@ -33,7 +32,7 @@ const handleDelete = async (file: FILES.File) => {
const TableList: React.FC = () => { const TableList: React.FC = () => {
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [params, setParams] = useState<Record<string, string | number>>({ tenantId: 'webApp' }); const [params, setParams] = useState<Record<string, string | number>>({ });
const columns: ProColumns<FILES.File>[] = [ const columns: ProColumns<FILES.File>[] = [
{ {
dataIndex: 'index', dataIndex: 'index',
@@ -46,6 +45,7 @@ const TableList: React.FC = () => {
{ {
title: '文件大小(B)', title: '文件大小(B)',
dataIndex: 'size', dataIndex: 'size',
valueType: 'digit',
}, },
{ {
title: '媒体类型', title: '媒体类型',
@@ -68,7 +68,7 @@ const TableList: React.FC = () => {
title: '操作', title: '操作',
key: 'action', key: 'action',
render: (_, entity) => <Popconfirm render: (_, entity) => <Popconfirm
title={`确认删除File?`} title={`确认删除文件[${entity.name}]?`}
onConfirm={async () => { onConfirm={async () => {
const success = await handleDelete(entity); const success = await handleDelete(entity);
if (success) { if (success) {
@@ -90,9 +90,7 @@ const TableList: React.FC = () => {
split split
span={6} span={6}
className="query-filter" className="query-filter"
initialValues={params}
onFinish={async (values) => setParams(values)} onFinish={async (values) => setParams(values)}
onReset={() => setParams({})}
> >
<ProFormText name="name" label="搜索" placeholder="输入关键字" /> <ProFormText name="name" label="搜索" placeholder="输入关键字" />
</QueryFilter> </QueryFilter>
@@ -0,0 +1,213 @@
import {
ModalForm,
ProForm,
ProFormCheckbox,
ProFormRadio,
ProFormText,
} from '@ant-design/pro-components';
import React from 'react';
export type FormValueType = {
authorizedGrantTypeCodes?: string[];
} & Partial<SYSTEM.App>;
export type CreateFormProps = {
onVisibleChange: (flag: boolean) => void;
onSubmit: (values: FormValueType) => Promise<void>;
visible: boolean;
values?: SYSTEM.App;
};
const UpdateForm: React.FC<CreateFormProps> = (props) => {
return (
<ModalForm
title="添加应用"
visible={props.visible}
initialValues={{
autoapprove: 'true',
accessTokenValiditySeconds: '18000',
refreshTokenValiditySeconds: '28800',
supportIdToken: 'true',
idTokenValiditySeconds: '60',
authorizedGrantTypeCodes:
'authorization_code,password,client_credentials,implicit,refresh_token,password_code,openId,mobile_password'.split(","),
}}
onFinish={props.onSubmit}
modalProps={{ destroyOnClose: true }}
onVisibleChange={props.onVisibleChange}
grid={true}
rowProps={{ gutter: 8 }}
>
<ProForm.Group>
<ProFormText
rules={[
{
required: true,
message: '应用标识不为空',
},
]}
colProps={{ span: 12 }}
width="md"
name="clientId"
label="应用标识"
placeholder="输入应用标识"
/>
<ProFormText
width="md"
colProps={{ span: 12 }}
name="clientName"
label="应用名称"
placeholder="输入应用名称"
/>
<ProFormText
rules={[
{
required: true,
message: '应用密钥不为空',
},
]}
width="md"
colProps={{ span: 12 }}
name="clientSecretStr"
label="应用密钥"
placeholder="输入应用密钥"
/>
<ProFormText
width="md"
colProps={{ span: 12 }}
name="webServerRedirectUri"
label="回调地址"
placeholder="输入回调地址"
/>
<ProFormRadio.Group
name="autoapprove"
label="自动审批"
colProps={{ span: 6 }}
width="lg"
options={[
{
label: '是',
value: 'true',
},
{
label: '否',
value: 'false',
},
]}
/>
<ProFormCheckbox.Group
name="authorizedGrantTypeCodes"
label="授权模式"
width={'xl'}
colProps={{ span: 18 }}
options={[
{
label: '授权码模式',
value: 'authorization_code',
},
{
label: '密码模式',
value: 'password',
},
{
label: '客户端模式',
value: 'client_credentials',
},
{
label: '简化模式',
value: 'implicit',
},
{
label: '刷新Token',
value: 'refresh_token',
},
{
label: '密码验证码模式',
value: 'password_code',
},
{
label: 'openId模式',
value: 'openId',
},
{
label: '手机号密码模式',
value: 'mobile_password',
},
]}
/>
<ProFormText
rules={[
{
required: true,
message: '令牌时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: '令牌时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="accessTokenValiditySeconds"
label="令牌时效(s)"
placeholder="输入令牌时效"
fieldProps={{suffix:'秒'}}
/>
<ProFormText
rules={[
{
required: true,
message: '刷新时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: '刷新时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="refreshTokenValiditySeconds"
label="刷新时效(s)"
placeholder="输入刷新时效"
fieldProps={{suffix:'秒'}}
/>
<ProFormRadio.Group
name="supportIdToken"
label="支持ID令牌"
width="md"
colProps={{ span: 12 }}
options={[
{
label: '是',
value: true,
},
{
label: '否',
value: false,
},
]}
/>
<ProFormText
rules={[
{
required: true,
message: 'ID时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: 'ID时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="idTokenValiditySeconds"
label="ID时效(s)"
placeholder="输入ID时效"
fieldProps={{suffix:'秒'}}
/>
</ProForm.Group>
</ModalForm>
);
};
export default UpdateForm;
@@ -0,0 +1,203 @@
import {
ModalForm,
ProForm,
ProFormCheckbox,
ProFormRadio,
ProFormText,
} from '@ant-design/pro-components';
import { Form } from 'antd';
import React, { useEffect } from 'react';
export type FormValueType = {
authorizedGrantTypeCodes?: string[];
} & Partial<SYSTEM.App>;
export type UpdateFormProps = {
onVisibleChange: (flag: boolean) => void;
onSubmit: (values: FormValueType) => Promise<void>;
visible: boolean;
values?: SYSTEM.App;
};
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const [form] = Form.useForm();
const { values } = props;
useEffect(() => {
if (values?.authorizedGrantTypes) {
const authorizedGrantTypeCodes = values.authorizedGrantTypes.split(",")
const formData: FormValueType = { ...values, authorizedGrantTypeCodes };
form.setFieldsValue(formData);
}
}, [form, values]);
return (
<ModalForm
title="修改应用"
form={form}
visible={props.visible}
onFinish={props.onSubmit}
modalProps={{ destroyOnClose: true }}
onVisibleChange={props.onVisibleChange}
grid={true}
rowProps={{ gutter: 8 }}
>
<ProForm.Group>
<ProFormText
readonly
colProps={{ span: 12 }}
width="md"
name="clientId"
label="应用标识"
/>
<ProFormText
width="md"
colProps={{ span: 12 }}
name="clientName"
label="应用名称"
placeholder="输入应用名称"
/>
<ProFormText
readonly
width="md"
colProps={{ span: 12 }}
name="clientSecretStr"
label="应用密钥"
/>
<ProFormText
width="md"
colProps={{ span: 12 }}
name="webServerRedirectUri"
label="回调地址"
placeholder="输入回调地址"
/>
<ProFormRadio.Group
name="autoapprove"
label="自动审批"
colProps={{ span: 6 }}
width="lg"
options={[
{
label: '是',
value: 'true',
},
{
label: '否',
value: 'false',
},
]}
/>
<ProFormCheckbox.Group
name="authorizedGrantTypeCodes"
label="授权模式"
width={'xl'}
colProps={{ span: 18 }}
options={[
{
label: '授权码模式',
value: 'authorization_code',
},
{
label: '密码模式',
value: 'password',
},
{
label: '客户端模式',
value: 'client_credentials',
},
{
label: '简化模式',
value: 'implicit',
},
{
label: '刷新Token',
value: 'refresh_token',
},
{
label: '密码验证码模式',
value: 'password_code',
},
{
label: 'openId模式',
value: 'openId',
},
{
label: '手机号密码模式',
value: 'mobile_password',
},
]}
/>
<ProFormText
rules={[
{
required: true,
message: '令牌时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: '令牌时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="accessTokenValiditySeconds"
label="令牌时效(s)"
placeholder="输入令牌时效"
fieldProps={{suffix:'秒'}}
/>
<ProFormText
rules={[
{
required: true,
message: '刷新时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: '刷新时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="refreshTokenValiditySeconds"
label="刷新时效(s)"
placeholder="输入刷新时效"
fieldProps={{suffix:'秒'}}
/>
<ProFormRadio.Group
name="supportIdToken"
label="支持ID令牌"
width="md"
colProps={{ span: 12 }}
options={[
{
label: '是',
value: true,
},
{
label: '否',
value: false,
},
]}
/>
<ProFormText
rules={[
{
required: true,
message: 'ID时效不为空',
},
{
pattern: new RegExp(/^[1-9]\d*$/, 'g'),
message: 'ID时效必须为整数',
},
]}
width="md"
colProps={{ span: 12 }}
name="idTokenValiditySeconds"
label="ID时效(s)"
placeholder="输入ID时效"
fieldProps={{suffix:'秒'}}
/>
</ProForm.Group>
</ModalForm>
);
};
export default UpdateForm;
@@ -1,13 +1,57 @@
import { app, deleteApp } from '@/services/system/api'; import { app, saveOrUpdateApp, deleteApp } from '@/services/system/api';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components'; import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components';
import { Typography, message, Popconfirm, Button } from 'antd'; import { Typography, message, Popconfirm, Button, Space } from 'antd';
import React, { useRef, useState } from 'react'; import React, { useRef, useState } from 'react';
import CreateForm from './components/CreateForm';
import UpdateForm from './components/UpdateForm';
const { Link } = Typography; const { Link } = Typography;
const handleAdd = async (fields: SYSTEM.App) => {
const hide = message.loading('正在添加');
try {
const result = await saveOrUpdateApp({ ...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.App) => {
const hide = message.loading('正在更新');
try {
const result = await saveOrUpdateApp({ ...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.App) => { const handleDelete = async (data: SYSTEM.App) => {
if (!data.id) {
message.error('缺少ID信息,删除应用失败');
return false;
}
const hide = message.loading('正在删除'); const hide = message.loading('正在删除');
try { try {
await deleteApp(data.id); await deleteApp(data.id);
@@ -24,6 +68,9 @@ const handleDelete = async (data: SYSTEM.App) => {
const TableList: React.FC = () => { const TableList: React.FC = () => {
const [params, setParams] = useState<Record<string, string | number>>(); const [params, setParams] = useState<Record<string, string | number>>();
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [createModalVisible, handleCreateModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<SYSTEM.App>();
const columns: ProColumns<SYSTEM.App>[] = [ const columns: ProColumns<SYSTEM.App>[] = [
{ {
dataIndex: 'index', dataIndex: 'index',
@@ -56,7 +103,7 @@ const TableList: React.FC = () => {
key: 'autoapprove', key: 'autoapprove',
width: 40, width: 40,
align: 'center', align: 'center',
render: (_, record) => (record.autoapprove === 'true' ? '是' : '否'), renderText: (_, record) => (record.autoapprove === 'true' ? '是' : '否'),
}, },
{ {
title: '令牌时效', title: '令牌时效',
@@ -75,7 +122,7 @@ const TableList: React.FC = () => {
key: 'supportIdToken', key: 'supportIdToken',
width: 40, width: 40,
align: 'center', align: 'center',
render: (_, record) => (record.supportIdToken ? '是' : '否'), renderText: (_, record) => (record.supportIdToken ? '是' : '否'),
}, },
{ {
title: 'ID时效', title: 'ID时效',
@@ -88,19 +135,31 @@ const TableList: React.FC = () => {
key: 'action', key: 'action',
fixed: 'right', fixed: 'right',
width: 40, width: 40,
render: (_, entity) => <Popconfirm render: (_, entity) => (
title={`确认删除用户[${entity.clientName}]?`} <Space>
onConfirm={async () => { <Link
const success = await handleDelete(entity); onClick={() => {
if (success) { setCurrentRow(entity);
if (actionRef.current) { handleUpdateModalVisible(true);
actionRef.current.reload(); }}
} >
} 修改
}} </Link>
> <Popconfirm
<Link>删除</Link> title={`确认删除应用[${entity.clientId}]?`}
</Popconfirm>, onConfirm={async () => {
const success = await handleDelete(entity);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
<Link>删除</Link>
</Popconfirm>
</Space>
),
}, },
]; ];
return ( return (
@@ -133,7 +192,7 @@ const TableList: React.FC = () => {
<Button <Button
type="primary" type="primary"
onClick={() => { onClick={() => {
handleModalVisible(true); handleCreateModalVisible(true);
}} }}
> >
<PlusOutlined /> 添加 <PlusOutlined /> 添加
@@ -141,6 +200,42 @@ const TableList: React.FC = () => {
</>, </>,
]} ]}
/> />
<CreateForm
visible={createModalVisible}
onVisibleChange={handleCreateModalVisible}
onSubmit={async (values) => {
const authorizedGrantTypeCodes: string[] = values.authorizedGrantTypeCodes || [];
const authorizedGrantTypes = authorizedGrantTypeCodes.join(',');
delete values.authorizedGrantTypeCodes;
const success = await handleAdd({ ...values, authorizedGrantTypes });
if (success) {
handleCreateModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
/>
<UpdateForm
onSubmit={async (values) => {
if (currentRow) {
const authorizedGrantTypeCodes: string[] = values.authorizedGrantTypeCodes || [];
const authorizedGrantTypes = authorizedGrantTypeCodes.join(',');
delete values.authorizedGrantTypeCodes;
const success = await handleEdit({ ...currentRow, ...values, authorizedGrantTypes });
if (success) {
handleUpdateModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
setCurrentRow(undefined);
}
}}
onVisibleChange={handleUpdateModalVisible}
visible={updateModalVisible}
values={currentRow}
/>
</PageContainer> </PageContainer>
); );
}; };
@@ -1 +1,2 @@
@import (reference) '~antd/es/style/themes/index'; @import (reference) '~antd/es/style/themes/index';
@@ -1,13 +1,26 @@
import { deleteMenus, menu, menuOnes, saveOrUpdateMenus } from '@/services/system/api'; import { appAll, deleteMenus, menu, menuOnes, saveOrUpdateMenus } from '@/services/system/api';
import { treeify } from '@/util/treeify'; import { treeify } from '@/util/treeify';
import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined, } from '@ant-design/icons'; import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined } from '@ant-design/icons';
import { idIDIntl, ProColumns, ProFormDigit } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProFormRadio, ProFormTreeSelect, ProForm, ProFormSelect } from '@ant-design/pro-components'; import { ProFormDigit } from '@ant-design/pro-components';
import { PageContainer, ProFormText, ProTable, QueryFilter, ModalForm } from '@ant-design/pro-components'; import {
import { Button, Space, Tag, Typography, TreeSelect, message, Popconfirm } from 'antd'; ProFormRadio,
ProFormTreeSelect,
ProForm,
ProFormSelect,
} from '@ant-design/pro-components';
import {
PageContainer,
ProFormText,
ProTable,
QueryFilter,
ModalForm,
} from '@ant-design/pro-components';
import { Button, Space, Tag, Typography, message, Popconfirm } from 'antd';
import React, { useRef, useEffect, useState } from 'react'; import React, { useRef, useEffect, useState } from 'react';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
const { Link } = Typography; const { Link } = Typography;
const handleAdd = async (fields: SYSTEM.Menu) => { const handleAdd = async (fields: SYSTEM.Menu) => {
@@ -67,28 +80,42 @@ const handleDelete = async (sysUser: SYSTEM.Menu) => {
} }
}; };
const Generator: React.FC = () => { const Generator: React.FC = () => {
const [tenantId, setTenantId] = useState<string>();
const [params, setParams] = useState<Record<string, string | number>>({ tenantId: 'webApp' }); const [keyword, setKeyword] = useState<string>();
const [apps, setApps] = useState<SYSTEM.App[]>([]);
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false); const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false); const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>(); const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>();
const [data, setData] = useState<SYSTEM.Menu[]>(); const [data, setData] = useState<SYSTEM.Menu[]>();
const [keys, setKeys] = useState<(React.Key)[]>([]); const [keys, setKeys] = useState<React.Key[]>([]);
const [expandedRowKeys, setExpandedRowKeys] = useState<(React.Key)[]>([]); const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
const query = async (params: Record<string, string | number>) => { const query = async (clientId: string) => {
const menus = await menu(params); const menus = await menu(clientId);
const treeData = treeify(menus, {}); const treeData = treeify(menus, {});
menus.forEach((node) => { menus.forEach((node) => {
if (node.children && node.children.length === 0) delete node.children; if (node.children && node.children.length === 0) delete node.children;
}); });
setKeys(menus.map(m => m.id)); setKeys(menus.map((m) => m.id));
setData(treeData); setData(treeData);
}; };
// useEffect(() => {
// query({ tenantId: 'webApp' });
// }, []);
useEffect(() => { useEffect(() => {
query({ tenantId: 'webApp' }); (async () => {
const appData = (await appAll()) || [];
setApps(appData);
if (appData.length > 0) {
const clientId = appData[0].clientId;
setTenantId(clientId);
query(clientId);
}
})();
}, []); }, []);
const columns: ProColumns<SYSTEM.Menu>[] = [ const columns: ProColumns<SYSTEM.Menu>[] = [
@@ -96,6 +123,10 @@ const Generator: React.FC = () => {
title: '菜单名称', title: '菜单名称',
key: 'name', key: 'name',
width: 120, width: 120,
onCell: (record) => {
if (keyword && record.name?.includes(keyword)) return { className: 'hightligh' };
return {};
},
render(dom, entity) { render(dom, entity) {
if (entity.type === 1) { if (entity.type === 1) {
if (entity.url?.startsWith('javascript')) { if (entity.url?.startsWith('javascript')) {
@@ -127,12 +158,20 @@ const Generator: React.FC = () => {
title: '菜单url', title: '菜单url',
dataIndex: 'url', dataIndex: 'url',
width: 100, width: 100,
onCell: (record) => {
if (keyword && record.url?.includes(keyword)) return { className: 'hightligh' };
return {};
},
}, },
{ {
title: '菜单path', title: '菜单path',
dataIndex: 'path', dataIndex: 'path',
width: 100, width: 100,
ellipsis: true, ellipsis: true,
onCell: (record) => {
if (keyword && record.path?.includes(keyword)) return { className: 'hightligh' };
return {};
},
}, },
{ {
title: '样式', title: '样式',
@@ -193,27 +232,32 @@ const Generator: React.FC = () => {
}, },
]; ];
return ( return (
<PageContainer header={{ subTitle: '生成代码' }}> <PageContainer header={{ subTitle: '维护系统菜单' }}>
<QueryFilter <QueryFilter
defaultCollapsed defaultCollapsed
split split
span={6} span={6}
initialValues={params}
className="query-filter" className="query-filter"
onFinish={async (values) => query(values)} onFinish={async (values) => {
setExpandedRowKeys(keys);
setKeyword(values.searchValue);
}}
// onReset={() => setParams({})} // onReset={() => setParams({})}
> >
<ProFormSelect <ProFormSelect
name="tenantId" name="tenantId"
label="所属应用" label="所属应用"
fieldProps={{ fieldProps={{
onChange: async (values) => query({ tenantId: values }) value: tenantId,
}} allowClear: false,
valueEnum={{ onChange: async (values) => {
webApp: 'pc端', setTenantId(values);
app: '移动端', query(values);
zlt: '第三方应用', },
}} }}
options={apps.map((item) => {
return { label: item.clientId, value: item.clientId };
})}
/> />
<ProFormText name="searchValue" /> <ProFormText name="searchValue" />
</QueryFilter> </QueryFilter>
@@ -227,7 +271,7 @@ const Generator: React.FC = () => {
menus.forEach((node) => { menus.forEach((node) => {
if (node.children && node.children.length === 0) delete node.children; if (node.children && node.children.length === 0) delete node.children;
}); });
setKeys(menus.map(m => m.id)); setKeys(menus.map((m) => m.id));
setData(treeData); setData(treeData);
}} }}
dataSource={data} dataSource={data}
@@ -270,7 +314,7 @@ const Generator: React.FC = () => {
// layout="horizontal" // layout="horizontal"
visible={createModalVisible} visible={createModalVisible}
onVisibleChange={handleModalVisible} onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true, okText: "保存" }} modalProps={{ destroyOnClose: true, okText: '保存' }}
onFinish={async (values) => { onFinish={async (values) => {
const success = await handleAdd(values as SYSTEM.Menu); const success = await handleAdd(values as SYSTEM.Menu);
if (success) { if (success) {
@@ -289,11 +333,11 @@ const Generator: React.FC = () => {
request={async () => { request={async () => {
const menus = await menuOnes(); const menus = await menuOnes();
if (menus) { if (menus) {
let a = menus.map(item => { const a = menus.map((item) => {
return { ...item, key: item.id, title: item.name, value: item.id } return { ...item, key: item.id, title: item.name, value: item.id };
}) });
let treeData = treeify(a, {}); const treeData = treeify(a, {});
let root = { const root = {
title: '顶级目录', title: '顶级目录',
value: -1, value: -1,
key: -1, key: -1,
@@ -324,18 +368,8 @@ const Generator: React.FC = () => {
label="菜单名" label="菜单名"
placeholder="输入菜单名" placeholder="输入菜单名"
/> />
<ProFormText <ProFormText width="md" name="url" label="菜单url" placeholder="输入菜单url" />
width="md" <ProFormText width="md" name="path" label="菜单path" placeholder="输入菜单path" />
name="url"
label="菜单url"
placeholder="输入菜单url"
/>
<ProFormText
width="md"
name="path"
label="菜单path"
placeholder="输入菜单path"
/>
<ProFormText <ProFormText
rules={[ rules={[
{ {
@@ -1,4 +1,4 @@
import { deleteRole, pageRole, saveOrUpdateRole } from '@/services/system/api'; import { appAll, deleteRole, pageRole, saveOrUpdateRole } from '@/services/system/api';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { import {
@@ -10,9 +10,9 @@ import {
ProTable, ProTable,
QueryFilter, QueryFilter,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Popconfirm, Space, Typography } from 'antd'; import { Form, Popconfirm, Space, Typography } from 'antd';
import { Button, message } from 'antd'; import { Button, message } from 'antd';
import React, { useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import AssignAuth from './components/AssignAuth'; import AssignAuth from './components/AssignAuth';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
@@ -82,8 +82,10 @@ const handleDelete = async (data: SYSTEM.Role) => {
}; };
const TableList: React.FC = () => { const TableList: React.FC = () => {
const [params, setParams] = useState<Record<string, string | number>>({tenantId: 'webApp'}); const [params, setParams] = useState<Record<string, string | number>>({});
const [form] = Form.useForm();
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [apps, setApps] = useState<SYSTEM.App[]>([]);
const [createModalVisible, handleModalVisible] = useState<boolean>(false); const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false); const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
@@ -91,6 +93,18 @@ const TableList: React.FC = () => {
const [assignAuth, setAssignAuth] = useState<AssignAuthProps>({ assignModalVisible: false }); const [assignAuth, setAssignAuth] = useState<AssignAuthProps>({ assignModalVisible: false });
useEffect(() => {
(async () => {
const appData = (await appAll()) || [];
setApps(appData);
if (appData.length > 0) {
const tenantId = appData[0].clientId;
setParams({ tenantId });
form.setFieldsValue({ tenantId });
}
})();
}, [form]);
const columns: ProColumns<SYSTEM.Role>[] = [ const columns: ProColumns<SYSTEM.Role>[] = [
{ {
dataIndex: 'index', dataIndex: 'index',
@@ -157,22 +171,24 @@ const TableList: React.FC = () => {
defaultCollapsed defaultCollapsed
split split
span={6} span={6}
initialValues={params} form={form}
className="query-filter" className="query-filter"
onValuesChange={(changedValues, allValues) => {
if (changedValues.tenantId) setParams(allValues);
}}
onFinish={async (values) => setParams(values)} onFinish={async (values) => setParams(values)}
onReset={async() => setParams({tenantId: 'webApp'})} onReset={() => {
form.setFieldsValue({ tenantId: params.tenantId });
setParams({ tenantId: params.tenantId });
}}
> >
<ProFormSelect <ProFormSelect
name="tenantId" name="tenantId"
label="所属应用" label="所属应用"
fieldProps={{ allowClear={false}
onChange:async (values) => setParams({tenantId: values}) options={apps.map((item) => {
}} return { label: item.clientId, value: item.clientId };
valueEnum={{ })}
webApp: 'pc端',
app: '移动端',
zlt: '第三方应用',
}}
/> />
<ProFormSelect <ProFormSelect
name="searchKey" name="searchKey"
@@ -1,4 +1,4 @@
import { deleteToken, token } from '@/services/system/api'; import { appAll, deleteToken, token } from '@/services/system/api';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { import {
ProFormSelect, ProFormSelect,
@@ -7,15 +7,15 @@ import {
ProTable, ProTable,
QueryFilter, QueryFilter,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Typography, message, Popconfirm } from 'antd'; import { Typography, message, Popconfirm, Form } from 'antd';
import React, { useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
const { Link } = Typography; const { Link } = Typography;
const handleDelete = async (token: SYSTEM.Token) => { const handleDelete = async (delToken: SYSTEM.Token) => {
const hide = message.loading('正在删除'); const hide = message.loading('正在删除');
try { try {
const result = await deleteToken(token.tokenValue); const result = await deleteToken(delToken.tokenValue);
hide(); hide();
if (result.resp_code === 0) { if (result.resp_code === 0) {
message.success('删除Token成功'); message.success('删除Token成功');
@@ -32,8 +32,22 @@ const handleDelete = async (token: SYSTEM.Token) => {
}; };
const TableList: React.FC = () => { const TableList: React.FC = () => {
const [form] = Form.useForm();
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [params, setParams] = useState<Record<string, string | number>>({ tenantId: 'webApp' }); const [apps, setApps] = useState<SYSTEM.App[]>([]);
const [params, setParams] = useState<Record<string, string | number>>({});
useEffect(() => {
(async () => {
const appData = (await appAll()) || [];
setApps(appData);
if (appData.length > 0) {
const tenantId = appData[0].clientId;
setParams({ tenantId });
form.setFieldsValue({ tenantId });
}
})();
}, [form]);
const columns: ProColumns<SYSTEM.Token>[] = [ const columns: ProColumns<SYSTEM.Token>[] = [
{ {
dataIndex: 'index', dataIndex: 'index',
@@ -89,23 +103,28 @@ const TableList: React.FC = () => {
defaultCollapsed defaultCollapsed
split split
span={6} span={6}
form={form}
className="query-filter" className="query-filter"
initialValues={params} onValuesChange={(changedValues, allValues) => {
if (changedValues.tenantId) setParams(allValues);
}}
onFinish={async (values) => setParams(values)} onFinish={async (values) => setParams(values)}
onReset={async() => setParams({tenantId: "webApp"})} onReset={() => {
form.setFieldsValue({ tenantId: params.tenantId });
setParams({ tenantId: params.tenantId });
}}
> >
<ProFormSelect <ProFormSelect
name="tenantId" name="tenantId"
label="所属应用" label="所属应用"
fieldProps={{ fieldProps={{
value: params.tenantId,
allowClear: false,
onChange:async (values) => setParams({tenantId: values}) onChange:async (values) => setParams({tenantId: values})
}} }}
valueEnum={{ options={apps.map((item) => {
webApp: 'pc端', return { label: item.clientId, value: item.clientId };
app: '移动端', })}
zlt: '第三方应用',
}}
allowClear={false}
/> />
<ProFormText name="username" label="搜索" placeholder="输入用户名" /> <ProFormText name="username" label="搜索" placeholder="输入用户名" />
</QueryFilter> </QueryFilter>
@@ -173,7 +173,7 @@ const TableList: React.FC = () => {
{ {
title: '性别', title: '性别',
dataIndex: 'sex', dataIndex: 'sex',
render: (value) => (value === 0 ? '男' : '女'), renderText: (value) => (value === 0 ? '男' : '女'),
}, },
{ {
title: '创建时间', title: '创建时间',
@@ -86,6 +86,7 @@ export async function role() {
} }
export async function pageRole(params?: { [key: string]: string | number }) { export async function pageRole(params?: { [key: string]: string | number }) {
if(!params || !params.tenantId) return {}
const { current, pageSize, ...rest } = params ?? {}; const { current, pageSize, ...rest } = params ?? {};
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', { const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
method: 'GET', method: 'GET',
@@ -121,6 +122,7 @@ export async function menuForAuth(roleId: number, tenantId: string) {
export async function token(params?: { [key: string]: string | number }) { export async function token(params?: { [key: string]: string | number }) {
if(!params || !params.tenantId) return {}
const { current, pageSize, ...rest } = params ?? {}; const { current, pageSize, ...rest } = params ?? {};
const result = await request<SYSTEM.Page<SYSTEM.Token>>('/api-uaa/tokens', { const result = await request<SYSTEM.Page<SYSTEM.Token>>('/api-uaa/tokens', {
method: 'GET', method: 'GET',
@@ -138,6 +140,21 @@ export async function app(params?: { [key: string]: string | number }) {
return { data: result.data, total: result.count }; return { data: result.data, total: result.count };
} }
export async function appAll() {
const result = await request<API.Result<SYSTEM.App>>('/api-uaa/clients/all', {
method: 'GET',
});
return result.datas;
}
export async function saveOrUpdateApp(data: SYSTEM.App): Promise<API.Result<SYSTEM.App>> {
const result = await request<API.Result<SYSTEM.App>>('/api-uaa/clients/saveOrUpdate', {
method: 'POST',
data,
});
return result;
}
export async function deleteApp(id: number) { export async function deleteApp(id: number) {
const url = `/api-uaa/clients/${id}` const url = `/api-uaa/clients/${id}`
await request<void>(url, { await request<void>(url, {
@@ -165,10 +182,10 @@ export function exportGenerator(tables: string) {
}); });
} }
export async function menu(params: { [key: string]: string | number }) { export async function menu(tenantId: string ) {
const result = await request<SYSTEM.Page<SYSTEM.Menu>>('/api-user/menus/findAlls', { const result = await request<SYSTEM.Page<SYSTEM.Menu>>('/api-user/menus/findAlls', {
method: 'GET', method: 'GET',
params, params: {tenantId},
}); });
return result.data; return result.data;
} }
+2 -3
View File
@@ -30,7 +30,6 @@ declare namespace SYSTEM {
del?: boolean; del?: boolean;
roles?: Role[]; roles?: Role[];
roleId?: string; roleId?: string;
headImgUrl?: string;
}; };
type Menu = { type Menu = {
@@ -62,13 +61,13 @@ declare namespace SYSTEM {
}; };
type App = { type App = {
id: number; id?: number;
accessTokenValiditySeconds?: number; accessTokenValiditySeconds?: number;
additionalInformation?: string; additionalInformation?: string;
authorities?: string; authorities?: string;
authorizedGrantTypes?: string; authorizedGrantTypes?: string;
autoapprove?: string; autoapprove?: string;
clientId?: string; clientId: string;
clientName?: string; clientName?: string;
clientSecret?: string; clientSecret?: string;
clientSecretStr?: string; clientSecretStr?: string;