提交 fcccb317 编写于 作者: G Gao Shan 提交者: Gao Shan

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

上级 36f9b6c1
......@@ -17,6 +17,11 @@ body,
left: unset;
}
.hightligh{
background-color: @yellow-2 !important;
}
canvas {
display: block;
}
......
import { deleteFile, file } from '@/services/files/api';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
ProFormSelect,
PageContainer,
ProFormText,
ProTable,
......@@ -12,10 +11,10 @@ import React, { useRef, useState } from 'react';
const { Link } = Typography;
const handleDelete = async (file: FILES.File) => {
const handleDelete = async (deletefile: FILES.File) => {
const hide = message.loading('正在删除');
try {
const result = await deleteFile(file.id);
const result = await deleteFile(deletefile.id);
hide();
if (result.resp_code === 0) {
message.success('删除File成功');
......@@ -33,7 +32,7 @@ const handleDelete = async (file: FILES.File) => {
const TableList: React.FC = () => {
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>[] = [
{
dataIndex: 'index',
......@@ -46,6 +45,7 @@ const TableList: React.FC = () => {
{
title: '文件大小(B)',
dataIndex: 'size',
valueType: 'digit',
},
{
title: '媒体类型',
......@@ -68,7 +68,7 @@ const TableList: React.FC = () => {
title: '操作',
key: 'action',
render: (_, entity) => <Popconfirm
title={`确认删除File?`}
title={`确认删除文件[${entity.name}]?`}
onConfirm={async () => {
const success = await handleDelete(entity);
if (success) {
......@@ -90,9 +90,7 @@ const TableList: React.FC = () => {
split
span={6}
className="query-filter"
initialValues={params}
onFinish={async (values) => setParams(values)}
onReset={() => setParams({})}
>
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
</QueryFilter>
......
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;
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;
import { app, deleteApp } from '@/services/system/api';
import { app, saveOrUpdateApp, deleteApp } from '@/services/system/api';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } 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 CreateForm from './components/CreateForm';
import UpdateForm from './components/UpdateForm';
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) => {
if (!data.id) {
message.error('缺少ID信息,删除应用失败');
return false;
}
const hide = message.loading('正在删除');
try {
await deleteApp(data.id);
......@@ -24,6 +68,9 @@ const handleDelete = async (data: SYSTEM.App) => {
const TableList: React.FC = () => {
const [params, setParams] = useState<Record<string, string | number>>();
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>[] = [
{
dataIndex: 'index',
......@@ -56,7 +103,7 @@ const TableList: React.FC = () => {
key: 'autoapprove',
width: 40,
align: 'center',
render: (_, record) => (record.autoapprove === 'true' ? '' : ''),
renderText: (_, record) => (record.autoapprove === 'true' ? '' : ''),
},
{
title: '令牌时效',
......@@ -75,7 +122,7 @@ const TableList: React.FC = () => {
key: 'supportIdToken',
width: 40,
align: 'center',
render: (_, record) => (record.supportIdToken ? '' : ''),
renderText: (_, record) => (record.supportIdToken ? '' : ''),
},
{
title: 'ID时效',
......@@ -88,19 +135,31 @@ const TableList: React.FC = () => {
key: 'action',
fixed: 'right',
width: 40,
render: (_, entity) => <Popconfirm
title={`确认删除用户[${entity.clientName}]?`}
onConfirm={async () => {
const success = await handleDelete(entity);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
<Link>删除</Link>
</Popconfirm>,
render: (_, entity) => (
<Space>
<Link
onClick={() => {
setCurrentRow(entity);
handleUpdateModalVisible(true);
}}
>
修改
</Link>
<Popconfirm
title={`确认删除应用[${entity.clientId}]?`}
onConfirm={async () => {
const success = await handleDelete(entity);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
<Link>删除</Link>
</Popconfirm>
</Space>
),
},
];
return (
......@@ -133,7 +192,7 @@ const TableList: React.FC = () => {
<Button
type="primary"
onClick={() => {
handleModalVisible(true);
handleCreateModalVisible(true);
}}
>
<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>
);
};
......
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 { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined, } from '@ant-design/icons';
import { idIDIntl, ProColumns, ProFormDigit } from '@ant-design/pro-components';
import { 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, TreeSelect, message, Popconfirm } from 'antd';
import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProFormDigit } from '@ant-design/pro-components';
import {
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 UpdateForm from './components/UpdateForm';
const { Link } = Typography;
const handleAdd = async (fields: SYSTEM.Menu) => {
......@@ -67,28 +80,42 @@ const handleDelete = async (sysUser: SYSTEM.Menu) => {
}
};
const Generator: React.FC = () => {
const [params, setParams] = useState<Record<string, string | number>>({ tenantId: 'webApp' });
const [tenantId, setTenantId] = useState<string>();
const [keyword, setKeyword] = useState<string>();
const [apps, setApps] = useState<SYSTEM.App[]>([]);
const actionRef = useRef<ActionType>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>();
const [data, setData] = useState<SYSTEM.Menu[]>();
const [keys, setKeys] = useState<(React.Key)[]>([]);
const [expandedRowKeys, setExpandedRowKeys] = useState<(React.Key)[]>([]);
const [keys, setKeys] = useState<React.Key[]>([]);
const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
const query = async (params: Record<string, string | number>) => {
const menus = await menu(params);
const query = async (clientId: string) => {
const menus = await menu(clientId);
const treeData = treeify(menus, {});
menus.forEach((node) => {
if (node.children && node.children.length === 0) delete node.children;
});
setKeys(menus.map(m => m.id));
setKeys(menus.map((m) => m.id));
setData(treeData);
};
// useEffect(() => {
// query({ tenantId: 'webApp' });
// }, []);
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>[] = [
......@@ -96,6 +123,10 @@ const Generator: React.FC = () => {
title: '菜单名称',
key: 'name',
width: 120,
onCell: (record) => {
if (keyword && record.name?.includes(keyword)) return { className: 'hightligh' };
return {};
},
render(dom, entity) {
if (entity.type === 1) {
if (entity.url?.startsWith('javascript')) {
......@@ -127,12 +158,20 @@ const Generator: React.FC = () => {
title: '菜单url',
dataIndex: 'url',
width: 100,
onCell: (record) => {
if (keyword && record.url?.includes(keyword)) return { className: 'hightligh' };
return {};
},
},
{
title: '菜单path',
dataIndex: 'path',
width: 100,
ellipsis: true,
onCell: (record) => {
if (keyword && record.path?.includes(keyword)) return { className: 'hightligh' };
return {};
},
},
{
title: '样式',
......@@ -193,27 +232,32 @@ const Generator: React.FC = () => {
},
];
return (
<PageContainer header={{ subTitle: '生成代码' }}>
<PageContainer header={{ subTitle: '维护系统菜单' }}>
<QueryFilter
defaultCollapsed
split
span={6}
initialValues={params}
className="query-filter"
onFinish={async (values) => query(values)}
onFinish={async (values) => {
setExpandedRowKeys(keys);
setKeyword(values.searchValue);
}}
// onReset={() => setParams({})}
>
<ProFormSelect
name="tenantId"
label="所属应用"
fieldProps={{
onChange: async (values) => query({ tenantId: values })
}}
valueEnum={{
webApp: 'pc端',
app: '移动端',
zlt: '第三方应用',
value: tenantId,
allowClear: false,
onChange: async (values) => {
setTenantId(values);
query(values);
},
}}
options={apps.map((item) => {
return { label: item.clientId, value: item.clientId };
})}
/>
<ProFormText name="searchValue" />
</QueryFilter>
......@@ -227,7 +271,7 @@ const Generator: React.FC = () => {
menus.forEach((node) => {
if (node.children && node.children.length === 0) delete node.children;
});
setKeys(menus.map(m => m.id));
setKeys(menus.map((m) => m.id));
setData(treeData);
}}
dataSource={data}
......@@ -270,7 +314,7 @@ const Generator: React.FC = () => {
// layout="horizontal"
visible={createModalVisible}
onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true, okText: "保存" }}
modalProps={{ destroyOnClose: true, okText: '保存' }}
onFinish={async (values) => {
const success = await handleAdd(values as SYSTEM.Menu);
if (success) {
......@@ -289,11 +333,11 @@ const Generator: React.FC = () => {
request={async () => {
const menus = await menuOnes();
if (menus) {
let a = menus.map(item => {
return { ...item, key: item.id, title: item.name, value: item.id }
})
let treeData = treeify(a, {});
let root = {
const a = menus.map((item) => {
return { ...item, key: item.id, title: item.name, value: item.id };
});
const treeData = treeify(a, {});
const root = {
title: '顶级目录',
value: -1,
key: -1,
......@@ -324,18 +368,8 @@ const Generator: React.FC = () => {
label="菜单名"
placeholder="输入菜单名"
/>
<ProFormText
width="md"
name="url"
label="菜单url"
placeholder="输入菜单url"
/>
<ProFormText
width="md"
name="path"
label="菜单path"
placeholder="输入菜单path"
/>
<ProFormText width="md" name="url" label="菜单url" placeholder="输入菜单url" />
<ProFormText width="md" name="path" label="菜单path" placeholder="输入菜单path" />
<ProFormText
rules={[
{
......
import { deleteRole, pageRole, saveOrUpdateRole } from '@/services/system/api';
import { appAll, deleteRole, pageRole, saveOrUpdateRole } from '@/services/system/api';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
......@@ -10,9 +10,9 @@ import {
ProTable,
QueryFilter,
} from '@ant-design/pro-components';
import { Popconfirm, Space, Typography } from 'antd';
import { Form, Popconfirm, Space, Typography } 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 UpdateForm from './components/UpdateForm';
......@@ -82,8 +82,10 @@ const handleDelete = async (data: SYSTEM.Role) => {
};
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 [apps, setApps] = useState<SYSTEM.App[]>([]);
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
......@@ -91,6 +93,18 @@ const TableList: React.FC = () => {
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>[] = [
{
dataIndex: 'index',
......@@ -157,22 +171,24 @@ const TableList: React.FC = () => {
defaultCollapsed
split
span={6}
initialValues={params}
form={form}
className="query-filter"
onValuesChange={(changedValues, allValues) => {
if (changedValues.tenantId) setParams(allValues);
}}
onFinish={async (values) => setParams(values)}
onReset={async() => setParams({tenantId: 'webApp'})}
onReset={() => {
form.setFieldsValue({ tenantId: params.tenantId });
setParams({ tenantId: params.tenantId });
}}
>
<ProFormSelect
name="tenantId"
label="所属应用"
fieldProps={{
onChange:async (values) => setParams({tenantId: values})
}}
valueEnum={{
webApp: 'pc端',
app: '移动端',
zlt: '第三方应用',
}}
allowClear={false}
options={apps.map((item) => {
return { label: item.clientId, value: item.clientId };
})}
/>
<ProFormSelect
name="searchKey"
......
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 {
ProFormSelect,
......@@ -7,15 +7,15 @@ import {
ProTable,
QueryFilter,
} from '@ant-design/pro-components';
import { Typography, message, Popconfirm } from 'antd';
import React, { useRef, useState } from 'react';
import { Typography, message, Popconfirm, Form } from 'antd';
import React, { useEffect, useRef, useState } from 'react';
const { Link } = Typography;
const handleDelete = async (token: SYSTEM.Token) => {
const handleDelete = async (delToken: SYSTEM.Token) => {
const hide = message.loading('正在删除');
try {
const result = await deleteToken(token.tokenValue);
const result = await deleteToken(delToken.tokenValue);
hide();
if (result.resp_code === 0) {
message.success('删除Token成功');
......@@ -32,8 +32,22 @@ const handleDelete = async (token: SYSTEM.Token) => {
};
const TableList: React.FC = () => {
const [form] = Form.useForm();
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>[] = [
{
dataIndex: 'index',
......@@ -89,23 +103,28 @@ const TableList: React.FC = () => {
defaultCollapsed
split
span={6}
form={form}
className="query-filter"
initialValues={params}
onValuesChange={(changedValues, allValues) => {
if (changedValues.tenantId) setParams(allValues);
}}
onFinish={async (values) => setParams(values)}
onReset={async() => setParams({tenantId: "webApp"})}
onReset={() => {
form.setFieldsValue({ tenantId: params.tenantId });
setParams({ tenantId: params.tenantId });
}}
>
<ProFormSelect
name="tenantId"
label="所属应用"
fieldProps={{
value: params.tenantId,
allowClear: false,
onChange:async (values) => setParams({tenantId: values})
}}
valueEnum={{
webApp: 'pc端',
app: '移动端',
zlt: '第三方应用',
}}
allowClear={false}
options={apps.map((item) => {
return { label: item.clientId, value: item.clientId };
})}
/>
<ProFormText name="username" label="搜索" placeholder="输入用户名" />
</QueryFilter>
......
......@@ -173,7 +173,7 @@ const TableList: React.FC = () => {
{
title: '性别',
dataIndex: 'sex',
render: (value) => (value === 0 ? '' : ''),
renderText: (value) => (value === 0 ? '' : ''),
},
{
title: '创建时间',
......
......@@ -86,6 +86,7 @@ export async function role() {
}
export async function pageRole(params?: { [key: string]: string | number }) {
if(!params || !params.tenantId) return {}
const { current, pageSize, ...rest } = params ?? {};
const result = await request<SYSTEM.Page<SYSTEM.Role>>('/api-user/roles', {
method: 'GET',
......@@ -121,6 +122,7 @@ export async function menuForAuth(roleId: number, tenantId: string) {
export async function token(params?: { [key: string]: string | number }) {
if(!params || !params.tenantId) return {}
const { current, pageSize, ...rest } = params ?? {};
const result = await request<SYSTEM.Page<SYSTEM.Token>>('/api-uaa/tokens', {
method: 'GET',
......@@ -138,6 +140,21 @@ export async function app(params?: { [key: string]: string | number }) {
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) {
const url = `/api-uaa/clients/${id}`
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', {
method: 'GET',
params,
params: {tenantId},
});
return result.data;
}
......@@ -211,4 +228,4 @@ export async function deleteToken(token: string) {
params: {token}
});
return result;
}
\ No newline at end of file
}
......@@ -30,7 +30,6 @@ declare namespace SYSTEM {
del?: boolean;
roles?: Role[];
roleId?: string;
headImgUrl?: string;
};
type Menu = {
......@@ -62,13 +61,13 @@ declare namespace SYSTEM {
};
type App = {
id: number;
id?: number;
accessTokenValiditySeconds?: number;
additionalInformation?: string;
authorities?: string;
authorizedGrantTypes?: string;
autoapprove?: string;
clientId?: string;
clientId: string;
clientName?: string;
clientSecret?: string;
clientSecretStr?: string;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册