feat(平台管理):新增小程序的管理,多个小程序登录unionId管理

This commit is contained in:
2025-05-22 16:31:46 +08:00
parent 52f0f9d54e
commit 5710c79d48
192 changed files with 562 additions and 12350 deletions
@@ -9,43 +9,43 @@
export default {
dev: {
'/api-uaa/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-user/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-log/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-search/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-generator/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-file/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-order/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
'/api-device/': {
// target: 'http://119.45.169.13:9900',
target: 'http://127.0.0.1:9900',
target: 'http://119.45.169.13:9900',
// target: 'http://127.0.0.1:9900',
changeOrigin: true,
},
},
@@ -0,0 +1,63 @@
import {
ModalForm,
ProForm,
ProFormText,
ProFormSelect,
} from '@ant-design/pro-components';
import React from 'react';
const STATUS_OPTIONS = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
] as const;
interface UpdateFormProps {
onSubmit: (values: any) => Promise<void>;
onVisibleChange: (visible: boolean) => void;
updateModalVisible: boolean;
values?: any;
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
return (
<ModalForm
title="修改小程序"
width={600}
visible={props.updateModalVisible}
onVisibleChange={props.onVisibleChange}
onFinish={props.onSubmit}
initialValues={props.values}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText
rules={[{ required: true, message: '小程序名称不能为空' }]}
width="md"
name="name"
label="小程序名称"
/>
<ProFormText
rules={[{ required: true, message: 'AppID不能为空' }]}
width="md"
name="appid"
label="AppID"
/>
<ProFormText
rules={[{ required: true, message: 'Secret不能为空' }]}
width="md"
name="secret"
label="Secret"
/>
<ProFormSelect
rules={[{ required: true, message: '状态不能为空' }]}
width="md"
name="status"
label="状态"
options={STATUS_OPTIONS}
/>
</ProForm.Group>
</ModalForm>
);
};
export default UpdateForm;
@@ -0,0 +1,262 @@
import {
PlusOutlined,
ExportOutlined,
ImportOutlined,
DownloadOutlined,
} from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
ModalForm,
PageContainer,
ProForm,
ProFormText,
ProFormSelect,
ProTable,
QueryFilter,
} from '@ant-design/pro-components';
import { Button, message, Space, Tag } from 'antd';
import React, { useRef, useState } from 'react';
import { getMiniAppList, saveOrUpdateMiniApp, deleteMiniApp } from '@/services/system/api';
import UpdateForm from './components/UpdateForm';
const STATUS_OPTIONS = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
] as const;
const TableList: React.FC = () => {
const [searchParams, setSearchParams] = useState<Record<string, string | number>>({});
const actionRef = useRef<ActionType>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<SYSTEM.MiniApp>();
// 统一的API请求处理函数
const handleRequest = async (
action: () => Promise<any>,
loadingMessage: string,
successMessage: string,
) => {
const hide = message.loading(loadingMessage);
try {
const result = await action();
hide();
if (result.resp_code === 0) {
message.success(successMessage);
return true;
}
message.error(result.resp_msg);
return false;
} catch (error) {
hide();
message.error(`${successMessage}失败`);
return false;
}
};
// 表格列定义
const columns: ProColumns<SYSTEM.MiniApp>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
width: 48,
},
{
title: '小程序名称',
dataIndex: 'name',
copyable: true,
},
{
title: 'AppID',
dataIndex: 'appid',
copyable: true,
},
{
title: '状态',
dataIndex: 'status',
valueType: 'select',
valueEnum: {
1: { text: '启用', status: 'Success' },
0: { text: '禁用', status: 'Error' },
},
render: (_, record) => (
<Tag color={record.status === 1 ? 'success' : 'error'}>
{STATUS_OPTIONS.find(item => item.value === record.status)?.label}
</Tag>
),
},
{
title: '创建时间',
dataIndex: 'createTime',
valueType: 'dateTime',
sorter: true,
},
{
title: '更新时间',
dataIndex: 'updateTime',
valueType: 'dateTime',
sorter: true,
},
{
title: '操作',
dataIndex: 'option',
valueType: 'option',
fixed: 'right',
width: 120,
render: (_, record) => [
<a
key="edit"
onClick={() => {
setCurrentRow(record);
handleUpdateModalVisible(true);
}}
>
修改
</a>,
<a
key="delete"
onClick={() => {
handleRequest(
() => deleteMiniApp(record.id),
'正在删除',
'删除成功'
).then((success) => {
if (success && actionRef.current) {
actionRef.current.reload();
}
});
}}
>
删除
</a>,
],
},
];
// 表单字段定义
const renderModalContent = () => (
<ProForm.Group>
<ProFormText
rules={[{ required: true, message: '小程序名称不能为空' }]}
width="md"
name="name"
label="小程序名称"
/>
<ProFormText
rules={[{ required: true, message: 'AppID不能为空' }]}
width="md"
name="appid"
label="AppID"
/>
<ProFormText
rules={[{ required: true, message: 'Secret不能为空' }]}
width="md"
name="secret"
label="Secret"
/>
<ProFormSelect
rules={[{ required: true, message: '状态不能为空' }]}
width="md"
name="status"
label="状态"
options={STATUS_OPTIONS}
initialValue={1}
/>
</ProForm.Group>
);
return (
<PageContainer header={{ subTitle: '管理系统中的小程序配置' }}>
<QueryFilter
defaultCollapsed
split
onFinish={async (values) => setSearchParams(values)}
>
<ProFormSelect
name="searchKey"
label="搜索"
valueEnum={{
name: '小程序名称',
appid: 'AppID',
}}
/>
<ProFormText name="searchValue" placeholder="请输入关键字" />
</QueryFilter>
<ProTable<SYSTEM.MiniApp>
rowKey="id"
headerTitle="小程序管理"
actionRef={actionRef}
request={async (params, sorter, filter) => {
const res = await getMiniAppList({
page: params.current,
limit: params.pageSize,
searchKey: params.searchKey,
searchValue: params.searchValue,
});
return {
data: res.data || [],
success: res.resp_code === 0,
total: res.count || 0,
};
}}
columns={columns}
search={false}
params={searchParams}
pagination={{
showSizeChanger: true,
showQuickJumper: true,
}}
toolBarRender={() => [
<Button type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined /> 新增
</Button>,
]}
/>
<ModalForm
title="新增小程序"
visible={createModalVisible}
onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true }}
onFinish={async (values) => {
const success = await handleRequest(
() => saveOrUpdateMiniApp(values),
'正在添加',
'添加成功'
);
if (success) {
handleModalVisible(false);
actionRef.current?.reload();
}
return success;
}}
>
{renderModalContent()}
</ModalForm>
{updateModalVisible && (
<UpdateForm
onSubmit={async (values) => {
const success = await handleRequest(
() => saveOrUpdateMiniApp({ ...values, id: currentRow?.id }),
'正在更新',
'更新成功'
);
if (success) {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
actionRef.current?.reload();
}
}}
onVisibleChange={handleUpdateModalVisible}
updateModalVisible={updateModalVisible}
values={currentRow}
/>
)}
</PageContainer>
);
};
export default TableList;
@@ -248,3 +248,28 @@ export async function deleteToken(token: string) {
return result;
}
export async function getMiniAppList(params: {
page: number;
limit: number;
searchKey?: string;
searchValue?: string;
}) {
return request<API.OptionalResult<SYSTEM.MiniApp[]>>('/api-user/miniApp/list', {
method: 'GET',
params,
});
}
export async function saveOrUpdateMiniApp(data: SYSTEM.MiniApp) {
return request<API.OptionalResult<any>>('/api-user/miniApp/save', {
method: 'POST',
data,
});
}
export async function deleteMiniApp(id: number) {
return request<API.OptionalResult<any>>(`/api-user/miniApp/delete/${id}`, {
method: 'DELETE',
});
}
@@ -101,4 +101,14 @@ declare namespace SYSTEM {
tenantId?: string;
updateTime?: string;
}
interface MiniApp {
id: number;
appid: string;
secret: string;
name: string;
status: number;
createTime: string;
updateTime: string;
}
}