feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件

This commit is contained in:
2025-09-23 10:32:35 +08:00
parent 10ddfd6f75
commit 408b500b6a
199 changed files with 16850 additions and 34874 deletions
+25
View File
@@ -0,0 +1,25 @@
import React from 'react';
import { Button, Result } from 'antd';
import { history } from 'umi';
const NotFoundPage: React.FC = () => {
return (
<div className="page-enter" style={{ padding: 24 }}>
<Result
status="404"
title={<span style={{ background: 'var(--tech-gradient)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>页面不存在</span>}
subTitle={<span style={{ color: 'var(--text-secondary)' }}>抱歉,您访问的页面不存在或已被移除</span>}
extra={<Button type="primary" className="tech-button" onClick={() => history.push('/')}>返回首页</Button>}
style={{
background: 'var(--bg-card)',
border: '1px solid var(--border-color)',
borderRadius: 16,
padding: 32,
}}
/>
</div>
);
};
export default NotFoundPage;
@@ -0,0 +1,230 @@
import React, { useEffect, useState } from 'react';
import { Card, Space, Typography, Row, Col, Statistic, Progress, Button } from 'antd';
import {
RocketOutlined,
TeamOutlined,
AppstoreOutlined,
CloudServerOutlined,
TrophyOutlined,
ThunderboltOutlined,
GlobalOutlined,
SafetyOutlined
} from '@ant-design/icons';
import TenantScopeFilter from '@/components/TenantScopeFilter';
const { Title, Paragraph } = Typography;
const Welcome: React.FC = () => {
const [time, setTime] = useState(new Date());
useEffect(() => {
let isMounted = true;
const timer = setInterval(() => {
if (isMounted) {
setTime(new Date());
}
}, 1000);
return () => {
isMounted = false;
clearInterval(timer);
};
}, []);
const stats = [
{ title: '今日订单', value: 1234, icon: <AppstoreOutlined />, color: '#667eea' },
{ title: '活跃用户', value: 856, icon: <TeamOutlined />, color: '#764ba2' },
{ title: '设备在线', value: 98, suffix: '%', icon: <CloudServerOutlined />, color: '#f093fb' },
{ title: '系统状态', value: 99.9, suffix: '%', icon: <SafetyOutlined />, color: '#4facfe' },
];
const quickActions = [
{ title: '新增订单', icon: <AppstoreOutlined />, color: '#667eea' },
{ title: '用户管理', icon: <TeamOutlined />, color: '#764ba2' },
{ title: '设备监控', icon: <CloudServerOutlined />, color: '#f093fb' },
{ title: '系统设置', icon: <SafetyOutlined />, color: '#4facfe' },
];
return (
<div className="page-enter" style={{ padding: 24 }}>
{/* 欢迎横幅 */}
<Card
className="modern-card"
style={{
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
border: 'none',
marginBottom: 24,
color: 'white'
}}
>
<Row align="middle" justify="space-between">
<Col>
<Space direction="vertical" size={8}>
<Title level={2} style={{ color: 'white', margin: 0 }}>
<RocketOutlined style={{ marginRight: 12 }} />
欢迎使用 Go-Fly Admin
</Title>
<Paragraph style={{ color: 'rgba(255,255,255,0.8)', margin: 0, fontSize: 16 }}>
现代化的智能管理平台 · 科技驱动未来
</Paragraph>
<Paragraph style={{ color: 'rgba(255,255,255,0.6)', margin: 0 }}>
当前时间:{time.toLocaleString()}
</Paragraph>
</Space>
</Col>
<Col>
<TenantScopeFilter />
</Col>
</Row>
</Card>
{/* 数据统计卡片 */}
<Row gutter={[24, 24]} style={{ marginBottom: 24 }}>
{stats.map((stat, index) => (
<Col xs={12} sm={12} md={6} key={index}>
<Card
className="modern-card"
style={{
textAlign: 'center',
borderLeft: `4px solid ${stat.color}`,
background: 'var(--bg-card)'
}}
>
<div style={{ color: stat.color, fontSize: 24, marginBottom: 8 }}>
{stat.icon}
</div>
<Statistic
title={stat.title}
value={stat.value}
suffix={stat.suffix}
valueStyle={{
color: 'var(--text-primary)',
fontSize: 28,
fontWeight: 'bold'
}}
/>
</Card>
</Col>
))}
</Row>
<Row gutter={[24, 24]}>
{/* 系统状态 */}
<Col xs={24} md={12}>
<Card className="modern-card" title={
<span style={{ color: 'var(--text-primary)' }}>
<ThunderboltOutlined style={{ marginRight: 8, color: '#667eea' }} />
系统状态
</span>
}>
<Space direction="vertical" style={{ width: '100%' }} size={16}>
<div>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
<span style={{ color: 'var(--text-secondary)' }}>CPU 使用率</span>
<span style={{ color: 'var(--text-primary)' }}>45%</span>
</div>
<Progress percent={45} strokeColor="#667eea" />
</div>
<div>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
<span style={{ color: 'var(--text-secondary)' }}>内存使用率</span>
<span style={{ color: 'var(--text-primary)' }}>68%</span>
</div>
<Progress percent={68} strokeColor="#764ba2" />
</div>
<div>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
<span style={{ color: 'var(--text-secondary)' }}>磁盘使用率</span>
<span style={{ color: 'var(--text-primary)' }}>32%</span>
</div>
<Progress percent={32} strokeColor="#f093fb" />
</div>
</Space>
</Card>
</Col>
{/* 快捷操作 */}
<Col xs={24} md={12}>
<Card className="modern-card" title={
<span style={{ color: 'var(--text-primary)' }}>
<TrophyOutlined style={{ marginRight: 8, color: '#667eea' }} />
快捷操作
</span>
}>
<Row gutter={[16, 16]}>
{quickActions.map((action, index) => (
<Col span={12} key={index}>
<Button
block
size="large"
className="tech-button"
style={{
height: 64,
background: `linear-gradient(135deg, ${action.color}33, ${action.color}11)`,
border: `1px solid ${action.color}44`,
color: action.color,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center'
}}
>
<div style={{ fontSize: 20, marginBottom: 4 }}>{action.icon}</div>
<div style={{ fontSize: 12 }}>{action.title}</div>
</Button>
</Col>
))}
</Row>
</Card>
</Col>
</Row>
{/* 功能介绍 */}
<Card className="modern-card" style={{ marginTop: 24 }} title={
<span style={{ color: 'var(--text-primary)' }}>
<GlobalOutlined style={{ marginRight: 8, color: '#667eea' }} />
平台特性
</span>
}>
<Row gutter={[24, 24]}>
<Col xs={24} sm={12} md={8}>
<div style={{ textAlign: 'center', padding: 16 }}>
<div style={{ fontSize: 32, color: '#667eea', marginBottom: 12 }}>
<RocketOutlined />
</div>
<Title level={4} style={{ color: 'var(--text-primary)' }}>高性能架构</Title>
<Paragraph style={{ color: 'var(--text-secondary)' }}>
基于微服务架构,支持高并发访问,确保系统稳定运行
</Paragraph>
</div>
</Col>
<Col xs={24} sm={12} md={8}>
<div style={{ textAlign: 'center', padding: 16 }}>
<div style={{ fontSize: 32, color: '#764ba2', marginBottom: 12 }}>
<SafetyOutlined />
</div>
<Title level={4} style={{ color: 'var(--text-primary)' }}>安全可靠</Title>
<Paragraph style={{ color: 'var(--text-secondary)' }}>
多层安全防护,数据加密传输,保障业务数据安全
</Paragraph>
</div>
</Col>
<Col xs={24} sm={12} md={8}>
<div style={{ textAlign: 'center', padding: 16 }}>
<div style={{ fontSize: 32, color: '#f093fb', marginBottom: 12 }}>
<ThunderboltOutlined />
</div>
<Title level={4} style={{ color: 'var(--text-primary)' }}>智能运维</Title>
<Paragraph style={{ color: 'var(--text-secondary)' }}>
实时监控预警,自动化运维管理,降低运维成本
</Paragraph>
</div>
</Col>
</Row>
</Card>
</div>
);
};
export default Welcome;
@@ -0,0 +1,56 @@
import React, { useEffect, useRef } from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
export type DeviceFormValues = {
id?: number;
deviceSn?: string;
deviceName?: string;
nickname?: string;
deviceType?: number;
firmwareVersion?: string;
remark?: string;
};
interface DeviceFormProps {
title: string;
visible: boolean;
onVisibleChange: (v: boolean) => void;
onFinish: (values: DeviceFormValues) => Promise<boolean>;
initialValues?: Partial<DeviceFormValues>;
}
const DEVICE_TYPE_OPTIONS = [
{ label: '机场', value: 1 },
{ label: '无人机', value: 2 },
{ label: '遥控器', value: 3 },
];
const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange, onFinish, initialValues }) => {
const formRef = useRef<any>();
useEffect(() => {
if (initialValues) formRef.current?.setFieldsValue(initialValues);
}, [initialValues]);
return (
<ModalForm<DeviceFormValues>
title={title}
visible={visible}
formRef={formRef}
onVisibleChange={onVisibleChange}
onFinish={onFinish}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText name="deviceSn" label="设备序列号" rules={[{ required: true, message: '请输入设备序列号' }]} width="md" />
<ProFormText name="deviceName" label="设备名称" rules={[{ required: true, message: '请输入设备名称' }]} width="md" />
<ProFormText name="nickname" label="昵称" width="md" />
<ProFormSelect name="deviceType" label="设备类型" options={DEVICE_TYPE_OPTIONS} width="md" />
<ProFormText name="firmwareVersion" label="固件版本" width="md" />
<ProFormTextArea name="remark" label="备注" width="lg" />
</ProForm.Group>
</ModalForm>
);
};
export default DeviceForm;
@@ -0,0 +1,53 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import { ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { Space, Switch } from 'antd';
import { deviceApi } from '@/services/device';
export interface DeviceTableRef { reload: () => void }
interface DeviceTableProps {
params?: Record<string, any>;
onEdit?: (record: any) => void;
onDelete?: (record: any) => void;
}
const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEdit, onDelete }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48, fixed: 'left' },
{ title: '设备序列号', dataIndex: 'deviceSn', copyable: true, fixed: 'left', width: 160 },
{ title: '设备名称', dataIndex: 'deviceName' },
{ title: '昵称', dataIndex: 'nickname' },
{ title: '设备类型', dataIndex: 'deviceType' },
{ title: '固件版本', dataIndex: 'firmwareVersion' },
{ title: '绑定状态', dataIndex: 'boundStatus', render: (_, r) => <Switch checked={r.boundStatus === 1} disabled /> },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作', key: 'action', valueType: 'option', width: 140, fixed: 'right',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
</Space>
)
},
];
return (
<ProTable<any>
rowKey="id"
headerTitle="设备列表"
actionRef={actionRef}
request={(p) => deviceApi.deviceList({ page: p.current, limit: p.pageSize, ...params })}
columns={columns}
search={false}
scroll={{ x: 1000 }}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
);
});
export default DeviceTable;
@@ -0,0 +1,95 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Modal, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
import DeviceTable, { DeviceTableRef } from './components/DeviceTable';
import DeviceForm, { DeviceFormValues } from './components/DeviceForm';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
const DevicePage: React.FC = () => {
const tableRef = useRef<DeviceTableRef>(null);
const [query, setQuery] = useState<Record<string, any>>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<any | null>(null);
const add = async (values: DeviceFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateDevice(values as any);
message.success('新增成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('新增失败');
return false;
} finally {
hide();
}
};
const edit = async (values: DeviceFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateDevice({ ...(current || {}), ...values } as any);
message.success('修改成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally {
hide();
}
};
const del = async (record: any) => {
Modal.confirm({
title: `确认删除设备[${record.deviceName || record.deviceSn}]?`,
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await deviceApi.deleteDevice(record.deviceSn);
message.success('删除成功');
tableRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally {
hide();
}
},
});
};
return (
<PageContainer header={{ title: '设备管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<ProFormText name="deviceSn" label="设备序列号" />
<ProFormText name="deviceName" label="设备名称" />
<ProFormSelect name="deviceType" label="设备类型" options={[
{ label: '无人机', value: 1 },
{ label: '地面站', value: 2 },
{ label: '遥控器', value: 3 },
]} />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<DeviceTable
ref={tableRef}
params={query}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={(r) => del(r)}
/>
</GlassCard>
<DeviceForm title="新增设备" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
<DeviceForm title="编辑设备" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
</PageContainer>
);
};
export default DevicePage;
@@ -0,0 +1,113 @@
import React, { useEffect, useRef, useState } from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Button, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
export type WaylineFormValues = {
id?: number;
name?: string;
workspaceId?: string;
waylineId?: string;
sign?: string;
};
interface WaylineFormProps {
title: string;
visible: boolean;
onVisibleChange: (v: boolean) => void;
onFinish: (values: WaylineFormValues) => Promise<boolean>;
initialValues?: Partial<WaylineFormValues>;
workspaceOptions?: Array<{ label: string; value: string }>;
}
// 简单上传到文件服务,返回 id/url/path
async function uploadWaylineFile(file: File) {
const formData = new FormData();
formData.append('file', file);
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData });
const data = await resp.json();
if (!data || !data.id) throw new Error('上传失败');
return data as { id: string; url: string; path: string };
}
const WaylineForm: React.FC<WaylineFormProps> = ({ title, visible, onVisibleChange, onFinish, initialValues, workspaceOptions }) => {
const formRef = useRef<any>();
const [fileInfo, setFileInfo] = useState<{ id: string; url: string } | undefined>();
useEffect(() => {
if (initialValues) {
formRef.current?.setFieldsValue(initialValues);
}
}, [initialValues]);
return (
<ModalForm<WaylineFormValues>
title={title}
visible={visible}
formRef={formRef}
onVisibleChange={(v) => {
onVisibleChange?.(v);
if (!v) setFileInfo(undefined);
}}
onFinish={async (values) => {
if (!values.waylineId && !fileInfo) {
message.warning('请上传航线文件');
return false;
}
const payload: WaylineFormValues = {
...initialValues,
...values,
waylineId: values.waylineId || fileInfo?.id,
};
return onFinish(payload);
}}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText
name="name"
label="航线名称"
rules={[{ required: true, message: '请输入航线名称' }]}
width="md"
/>
<ProFormSelect
name="workspaceId"
label="工作区"
rules={[{ required: true, message: '请选择工作区' }]}
options={workspaceOptions}
width="md"
/>
<ProFormText name="waylineId" hidden />
<ProFormText name="sign" hidden />
</ProForm.Group>
<div style={{ marginBottom: 12 }}>航线文件</div>
<Upload
maxCount={1}
accept=".kmz,.kml"
showUploadList={false}
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
const r = await uploadWaylineFile(file);
setFileInfo({ id: r.id, url: r.url });
formRef.current?.setFieldsValue({ waylineId: r.id });
message.success('上传成功');
onSuccess?.('ok');
}
} catch (err) {
message.error('上传失败');
onError?.(err as any);
}
}}
>
<Button icon={<UploadOutlined />}>{fileInfo ? '重新上传' : '上传文件'}</Button>
</Upload>
{fileInfo && (
<div style={{ marginTop: 8, color: '#666' }}>已上传:{fileInfo.id}</div>
)}
</ModalForm>
);
};
export default WaylineForm;
@@ -0,0 +1,64 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import type { ProColumns } from '@ant-design/pro-components';
import { Space } from 'antd';
import { deviceApi } from '@/services/device';
import { downloadByUrl } from '@/utils/download';
export interface WaylineTableRef {
reload: () => void;
}
interface WaylineTableProps {
params?: Record<string, any>;
onEdit?: (record: any) => void;
onDelete?: (record: any) => void;
}
const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, onEdit, onDelete }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '航线名称', dataIndex: 'name' },
{ title: '航线ID', dataIndex: 'waylineId' },
{ title: '空间ID', dataIndex: 'workspaceId' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '航线文件', dataIndex: 'fileUrl', search: false,
render: (_, record) => record.fileUrl ? (
<a
href={record.fileUrl}
onClick={(e) => { e.preventDefault(); downloadByUrl(record.fileUrl, record.name || 'wayline.kmz'); }}
>下载文件</a>
) : '-'
},
{ title: '文件签名', dataIndex: 'sign', ellipsis: true, copyable: true },
{
title: '操作', key: 'action', valueType: 'option',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
</Space>
)
},
];
return (
<ProTable<any>
rowKey="id"
headerTitle="航线列表"
actionRef={actionRef}
request={(p) => deviceApi.wayline({ ...p, ...params })}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
);
});
export default WaylineTable;
@@ -0,0 +1,88 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormText } from '@ant-design/pro-components';
import { Modal, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
import WaylineTable, { WaylineTableRef } from './components/WaylineTable';
import WaylineForm, { WaylineFormValues } from './components/WaylineForm';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
const WaylinePage: React.FC = () => {
const tableRef = useRef<WaylineTableRef>(null);
const [query, setQuery] = useState<Record<string, any>>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<any | null>(null);
const add = async (values: WaylineFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateWayline(values as any);
message.success('新增成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('新增失败');
return false;
} finally {
hide();
}
};
const edit = async (values: WaylineFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateWayline({ ...(current || {}), ...values } as any);
message.success('修改成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally {
hide();
}
};
const del = async (record: any) => {
Modal.confirm({
title: `确认删除航线[${record.name}]?`,
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await deviceApi.deleteWayline(record.id);
message.success('删除成功');
tableRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
},
});
};
return (
<PageContainer header={{ title: '航线管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<ProFormText name="name" label="名称" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<WaylineTable
ref={tableRef}
params={query}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={(r) => del(r)}
/>
</GlassCard>
<WaylineForm title="新增航线" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
<WaylineForm title="编辑航线" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
</PageContainer>
);
};
export default WaylinePage;
@@ -0,0 +1,67 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { Image, Popconfirm, Typography, message } from 'antd';
import { GlassCard, SearchBarPlus } from '@/components/ui';
import { filesApi } from '@/services/files';
const { Link } = Typography;
const FilesPage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [params, setParams] = useState<Record<string, any>>({});
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '资源名称', dataIndex: 'name' },
{ title: '文件大小(MB)', dataIndex: 'size', valueType: 'digit' },
{ title: '文件预览', dataIndex: 'url', search: false, width: 140, render: (url: string) => (url ? <Image src={url} width={100} /> : '-') },
{ title: '媒体类型', dataIndex: 'contentType' },
{ title: '文件系统', dataIndex: 'source', render: (_: any, record: any) => record?.source || record?.grantType || '-' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{ title: '账户', dataIndex: 'accountType' },
{
title: '操作', key: 'action', width: 100,
render: (_: any, record: any) => (
<Popconfirm
title={`确认删除文件[${record.name}]?`}
onConfirm={async () => {
const hide = message.loading('正在删除...');
try {
await filesApi.delete(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}
>
<Link>删除</Link>
</Popconfirm>
)
},
];
return (
<PageContainer header={{ title: '文件管理', subTitle: '平台文件' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => actionRef.current?.reload()} onFinish={async (values) => setParams(values)}>
<ProFormText name="name" label="名称" placeholder="请输入关键字" />
</SearchBarPlus>
<GlassCard>
<ProTable<any>
rowKey="id"
headerTitle="文件列表"
request={(p) => filesApi.list({ ...p, ...params })}
actionRef={actionRef}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default FilesPage;
@@ -0,0 +1,61 @@
import React, { useState, useRef } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { GlassCard, SearchBarPlus } from '@/components/ui';
import { searchApi } from '@/services/search';
const AuditLogPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const actionRef = useRef<ActionType>();
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '日志时间', key: 'timestamp', width: 140, render: (_, r) => r.timestamp },
{ title: '用户ID', dataIndex: 'userId', width: 80 },
{ title: '用户名', dataIndex: 'userName', width: 120 },
{ title: '租户ID', dataIndex: 'clientId', width: 120 },
{ title: '操作信息', dataIndex: 'operation', width: 300, ellipsis: true, render: (_, r) => r.operation && <span dangerouslySetInnerHTML={{ __html: r.operation }} /> },
{ title: '应用名', dataIndex: 'appName', width: 140, ellipsis: true },
{ title: '类名', dataIndex: 'className', width: 240, ellipsis: true },
];
return (
<PageContainer header={{ title: '审计日志' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => {
const { searchKey, searchValue } = values as any;
let queryStr = '';
if (searchKey && searchValue) queryStr = searchKey === 'none' ? searchValue : `${searchKey}:${searchValue}`;
setParams({ ...params, queryStr });
}}
>
<ProFormSelect
name="searchKey"
label="检索"
valueEnum={{ none: '全文检索', appName: '应用名', classname: '类名', methodName: '方法名', userId: '用户ID', userName: '用户名', clientId: '租户ID', operation: '操作信息' }}
/>
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<GlassCard>
<ProTable<any>
actionRef={actionRef}
rowKey="id"
headerTitle="审计日志"
request={(p) => searchApi.auditlog({ ...p, ...params })}
columns={columns}
search={false}
size="small"
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default AuditLogPage;
@@ -0,0 +1,56 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { GlassCard, SearchBarPlus } from '@/components/ui';
import { searchApi } from '@/services/search';
const SlowSqlLogPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const actionRef = useRef<ActionType>();
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '日志时间', key: 'timestamp', width: 140, render: (_, r) => r.timestamp },
{ title: '查询语句', dataIndex: 'query_str', width: 400, ellipsis: true },
{ title: '查询时间(ms)', dataIndex: 'query_time', width: 120 },
{ title: '锁等待(ms)', dataIndex: 'lock_time', width: 120 },
{ title: '返回行数', dataIndex: 'rows_sent', width: 120 },
{ title: '扫描行数', dataIndex: 'rows_examined', width: 160 },
];
return (
<PageContainer header={{ title: '慢查询日志' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => {
const { searchKey, searchValue } = values as any;
let queryStr = '';
if (searchKey && searchValue) queryStr = searchKey === 'none' ? searchValue : `${searchKey}:${searchValue}`;
setParams({ ...params, queryStr });
}}
>
<ProFormSelect name="searchKey" label="检索" valueEnum={{ none: '全文检索', query_str: '查询语句' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<GlassCard>
<ProTable<any>
actionRef={actionRef}
rowKey="id"
headerTitle="慢查询日志"
request={(p) => searchApi.slowQueryLog({ ...p, ...params })}
columns={columns}
search={false}
size="small"
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default SlowSqlLogPage;
@@ -0,0 +1,38 @@
import React, { useEffect, useState } from 'react';
import { Button, Modal, Table } from 'antd';
import { searchApi } from '@/services/search';
interface Props {
traceId?: string;
open: boolean;
onCancel: () => void;
}
const TraceView: React.FC<Props> = ({ traceId, open, onCancel }) => {
const [data, setData] = useState<any[]>([]);
useEffect(() => {
(async () => {
if (open && traceId) {
const list = await searchApi.tracelog(traceId);
setData(list || []);
}
})();
}, [open, traceId]);
const columns = [
{ title: '应用名', dataIndex: 'appName' },
{ title: 'spanId', dataIndex: 'spanId' },
{ title: '服务IP', dataIndex: 'serverIp' },
{ title: '端口', dataIndex: 'serverPort' },
{ title: '时间', dataIndex: 'timestamp' },
];
return (
<Modal title="日志链路" width={800} open={open} onCancel={onCancel} footer={<Button type="primary" onClick={onCancel}>关闭</Button>}>
<Table rowKey={(r) => r.spanId || r.id} dataSource={data} columns={columns as any} pagination={false} size="small" />
</Modal>
);
};
export default TraceView;
@@ -0,0 +1,75 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { Typography } from 'antd';
import { GlassCard, SearchBarPlus } from '@/components/ui';
import { searchApi } from '@/services/search';
import TraceView from './components/TraceView';
const { Link } = Typography;
const SysLogPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({ sortCol: 'timestamp', isHighlighter: 'true' });
const [trace, setTrace] = useState<{ open: boolean; traceId?: string }>({ open: false });
const actionRef = useRef<ActionType>();
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '时间', key: 'timestamp', width: 120, render: (_, r) => r.timestamp },
{ title: '日志信息', dataIndex: 'message', ellipsis: true, width: 400, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.message || '' }} /> },
{ title: '日志级别', dataIndex: 'logLevel', width: 80, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.logLevel || '' }} /> },
{ title: '应用名', dataIndex: 'appName', width: 120, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.appName || '' }} /> },
{
title: '追踪ID', key: 'traceId', width: 200,
render: (_, r) => (
<Link onClick={() => setTrace({ open: true, traceId: String(r.traceId || '').replace('<mark>', '').replace('</mark>', '') })}>
<span dangerouslySetInnerHTML={{ __html: r.traceId || '' }} />
</Link>
)
},
{ title: 'spanId', dataIndex: 'spanId', width: 120, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.spanId || '' }} /> },
{ title: '类名', dataIndex: 'classname', width: 200, ellipsis: true, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.classname || '' }} /> },
{ title: '线程名', dataIndex: 'threadName', width: 140, ellipsis: true, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.threadName || '' }} /> },
{ title: '服务IP', dataIndex: 'serverIp', width: 120, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.serverIp || '' }} /> },
{ title: '服务端口', dataIndex: 'serverPort', width: 100, render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.serverPort || '' }} /> },
];
return (
<PageContainer header={{ title: '系统日志' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => {
const { searchKey, searchValue } = values as any;
let queryStr = '';
if (searchKey && searchValue) queryStr = searchKey === 'none' ? searchValue : `${searchKey}:${searchValue}`;
setParams({ ...params, queryStr });
}}
>
<ProFormSelect name="searchKey" label="检索" valueEnum={{ none: '全文检索', message: '日志信息', logLevel: '日志级别', appName: '应用名', classname: '类名', traceId: '链路追踪ID' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<GlassCard>
<ProTable<any>
rowKey="id"
headerTitle="系统日志"
actionRef={actionRef}
request={(p) => searchApi.syslog({ ...p, ...params })}
columns={columns}
search={false}
size="small"
pagination={{ showSizeChanger: true, showQuickJumper: true }}
scroll={{ x: 1600 }}
/>
</GlassCard>
<TraceView open={trace.open} traceId={trace.traceId} onCancel={() => setTrace({ open: false })} />
</PageContainer>
);
};
export default SysLogPage;
@@ -0,0 +1,121 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { Modal, Space, Tag, Typography, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { messageApi, MessageItem } from '@/services/message';
const { Link } = Typography;
const MESSAGE_TYPE: Record<number, { text: string; color: string }> = {
1: { text: '退款通知', color: 'warning' },
2: { text: '订单通知', color: 'success' },
3: { text: '系统通知', color: 'blue' },
};
const MESSAGE_STATUS: Record<number, { text: string; color: string }> = {
0: { text: '未读', color: 'processing' },
1: { text: '已读', color: 'default' },
};
const MessageList: React.FC = () => {
const actionRef = useRef<ActionType>();
const [selectedRows, setSelectedRows] = useState<MessageItem[]>([]);
const handleMessageClick = async (record: MessageItem) => {
if (record.status === 0) {
await messageApi.markAsRead(record.id);
actionRef.current?.reload();
}
};
const handleMarkAllRead = async () => {
try {
await messageApi.markAllAsRead();
message.success('已全部标记为已读');
actionRef.current?.reload();
} catch (error) {
message.error('操作失败');
}
};
const columns: ProColumns<MessageItem>[] = [
{
title: '类型',
dataIndex: 'type',
width: 100,
render: (type) => {
const info = MESSAGE_TYPE[type as number] || { text: '未知', color: 'default' };
return <Tag color={info.color}>{info.text}</Tag>;
},
valueEnum: Object.fromEntries(Object.entries(MESSAGE_TYPE).map(([k, v]) => [k, { text: v.text }])) as any,
},
{
title: '标题',
dataIndex: 'title',
render: (_, record) => (
<Link onClick={() => handleMessageClick(record)}>{record.title}</Link>
),
},
{ title: '内容', dataIndex: 'content', ellipsis: true, width: 300 },
{
title: '状态', dataIndex: 'status', width: 80,
render: (status) => {
const s = MESSAGE_STATUS[status as number] || { text: '未知', color: 'default' };
return <Tag color={s.color}>{s.text}</Tag>;
},
},
{ title: '时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180, sorter: true },
{
title: '操作', key: 'action', width: 120,
render: (_, record) => (
<Space>
{record.status === 0 && (
<Link onClick={() => handleMessageClick(record)}>查看</Link>
)}
<Link
onClick={() => {
Modal.confirm({
title: '确认删除该消息吗?',
onOk: async () => {
await messageApi.delete(record.id);
actionRef.current?.reload();
message.success('删除成功');
},
});
}}
>删除</Link>
</Space>
),
},
];
return (
<PageContainer header={{ title: '消息列表' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => actionRef.current?.reload()}
/>
<ActionBar right={<GradientButton size="middle" key="markAllRead" onClick={handleMarkAllRead}>全部标记已读</GradientButton>} />
<GlassCard>
<ProTable<MessageItem>
actionRef={actionRef}
rowKey="id"
search={{ labelWidth: 120 }}
toolBarRender={false}
request={(p) => messageApi.list(p)}
columns={columns}
rowSelection={{ onChange: (_, rows) => setSelectedRows(rows) }}
pagination={{ showQuickJumper: true, showSizeChanger: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default MessageList;
@@ -0,0 +1,204 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProForm, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { DatePicker, Form, Input, InputNumber, Modal, Select, Space, Tag, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { ordersApi } from '@/services/orders';
import moment from 'moment';
const { RangePicker } = DatePicker;
const COUPON_TYPES = [
{ label: '满减券', value: 1 },
{ label: '折扣券', value: 2 },
{ label: '代金券', value: 3 },
];
const STATUS_OPTIONS = [
{ label: '未使用', value: 0 },
{ label: '已使用', value: 1 },
{ label: '已过期', value: 2 },
{ label: '已作废', value: 3 },
];
const SOURCE_OPTIONS = [
{ label: '携程', value: 1 },
{ label: '后台发放', value: 2 },
];
const CouponPage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
const [open, setOpen] = useState(false);
const [editing, setEditing] = useState<any | null>(null);
const [form] = Form.useForm();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '优惠券编号', dataIndex: 'couponNo', width: 160 },
{ title: '优惠券名称', dataIndex: 'couponName', width: 200 },
{ title: '类型', dataIndex: 'couponType', width: 100, render: (v: number) => COUPON_TYPES.find(i => i.value === v)?.label || '-' },
{ title: '金额/折扣', key: 'amount', width: 120, render: (_: any, r: any) => r.couponType === 2 ? `${r.discountRate}%` : `¥${r.amount}` },
{ title: '使用门槛', dataIndex: 'minAmount', width: 100, render: (v: number) => v ? `¥${v}` : '-' },
{ title: '状态', dataIndex: 'status', width: 100, render: (v: number) => { const color = v === 0 ? 'green' : v === 1 ? 'blue' : v === 2 ? 'orange' : 'red'; return <Tag color={color}>{STATUS_OPTIONS.find(i => i.value === v)?.label || '-'}</Tag>; } },
{ title: '用户手机号', dataIndex: 'userPhone', width: 140 },
{ title: '来源', dataIndex: 'source', width: 100, render: (v: number) => SOURCE_OPTIONS.find(i => i.value === v)?.label || '-' },
{ title: '有效期', key: 'validTime', width: 220, render: (_: any, r: any) => (<div><div>{r.validStartTime ? moment(r.validStartTime).format('YYYY-MM-DD HH:mm') : '-'}</div><div>~</div><div>{r.validEndTime ? moment(r.validEndTime).format('YYYY-MM-DD HH:mm') : '-'}</div></div>) },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{ title: '操作', key: 'action', width: 160, fixed: 'right', render: (_: any, record: any) => (
<Space size="small">
<a onClick={() => handleView(record)}>查看</a>
<a onClick={() => handleEdit(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => handleDelete(record)}>删除</a>
</Space>
) },
];
const handleView = (record: any) => {
setEditing(record);
form.setFieldsValue({
...record,
validTime: record.validStartTime && record.validEndTime ? [moment(record.validStartTime), moment(record.validEndTime)] : undefined,
});
setOpen(true);
};
const handleEdit = (record: any) => {
setEditing(record);
form.setFieldsValue({
...record,
validTime: record.validStartTime && record.validEndTime ? [moment(record.validStartTime), moment(record.validEndTime)] : undefined,
});
setOpen(true);
};
const handleDelete = async (record: any) => {
Modal.confirm({
title: '确认删除该优惠券?',
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await ordersApi.deleteCoupon(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
},
});
};
const handleAdd = () => {
setEditing(null);
form.resetFields();
setOpen(true);
};
return (
<PageContainer header={{ title: '优惠券管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => actionRef.current?.reload()}
onFinish={async (values) => setSearchParams(values)}
>
<ProFormText name="couponNo" label="优惠券编号" />
<ProFormText name="couponName" label="优惠券名称" />
<ProFormText name="userPhone" label="手机号" />
<ProFormSelect name="couponType" label="类型" options={COUPON_TYPES} />
<ProFormSelect name="status" label="状态" options={STATUS_OPTIONS} />
<ProFormSelect name="source" label="来源" options={SOURCE_OPTIONS} />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增</GradientButton>} />
<GlassCard>
<ProTable<any>
rowKey="id"
actionRef={actionRef}
request={(p) => ordersApi.getCouponList({ ...p, ...searchParams })}
columns={columns}
scroll={{ x: 1200 }}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<Modal
title={editing ? '编辑优惠券' : '新增优惠券'}
open={open}
onCancel={() => setOpen(false)}
onOk={async () => {
try {
const values = await form.validateFields();
const payload: any = { ...values };
if (values.validTime && values.validTime.length === 2) {
payload.validStartTime = values.validTime[0].format('YYYY-MM-DD HH:mm:ss');
payload.validEndTime = values.validTime[1].format('YYYY-MM-DD HH:mm:ss');
}
delete payload.validTime;
const hide = message.loading('保存中...');
if (editing && editing.id) {
await ordersApi.updateCoupon(editing.id, payload);
} else {
await ordersApi.createCoupon(payload);
}
hide();
message.success('保存成功');
setOpen(false);
actionRef.current?.reload();
} catch (e) {
if ((e as any)?.errorFields) return; // 表单校验
message.error('保存失败');
}
}}
destroyOnClose
maskClosable={false}
>
<Form form={form} layout="vertical" preserve={false}>
<Form.Item name="couponName" label="优惠券名称" rules={[{ required: true, message: '请输入优惠券名称' }]}>
<Input placeholder="请输入优惠券名称" />
</Form.Item>
<Form.Item name="couponType" label="优惠券类型" rules={[{ required: true, message: '请选择优惠券类型' }]}>
<Select options={COUPON_TYPES} style={{ width: '100%' }} placeholder="请选择优惠券类型" />
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.couponType !== cur.couponType}>
{({ getFieldValue }) => getFieldValue('couponType') === 2 ? (
<Form.Item name="discountRate" label="折扣率(%)" rules={[{ required: true, message: '请输入折扣率' }]}>
<InputNumber min={1} max={99} style={{ width: '100%' }} placeholder="请输入折扣率" />
</Form.Item>
) : (
<Form.Item name="amount" label="优惠券面额" rules={[{ required: true, message: '请输入优惠券面额' }]}>
<InputNumber min={0} style={{ width: '100%' }} placeholder="请输入优惠券面额" />
</Form.Item>
)}
</Form.Item>
<Form.Item name="minAmount" label="使用门槛">
<InputNumber min={0} style={{ width: '100%' }} placeholder="请输入使用门槛" />
</Form.Item>
<Form.Item name="userPhone" label="用户手机号" rules={[{ required: true, message: '请输入用户手机号' }]}>
<Input placeholder="请输入用户手机号" />
</Form.Item>
<Form.Item name="source" label="来源" rules={[{ required: true, message: '请选择来源' }]}>
<Select options={SOURCE_OPTIONS} style={{ width: '100%' }} placeholder="请选择来源" />
</Form.Item>
<Form.Item name="ctripCouponId" label="携程优惠券ID">
<Input placeholder="当来源为携程时需填写" />
</Form.Item>
<Form.Item name="validTime" label="有效期" rules={[{ required: true, message: '请选择有效期' }]}>
<RangePicker showTime format="YYYY-MM-DD HH:mm:ss" style={{ width: '100%' }} />
</Form.Item>
<Form.Item name="remark" label="备注">
<Input.TextArea rows={3} placeholder="请输入备注" />
</Form.Item>
</Form>
</Modal>
</PageContainer>
);
};
export default CouponPage;
@@ -0,0 +1,65 @@
import React, { useState } from 'react';
import { PageContainer, ProFormText, ProTable, ProFormSelect } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
const EditTaskPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '任务ID', dataIndex: 'id' },
{ title: '订单号', dataIndex: 'orderNo' },
{ title: '状态', dataIndex: 'status' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
{
title: '操作', key: 'action',
render: (_: any, record: any) => (
<Space>
<Popconfirm title="确认删除?" onConfirm={async () => { try { await ordersApi.deleteEditTask(record.id); message.success('删除成功'); } catch { message.error('删除失败'); } }}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<PageContainer header={{ title: '剪辑任务' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => { /* 后端上下文 */ }}
onFinish={async (values) => setParams(values)}
>
<ProFormText name="orderNo" label="订单号" />
<ProFormSelect name="status" label="状态" valueEnum={{ pending: '待处理', processing: '处理中', done: '完成' }} />
</SearchBarPlus>
<ActionBar
left={
<Space>
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={async () => {
const hide = message.loading('提交中...');
try { await ordersApi.saveOrUpdateEditTask({ orderNo: 'DEMO' }); message.success('新增成功'); } catch { message.error('新增失败'); } finally { hide(); }
}}>新增</GradientButton>
</Space>
}
/>
<ProTable<any>
rowKey="id"
request={(p) => ordersApi.getEditTaskList({ ...p, ...params } as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</PageContainer>
);
};
export default EditTaskPage;
@@ -0,0 +1,38 @@
import React from 'react';
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
export interface HomeCarouselItem {
id?: number;
imageUrl?: string;
linkUrl?: string;
sort?: number;
status?: number;
}
export interface HomeCarouselFormProps {
open: boolean;
title: string;
initialValues?: Partial<HomeCarouselItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: HomeCarouselItem) => Promise<boolean>;
}
const HomeCarouselForm: React.FC<HomeCarouselFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<HomeCarouselItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProFormText name="imageUrl" label="图片地址" rules={[{ required: true, message: '请输入图片地址' }]} />
<ProFormText name="linkUrl" label="跳转链接" />
<ProFormDigit name="sort" label="排序" min={1} fieldProps={{ precision: 0 }} initialValue={1} />
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
</ModalForm>
);
};
export default HomeCarouselForm;
@@ -0,0 +1,96 @@
import React, { useState } from 'react';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Popconfirm, Space, Tag, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import HomeCarouselForm, { HomeCarouselItem } from './components/HomeCarouselForm';
const HomeCarouselPage: React.FC = () => {
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '图片', dataIndex: 'imageUrl', render: (v: string) => <img src={v} alt="img" style={{ width: 80, height: 40, objectFit: 'cover' }} /> },
{ title: '跳转链接', dataIndex: 'linkUrl', ellipsis: true },
{ title: '排序', dataIndex: 'sort' },
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
{
title: '操作', key: 'action',
render: (_: any, record: HomeCarouselItem) => (
<Space>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<Popconfirm title={`确认删除?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await ordersApi.deleteHomeCarousel(record.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<PageContainer header={{ title: '首页轮播' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 切换后后端生效 */ }} />
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<ProTable<HomeCarouselItem>
rowKey="id"
request={(p) => ordersApi.homeCarouselList(p as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
<HomeCarouselForm
title="新增轮播"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateHomeCarousel(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<HomeCarouselForm
title="编辑轮播"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default HomeCarouselPage;
@@ -0,0 +1,63 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { Tag } from 'antd';
import { ordersApi, OrderItem } from '@/services/orders';
import { GlassCard, SearchBarPlus } from '@/components/ui';
const STATUS_OPTIONS = [
{ label: '未支付', value: 0 },
{ label: '已支付', value: 1 },
{ label: '已退款', value: 2 },
{ label: '已取消', value: 3 },
];
const PAY_TYPE_OPTIONS = [
{ label: '微信支付', value: 1 },
{ label: '优惠券支付', value: 2 },
];
const OrderPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const actionRef = useRef<ActionType>();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '订单编号', dataIndex: 'orderNo' },
{ title: '金额', dataIndex: 'amount' },
{ title: '支付方式', dataIndex: 'payType', render: (v: number) => <Tag color={v === 1 ? 'green' : 'blue'}>{PAY_TYPE_OPTIONS.find(o => o.value === v)?.label || '未知'}</Tag> },
{ title: '状态', dataIndex: 'orderStatus', render: (v: number) => <Tag>{STATUS_OPTIONS.find(o => o.value === v)?.label || '未知'}</Tag> },
{ title: '旅游项目', dataIndex: 'tourismName' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
];
return (
<PageContainer header={{ title: '订单管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={6}
onTenantChanged={() => actionRef.current?.reload()}
onFinish={async (values) => setParams(values)}
>
<ProFormText name="orderNo" label="订单编号" placeholder="请输入订单编号" />
<ProFormSelect name="orderStatus" label="订单状态" options={STATUS_OPTIONS} allowClear />
<ProFormSelect name="payType" label="支付方式" options={PAY_TYPE_OPTIONS} allowClear />
</SearchBarPlus>
<GlassCard>
<ProTable<OrderItem>
rowKey="id"
headerTitle="订单列表"
actionRef={actionRef}
request={(p) => ordersApi.order({ ...p, ...params } as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true, defaultPageSize: 20 }}
/>
</GlassCard>
</PageContainer>
);
};
export default OrderPage;
@@ -0,0 +1,115 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormDateRangePicker, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { Image, Popconfirm, Space, Tag, message, Typography } from 'antd';
import { SearchBarPlus, GlassCard } from '@/components/ui';
import { ordersApi } from '@/services/orders';
import { downloadByUrl } from '@/utils/download';
const { Link } = Typography;
const TYPE_COLORS: Record<string, string> = {
'image/jpeg': 'blue',
'image/png': 'blue',
'image/gif': 'blue',
'video/mp4': 'green',
'video/mpeg': 'green',
'application/pdf': 'orange',
'application/msword': 'orange',
default: 'default',
};
const isImageType = (t?: string | null) => !!t && t.startsWith('image/');
const typeLabel = (t?: string | null) => {
if (!t) return 'UNKNOWN';
const parts = String(t).split('/');
return parts.length > 1 ? parts[1].toUpperCase() : String(t).toUpperCase();
};
const OrderFilePage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [params, setParams] = useState<Record<string, any>>({});
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '订单编号', dataIndex: 'orderNo', copyable: true, ellipsis: true },
{
title: '文件预览', dataIndex: 'viewUrl', search: false, width: 220,
render: (_, record) => (
<Space direction="vertical">
{isImageType(record.fileType) ? (
<Image src={record.viewUrl} width={120} height={80} style={{ objectFit: 'cover' }} />
) : (
<Tag color={TYPE_COLORS[record.fileType as string] || TYPE_COLORS.default}>
{typeLabel(record.fileType)}
</Tag>
)}
<Space>
<a href={record.viewUrl} onClick={(e) => { e.preventDefault(); downloadByUrl(record.viewUrl); }}>下载</a>
<Link href={record.viewUrl} target="_blank" rel="noopener noreferrer">预览</Link>
</Space>
</Space>
)
},
{ title: '文件类型', dataIndex: 'fileType', width: 120, render: (t) => (<Tag color={TYPE_COLORS[t as string] || TYPE_COLORS.default}>{typeLabel(t as string)}</Tag>) },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作', valueType: 'option', width: 100,
render: (_, record) => (
<Popconfirm
title={`确认删除文件[${record.id}]?`}
onConfirm={async () => {
const hide = message.loading('正在删除...');
try {
await ordersApi.deleteOrderFile(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}
>
<a>删除</a>
</Popconfirm>
)
},
];
return (
<PageContainer header={{ title: '订单文件' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => {
const p: Record<string, any> = { ...values };
if (values.createTime?.length === 2) {
p.startTime = values.createTime?.[0]?.format?.('YYYY-MM-DD 00:00:00') || values.createTime?.[0];
p.endTime = values.createTime?.[1]?.format?.('YYYY-MM-DD 23:59:59') || values.createTime?.[1];
delete p.createTime;
}
setParams(p);
}}
>
<ProFormText name="orderNo" label="订单编号" placeholder="请输入订单编号" />
<ProFormDateRangePicker name="createTime" label="创建时间" />
</SearchBarPlus>
<GlassCard>
<ProTable<any>
rowKey="id"
headerTitle="文件列表"
actionRef={actionRef}
request={(p) => ordersApi.orderFiles({ ...p, ...params })}
columns={columns}
search={false}
pagination={{ defaultPageSize: 10, showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default OrderFilePage;
@@ -0,0 +1,37 @@
import React, { useEffect, useState } from 'react';
import { PageContainer } from '@ant-design/pro-components';
import { Card, Col, Row, Statistic, message, Button } from 'antd';
import TenantScopeFilter from '@/components/TenantScopeFilter';
import { ordersApi } from '@/services/orders';
import { ActionBar } from '@/components/ui';
const ProfitSharingStatisticsPage: React.FC = () => {
const [loading, setLoading] = useState(false);
const [stat, setStat] = useState<any>({});
const load = async () => {
setLoading(true);
try {
const res = await ordersApi.getProfitSharingStatistics();
setStat(res?.data || res);
} catch (e) {
message.error('加载统计失败');
} finally { setLoading(false); }
};
useEffect(() => { load(); }, []);
return (
<PageContainer header={{ title: '分账统计' }} extra={<TenantScopeFilter onChanged={() => load()} /> }>
<ActionBar right={<Button size="middle" onClick={() => load()}>刷新</Button>} />
<Row gutter={16}>
<Col span={6}><Card loading={loading}><Statistic title="总分账额" value={stat?.totalSharingAmount || 0} precision={2} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="分账笔数" value={stat?.sharingCount || 0} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="成功笔数" value={stat?.successCount || 0} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="失败笔数" value={stat?.failedCount || 0} /></Card></Col>
</Row>
</PageContainer>
);
};
export default ProfitSharingStatisticsPage;
@@ -0,0 +1,65 @@
import { GlassCard, GradientButton, ActionBar, SearchBarPlus } from '@/components/ui';
import React, { useState } from 'react';
import { PageContainer, ProFormText } from '@ant-design/pro-components';
import { Descriptions, message, Space } from 'antd';
import { ordersApi } from '@/services/orders';
const ProfitSharingPage: React.FC = () => {
const [orderNo, setOrderNo] = useState<string>('');
const [detail, setDetail] = useState<any>();
const load = async (no: string) => {
try {
const res = await ordersApi.getProfitSharingDetail(no);
setDetail(res?.data || res);
} catch (e) {
message.error('加载分账明细失败');
}
};
const exec = async (no: string) => {
try {
await ordersApi.executeProfitSharing(no);
message.success('已发起分账');
load(no);
} catch (e) {
message.error('分账执行失败');
}
};
return (
<PageContainer header={{ title: '分账管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => orderNo && load(orderNo)}
onFinish={async (v) => { setOrderNo(v.orderNo); load(v.orderNo); }}
>
<ProFormText name="orderNo" label="订单号" placeholder="请输入订单号" />
</SearchBarPlus>
<ActionBar
left={
<Space>
<GradientButton size="middle" type="primary" disabled={!orderNo} onClick={() => exec(orderNo)}>执行分账</GradientButton>
</Space>
}
/>
<GlassCard title="分账明细">
{detail ? (
<Descriptions column={2}>
<Descriptions.Item label="订单号">{detail.orderNo}</Descriptions.Item>
<Descriptions.Item label="总金额">{detail.totalAmount}</Descriptions.Item>
<Descriptions.Item label="状态">{detail.status}</Descriptions.Item>
<Descriptions.Item label="分账笔数">{detail.items?.length || 0}</Descriptions.Item>
</Descriptions>
) : '请输入订单号后查询'}
</GlassCard>
</PageContainer>
);
};
export default ProfitSharingPage;
@@ -0,0 +1,38 @@
import React from 'react';
import { ModalForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
export interface QrcodeItem {
id?: number;
name?: string;
type?: number;
url?: string;
status?: number;
}
export interface QrcodeFormProps {
open: boolean;
title: string;
initialValues?: Partial<QrcodeItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: QrcodeItem) => Promise<boolean>;
}
const QrcodeForm: React.FC<QrcodeFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<QrcodeItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入名称' }]} />
<ProFormText name="url" label="地址" />
<ProFormSelect name="type" label="类型" valueEnum={{ 1: '类型一', 2: '类型二' }} />
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
</ModalForm>
);
};
export default QrcodeForm;
@@ -0,0 +1,94 @@
import React, { useState } from 'react';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Popconfirm, Space, Tag, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import QrcodeForm, { QrcodeItem } from './components/QrcodeForm';
const QrcodePage: React.FC = () => {
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '名称', dataIndex: 'name' },
{ title: '链接', dataIndex: 'url', ellipsis: true },
{ title: '类型', dataIndex: 'type' },
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
{
title: '操作', key: 'action',
render: (_: any, record: QrcodeItem) => (
<Space>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<Popconfirm title={`确认删除二维码[${record.name}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await ordersApi.deleteQrcode(record.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<PageContainer header={{ title: '二维码管理' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} />
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<ProTable<QrcodeItem>
rowKey="id"
request={(p) => ordersApi.qrcodeList(p as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
<QrcodeForm
title="新增二维码"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateQrcode(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<QrcodeForm
title="编辑二维码"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateQrcode({ ...(current as any), ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default QrcodePage;
@@ -0,0 +1,88 @@
import React, { useRef, useState } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { PageContainer, ProForm, ProFormText, ProTable } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
import { ordersApi } from '@/services/orders';
const RefundPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const [creating, setCreating] = useState(false);
const actionRef = useRef<ActionType>();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '订单号', dataIndex: 'orderNo' },
{ title: '退款单号', dataIndex: 'refundNo' },
{ title: '金额', dataIndex: 'amount' },
{ title: '状态', dataIndex: 'status' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
{
title: '操作', key: 'action',
render: (_: any, record: any) => (
<Space>
<Popconfirm
title="确认审核通过?"
onConfirm={async () => {
const hide = message.loading('正在处理...');
try {
await ordersApi.updateRefund({ id: record.id, status: 1 });
message.success('审核通过');
actionRef.current?.reload();
} catch (e) {
message.error('操作失败');
} finally {
hide();
}
}}
>
<a>审核通过</a>
</Popconfirm>
</Space>
),
},
];
return (
<PageContainer header={{ title: '退款管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => actionRef.current?.reload()}
onFinish={async (values) => setParams(values)}
>
<ProFormText name="orderNo" label="订单号" placeholder="请输入订单号" />
</SearchBarPlus>
<div style={{ display: 'flex', gap: 12, alignItems: 'center', margin: '8px 0 12px' }}>
<ProForm layout="inline" onFinish={async (values) => {
if (!values.orderNo) return message.warning('请输入订单号');
setCreating(true);
try {
await ordersApi.createRefund({ orderNo: values.orderNo });
message.success('已提交自动退款');
actionRef.current?.reload();
} catch (e) {
message.error('提交失败');
} finally { setCreating(false); }
}} submitter={{ render: (props) => <GradientButton type="primary" loading={creating} onClick={() => props.submit?.()}>创建退款</GradientButton> }}>
<ProFormText name="orderNo" label="订单号" placeholder="请输入订单号" />
</ProForm>
</div>
<ProTable<any>
rowKey="id"
headerTitle="退款列表"
actionRef={actionRef}
request={(p) => ordersApi.refund({ ...p, ...params } as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</PageContainer>
);
};
export default RefundPage;
@@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import { PageContainer } from '@ant-design/pro-components';
import { Card, Col, Row, Statistic, DatePicker, Space, message, Form } from 'antd';
import { SearchBarPlus } from '@/components/ui';
import { ordersApi } from '@/services/orders';
const { RangePicker } = DatePicker;
const StatisticsPage: React.FC = () => {
const [loading, setLoading] = useState(false);
const [stat, setStat] = useState<any>({});
const [range, setRange] = useState<any>();
const load = async (p?: any) => {
setLoading(true);
try {
const res = await ordersApi.dashboard(p);
setStat(res?.data || res);
} catch (e) {
message.error('加载统计失败');
} finally { setLoading(false); }
};
useEffect(() => { load(); }, []);
return (
<PageContainer header={{ title: '订单统计' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => load(range)}
onFinish={async (values) => {
const v = values?.timeRange;
const r = v && v.length === 2 ? { startTime: v[0]?.toISOString(), endTime: v[1]?.toISOString() } : undefined;
setRange(r);
await load(r);
}}
>
<Form.Item name="timeRange" label="时间范围">
<RangePicker showTime />
</Form.Item>
</SearchBarPlus>
<Row gutter={16}>
<Col span={6}><Card loading={loading}><Statistic title="订单总数" value={stat?.totalOrders || 0} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="支付总额" value={stat?.totalAmount || 0} precision={2} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="退款总额" value={stat?.refundAmount || 0} precision={2} /></Card></Col>
<Col span={6}><Card loading={loading}><Statistic title="转化率" value={stat?.conversionRate || 0} suffix="%" /></Card></Col>
</Row>
</PageContainer>
);
};
export default StatisticsPage;
@@ -0,0 +1,42 @@
import React from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
export interface TourismItem {
id?: number;
tourismName?: string;
address?: string;
contactPerson?: string;
contactPhone?: string;
status?: number;
description?: string;
}
export interface TourismFormProps {
open: boolean;
title: string;
initialValues?: Partial<TourismItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: TourismItem) => Promise<boolean>;
}
const TourismForm: React.FC<TourismFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<TourismItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProFormText name="tourismName" label="景区名称" rules={[{ required: true, message: '请输入景区名称' }]} />
<ProFormText name="address" label="地址" />
<ProFormText name="contactPerson" label="联系人" />
<ProFormText name="contactPhone" label="联系电话" />
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
<ProFormTextArea name="description" label="描述" />
</ModalForm>
);
};
export default TourismForm;
@@ -0,0 +1,95 @@
import React, { useState } from 'react';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Popconfirm, Space, Tag, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import TourismForm, { TourismItem } from './components/TourismForm';
const TourismPage: React.FC = () => {
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<TourismItem | undefined>(undefined);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '旅游项目', dataIndex: 'tourismName' },
{ title: '地址', dataIndex: 'address' },
{ title: '联系人', dataIndex: 'contactPerson' },
{ title: '联系电话', dataIndex: 'contactPhone' },
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
{
title: '操作', key: 'action',
render: (_: any, record: TourismItem) => (
<Space>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<Popconfirm title={`确认删除项目[${record.tourismName}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await ordersApi.deleteTourism(record.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<PageContainer header={{ title: '旅游项目' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} />
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<ProTable<TourismItem>
rowKey="id"
request={(p) => ordersApi.tourism(p as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
<TourismForm
title="新增项目"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateTourism(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<TourismForm
title="编辑项目"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateTourism({ ...(current as any), ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default TourismPage;
@@ -0,0 +1,289 @@
import React, { useEffect, useRef, useState } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { ActionBar, GlassCard, SearchBarPlus } from '@/components/ui';
import {
ModalForm,
PageContainer,
ProForm,
ProFormSelect,
ProFormText,
ProTable,
} from '@ant-design/pro-components';
import { Button, Image, Popconfirm, Space, Tag, Upload, message, Form } from 'antd';
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
const TYPE_OPTIONS = [
{ label: '视频', value: 5, color: '#f5222d' },
{ label: '首页 Banner', value: 6, color: '#2f54eb' },
{ label: '展示封面', value: 4, color: '#52c41a' },
{ label: '入口引导', value: 3, color: '#722ed1' },
{ label: '服务小结展示', value: 2, color: '#13c2c2' },
{ label: '活动', value: 1, color: '#1890ff' },
] as const;
const STATUS_OPTIONS = [
{ label: '启用', value: 0 },
{ label: '禁用', value: 1 },
] as const;
const TourismFilePage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [query, setQuery] = useState<Record<string, any>>({});
const [tourismOptions, setTourismOptions] = useState<Array<{ label: string; value: number }>>([]);
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<any>();
const [uploadPreviewUrl, setUploadPreviewUrl] = useState<string | undefined>();
const [uploadPath, setUploadPath] = useState<string | undefined>();
const [editUploadPreviewUrl, setEditUploadPreviewUrl] = useState<string | undefined>();
const [editUploadPath, setEditUploadPath] = useState<string | undefined>();
useEffect(() => {
(async () => {
try {
const res = await ordersApi.tourism({ page: 1, limit: 1000 });
const list: Array<{ id: number; tourismName: string }> = (res as any).data || res?.data || [];
setTourismOptions(list.map((it) => ({ label: (it as any).tourismName, value: (it as any).id })));
} catch (e) {
// 忽略错误以不影响页面
}
})();
}, []);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{
title: '旅游项目',
dataIndex: 'tourismId',
render: (_: any, record: any) => tourismOptions.find((o) => o.value === record.tourismId)?.label || record.tourismName || '-',
},
{
title: '图片/预览',
dataIndex: 'imageUrl',
search: false,
width: 140,
render: (_: any, record: any) =>
record.type === 5 ? (
<video src={record.imageUrl} controls style={{ width: 120, height: 80, objectFit: 'cover' }} />
) : (
<Image src={record.imageUrl} width={120} height={80} style={{ objectFit: 'cover' }} />
),
},
{ title: '页面链接', dataIndex: 'linkUrl', ellipsis: true, copyable: true },
{ title: '描述', dataIndex: 'description', ellipsis: true },
{
title: '状态',
dataIndex: 'status',
width: 90,
render: (v: number) => <Tag color={v === 0 ? 'green' : 'default'}>{v === 0 ? '启用' : '禁用'}</Tag>,
},
{
title: '类型',
dataIndex: 'type',
width: 120,
render: (v: number) => {
const t = TYPE_OPTIONS.find((i) => i.value === Number(v));
return t ? <Tag color={t.color}>{t.label}</Tag> : '-';
},
},
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作',
key: 'action',
width: 160,
render: (_: any, record: any) => (
<Space>
<a
onClick={() => {
setCurrent(record);
setEditOpen(true);
setEditUploadPreviewUrl(undefined);
setEditUploadPath(undefined);
}}
>
编辑
</a>
<Popconfirm
title={`确认删除资源[${record.id}]?`}
onConfirm={async () => {
const hide = message.loading('正在删除...');
try {
await ordersApi.deleteTourismFile(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally {
hide();
}
}}
>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
),
},
];
const doUpload = async (file: File) => {
const formData = new FormData();
formData.append('file', file);
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData });
const data = await resp.json();
if (!data || (!data.url && !data.path)) throw new Error('上传失败');
return data as { url: string; path: string };
};
return (
<PageContainer header={{ title: '旅游资源管理' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => actionRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<ProFormText name="description" label="资源描述" placeholder="请输入关键字" />
<ProFormSelect name="tourismId" label="项目" placeholder="请选择" options={tourismOptions} showSearch />
<ProFormSelect name="type" label="资源类型" placeholder="请选择" options={TYPE_OPTIONS as any} />
</SearchBarPlus>
<ActionBar left={<Button size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</Button>} />
<GlassCard>
<ProTable<any>
rowKey="id"
headerTitle="资源列表"
actionRef={actionRef}
request={(p) => ordersApi.tourismFile({ ...p, ...query })}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true, defaultPageSize: 10 }}
/>
</GlassCard>
{/* 新建 */}
<ModalForm
title="新增资源"
open={createOpen}
onOpenChange={(v: boolean) => {
if (!v) {
setUploadPreviewUrl(undefined);
setUploadPath(undefined);
}
setCreateOpen(v);
}}
onFinish={async (values) => {
if (!uploadPath) {
message.warning('请先上传资源');
return false;
}
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateTourismFile({ ...values, imageUrl: uploadPath, status: values.status ?? 0 });
message.success('新增成功');
actionRef.current?.reload();
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally {
hide();
}
}}
>
<ProForm.Group>
<ProFormSelect rules={[{ required: true, message: '请选择项目' }]} width="md" name="tourismId" label="项目" options={tourismOptions} showSearch />
<ProFormSelect rules={[{ required: true, message: '请选择资源类型' }]} width="md" name="type" label="资源类型" options={TYPE_OPTIONS as any} />
<ProFormSelect width="md" name="status" label="状态" options={STATUS_OPTIONS as any} initialValue={0} />
<ProFormText width="md" name="linkUrl" label="页面链接" placeholder="可为空" />
<ProFormText rules={[{ required: true, message: '请输入资源描述' }]} width="md" name="description" label="资源描述" placeholder="请输入资源描述" />
</ProForm.Group>
<Upload
maxCount={1}
showUploadList={false}
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
const r = await doUpload(file as File);
setUploadPreviewUrl(r.url);
setUploadPath(r.path);
onSuccess?.('ok');
}
} catch (err) {
onError?.(err as any);
}
}}
accept="image/*,video/*"
>
<Button icon={<UploadOutlined />}>上传图片/视频</Button>
</Upload>
{uploadPreviewUrl && (
<div style={{ marginTop: 12 }}>
{(ProForm as any) && <Image src={uploadPreviewUrl} width={200} />}
</div>
)}
</ModalForm>
{/* 编辑 */}
<ModalForm
title="编辑资源"
open={editOpen}
initialValues={current}
onOpenChange={(v: boolean) => {
if (!v) {
setEditUploadPreviewUrl(undefined);
setEditUploadPath(undefined);
}
setEditOpen(v);
}}
onFinish={async (values) => {
const payload = { ...(current || {}), ...values } as any;
if (editUploadPath) payload.imageUrl = editUploadPath;
const hide = message.loading('保存中...');
try {
await ordersApi.saveOrUpdateTourismFile(payload);
message.success('修改成功');
actionRef.current?.reload();
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally {
hide();
}
}}
>
<ProForm.Group>
<ProFormSelect rules={[{ required: true, message: '请选择项目' }]} width="md" name="tourismId" label="项目" options={tourismOptions} showSearch />
<ProFormSelect rules={[{ required: true, message: '请选择资源类型' }]} width="md" name="type" label="资源类型" options={TYPE_OPTIONS as any} />
<ProFormSelect width="md" name="status" label="状态" options={STATUS_OPTIONS as any} />
<ProFormText width="md" name="linkUrl" label="页面链接" placeholder="可为空" />
<ProFormText rules={[{ required: true, message: '请输入资源描述' }]} width="md" name="description" label="资源描述" placeholder="请输入资源描述" />
</ProForm.Group>
<Upload
maxCount={1}
showUploadList={false}
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
const r = await doUpload(file as File);
setEditUploadPreviewUrl(r.url);
setEditUploadPath(r.path);
onSuccess?.('ok');
}
} catch (err) {
onError?.(err as any);
}
}}
accept="image/*,video/*"
>
<Button icon={<UploadOutlined />}>上传图片/视频</Button>
</Upload>
{(editUploadPreviewUrl || current?.imageUrl) && (
<div style={{ marginTop: 12 }}>
<Image src={editUploadPreviewUrl || current?.imageUrl} width={200} />
</div>
)}
</ModalForm>
</PageContainer>
);
};
export default TourismFilePage;
@@ -0,0 +1,52 @@
import React, { useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import { Space, Switch, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { ordersApi } from '@/services/orders';
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
const VideoTemplatePage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '模板名称', dataIndex: 'name' },
{ title: '描述', dataIndex: 'description' },
{ title: '状态', dataIndex: 'status', render: (v: number, r: any) => <Switch checked={v === 1} onChange={(c) => ordersApi.updateVideoTemplateStatus(r.id, c ? 1 : 0)} /> },
{
title: '操作', key: 'action',
render: (_: any, record: any) => (
<Space>
<a onClick={async () => { message.info('演示环境暂不提供修改参数'); }}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={async () => { try { await ordersApi.deleteVideoTemplate(record.id); message.success('删除成功'); } catch { message.error('删除失败'); } }}>删除</a>
</Space>
)
},
];
return (
<PageContainer header={{ title: '视频模板' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} onFinish={async (values) => setParams(values)}>
<ProFormText name="name" label="模板名称" />
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} allowClear />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" onClick={async () => {
const hide = message.loading('保存中...');
try { await ordersApi.saveVideoTemplate({ name: '新模板', status: 1 }); message.success('新增成功'); }
catch { message.error('新增失败'); } finally { hide(); }
}}><PlusOutlined /> 新增</GradientButton>} />
<ProTable<any>
rowKey="id"
request={(p) => ordersApi.getVideoTemplateList({ ...p, ...params } as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</PageContainer>
);
};
export default VideoTemplatePage;
@@ -0,0 +1,54 @@
import React, { useRef, useState } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { PageContainer, ProFormDateTimeRangePicker, ProTable } from '@ant-design/pro-components';
import { Card, Statistic, Row, Col, message } from 'antd';
import { ordersApi } from '@/services/orders';
import { ActionBar, SearchBarPlus } from '@/components/ui';
const WxMessagePage: React.FC = () => {
const [range, setRange] = useState<{ startTime?: string; endTime?: string }>({});
const [stat, setStat] = useState<any>({});
const actionRef = useRef<ActionType>();
const load = async (p?: any) => {
try { const res = await ordersApi.getWxMessageStatistics(p || range); setStat(res?.data || res); } catch { message.error('加载统计失败'); }
};
return (
<PageContainer header={{ title: '微信消息' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => { load(); actionRef.current?.reload(); }}
onFinish={async (v) => { const [a,b] = v.timeRange || []; const p = { startTime: a?.toISOString(), endTime: b?.toISOString() }; setRange(p); await load(p); }}
>
<ProFormDateTimeRangePicker name="timeRange" label="时间范围" />
</SearchBarPlus>
<Row gutter={16} style={{ marginTop: 12 }}>
<Col span={6}><Card><Statistic title="消息总数" value={stat?.total || 0} /></Card></Col>
<Col span={6}><Card><Statistic title="成功数" value={stat?.success || 0} /></Card></Col>
<Col span={6}><Card><Statistic title="失败数" value={stat?.failed || 0} /></Card></Col>
</Row>
<ProTable<any>
actionRef={actionRef}
rowKey="id"
request={(p) => ordersApi.getWxMessageRecords({ ...p, ...range } as any)}
columns={[
{ dataIndex: 'index', valueType: 'indexBorder' },
{ title: '消息ID', dataIndex: 'id' },
{ title: '用户', dataIndex: 'user' },
{ title: '类型', dataIndex: 'type' },
{ title: '状态', dataIndex: 'status' },
{ title: '时间', dataIndex: 'createTime', valueType: 'dateTime' },
]}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</PageContainer>
);
};
export default WxMessagePage;
@@ -0,0 +1,20 @@
import React, { useEffect, useState } from 'react';
import { Button, Modal } from 'antd';
import { searchApi } from '@/services/search';
interface Props { indexName?: string; open: boolean; onCancel: () => void }
const IndexView: React.FC<Props> = ({ indexName, open, onCancel }) => {
const [json, setJson] = useState<any>({});
useEffect(() => { (async () => { if (indexName) setJson(await searchApi.index(indexName)); })(); }, [indexName]);
return (
<Modal title="查看索引" width={800} open={open} onCancel={onCancel} footer={<Button type="primary" onClick={onCancel}>关闭</Button>}>
<pre style={{ maxHeight: 520, overflow: 'auto', background: '#fafafa', padding: 12 }}>
{JSON.stringify(json, null, 2)}
</pre>
</Modal>
);
};
export default IndexView;
@@ -0,0 +1,64 @@
import React, { useState } from 'react';
import { ModalForm, PageContainer, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
import { Space, Typography, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
import { searchApi } from '@/services/search';
import IndexView from './components/IndexView';
const { Link } = Typography;
const IndexPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const [open, setOpen] = useState(false);
const [indexView, setIndexView] = useState<{ open: boolean; indexName?: string }>({ open: false });
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '集群健康', dataIndex: 'health' },
{ title: '集群状态', dataIndex: 'status' },
{ title: '索引名', dataIndex: 'index' },
{ title: '文档数', dataIndex: 'docsCount' },
{ title: '删除文档数', dataIndex: 'docsDeleted' },
{ title: '存储大小', dataIndex: 'storeSize' },
{ title: '操作', key: 'action', render: (_: any, record: any) => (
<Space>
<Link onClick={() => setIndexView({ open: true, indexName: record.index })}>查看</Link>
<Link onClick={() => message.info('演示环境不支持此操作')}>删除</Link>
</Space>
) },
];
return (
<PageContainer header={{ title: '索引管理' }}>
<SearchBarPlus defaultCollapsed split span={12} onTenantChanged={() => { /* 租户切换后统一生效 */ }} onFinish={async (values) => setParams(values)}>
<ProFormText name="queryStr" label="查询" placeholder="支持关键字;通配需用*" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" key="add" type="primary" onClick={() => setOpen(true)}><PlusOutlined /> 新增</GradientButton>} />
<ProTable<any>
rowKey="index"
headerTitle="索引列表"
request={(p) => searchApi.indice({ ...p, ...params })}
columns={columns}
search={false}
pagination={false}
toolBarRender={false}
/>
<ModalForm title="创建索引" width={800} open={open} onOpenChange={setOpen} onFinish={async () => { message.info('演示环境不支持此操作'); return true; }}>
<ProFormText name="index" label="索引名" placeholder="请输入索引名" rules={[{ required: true, message: '索引名不能为空' }]} width="md" />
<ProFormText name="numberOfShards" label="分片数" placeholder="请输入分片数" rules={[{ required: true, message: '分片数不能为空' }]} width="md" />
<ProFormText name="numberOfReplicas" label="副本数" placeholder="请输入副本数" rules={[{ required: true, message: '副本数不能为空' }]} width="md" />
<ProFormText name="type" label="类型" placeholder="请输入类型" rules={[{ required: true, message: '类型不能为空' }]} width="md" />
<ProFormTextArea name="mappingsSource" label="mappings" placeholder="请输入 mappings 的 JSON 内容" rules={[{ required: true, message: 'mappings 不能为空' }]} width="xl" />
</ModalForm>
<IndexView open={indexView.open} indexName={indexView.indexName} onCancel={() => setIndexView({ open: false })} />
</PageContainer>
);
};
export default IndexPage;
@@ -0,0 +1,50 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { systemApi } from '@/services/system';
import { ActionBar, SearchBarPlus } from '@/components/ui';
const UserSearchPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const actionRef = useRef<ActionType>();
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '用户ID', dataIndex: 'id', width: 100 },
{ title: '账号', dataIndex: 'username', render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.username || '' }} /> },
{ title: '用户昵称', dataIndex: 'nickname', render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.nickname || '' }} /> },
{ title: '手机号', dataIndex: 'mobile', render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.mobile || '' }} /> },
{ title: '性别', dataIndex: 'sex', render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.sex || '' }} /> },
{ title: '类型', dataIndex: 'type', render: (_, r) => <span dangerouslySetInnerHTML={{ __html: r.type || '' }} /> },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
];
return (
<PageContainer header={{ title: '用户检索' }}>
<SearchBarPlus defaultCollapsed split onTenantChanged={() => actionRef.current?.reload?.()} onFinish={async (values) => {
const { searchKey, searchValue } = values as any;
let queryStr = '';
if (searchKey && searchValue) queryStr = searchKey === 'none' ? searchValue : `${searchKey}:${searchValue}`;
setParams({ ...params, queryStr });
}}>
<ProFormSelect name="searchKey" label="检索" valueEnum={{ none: '全文检索', id: 'ID', username: '账号', nickname: '用户昵称', mobile: '手机号', sex: '性别', type: '用户类型' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar />
<ProTable<any>
actionRef={actionRef}
rowKey="id"
headerTitle="用户检索"
request={(p) => systemApi.searchUsers({ ...p, ...params })}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</PageContainer>
);
};
export default UserSearchPage;
@@ -0,0 +1,56 @@
import React from 'react';
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { AppItem } from '@/services/app';
export interface AppFormValues extends AppItem {
authorizedGrantTypeCodes?: string[];
}
export interface AppFormProps {
open: boolean;
title: string;
initialValues?: Partial<AppFormValues>;
onOpenChange: (v: boolean) => void;
onFinish: (values: AppFormValues) => Promise<boolean>;
}
const AppForm: React.FC<AppFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
const initial: Partial<AppFormValues> = initialValues || {};
if (initial.authorizedGrantTypes && !initial.authorizedGrantTypeCodes) {
initial.authorizedGrantTypeCodes = (initial.authorizedGrantTypes || '').split(',').filter(Boolean);
}
return (
<ModalForm<AppFormValues>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initial}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText name="clientId" label="应用标识" rules={[{ required: true, message: '请输入应用标识' }]} />
<ProFormText name="clientName" label="应用名称" />
</ProForm.Group>
<ProFormText name="webServerRedirectUri" label="回调地址" />
<ProFormSelect
name="authorizedGrantTypeCodes"
label="授权方式"
mode="multiple"
valueEnum={{ password: 'password', authorization_code: 'authorization_code', client_credentials: 'client_credentials', refresh_token: 'refresh_token' }}
/>
<ProFormSelect
name="autoapprove"
label="自动审批"
valueEnum={{ 'true': '是', 'false': '否' }}
/>
<ProForm.Group>
<ProFormDigit name="accessTokenValiditySeconds" label="令牌时效(秒)" min={0} fieldProps={{ precision: 0 }} />
<ProFormDigit name="refreshTokenValiditySeconds" label="刷新时效(秒)" min={0} fieldProps={{ precision: 0 }} />
</ProForm.Group>
<ProFormSelect name="tokenFormat" label="令牌类型" valueEnum={{ reference: '引用令牌', 'self-contained': '自包含令牌' }} />
</ModalForm>
);
};
export default AppForm;
@@ -0,0 +1,112 @@
import React, { useState } from 'react';
import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { appApi, AppItem } from '@/services/app';
import AppForm, { AppFormValues } from './components/AppForm';
const AppPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<AppItem | undefined>(undefined);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '应用标识', dataIndex: 'clientId', width: 140 },
{ title: '应用名称', dataIndex: 'clientName', width: 180 },
{ title: '回调地址', dataIndex: 'webServerRedirectUri', width: 240, ellipsis: true },
{ title: '授权方式', dataIndex: 'authorizedGrantTypes', width: 200, ellipsis: true },
{ title: '自动授权', dataIndex: 'autoapprove', width: 100, renderText: (v: any) => (String(v) === 'true' ? '是' : '否') },
{ title: '令牌时效(秒)', dataIndex: 'accessTokenValiditySeconds', width: 120 },
{ title: '刷新时效(秒)', dataIndex: 'refreshTokenValiditySeconds', width: 120 },
{ title: '令牌格式', dataIndex: 'tokenFormat', width: 120, renderText: (v: any) => (v === 'reference' ? '引用令牌' : '自包含令牌') },
{
title: '操作', key: 'action', fixed: 'right', width: 160,
render: (_: any, entity: AppItem) => (
<Space>
<a onClick={() => { setCurrent(entity); setEditOpen(true); }}>修改</a>
<Popconfirm title={`确认删除应用[${entity.clientId}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await appApi.delete(entity.id!);
message.success('删除应用成功');
} catch (e) {
message.error('删除应用失败');
} finally { hide(); }
}}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<PageContainer header={{ title: '应用管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => { /* 默认无租户检索 */ }} onFinish={async (values) => setParams(values)}>
<ProFormText name="searchKey" label="搜索" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" key="add" type="primary" onClick={() => setCreateOpen(true)}><PlusOutlined /> 新增</GradientButton>} />
<GlassCard>
<ProTable<AppItem>
rowKey="id"
headerTitle="应用列表"
request={async (p) => appApi.page({ ...p, ...params })}
columns={columns}
search={false}
scroll={{ x: 1300 }}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<AppForm
title="新增应用"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values: AppFormValues) => {
const hide = message.loading('保存中...');
try {
const authorizedGrantTypes = (values.authorizedGrantTypeCodes || []).join(',');
const payload: AppItem = { ...values, authorizedGrantTypes } as any;
delete (payload as any).authorizedGrantTypeCodes;
await appApi.saveOrUpdate(payload);
message.success('新增应用成功');
return true;
} catch (e) {
message.error('新增应用失败');
return false;
} finally { hide(); }
}}
/>
<AppForm
title="修改应用"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values: AppFormValues) => {
const hide = message.loading('保存中...');
try {
const authorizedGrantTypes = (values.authorizedGrantTypeCodes || []).join(',');
const payload: AppItem = { ...(current as any), ...values, authorizedGrantTypes } as any;
delete (payload as any).authorizedGrantTypeCodes;
await appApi.saveOrUpdate(payload);
message.success('修改应用成功');
return true;
} catch (e) {
message.error('修改应用失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default AppPage;
@@ -0,0 +1,46 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { generatorApi, GeneratorItem } from '@/services/generator';
import { GlassCard, SearchBarPlus } from '@/components/ui';
const GeneratorPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const actionRef = useRef<ActionType>();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '数据库引擎', dataIndex: 'engine', width: 140 },
{ title: '表名', dataIndex: 'tableName', width: 220 },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作', key: 'action', fixed: 'right', width: 100,
render: (_: any, entity: GeneratorItem) => (
<a onClick={() => entity.tableName && generatorApi.export(entity.tableName!)}>导出</a>
)
},
];
return (
<PageContainer header={{ title: '代码生成器' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => actionRef.current?.reload?.()} onFinish={async (values) => setParams(values)}>
<ProFormText name="tableName" label="表名" placeholder="请输入表名" />
</SearchBarPlus>
<GlassCard>
<ProTable<GeneratorItem>
rowKey="tableName"
headerTitle="表列表"
actionRef={actionRef}
request={(p) => generatorApi.list({ ...p, ...params })}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default GeneratorPage;
@@ -0,0 +1,50 @@
import React from 'react';
import { ModalForm, ProForm, ProFormDigit, ProFormRadio, ProFormSelect, ProFormText, ProFormTreeSelect } from '@ant-design/pro-components';
import { menuApi, MenuItem } from '@/services/menu';
import { buildTree } from '@/utils/tree';
export interface MenuFormProps {
open: boolean;
title: string;
initialValues?: Partial<MenuItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: MenuItem) => Promise<boolean>;
}
const MenuForm: React.FC<MenuFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<MenuItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormTreeSelect
label="上级菜单"
name="parentId"
width="md"
request={async () => {
const menus = await menuApi.simpleList();
const nodes = (menus || []).map((m: any) => ({ id: m.id, pId: m.pId, name: m.name }));
const tree = buildTree(nodes).map((n) => ({ ...n, value: n.key }));
return [{ title: '顶级目录', value: -1, key: -1 }, ...tree];
}}
fieldProps={{ fieldNames: { label: 'title' }, placeholder: '选择上级菜单' }}
/>
<ProFormText name="name" label="菜单名称" width="md" rules={[{ required: true, message: '菜单名不能为空' }]} />
<ProFormText name="url" label="菜单URL" width="md" />
<ProFormText name="path" label="路由Path" width="md" />
<ProFormText name="css" label="菜单图标" width="md" rules={[{ required: true, message: '菜单图标不能为空' }]} />
<ProFormRadio.Group name="hidden" label="是否隐藏" width="lg" options={[{ label: '否', value: false }, { label: '是', value: true }]} />
<ProFormRadio.Group name="type" label="菜单类型" width="lg" options={[{ label: '菜单', value: 1 }, { label: '按钮', value: 2 }]} />
<ProFormSelect name="pathMethod" label="请求方法" width="md" valueEnum={{ GET: 'GET', POST: 'POST', PUT: 'PUT', DELETE: 'DELETE' }} />
<ProFormDigit name="sort" label="排序" width="md" min={1} fieldProps={{ precision: 0 }} rules={[{ required: true, message: '请选择排序' }]} />
</ProForm.Group>
</ModalForm>
);
};
export default MenuForm;
@@ -0,0 +1,70 @@
import React from 'react';
import { Table, Space, Popconfirm, Tag } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { MenuItem } from '@/services/menu';
import { MenuOutlined, FolderOpenOutlined, ProfileOutlined } from '@ant-design/icons';
export interface MenuTreeProps {
data: MenuItem[];
loading?: boolean;
keyword?: string;
onEdit: (record: MenuItem) => void;
onDelete: (record: MenuItem) => void;
}
const MenuTree: React.FC<MenuTreeProps> = ({ data, loading, keyword, onEdit, onDelete }) => {
const columns: ColumnsType<MenuItem> = [
{
title: '菜单名称',
dataIndex: 'name',
render: (_: any, record: MenuItem) => (
<Space size="small">
{record.type === 1 ? (record.url?.startsWith('javascript') ? <FolderOpenOutlined /> : <MenuOutlined />) : <ProfileOutlined />}
<span style={keyword && record.name?.includes(keyword) ? { background: 'yellow' } : undefined}>{record.name}</span>
</Space>
),
},
{
title: 'URL',
dataIndex: 'url',
width: 200,
ellipsis: true,
},
{ title: 'Path', dataIndex: 'path', width: 160 },
{ title: 'Icon', dataIndex: 'css', width: 120 },
{
title: '类型', dataIndex: 'type', width: 100,
render: (v: any) => (v === 1 ? <Tag color="blue">菜单</Tag> : <Tag>按钮</Tag>),
},
{
title: '隐藏', dataIndex: 'hidden', width: 100,
render: (v: any) => (v ? <Tag color="red">是</Tag> : <Tag color="green">否</Tag>),
},
{ title: '排序', dataIndex: 'sort', width: 80 },
{
title: '操作', key: 'action', width: 180,
render: (_: any, record: MenuItem) => (
<Space>
<a onClick={() => onEdit(record)}>编辑</a>
<Popconfirm title={`确认删除菜单[${record.name}]?`} onConfirm={() => onDelete(record)}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
),
},
];
return (
<Table
rowKey="id"
columns={columns}
dataSource={data}
loading={loading}
pagination={false}
expandable={{ defaultExpandAllRows: true }}
size="middle"
/>
);
};
export default MenuTree;
@@ -0,0 +1,155 @@
import React, { useCallback, useEffect, useState } from 'react';
import { PageContainer, ProFormText, ProFormSelect } from '@ant-design/pro-components';
import { Space, message } from 'antd';
import { ActionBar, GradientButton, GlassCard, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import MenuTree from './components/MenuTree';
import MenuForm from './components/MenuForm';
import { menuApi, MenuItem } from '@/services/menu';
import { roleApi } from '@/services/role';
import { buildTree } from '@/utils/tree';
const MenuPage: React.FC = () => {
const [apps, setApps] = useState<any[]>([]);
const [tenantId, setTenantId] = useState<string | undefined>();
const [keyword, setKeyword] = useState<string | undefined>();
const [data, setData] = useState<MenuItem[]>([]);
const [loading, setLoading] = useState(false);
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<MenuItem | undefined>(undefined);
const fetchMenu = useCallback(async (clientId: string) => {
setLoading(true);
try {
const menus = await menuApi.list(clientId);
const list: any[] = menus || [];
const hasSubMenus = list.some((m) => Array.isArray(m?.subMenus));
if (hasSubMenus) {
const toTree = (arr: any[] | null | undefined): any[] | undefined =>
(arr || undefined)?.map((m) => ({
...m,
children: m.subMenus && m.subMenus.length ? toTree(m.subMenus) : undefined,
}));
const idSet = new Set(list.map((x) => String(x.id)));
const roots = list.filter((m) => (m.parentId === -1 || m.parentId === '-1' || !idSet.has(String(m.parentId))));
setData((toTree(roots) || []) as any);
} else {
const nodes = list.map((m: any) => ({
...m,
id: String(m.id),
pId: (m.parentId === -1 || m.parentId === '-1' || m.parentId == null) ? undefined : String(m.parentId),
origin: m,
}));
const rawTree = buildTree(nodes as any) as any[];
const toMenuTree = (arr: any[] | undefined): any[] | undefined =>
(arr || []).map((n: any) => {
const r = (n.raw && n.raw.origin) ? n.raw.origin : (n.raw || n);
const children = n.children && n.children.length ? toMenuTree(n.children) : undefined;
return { ...r, children };
});
setData((toMenuTree(rawTree) || []) as any);
}
} catch (e) {
message.error('获取菜单数据失败');
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
(async () => {
const list = await roleApi.apps();
setApps(list || []);
if (list?.length) {
const id = list[0].clientId;
setTenantId(id);
fetchMenu(id);
}
})();
}, [fetchMenu]);
const handleDelete = async (record: MenuItem) => {
const hide = message.loading('删除中...');
try {
await menuApi.delete(record.id!);
message.success('删除菜单成功');
if (tenantId) fetchMenu(tenantId);
} catch (e) {
message.error('删除菜单失败');
} finally { hide(); }
};
return (
<PageContainer header={{ title: '菜单管理' }}>
<SearchBarPlus
defaultCollapsed
split
span={8}
onTenantChanged={() => tenantId && fetchMenu(tenantId)}
onFinish={async (values: any) => { setTenantId(values.tenantId); fetchMenu(values.tenantId); setKeyword(values.keyword); }}
>
<ProFormSelect name="tenantId" label="所属应用" allowClear={false} options={(apps || []).map((i) => ({ label: i.clientId, value: i.clientId }))} />
<ProFormText name="keyword" label="关键字" placeholder="菜单名称关键字" />
</SearchBarPlus>
<ActionBar
left={
<Space>
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => { setCurrent(undefined); setCreateOpen(true); }}>新增</GradientButton>
</Space>
}
/>
<GlassCard>
<MenuTree
data={data}
loading={loading}
keyword={keyword}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={handleDelete}
/>
</GlassCard>
<MenuForm
title="新增菜单"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await menuApi.saveOrUpdate(values);
message.success('新增菜单成功');
tenantId && fetchMenu(tenantId);
return true;
} catch (e) {
message.error('新增菜单失败');
return false;
} finally { hide(); }
}}
/>
<MenuForm
title="修改菜单"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await menuApi.saveOrUpdate({ ...current, ...values });
message.success('修改菜单成功');
tenantId && fetchMenu(tenantId);
return true;
} catch (e) {
message.error('修改菜单失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default MenuPage;
@@ -0,0 +1,52 @@
import React from 'react';
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormSwitch, ProFormText } from '@ant-design/pro-components';
import { MiniAppItem } from '@/services/miniapp';
export interface MiniAppFormProps {
open: boolean;
title: string;
initialValues?: Partial<MiniAppItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: MiniAppItem) => Promise<boolean>;
}
const MiniAppForm: React.FC<MiniAppFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<MiniAppItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProFormSelect
name="type"
label="配置类型"
valueEnum={{ MP: '公众号', MINI: '小程序', PAY: '支付', MA: '小程序消息' }}
rules={[{ required: true, message: '请选择配置类型' }]}
/>
<ProForm.Group>
<ProFormText name="tenantId" label="租户ID" />
<ProFormText name="merchantId" label="商户ID" />
<ProFormText name="appId" label="应用ID" />
</ProForm.Group>
<ProFormText name="appSecret" label="应用密钥" />
<ProFormSwitch name="asyncEnabled" label="启用异步处理" />
<ProFormDigit name="asyncPoolSize" label="异步处理线程池大小" min={1} max={100} />
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} rules={[{ required: true }]} />
<ProFormText name="remark" label="备注" />
<ProForm.Group title="服务商模式相关">
<ProFormSwitch name="isServiceMode" label="服务商模式" />
<ProFormText name="serviceAppId" label="服务商应用ID" />
<ProFormText name="serviceMchId" label="服务商商户号" />
<ProFormText name="subMchId" label="子商户号" />
<ProFormText name="subAppId" label="子商户应用ID" />
<ProFormText name="subMchName" label="子商户名称" />
<ProFormText name="subMchDescription" label="子商户描述" />
</ProForm.Group>
</ModalForm>
);
};
export default MiniAppForm;
@@ -0,0 +1,114 @@
import React, { useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import { Space, Tag, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { miniAppApi, MiniAppItem } from '@/services/miniapp';
import MiniAppForm from './components/MiniAppForm';
const MiniAppPage: React.FC = () => {
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<MiniAppItem | undefined>(undefined);
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '平台类型', dataIndex: 'type', valueType: 'select', valueEnum: { MP: { text: '公众号' }, MINI: { text: '小程序' }, PAY: { text: '支付' }, MA: { text: '小程序消息' } } },
{ title: '租户ID', dataIndex: 'tenantId', copyable: true },
{ title: '商户ID', dataIndex: 'merchantId', copyable: true },
{ title: '应用ID', dataIndex: 'appId', copyable: true },
{
title: '服务商模式', dataIndex: 'isServiceMode', valueType: 'select', valueEnum: { true: { text: '服务商' }, false: { text: '普通商户' } },
render: (_: any, record: MiniAppItem) => <Tag color={record.isServiceMode ? 'blue' : 'default'}>{record.isServiceMode ? '服务商' : '普通商户'}</Tag>,
},
{ title: '服务商商户号', dataIndex: 'serviceMchId' },
{ title: '子商户号', dataIndex: 'subMchId' },
{
title: '状态', dataIndex: 'status', valueType: 'select', valueEnum: { 1: { text: '启用', status: 'Success' }, 0: { text: '禁用', status: 'Error' } },
render: (_: any, record: MiniAppItem) => <Tag color={record.status === 1 ? 'success' : 'error'}>{record.status === 1 ? '启用' : '禁用'}</Tag>,
},
{
title: '操作', key: 'action',
render: (_: any, entity: MiniAppItem) => (
<Space>
<a onClick={() => { setCurrent(entity); setEditOpen(true); }}>编辑</a>
<a onClick={async () => {
const hide = message.loading('删除中...');
try {
await miniAppApi.remove(entity.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>删除</a>
</Space>
)
}
];
return (
<PageContainer header={{ title: '微信应用管理' }}>
<SearchBarPlus defaultCollapsed split onTenantChanged={() => { /* 后端切换生效 */ }} onFinish={async (values) => setSearchParams(values)}>
<ProFormSelect name="searchKey" label="检索" valueEnum={{ type: '平台类型', merchantId: '商户ID', appId: '应用ID' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" key="add" type="primary" onClick={() => setCreateOpen(true)}><PlusOutlined /> 新增</GradientButton>} />
<GlassCard>
<ProTable<MiniAppItem>
rowKey="id"
headerTitle="应用列表"
request={async (params) => {
const res = await miniAppApi.list({ page: (params as any).current || 1, limit: (params as any).pageSize || 10, searchKey: searchParams.searchKey, searchValue: searchParams.searchValue });
return { data: (res as any).data, success: (res as any).resp_code === 0, total: (res as any).total } as any;
}}
columns={columns}
search={false}
params={searchParams}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<MiniAppForm
title="新增应用"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await miniAppApi.create(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<MiniAppForm
title="编辑应用"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await miniAppApi.update({ ...(current as any), ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
</PageContainer>
);
};
export default MiniAppPage;
@@ -0,0 +1,59 @@
import React, { useEffect, useState } from 'react';
import { Modal, Tree, message } from 'antd';
import { roleApi } from '@/services/role';
import { buildTree } from '@/utils/tree';
type Key = string | number;
export interface AssignAuthProps {
roleId?: number;
tenantId?: string;
open: boolean;
onClose: () => void;
}
const AssignAuth: React.FC<AssignAuthProps> = ({ roleId, tenantId, open, onClose }) => {
const [treeData, setTreeData] = useState<any[]>([]);
const [checkedKeys, setCheckedKeys] = useState<Key[]>([]);
useEffect(() => {
(async () => {
if (open && roleId && tenantId) {
const menus = await roleApi.menuForAuth(roleId, tenantId);
const nodes = menus.map((m: any) => ({ id: m.id, pId: m.pId, title: m.name, name: m.name }));
setTreeData(buildTree(nodes));
setCheckedKeys(menus.filter((m: any) => m.checked).map((m: any) => m.id));
}
})();
}, [open, roleId, tenantId]);
const handleOk = async () => {
if (!roleId) return;
const hide = message.loading('淇濆瓨涓?..');
try {
await roleApi.assignMenu({ roleId, menuIds: checkedKeys });
message.success('鏉冮檺鍒嗛厤鎴愬姛');
onClose();
} catch (e) {
message.error('鏉冮檺鍒嗛厤澶辫触');
} finally {
hide();
}
};
return (
<Modal title="鏉冮檺鍒嗛厤" open={open} destroyOnClose onOk={handleOk} onCancel={onClose}>
<Tree
defaultExpandAll
checkable
treeData={treeData}
checkedKeys={checkedKeys}
onCheck={(keys: any) => setCheckedKeys(Array.isArray(keys) ? keys : keys.checked)}
/>
</Modal>
);
};
export default AssignAuth;
@@ -0,0 +1,38 @@
import React from 'react';
import { ModalForm, ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components';
import { RoleItem } from '@/services/role';
export interface RoleFormProps {
open: boolean;
title: string;
initialValues?: Partial<RoleItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: RoleItem) => Promise<boolean>;
}
const RoleForm: React.FC<RoleFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<RoleItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues ?? { dataScope: 'ALL' }}
modalProps={{ destroyOnClose: true }}
width={500}
>
<ProForm.Group>
<ProFormText name="name" label="角色名称" rules={[{ required: true, message: '角色名不能为空' }]} width="lg" />
<ProFormText name="code" label="编码" rules={[{ required: true, message: '编码不能为空' }]} width="lg" />
<ProFormRadio.Group
name="dataScope"
label="数据权限"
width="lg"
options={[{ label: '全部', value: 'ALL' }, { label: '本人', value: 'CREATOR' }]}
/>
</ProForm.Group>
</ModalForm>
);
};
export default RoleForm;
@@ -0,0 +1,137 @@
import React, { useEffect, useState } from 'react';
import { PageContainer, ProTable, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { PlusOutlined } from '@ant-design/icons';
import { roleApi, RoleItem } from '@/services/role';
import RoleForm from './components/RoleForm';
import AssignAuth from './components/AssignAuth';
const RolePage: React.FC = () => {
const [apps, setApps] = useState<any[]>([]);
const [params, setParams] = useState<{ tenantId?: string; searchKey?: string; searchValue?: string }>({});
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [assignOpen, setAssignOpen] = useState(false);
const [current, setCurrent] = useState<RoleItem | undefined>(undefined);
useEffect(() => {
(async () => {
const list = await roleApi.apps();
setApps(list || []);
if (list?.length) {
const tenantId = list[0].clientId;
setParams((p) => ({ ...p, tenantId }));
}
})();
}, []);
const columns = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: 'ID', dataIndex: 'id' },
{ title: '角色名称', dataIndex: 'name' },
{ title: '编码', dataIndex: 'code' },
{ title: '数据权限', dataIndex: 'dataScope', renderText: (v: any) => (v === 'ALL' ? '全部' : '自定义') },
{
title: '操作', valueType: 'option', width: 220,
render: (_: any, record: RoleItem) => (
<Space>
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
<a onClick={() => { setCurrent(record); setAssignOpen(true); }}>授权</a>
<Popconfirm title={`确认删除角色[${record.name}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await roleApi.delete(record.id!);
message.success('删除成功');
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}>
<a>删除</a>
</Popconfirm>
</Space>
)
}
];
return (
<PageContainer header={{ title: '角色管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={6}
onTenantChanged={() => { /* 切换租户后服务端上下文生效 */ }}
onFinish={async (values) => setParams(values)}
>
<ProFormSelect name="tenantId" label="所属应用" allowClear={false} options={(apps || []).map((i) => ({ label: i.clientId, value: i.clientId }))} />
<ProFormSelect name="searchKey" label="搜索" valueEnum={{ name: '角色名称' }} />
<ProFormText name="searchValue" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar
left={
<GradientButton size="middle" key="add" type="primary" onClick={() => setCreateOpen(true)}>
<PlusOutlined /> 新增
</GradientButton>
}
/>
<GlassCard>
<ProTable<RoleItem>
rowKey="id"
headerTitle="角色列表"
request={async (p) => roleApi.page({ ...p, ...params })}
columns={columns as any}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<RoleForm
title="新增角色"
open={createOpen}
onOpenChange={setCreateOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await roleApi.saveOrUpdate(values);
message.success('新增成功');
return true;
} catch (e) {
message.error('保存失败');
return false;
} finally { hide(); }
}}
/>
<RoleForm
title="修改角色"
open={editOpen}
initialValues={current}
onOpenChange={setEditOpen}
onFinish={async (values) => {
const hide = message.loading('保存中...');
try {
await roleApi.saveOrUpdate({ ...current, ...values });
message.success('修改成功');
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally { hide(); }
}}
/>
<AssignAuth
open={assignOpen}
roleId={current?.id}
tenantId={params.tenantId}
onClose={() => setAssignOpen(false)}
/>
</PageContainer>
);
};
export default RolePage;
@@ -0,0 +1,165 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ModalForm, PageContainer, ProForm, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
import { Button, Card, Col, Form, message, Popconfirm, Row, Space, Switch, Tree, TreeSelect } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { tenantApi, TenantInfo, TenantTreeNode } from '@/services/tenant';
import { ActionBar, SearchBarPlus } from '@/components/ui';
const toTreeData = (nodes: TenantTreeNode[] = []): any[] =>
nodes.map((n) => ({ title: n.tenantName, value: n.tenantId, key: n.tenantId, children: n.children ? toTreeData(n.children) : undefined }));
const TenantManage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [form] = Form.useForm<TenantInfo>();
const [orgTree, setOrgTree] = useState<TenantTreeNode[]>([]);
const [loadingTree, setLoadingTree] = useState(false);
const [currentNode, setCurrentNode] = useState<string | undefined>(undefined);
const [visible, setVisible] = useState(false);
const [editing, setEditing] = useState(false);
const treeSelectData = useMemo(() => toTreeData(orgTree), [orgTree]);
const loadTree = async () => {
setLoadingTree(true);
try {
const res = await tenantApi.getAccessibleTenants();
if (res.success) setOrgTree(res.data || []);
} finally {
setLoadingTree(false);
}
};
useEffect(() => { loadTree(); }, []);
const columns: ProColumns<TenantInfo>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '租户ID', dataIndex: 'tenantId', copyable: true },
{ title: '租户名称', dataIndex: 'tenantName' },
{ title: '类型', dataIndex: 'tenantType' },
{ title: '父租户ID', dataIndex: 'parentTenantId', hideInSearch: true },
{ title: '状态', dataIndex: 'status', valueType: 'select', valueEnum: { 1: { text: '启用' }, 0: { text: '停用' } } },
{
title: '操作', valueType: 'option', width: 200,
render: (_, record) => (
<Space>
<a onClick={async () => {
setEditing(true);
const d = await tenantApi.getTenantDetail(record.tenantId);
if (d.success) {
form.setFieldsValue(d.data);
setVisible(true);
}
}}>编辑</a>
<Popconfirm title={`确认删除租户[${record.tenantName}]?`} onConfirm={async () => {
const hide = message.loading('删除中...');
try {
const r = await tenantApi.deleteTenant(record.tenantId);
if (r.success) {
message.success('删除成功');
actionRef.current?.reload();
loadTree();
} else {
message.error(r.msg || '删除失败');
}
} finally { hide(); }
}}>
<a>删除</a>
</Popconfirm>
</Space>
)
}
];
const onSave = async (vals: TenantInfo) => {
const hide = message.loading('保存中...');
try {
const payload = { ...vals, status: vals.status ?? 1 };
const res = editing ? await tenantApi.updateTenant(payload) : await tenantApi.createTenant(payload);
if (res.success) {
message.success(editing ? '修改成功' : '新增成功');
setVisible(false);
actionRef.current?.reload();
loadTree();
return true;
}
message.error(res.msg || '保存失败');
return false;
} finally { hide(); }
};
return (
<PageContainer header={{ title: '租户管理' }}>
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { actionRef.current?.reload(); loadTree(); }} />
<ActionBar
right={(
<Space>
<Button size="middle" type="primary" icon={<PlusOutlined />} onClick={() => {
setEditing(false);
form.resetFields();
form.setFieldsValue({ parentTenantId: currentNode, status: 1 });
setVisible(true);
}}>新增租户</Button>
</Space>
)}
/>
<Row gutter={16}>
<Col span={6}>
<Card size="small" title="组织">
<Tree treeData={toTreeData(orgTree)} defaultExpandAll onSelect={(keys) => {
const k = (keys && keys[0]) as string | undefined;
setCurrentNode(k);
actionRef.current?.reload();
}} />
</Card>
</Col>
<Col span={18}>
<ProTable<TenantInfo>
actionRef={actionRef}
rowKey="tenantId"
columns={columns}
toolBarRender={false}
request={async (p) => {
const res = await tenantApi.getTenantList({ parentTenantId: currentNode, tenantName: (p as any).tenantName, status: (p as any).status as any, current: (p as any).current, pageSize: (p as any).pageSize });
const list = res.data?.data || [];
const total = res.data?.total || list.length;
return { data: list, total, success: true };
}}
pagination={{ pageSize: 10 }}
search={{ labelWidth: 'auto' }}
/>
</Col>
</Row>
<ModalForm<TenantInfo>
title={editing ? '编辑租户' : '新建租户'}
open={visible}
onOpenChange={setVisible}
form={form}
width={640}
onFinish={onSave}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText name="tenantId" label="租户ID" rules={[{ required: true }]} disabled={editing} />
<ProFormText name="tenantName" label="租户名称" rules={[{ required: true }]} />
</ProForm.Group>
<ProForm.Group>
<ProForm.Item name="parentTenantId" label="上级租户">
<TreeSelect style={{ width: 260 }} allowClear dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} treeDefaultExpandAll treeData={treeSelectData} />
</ProForm.Item>
<ProFormText name="tenantType" label="类型" rules={[{ required: true }]} />
</ProForm.Group>
<ProFormText name="tenantCode" label="租户编码" />
<ProFormText name="contactPerson" label="联系人" />
<ProFormText name="contactPhone" label="联系电话" />
<ProFormText name="address" label="地址" />
<ProFormTextArea name="description" label="描述" />
<ProForm.Item name="status" label="状态" valuePropName="checked"><Switch checkedChildren="启用" unCheckedChildren="停用" /></ProForm.Item>
</ModalForm>
</PageContainer>
);
};
export default TenantManage;
@@ -0,0 +1,91 @@
import React, { useEffect, useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { Popconfirm, Form, message } from 'antd';
import { roleApi } from '@/services/role';
import { tokenApi, TokenItem } from '@/services/token';
import { GlassCard, SearchBarPlus } from '@/components/ui';
const TokenPage: React.FC = () => {
const [apps, setApps] = useState<any[]>([]);
const [params, setParams] = useState<{ tenantId?: string; username?: string }>({});
const [form] = Form.useForm();
const actionRef = useRef<ActionType>();
useEffect(() => {
(async () => {
const appData = (await roleApi.apps()) || [];
setApps(appData);
if (appData.length > 0) {
const tenantId = appData[0].clientId;
setParams({ tenantId });
form.setFieldsValue({ tenantId });
}
})();
}, []);
const columns = [
{ dataIndex: 'index', valueType: 'indexBorder' },
{ title: 'Token', dataIndex: 'tokenValue', width: 200 },
{ title: '过期时间', dataIndex: 'expiration', valueType: 'dateTime' },
{ title: '用户名', dataIndex: 'username' },
{ title: '授权方式', dataIndex: 'grantType' },
{ title: '所属应用', dataIndex: 'clientId' },
{ title: '账号类型', dataIndex: 'accountType' },
{
title: '操作', key: 'action',
render: (_: any, entity: TokenItem) => (
<Popconfirm
title={`确认删除 Token?`}
onConfirm={async () => {
const hide = message.loading('删除中...');
try {
await tokenApi.delete(entity.tokenValue);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
}}
>
<a>删除</a>
</Popconfirm>
)
},
];
return (
<PageContainer header={{ title: 'Token 管理' }}>
<SearchBarPlus
defaultCollapsed
split
span={6}
onTenantChanged={() => actionRef.current?.reload?.()}
onFinish={async (values) => setParams(values)}
>
<ProFormSelect
name="tenantId"
label="所属应用"
fieldProps={{ allowClear: false }}
options={apps.map((item) => ({ label: item.clientId, value: item.clientId }))}
/>
<ProFormText name="username" label="搜索" placeholder="请输入用户名" />
</SearchBarPlus>
<GlassCard>
<ProTable<TokenItem>
rowKey="tokenValue"
headerTitle="Token 列表"
actionRef={actionRef}
request={async (p) => tokenApi.page({ ...p, ...params } as any)}
columns={columns as any}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
</GlassCard>
</PageContainer>
);
};
export default TokenPage;
@@ -0,0 +1,27 @@
import React from 'react';
import { Button, Upload } from 'antd';
import { ExportOutlined, ImportOutlined, PlusOutlined } from '@ant-design/icons';
import { GradientButton } from '@/components/ui';
export interface ToolbarProps {
// 新增
onCreate: () => void;
// 导出
onExport: () => void;
}
// 统一:新增按钮固定在左侧;去掉刷新按钮(以查询为主)
const Toolbar: React.FC<ToolbarProps> = ({ onCreate, onExport }) => {
return (
<>
<GradientButton size="middle" key="add" type="primary" icon={<PlusOutlined />} onClick={onCreate}>新增</GradientButton>
<Button size="middle" key="export" icon={<ExportOutlined />} onClick={onExport}>导出</Button>
<Upload key="import" action="/api-user/users/import" showUploadList={false} accept=".xls,.xlsx">
<Button size="middle" icon={<ImportOutlined />}>导入</Button>
</Upload>
</>
);
};
export default Toolbar;
@@ -0,0 +1,35 @@
import React from 'react';
import { ModalForm, ProForm, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
import { systemApi, UserItem } from '@/services/system';
export interface UserFormProps {
open: boolean;
title: string;
initialValues?: Partial<UserItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: UserItem) => Promise<boolean>;
}
const UserForm: React.FC<UserFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
return (
<ModalForm<UserItem>
title={title}
visible={open}
onVisibleChange={onOpenChange}
onFinish={onFinish}
initialValues={initialValues}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText name="username" label="账号" rules={[{ required: true, message: '账号不能为空' }]} />
<ProFormText name="nickname" label="用户昵称" rules={[{ required: true, message: '用户昵称不能为空' }]} />
<ProFormText name="mobile" label="手机号" rules={[{ required: true, message: '手机号不能为空' }]} />
</ProForm.Group>
<ProFormRadio.Group name="sex" label="性别" options={[{ label: '男', value: 0 }, { label: '女', value: 1 }]} />
<ProFormSelect name="roleIds" label="角色" mode="multiple" request={systemApi.roles} placeholder="选择角色" />
<ProFormTextArea name="remark" label="备注" />
</ModalForm>
);
};
export default UserForm;
@@ -0,0 +1,76 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Space, Switch, Popconfirm } from 'antd';
import { systemApi, UserItem } from '@/services/system';
export interface UserTableRef {
reload: () => void;
}
export interface UserTableProps {
onEdit: (record: UserItem) => void;
onResetPassword: (record: UserItem) => void;
onDelete: (record: UserItem) => void;
// 额外查询参数(由外层统一查询栏传入)
extraParams?: Record<string, any>;
}
const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPassword, onDelete, extraParams }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({
reload: () => actionRef.current?.reload(),
}));
const switchEnabled = async (record: UserItem) => {
await systemApi.updateEnabled(record.id!, !record.enabled);
actionRef.current?.reload();
};
const columns: ProColumns<UserItem>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '用户ID', dataIndex: 'id', width: 100, search: false },
{ title: '用户名', dataIndex: 'username' },
{ title: '用户昵称', dataIndex: 'nickname' },
{ title: '手机号', dataIndex: 'mobile' },
{ title: '性别', dataIndex: 'sex', valueType: 'select', valueEnum: { 0: { text: '男' }, 1: { text: '女' } }, width: 80 },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', search: false },
{
title: '状态', dataIndex: 'enabled', search: false,
render: (_, entity) => (
<Switch checkedChildren="启用" unCheckedChildren="禁用" checked={!!entity.enabled} onClick={() => switchEnabled(entity)} style={entity.enabled ? { backgroundColor: '#52c41a' } : undefined} />
)
},
{
title: '操作', valueType: 'option', width: 220,
render: (_, entity) => (
<Space>
<a onClick={() => onEdit(entity)}>编辑</a>
<a onClick={() => onResetPassword(entity)}>重置密码</a>
<Popconfirm title={`确认删除用户[${entity.username}]?`} onConfirm={() => onDelete(entity)}>
<a style={{ color: '#1677ff' }}>删除</a>
</Popconfirm>
</Space>
)
},
];
return (
<ProTable<UserItem>
actionRef={actionRef}
rowKey="id"
columns={columns}
request={async (p) => {
const { data, total } = await systemApi.users({ ...(p as any), ...(extraParams || {}) } as any);
return { data, total, success: true };
}}
pagination={{ pageSize: 10 }}
// 统一:关闭 ProTable 自带搜索,由外层 SearchBarPlus 统一承载
search={false}
toolBarRender={false}
/>
);
});
export default UserTable;
@@ -0,0 +1,140 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormText } from '@ant-design/pro-components';
import { message } from 'antd';
import { ActionBar, GlassCard, SearchBarPlus } from '@/components/ui';
import { systemApi, UserItem } from '@/services/system';
import UserTable, { UserTableRef } from './components/UserTable';
import Toolbar from './components/Toolbar';
import UserForm from './components/UserForm';
const UsersPage: React.FC = () => {
const tableRef = useRef<UserTableRef>(null);
const [params, setParams] = useState<Record<string, any>>({});
const [createVisible, setCreateVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false);
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
const addUser = async (values: UserItem) => {
const hide = message.loading('正在添加');
try {
const res = await systemApi.saveOrUpdateUser(values);
hide();
message.success('添加用户成功');
tableRef.current?.reload();
return true;
} catch (e) {
hide();
message.error('添加用户失败');
return false;
}
};
const editUser = async (values: UserItem) => {
const hide = message.loading('正在更新');
try {
const res = await systemApi.saveOrUpdateUser({ ...currentRow, ...values });
hide();
message.success('修改用户成功');
tableRef.current?.reload();
return true;
} catch (e) {
hide();
message.error('修改用户失败');
return false;
}
};
const switchEnabled = async (record: UserItem) => {
const hide = message.loading('正在更新');
try {
await systemApi.updateEnabled(record.id!, !record.enabled);
hide();
message.success('修改用户成功');
tableRef.current?.reload();
} catch (e) {
hide();
message.error('修改用户失败');
}
};
const resetPwd = async (record: UserItem) => {
const hide = message.loading('正在更新');
try {
await systemApi.resetPassword(record.id!);
hide();
message.success('重置密码成功');
} catch (e) {
hide();
message.error('重置密码失败');
}
};
const delUser = async (record: UserItem) => {
const hide = message.loading('正在删除');
try {
await systemApi.deleteUser(record.id!);
hide();
message.success('删除用户成功');
tableRef.current?.reload();
} catch (e) {
hide();
message.error('删除用户失败');
}
};
return (
<PageContainer header={{ title: '用户管理' }}>
<ActionBar
left={
<Toolbar
onCreate={() => setCreateVisible(true)}
onExport={() => systemApi.exportUser()}
/>
}
/>
<SearchBarPlus
defaultCollapsed={false}
split
span={6}
onTenantChanged={() => tableRef.current?.reload()}
onFinish={async (values) => {
setParams(values);
tableRef.current?.reload();
}}
>
<ProFormText name="username" label="用户名" placeholder="请输入用户名" />
<ProFormText name="mobile" label="手机号" placeholder="请输入手机号" />
</SearchBarPlus>
<GlassCard>
<UserTable
ref={tableRef}
onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }}
onResetPassword={(r) => resetPwd(r)}
onDelete={(r) => delUser(r)}
extraParams={params}
/>
</GlassCard>
{/* 新建 */}
<UserForm
title="新建用户"
open={createVisible}
onOpenChange={setCreateVisible}
onFinish={addUser}
/>
{/* 编辑 */}
<UserForm
title="修改用户"
open={editVisible}
onOpenChange={setEditVisible}
onFinish={editUser}
initialValues={currentRow}
/>
</PageContainer>
);
};
export default UsersPage;
@@ -0,0 +1,92 @@
import React, { useEffect, useRef, useState } from 'react';
import { PageContainer, ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components';
import type { ProFormInstance } from '@ant-design/pro-components';
import { Button, Upload, message, Space } from 'antd';
import { UploadOutlined, SaveOutlined } from '@ant-design/icons';
import { currentUser as fetchCurrentUser } from '@/services/login';
import { systemApi, UserItem } from '@/services/system';
import { ActionBar } from '@/components/ui';
const UserInfoPage: React.FC = () => {
const formRef = useRef<ProFormInstance<UserItem>>();
const [user, setUser] = useState<UserItem | null>(null);
const loadUser = async () => {
const res = await fetchCurrentUser();
if (res) setUser(res as any);
};
useEffect(() => { loadUser(); }, []);
const setImage = (headImgUrl: string) => {
if (user) setUser({ ...user, headImgUrl } as any);
};
if (!user) return null;
formRef.current?.setFieldsValue(user as any);
return (
<PageContainer header={{ title: '个人信息' }}>
<ActionBar
right={(
<Space>
{/* 统一去掉刷新按钮 */}
<Button size="middle" type="primary" icon={<SaveOutlined />} onClick={() => formRef.current?.submit?.()}>保存</Button>
</Space>
)}
/>
<div style={{ display: 'flex', gap: 24 }}>
<div style={{ flex: 1 }}>
<ProForm<UserItem>
formRef={formRef}
initialValues={user as any}
onFinish={async (values) => {
const saveUser = { ...(user as any), ...values };
const hide = message.loading('保存中...');
try {
await systemApi.saveOrUpdateUser(saveUser as any);
message.success('修改个人信息成功');
} catch (e) {
message.error('修改个人信息失败');
} finally { hide(); }
}}
>
<ProFormText name="username" label="账号" readonly />
<ProFormText name="nickname" label="用户昵称" rules={[{ required: true, message: '用户昵称不能为空' }]} />
<ProFormText name="mobile" label="手机号" rules={[{ required: true, message: '手机号不能为空' }]} />
<ProFormRadio.Group name="sex" label="性别" options={[{ label: '男', value: 0 }, { label: '女', value: 1 }]} />
</ProForm>
</div>
<div style={{ width: 240 }}>
<div style={{ marginBottom: 8, color: '#999' }}>头像</div>
<div style={{ width: 120, height: 120, borderRadius: 60, overflow: 'hidden', background: '#f5f5f5', marginBottom: 12 }}>
{ (user as any).headImgUrl && (<img src={(user as any).headImgUrl} alt="avatar" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />) }
</div>
<Upload
maxCount={1}
action="/api-file/files-anon"
showUploadList={false}
beforeUpload={async (file) => {
const formData = new FormData();
formData.append('file', file as any);
try {
const res = await fetch('/api-file/files-anon', { method: 'POST', body: formData });
const data = await res.json();
if (data && data.url) setImage(data.url);
} catch (e) {
message.error('上传头像失败');
}
return false;
}}
>
<Button icon={<UploadOutlined />}>上传头像</Button>
</Upload>
</div>
</div>
</PageContainer>
);
};
export default UserInfoPage;
@@ -0,0 +1,80 @@
.login-page {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 24px;
/* 渐变 + 背景图叠加(assets/beijing.png) */
background:
linear-gradient(135deg, rgba(14,165,233,.85) 0%, rgba(37,99,235,.75) 55%, rgba(30,41,59,.85) 100%),
url(~@/assets/beijing.png) center / cover no-repeat fixed;
}
.login-wrap {
width: 100%;
max-width: 1000px;
display: flex;
gap: 24px;
align-items: stretch;
}
.login-hero {
flex: 1;
min-height: 420px;
color: #fff;
border-radius: 14px;
padding: 32px;
background: rgba(255, 255, 255, 0.06);
backdrop-filter: blur(6px);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}
.login-hero h1 {
margin: 0 0 8px;
font-weight: 700;
}
.login-hero p {
opacity: 0.95;
}
.login-hero ul {
margin: 16px 0 0;
padding-left: 18px;
}
.login-form-card {
width: 420px;
max-width: 100%;
background: var(--bg-secondary);
border-radius: 14px;
padding: 24px;
box-shadow: var(--shadow-card);
border: 1px solid var(--border-color);
}
.login-form :global(.ant-pro-form-login-logo) img {
border-radius: 8px;
}
.login-form-extra {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.login-footer {
margin-top: 16px;
color: var(--text-secondary);
}
@media (max-width: 768px) {
.login-wrap {
max-width: 420px;
}
.login-hero { display: none; }
.login-page { padding: 16px; }
.login-form-card { padding: 20px; }
}
@@ -0,0 +1,131 @@
import logo from '@/assets/logo.png';
import React, { useEffect, useRef, useState } from 'react';
import { LoginForm, ProFormText, ProFormCaptcha, ProFormCheckbox } from '@ant-design/pro-components';
import { AppstoreOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
import { Form, message, Spin } from 'antd';
import { v4 as uuidv4 } from 'uuid';
import { history } from 'umi';
import { login, LoginParams } from '@/services/login';
import './index.less';
const LoginPage: React.FC = () => {
const [uuid, setUuid] = useState<string>(uuidv4());
const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
const mountedRef = useRef(true);
useEffect(() => () => { mountedRef.current = false; }, []);
// 自动回填“租户标识”
useEffect(() => {
const clientId = localStorage.getItem('tenant_client_id');
if (clientId) form.setFieldsValue({ clientId });
}, []);
const handleSubmit = async (values: LoginParams) => {
if (loading) return;
setLoading(true);
try {
const res = await login({ ...values, deviceId: uuid });
// 检查多种可能的token字段位置
const accessToken = res?.access_token || res?.data?.access_token || res?.accessToken;
if (accessToken) {
sessionStorage.setItem('access_token', accessToken);
localStorage.setItem('tenant_client_id', String(values.clientId ?? ''));
message.success('登录成功,正在跳转...');
// 使用umi的history进行路由跳转
setTimeout(() => {
const { query } = history.location as any;
const { redirect } = query || {};
const targetPath = redirect || '/welcome';
history.push(targetPath);
}, 1000);
// 注意:不要在这里return,让finally块执行
} else {
const errorMsg = (res as any)?.resp_msg || (res as any)?.msg || '登录失败';
message.error(errorMsg);
setUuid(uuidv4());
}
} catch (e) {
const errorMsg = (e as any)?.message || '登录失败,请重试';
message.error(errorMsg);
} finally {
if (mountedRef.current) setLoading(false);
}
};
return (
<div className="login-page">
<div className="login-wrap">
<div className="login-hero">
<h1>Go-Fly Admin</h1>
<p>G0-Fly后台管理系统,支持多租户与子租户查询。</p>
<ul>
<li>全球景区智能服务运营商</li>
<li>让旅行记忆触手可及</li>
<li>统一下载/导出与请求封装</li>
</ul>
</div>
<div className="login-form-card">
<Spin spinning={loading}>
<LoginForm
className="login-form"
logo={<img alt="logo" src={logo} />}
title="Go-Fly Admin"
subTitle="请输入账号后继续"
initialValues={{ autoLogin: true }}
form={form}
onFinish={handleSubmit as any}
submitter={{ searchConfig: { submitText: '登录' } }}
>
<ProFormText
name="clientId"
fieldProps={{ size: 'large', prefix: <AppstoreOutlined /> }}
placeholder="请输入租户标识"
rules={[{ required: true, message: '请输入租户标识' }]}
/>
<ProFormText
name="username"
fieldProps={{ size: 'large', prefix: <UserOutlined /> }}
placeholder="请输入用户名"
rules={[{ required: true, message: '请输入用户名' }]}
/>
<ProFormText.Password
name="password"
fieldProps={{ size: 'large', prefix: <LockOutlined /> }}
placeholder="请输入密码"
rules={[{ required: true, message: '请输入密码' }]}
/>
<ProFormCaptcha
name="validCode"
fieldProps={{ size: 'large', prefix: <LockOutlined /> }}
captchaProps={{ size: 'large' }}
placeholder="请输入验证码"
captchaTextRender={() => (
<img
src={`/api-uaa/validata/code/${uuid}`}
alt="验证码"
style={{ height: 32, cursor: 'pointer' }}
onClick={() => setUuid(uuidv4())}
/>
)}
onGetCaptcha={async () => Promise.resolve()}
rules={[{ required: true, message: '请输入验证码' }]}
/>
<div className="login-form-extra">
<ProFormCheckbox noStyle name="autoLogin">自动登录</ProFormCheckbox>
</div>
</LoginForm>
</Spin>
</div>
</div>
<div className="login-footer">© {new Date().getFullYear()} Go-Fly</div>
</div>
);
};
export default LoginPage;