feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// 避免类型耦合,使用 any 降级
|
||||
import './global.less';
|
||||
import React from 'react';
|
||||
import { ThemeProvider } from './theme';
|
||||
import { history } from 'umi';
|
||||
|
||||
export function rootContainer(container: React.ReactNode, _args?: any) {
|
||||
return React.createElement(ThemeProvider, null, container);
|
||||
}
|
||||
|
||||
// 使用简化的 request 配置,避免与类型强绑定(兼容 umi 3)
|
||||
export const request: any = {
|
||||
errorConfig: {
|
||||
errorHandler(error: any) {
|
||||
// 可在此处统一处理错误,如通知等
|
||||
throw error;
|
||||
},
|
||||
},
|
||||
requestInterceptors: [
|
||||
(url: string, options: any) => {
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
const headers: Record<string, string> = { ...(options?.headers as any) };
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||
return { url, options: { ...options, headers } };
|
||||
},
|
||||
],
|
||||
responseInterceptors: [
|
||||
async (response: Response) => {
|
||||
// 兼容后端 Result 结构
|
||||
try {
|
||||
const cloned = response.clone();
|
||||
const data = await cloned.json();
|
||||
if (data && typeof (data as any).resp_code !== 'undefined') {
|
||||
const mapped = {
|
||||
success: (data as any).resp_code === 0,
|
||||
code: (data as any).resp_code,
|
||||
msg: (data as any).resp_msg,
|
||||
data: (data as any).data,
|
||||
} as any;
|
||||
(response as any).data = mapped;
|
||||
}
|
||||
} catch (e) {
|
||||
// 静默处理解析错误
|
||||
}
|
||||
return response;
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// 简单路由守卫:未登录访问受保护路由时跳回登录;已登录访问登录页时跳到欢迎页
|
||||
export function onRouteChange({ location }: any) {
|
||||
try {
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
const isLoginPath = String(location?.pathname || '').startsWith('/user/login');
|
||||
if (!token && !isLoginPath) {
|
||||
history.push('/user/login');
|
||||
} else if (token && isLoginPath) {
|
||||
history.push('/welcome');
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import { Spin } from 'antd';
|
||||
import { LoadingOutlined } from '@ant-design/icons';
|
||||
|
||||
const PageLoading: React.FC = () => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100vh',
|
||||
background: 'var(--bg-primary, #0f1419)',
|
||||
color: 'var(--text-primary, #ffffff)'
|
||||
}}
|
||||
>
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<Spin
|
||||
indicator={<LoadingOutlined style={{ fontSize: 32, color: '#667eea' }} spin />}
|
||||
size="large"
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
marginTop: 16,
|
||||
fontSize: 16,
|
||||
color: 'var(--text-secondary, #a0a6b8)'
|
||||
}}
|
||||
>
|
||||
正在加载...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageLoading;
|
||||
@@ -0,0 +1,51 @@
|
||||
.secure-login-form {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
|
||||
.password-strength {
|
||||
margin-bottom: 16px;
|
||||
|
||||
.strength-label {
|
||||
font-size: 12px;
|
||||
margin-bottom: 4px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.strength-suggestions {
|
||||
font-size: 11px;
|
||||
color: #999;
|
||||
margin-top: 4px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper-lg,
|
||||
.ant-input-password-large {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
.ant-btn-lg {
|
||||
height: 48px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
// 深色主题适配
|
||||
.dark-theme {
|
||||
.secure-login-form {
|
||||
.password-strength {
|
||||
.strength-label {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.strength-suggestions {
|
||||
color: #aaa;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Input, Button, message, Progress } from 'antd';
|
||||
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
|
||||
import { useSecurity } from '../../hooks/useSecurity';
|
||||
import './index.less';
|
||||
|
||||
interface LoginFormData {
|
||||
username: string;
|
||||
password: string;
|
||||
rememberMe?: boolean;
|
||||
}
|
||||
|
||||
interface SecureLoginFormProps {
|
||||
onLogin: (loginData: LoginFormData) => Promise<void>;
|
||||
loading?: boolean;
|
||||
showPasswordStrength?: boolean;
|
||||
}
|
||||
|
||||
const SecureLoginForm: React.FC<SecureLoginFormProps> = ({
|
||||
onLogin,
|
||||
loading = false,
|
||||
showPasswordStrength = true
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const { secureLogin, validatePassword, isEncrypting } = useSecurity();
|
||||
const [passwordStrength, setPasswordStrength] = useState<{
|
||||
level: 'weak' | 'medium' | 'strong';
|
||||
score: number;
|
||||
suggestions: string[];
|
||||
} | null>(null);
|
||||
|
||||
/**
|
||||
* 密码输入变化处理
|
||||
*/
|
||||
const handlePasswordChange = (value: string) => {
|
||||
if (showPasswordStrength && value) {
|
||||
const strength = validatePassword(value);
|
||||
setPasswordStrength(strength);
|
||||
} else {
|
||||
setPasswordStrength(null);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 表单提交处理
|
||||
*/
|
||||
const handleSubmit = async (values: LoginFormData) => {
|
||||
try {
|
||||
// 使用安全登录处理
|
||||
const secureData = await secureLogin(values);
|
||||
if (!secureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用父组件的登录方法
|
||||
await onLogin(secureData);
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error);
|
||||
message.error('登录失败,请重试');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取密码强度颜色
|
||||
*/
|
||||
const getPasswordStrengthColor = (level: string) => {
|
||||
switch (level) {
|
||||
case 'weak':
|
||||
return '#ff4d4f';
|
||||
case 'medium':
|
||||
return '#faad14';
|
||||
case 'strong':
|
||||
return '#52c41a';
|
||||
default:
|
||||
return '#d9d9d9';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="secure-login-form">
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={handleSubmit}
|
||||
autoComplete="off"
|
||||
layout="vertical"
|
||||
>
|
||||
<Form.Item
|
||||
name="username"
|
||||
rules={[
|
||||
{ required: true, message: '请输入用户名' },
|
||||
{ min: 2, message: '用户名至少2个字符' }
|
||||
]}
|
||||
>
|
||||
<Input
|
||||
prefix={<UserOutlined />}
|
||||
placeholder="用户名"
|
||||
size="large"
|
||||
autoComplete="username"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="password"
|
||||
rules={[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, message: '密码至少6个字符' }
|
||||
]}
|
||||
>
|
||||
<Input.Password
|
||||
prefix={<LockOutlined />}
|
||||
placeholder="密码"
|
||||
size="large"
|
||||
iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
|
||||
autoComplete="current-password"
|
||||
onChange={(e) => handlePasswordChange(e.target.value)}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
{/* 密码强度指示器 */}
|
||||
{showPasswordStrength && passwordStrength && (
|
||||
<div className="password-strength">
|
||||
<div className="strength-label">
|
||||
密码强度: <span style={{ color: getPasswordStrengthColor(passwordStrength.level) }}>
|
||||
{passwordStrength.level === 'weak' ? '弱' :
|
||||
passwordStrength.level === 'medium' ? '中等' : '强'}
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
percent={passwordStrength.score}
|
||||
strokeColor={getPasswordStrengthColor(passwordStrength.level)}
|
||||
showInfo={false}
|
||||
size="small"
|
||||
/>
|
||||
{passwordStrength.suggestions.length > 0 && (
|
||||
<div className="strength-suggestions">
|
||||
建议: {passwordStrength.suggestions.join('、')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Form.Item>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
size="large"
|
||||
loading={loading || isEncrypting}
|
||||
block
|
||||
>
|
||||
{isEncrypting ? '加密中...' : '登录'}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SecureLoginForm;
|
||||
@@ -0,0 +1,77 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Space, Button, TreeSelect, Checkbox, message } from 'antd';
|
||||
import { tenantApi, TenantTreeNode } from '@/services/tenant';
|
||||
|
||||
interface Props {
|
||||
// 当租户或“包含子租户”变更后回调
|
||||
onChanged?: (tenantId: string, includeChildren: boolean) => void;
|
||||
}
|
||||
|
||||
const TenantScopeFilter: React.FC<Props> = ({ onChanged }) => {
|
||||
const [tree, setTree] = useState<TenantTreeNode[]>([]);
|
||||
const [tenantId, setTenantId] = useState<string | undefined>();
|
||||
const [includeChildren, setIncludeChildren] = useState(true);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [treeRes, currentRes] = await Promise.all([
|
||||
tenantApi.getAccessibleTenants(),
|
||||
tenantApi.getCurrentTenant(),
|
||||
]);
|
||||
if (treeRes.success) setTree(treeRes.data || []);
|
||||
if (currentRes.success) setTenantId(currentRes.data?.tenantId);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
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 handleApply = async () => {
|
||||
if (!tenantId) return;
|
||||
try {
|
||||
const res = await tenantApi.switchTenant(tenantId);
|
||||
if (res.success) {
|
||||
message.success('租户范围已更新');
|
||||
onChanged?.(tenantId, includeChildren);
|
||||
} else {
|
||||
message.error(res.msg || '切换失败');
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('切换失败');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<TreeSelect
|
||||
style={{ minWidth: 260 }}
|
||||
treeDefaultExpandAll
|
||||
loading={loading}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
placeholder="选择租户(含子租户)"
|
||||
value={tenantId}
|
||||
onChange={(val) => setTenantId(val)}
|
||||
treeData={toTreeData(tree)}
|
||||
/>
|
||||
<Checkbox checked={includeChildren} onChange={(e) => setIncludeChildren(e.target.checked)}>
|
||||
包含子租户
|
||||
</Checkbox>
|
||||
<Button type="primary" onClick={handleApply}>
|
||||
应用
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantScopeFilter;
|
||||
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
|
||||
/**
|
||||
* 页面动作栏容器:统一按钮间距、两侧分布布局。
|
||||
* - left: 左侧节点(常放主要操作)
|
||||
* - right: 右侧节点(常放过滤器、视图切换等)
|
||||
*/
|
||||
export interface ActionBarProps {
|
||||
left?: React.ReactNode;
|
||||
right?: React.ReactNode;
|
||||
style?: React.CSSProperties;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const ActionBar: React.FC<ActionBarProps> = ({ left, right, style, className }) => {
|
||||
return (
|
||||
<div
|
||||
className={["gf-action-bar", className].filter(Boolean).join(' ')}
|
||||
style={style}
|
||||
>
|
||||
<div className="gf-action-bar-left">{left}</div>
|
||||
<div className="gf-action-bar-right">{right}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActionBar;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Card } from 'antd';
|
||||
import type { CardProps } from 'antd';
|
||||
|
||||
/**
|
||||
* 玻璃质感卡片:在 Antd Card 基础上增加统一的现代化样式。
|
||||
*/
|
||||
const GlassCard: React.FC<CardProps> = ({ className, children, ...rest }) => {
|
||||
const cls = ['modern-card', className].filter(Boolean).join(' ');
|
||||
return (
|
||||
<Card className={cls} {...rest}>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlassCard;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { Button } from 'antd';
|
||||
import type { ButtonProps } from 'antd';
|
||||
|
||||
/**
|
||||
* 渐变主按钮:在 Antd Button 基础上提供更亮丽的渐变样式。
|
||||
* - 默认 type=primary,支持透传所有 ButtonProps。
|
||||
* - 通过 className="gf-gradient-btn" 统一样式,也可与 ghost/danger 等属性叠加。
|
||||
*/
|
||||
const GradientButton: React.FC<ButtonProps> = ({ className, type = 'primary', children, ...rest }) => {
|
||||
const cls = ['gf-gradient-btn', className].filter(Boolean).join(' ');
|
||||
return (
|
||||
<Button type={type} className={cls} {...rest}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export default GradientButton;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import { Statistic } from 'antd';
|
||||
|
||||
export interface KPIStatProps {
|
||||
title: React.ReactNode;
|
||||
value: number | string;
|
||||
suffix?: React.ReactNode;
|
||||
color?: string; // 左侧高亮条与图标色
|
||||
icon?: React.ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* KPIStat:统一的指标卡片内容块,建议搭配 GlassCard 使用。
|
||||
*/
|
||||
const KPIStat: React.FC<KPIStatProps> = ({ title, value, suffix, color = '#667eea', icon }) => {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', borderLeft: `4px solid ${color}`, background: 'var(--bg-card)' }}>
|
||||
<div style={{ color, fontSize: 24, marginBottom: 8 }}>{icon}</div>
|
||||
<Statistic
|
||||
title={title}
|
||||
value={value}
|
||||
suffix={suffix}
|
||||
valueStyle={{ color: 'var(--text-primary)', fontSize: 28, fontWeight: 'bold' }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default KPIStat;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
|
||||
/**
|
||||
* PageHeaderPlus:美化后的页面容器。保留 PageContainer 能力,增强标题与背景视觉。
|
||||
*/
|
||||
export interface PageHeaderPlusProps {
|
||||
title?: React.ReactNode;
|
||||
subTitle?: React.ReactNode;
|
||||
extra?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const PageHeaderPlus: React.FC<PageHeaderPlusProps> = ({ title, subTitle, extra, children }) => {
|
||||
return (
|
||||
<PageContainer
|
||||
header={{
|
||||
title: (
|
||||
<span
|
||||
style={{
|
||||
color: 'var(--text-primary)',
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</span>
|
||||
),
|
||||
subTitle,
|
||||
}}
|
||||
extra={extra}
|
||||
>
|
||||
{children}
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageHeaderPlus;
|
||||
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import { QueryFilter } from '@ant-design/pro-components';
|
||||
import TenantSelector from '@/components/ui/TenantSelector';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
|
||||
export interface SearchBarPlusProps {
|
||||
// QueryFilter 透传属性(常用)
|
||||
defaultCollapsed?: boolean;
|
||||
split?: boolean;
|
||||
span?: number | { xs?: number; sm?: number; md?: number; lg?: number; xl?: number; xxl?: number };
|
||||
form?: any;
|
||||
onFinish?: (values: Record<string, any>) => Promise<any> | void;
|
||||
// 子节点:放置各业务查询项(ProForm* 或 Form.Item 均可)
|
||||
children?: React.ReactNode;
|
||||
// 是否显示租户筛选(默认显示)
|
||||
showTenant?: boolean;
|
||||
// 租户变化回调:用于触发表格 reload 等
|
||||
onTenantChanged?: (tenantId: string, includeChildren: boolean) => void;
|
||||
// 租户筛选放置位置:start 放在最前,end 放在最后(默认 start)
|
||||
tenantPosition?: 'start' | 'end';
|
||||
}
|
||||
|
||||
const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
||||
defaultCollapsed,
|
||||
split,
|
||||
span,
|
||||
form,
|
||||
onFinish,
|
||||
children,
|
||||
showTenant = true,
|
||||
onTenantChanged,
|
||||
tenantPosition = 'start',
|
||||
}) => {
|
||||
const handleFinish = async (values: Record<string, any>) => {
|
||||
try {
|
||||
if (showTenant && values && values.tenantId) {
|
||||
await tenantApi.switchTenant(values.tenantId);
|
||||
}
|
||||
onTenantChanged?.(values?.tenantId, !!values?.includeChildren);
|
||||
} finally {
|
||||
await onFinish?.(values);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryFilter
|
||||
defaultCollapsed={defaultCollapsed}
|
||||
split={split}
|
||||
span={span as any}
|
||||
form={form}
|
||||
onFinish={handleFinish}
|
||||
>
|
||||
{showTenant && tenantPosition === 'start' ? <TenantSelector /> : null}
|
||||
{children}
|
||||
{showTenant && tenantPosition === 'end' ? <TenantSelector /> : null}
|
||||
</QueryFilter>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchBarPlus;
|
||||
@@ -0,0 +1,64 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Form, TreeSelect, Checkbox } from 'antd';
|
||||
import { tenantApi, TenantTreeNode } from '@/services/tenant';
|
||||
|
||||
export interface TenantSelectorProps {
|
||||
// 字段名可自定义;默认与后端接口约定一致
|
||||
nameTenant?: string; // 默认 'tenantId'
|
||||
nameIncludeChildren?: string; // 默认 'includeChildren'
|
||||
labelTenant?: React.ReactNode;
|
||||
labelIncludeChildren?: React.ReactNode;
|
||||
}
|
||||
|
||||
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 TenantSelector: React.FC<TenantSelectorProps> = ({
|
||||
nameTenant = 'tenantId',
|
||||
nameIncludeChildren = 'includeChildren',
|
||||
labelTenant = '租户',
|
||||
labelIncludeChildren = '包含子租户',
|
||||
}) => {
|
||||
const [tree, setTree] = useState<TenantTreeNode[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [treeRes] = await Promise.all([
|
||||
tenantApi.getAccessibleTenants(),
|
||||
]);
|
||||
if (treeRes?.success) setTree(treeRes.data || []);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form.Item name={nameTenant} label={labelTenant}>
|
||||
<TreeSelect
|
||||
style={{ minWidth: 260 }}
|
||||
treeDefaultExpandAll
|
||||
loading={loading}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
placeholder="选择租户(含子租户)"
|
||||
treeData={toTreeData(tree)}
|
||||
allowClear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name={nameIncludeChildren} label={labelIncludeChildren} valuePropName="checked" initialValue={true}>
|
||||
<Checkbox>包含子租户</Checkbox>
|
||||
</Form.Item>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantSelector;
|
||||
@@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import { Button, Tooltip } from 'antd';
|
||||
import { MoonOutlined, SunOutlined } from '@ant-design/icons';
|
||||
import type { ThemeMode } from '@/theme';
|
||||
|
||||
export interface ThemeSwitchProps {
|
||||
mode: ThemeMode;
|
||||
onToggle: () => void;
|
||||
}
|
||||
|
||||
const ThemeSwitch: React.FC<ThemeSwitchProps> = ({ mode, onToggle }) => {
|
||||
return (
|
||||
<Tooltip title={mode === 'dark' ? '切换为亮色' : '切换为暗色'}>
|
||||
<Button
|
||||
type="text"
|
||||
onClick={onToggle}
|
||||
icon={mode === 'dark' ? <SunOutlined /> : <MoonOutlined />}
|
||||
style={{ color: 'var(--text-primary)' }}
|
||||
>
|
||||
{mode === 'dark' ? '亮色' : '暗色'}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeSwitch;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
@@ -0,0 +1,7 @@
|
||||
export { default as GradientButton } from './GradientButton';
|
||||
export { default as ActionBar } from './ActionBar';
|
||||
export { default as GlassCard } from './GlassCard';
|
||||
export { default as PageHeaderPlus } from './PageHeaderPlus';
|
||||
export { default as KPIStat } from './KPIStat';
|
||||
export { default as ThemeSwitch } from './ThemeSwitch';
|
||||
export { default as SearchBarPlus } from './SearchBarPlus';
|
||||
@@ -0,0 +1,68 @@
|
||||
@import '~antd/es/style/variable.less';
|
||||
@import './theme/modern.less';
|
||||
|
||||
:root {
|
||||
--page-padding: 16px;
|
||||
}
|
||||
|
||||
html, body, #root, .ant-pro {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body { background: var(--bg-primary); color: var(--text-primary); }
|
||||
.ant-layout { background: var(--bg-primary); }
|
||||
|
||||
.page-enter {
|
||||
animation: pageFadeIn .36s var(--ease-out-quart, cubic-bezier(0.25, 1, 0.5, 1));
|
||||
}
|
||||
|
||||
@keyframes pageFadeIn {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.page-header-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
/* 全局样式优化与移动端适配 */
|
||||
|
||||
html, body, #root { height: 100%; }
|
||||
|
||||
/* 统一卡片与页面留白 */
|
||||
.ant-card { border-radius: 8px; background: var(--card-bg); }
|
||||
.ant-pro-page-container-children-content { padding: 16px; }
|
||||
|
||||
/* PageContainer 头部背景与分割线优化,适配深色科技风 */
|
||||
.ant-pro-page-container-warp {
|
||||
background: transparent;
|
||||
}
|
||||
.ant-pro-page-container {
|
||||
background: transparent;
|
||||
}
|
||||
.ant-pro-page-container .ant-page-header {
|
||||
background: transparent;
|
||||
border-bottom: 1px solid var(--divider-color, rgba(255,255,255,.08));
|
||||
}
|
||||
|
||||
/* 表格在小屏下横向滚动 */
|
||||
@media (max-width: 768px) {
|
||||
.ant-pro-table .ant-table-wrapper, .ant-table-wrapper { overflow-x: auto; }
|
||||
.ant-pro-table .ant-table { min-width: 720px; }
|
||||
.ant-pro-page-container-children-content { padding: 12px; }
|
||||
}
|
||||
|
||||
/* 更友好的表单间距 */
|
||||
.ant-form-item { margin-bottom: 12px; }
|
||||
|
||||
/* 标题字号适配 */
|
||||
@media (max-width: 768px) {
|
||||
h1, .ant-typography h1 { font-size: 22px; }
|
||||
h2, .ant-typography h2 { font-size: 18px; }
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { message } from 'antd';
|
||||
import RSAUtil from '../utils/rsaUtil';
|
||||
import SecurityUtil from '../utils/securityUtil';
|
||||
|
||||
/**
|
||||
* 安全操作Hook
|
||||
*/
|
||||
export const useSecurity = () => {
|
||||
const [isEncrypting, setIsEncrypting] = useState(false);
|
||||
|
||||
/**
|
||||
* 安全加密处理
|
||||
*/
|
||||
const secureEncrypt = useCallback(async (data: string): Promise<string | null> => {
|
||||
setIsEncrypting(true);
|
||||
try {
|
||||
// 模拟加密耗时(可选)
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
|
||||
const encrypted = RSAUtil.encrypt(data);
|
||||
if (!encrypted) {
|
||||
message.error('数据加密失败,请重试');
|
||||
return null;
|
||||
}
|
||||
|
||||
return encrypted;
|
||||
} catch (error) {
|
||||
console.error('加密过程中发生错误:', error);
|
||||
message.error('加密失败,请重试');
|
||||
return null;
|
||||
} finally {
|
||||
setIsEncrypting(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 安全登录处理
|
||||
*/
|
||||
const secureLogin = useCallback(async (loginData: {
|
||||
username: string;
|
||||
password: string;
|
||||
[key: string]: any;
|
||||
}) => {
|
||||
try {
|
||||
// 输入验证
|
||||
if (!loginData.username?.trim()) {
|
||||
message.error('请输入用户名');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!loginData.password?.trim()) {
|
||||
message.error('请输入密码');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 密码强度检查(可选)
|
||||
const passwordStrength = SecurityUtil.validatePasswordStrength(loginData.password);
|
||||
if (passwordStrength.level === 'weak') {
|
||||
// 弱密码警告(不阻止登录,只提示)
|
||||
console.warn('检测到弱密码,建议修改');
|
||||
}
|
||||
|
||||
// 安全处理登录数据
|
||||
const processedData = SecurityUtil.processLoginData(loginData);
|
||||
return processedData;
|
||||
|
||||
} catch (error) {
|
||||
console.error('登录数据处理失败:', error);
|
||||
message.error('登录处理失败,请重试');
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 安全表单提交处理
|
||||
*/
|
||||
const secureFormSubmit = useCallback(async <T extends Record<string, any>>(
|
||||
formData: T,
|
||||
sensitiveFields?: (keyof T)[]
|
||||
): Promise<T | null> => {
|
||||
try {
|
||||
const processedData = SecurityUtil.processFormData(formData, sensitiveFields);
|
||||
return processedData;
|
||||
} catch (error) {
|
||||
console.error('表单数据处理失败:', error);
|
||||
message.error('数据处理失败,请重试');
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 密码强度验证
|
||||
*/
|
||||
const validatePassword = useCallback((password: string) => {
|
||||
return SecurityUtil.validatePasswordStrength(password);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 敏感数据脱敏
|
||||
*/
|
||||
const maskSensitiveData = useCallback((data: string, type: 'phone' | 'email' | 'idcard' | 'bankcard') => {
|
||||
return SecurityUtil.maskSensitiveData(data, type);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
isEncrypting,
|
||||
secureEncrypt,
|
||||
secureLogin,
|
||||
secureFormSubmit,
|
||||
validatePassword,
|
||||
maskSensitiveData
|
||||
};
|
||||
};
|
||||
|
||||
export default useSecurity;
|
||||
@@ -0,0 +1,222 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Space, message, Avatar, Dropdown } from 'antd';
|
||||
import {
|
||||
LogoutOutlined,
|
||||
UserOutlined,
|
||||
SettingOutlined,
|
||||
DashboardOutlined,
|
||||
AppstoreOutlined,
|
||||
FileTextOutlined,
|
||||
TeamOutlined,
|
||||
ToolOutlined,
|
||||
BarChartOutlined,
|
||||
CloudServerOutlined,
|
||||
BugOutlined,
|
||||
SearchOutlined,
|
||||
MessageOutlined,
|
||||
FolderOutlined,
|
||||
SafetyOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Link, useLocation, history } from 'umi';
|
||||
import ProLayout, { MenuDataItem } from '@ant-design/pro-layout';
|
||||
import { fetchMenuData, outLogin } from '@/services/login';
|
||||
import { useTheme } from '@/theme';
|
||||
import { ThemeSwitch } from '@/components/ui';
|
||||
|
||||
// 后端菜单节点(兼容 children 与 subMenus)
|
||||
type MenuNode = {
|
||||
id?: number | string;
|
||||
name?: string;
|
||||
url?: string;
|
||||
path?: string;
|
||||
css?: string;
|
||||
children?: MenuNode[];
|
||||
subMenus?: MenuNode[];
|
||||
};
|
||||
|
||||
const BasicLayout: React.FC = (props: any) => {
|
||||
const location = useLocation();
|
||||
const { mode, toggle } = useTheme();
|
||||
const [menus, setMenus] = useState<MenuNode[]>([]);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
(async () => {
|
||||
try {
|
||||
const list = await fetchMenuData();
|
||||
if (mounted) {
|
||||
setMenus(Array.isArray(list) ? (list as MenuNode[]) : []);
|
||||
setLoaded(true);
|
||||
}
|
||||
} catch {
|
||||
if (mounted) setLoaded(true);
|
||||
}
|
||||
})();
|
||||
return () => { mounted = false; };
|
||||
}, []);
|
||||
|
||||
// 将后端菜单转换为 ProLayout 菜单(对齐 react-web 映射规则)
|
||||
const menuDataRender = useMemo(() => {
|
||||
const mapPath = (m: MenuNode): string | undefined => {
|
||||
const cand = (m.path || m.url || '').trim();
|
||||
if (!cand) return undefined;
|
||||
const lower = cand.toLowerCase();
|
||||
if (lower.startsWith('http')) return cand; // 外链
|
||||
if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 仅 .html 可点击
|
||||
if (lower === '/welcome' || lower === 'welcome') return '/welcome';
|
||||
return undefined; // 其余作为分组,仅展开不跳转
|
||||
};
|
||||
|
||||
const getIcon = (p?: string) => {
|
||||
const s = (p || '').toLowerCase();
|
||||
if (s.includes('system')) return <SettingOutlined />;
|
||||
if (s.includes('order')) return <AppstoreOutlined />;
|
||||
if (s.includes('device')) return <CloudServerOutlined />;
|
||||
if (s.includes('log')) return <BugOutlined />;
|
||||
if (s.includes('search')) return <SearchOutlined />;
|
||||
if (s.includes('message')) return <MessageOutlined />;
|
||||
if (s.includes('file')) return <FolderOutlined />;
|
||||
if (s.includes('user')) return <TeamOutlined />;
|
||||
if (s.includes('welcome')) return <DashboardOutlined />;
|
||||
return <FileTextOutlined />;
|
||||
};
|
||||
|
||||
const normalize = (menu: MenuNode, index: number, parentKey = ''): MenuDataItem => {
|
||||
const stableKey =
|
||||
menu.id ||
|
||||
(menu.url && menu.url !== 'javascript:;' ? menu.url : '') ||
|
||||
(menu.path && menu.path !== 'javascript:;' ? menu.path : '') ||
|
||||
`${parentKey}-${menu.name}-${index}`;
|
||||
const keyStr = String(stableKey);
|
||||
|
||||
const path = mapPath(menu);
|
||||
const childrenList: MenuNode[] = (menu.children && menu.children.length ? menu.children : (menu.subMenus || [])) || [];
|
||||
|
||||
const item: MenuDataItem = {
|
||||
key: keyStr,
|
||||
name: menu.name || `菜单项${index + 1}`,
|
||||
path,
|
||||
icon: getIcon(path),
|
||||
children: childrenList.map((child: MenuNode, i: number) => normalize(child, i, keyStr)),
|
||||
};
|
||||
return item;
|
||||
};
|
||||
|
||||
// 首次未加载完毕前不渲染默认菜单,避免覆盖接口菜单
|
||||
if (!loaded) return [];
|
||||
const list = menus && menus.length ? menus : [{ name: '欢迎页', url: '/welcome', id: 'welcome-default' }];
|
||||
return list.map((m, i) => normalize(m, i));
|
||||
}, [menus, mode, loaded]);
|
||||
|
||||
// 右上角操作区
|
||||
const rightContentRender = () => (
|
||||
<Space size="middle">
|
||||
<ThemeSwitch mode={mode} onToggle={toggle} />
|
||||
<Dropdown
|
||||
menu={{
|
||||
items: [
|
||||
{ key: 'profile', icon: <UserOutlined />, label: '个人中心' },
|
||||
{ key: 'settings', icon: <SettingOutlined />, label: '系统设置' },
|
||||
{ type: 'divider' as any },
|
||||
{
|
||||
key: 'logout',
|
||||
icon: <LogoutOutlined />,
|
||||
label: '退出登录',
|
||||
onClick: async () => {
|
||||
try { await outLogin(); } catch {}
|
||||
try {
|
||||
sessionStorage.removeItem('access_token');
|
||||
sessionStorage.removeItem('current_user');
|
||||
} catch {}
|
||||
message.success('已退出登录');
|
||||
history.push('/user/login');
|
||||
},
|
||||
},
|
||||
],
|
||||
}}
|
||||
placement="bottomRight"
|
||||
>
|
||||
<div style={{ cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<Avatar size="small" icon={<UserOutlined />} />
|
||||
<span style={{ color: 'var(--text-primary)' }}>管理员</span>
|
||||
</div>
|
||||
</Dropdown>
|
||||
</Space>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="page-enter">
|
||||
<ProLayout
|
||||
key="go-fly-pro-layout"
|
||||
title="Go-Fly Admin"
|
||||
logo={false}
|
||||
location={location}
|
||||
route={{ routes: menuDataRender }}
|
||||
navTheme={mode === 'dark' ? 'realDark' : 'light'}
|
||||
colorPrimary="var(--primary-color)"
|
||||
layout="mix"
|
||||
contentWidth="Fluid"
|
||||
fixedHeader
|
||||
fixSiderbar
|
||||
splitMenus={false}
|
||||
siderWidth={256}
|
||||
rightContentRender={rightContentRender}
|
||||
menuDataRender={() => menuDataRender}
|
||||
menuItemRender={(menuItemProps, defaultDom) => {
|
||||
if (menuItemProps.isUrl || !menuItemProps.path) return defaultDom;
|
||||
const path = String(menuItemProps.path);
|
||||
if (path === 'javascript:;' || path === '#' || path.startsWith('menu-item-')) {
|
||||
return <span className="menu-enter">{defaultDom}</span>;
|
||||
}
|
||||
return (
|
||||
<Link to={path} className="menu-enter">
|
||||
{defaultDom}
|
||||
</Link>
|
||||
);
|
||||
}}
|
||||
headerTitleRender={(logo, title) => (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, fontWeight: 600 }}>
|
||||
<div
|
||||
style={{
|
||||
width: 32,
|
||||
height: 32,
|
||||
background: 'var(--tech-gradient)',
|
||||
borderRadius: '8px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
color: 'var(--logo-initial-color, #0f5132)',
|
||||
}}
|
||||
>
|
||||
G
|
||||
</div>
|
||||
<span style={{ fontSize: 18, color: 'var(--text-primary)', fontWeight: 700 }}>{title}</span>
|
||||
</div>
|
||||
)}
|
||||
token={{
|
||||
sider: {
|
||||
// 左侧侧边栏背景使用更柔和的浅色,避免纯白突兀
|
||||
colorMenuBackground: 'var(--sider-bg)',
|
||||
colorBgMenuItemSelected: 'var(--primary-color)',
|
||||
colorTextMenuSelected: '#ffffff',
|
||||
colorTextMenu: 'var(--text-secondary)',
|
||||
colorBgMenuItemHover: 'var(--bg-glass)',
|
||||
},
|
||||
header: {
|
||||
// 顶部导航背景采用柔和渐变
|
||||
colorBgHeader: 'var(--header-bg)',
|
||||
colorHeaderTitle: 'var(--text-primary)',
|
||||
colorTextRightActionsItem: 'var(--text-secondary)',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<div className="layout-content-wrapper" style={{ margin: 0, borderRadius: 0, minHeight: '100%' }}>
|
||||
{props.children}
|
||||
</div>
|
||||
</ProLayout>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BasicLayout;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface AppItem {
|
||||
id?: number;
|
||||
clientId: string;
|
||||
clientName?: string;
|
||||
webServerRedirectUri?: string;
|
||||
authorizedGrantTypes?: string; // comma joined
|
||||
autoapprove?: string; // 'true' | 'false'
|
||||
accessTokenValiditySeconds?: number;
|
||||
refreshTokenValiditySeconds?: number;
|
||||
tokenFormat?: 'reference' | 'self-contained' | string;
|
||||
}
|
||||
|
||||
export const appApi = {
|
||||
page: async (params: { current?: number; pageSize?: number; searchKey?: string }) => {
|
||||
const res = await request('/api-uaa/clients/list', { method: 'GET', params: { page: params.current, limit: params.pageSize, ...params } });
|
||||
const data = (res as any).data;
|
||||
const total = (res as any).count ?? data?.length ?? 0;
|
||||
return { data, total } as { data: AppItem[]; total: number };
|
||||
},
|
||||
saveOrUpdate: async (data: AppItem) => {
|
||||
const res = await request('/api-uaa/clients/saveOrUpdate', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
delete: async (id: number) => {
|
||||
const res = await request(`/api-uaa/clients/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface WaylineItem {
|
||||
id?: number;
|
||||
waylineId?: string;
|
||||
name?: string;
|
||||
sign?: string;
|
||||
workspaceId?: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export interface DeviceItem {
|
||||
deviceSn?: string;
|
||||
deviceName?: string;
|
||||
boundStatus?: number;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export const deviceApi = {
|
||||
wayline: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-device/wayline', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: WaylineItem[]; total: number };
|
||||
},
|
||||
saveOrUpdateWayline: async (data: any) => {
|
||||
const res = await request('/api-device/wayline', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteWayline: async (id: number) => {
|
||||
const res = await request(`/api-device/wayline/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deviceList: async (params: { page?: number; limit?: number; [k:string]: any }) => {
|
||||
const res = await request('/api-device/device', { method: 'GET', params });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: DeviceItem[]; total: number };
|
||||
},
|
||||
saveOrUpdateDevice: async (data: Partial<DeviceItem>) => {
|
||||
const res = await request('/api-device/device', { method: 'POST', data: { ...data, updateTime: Date.now() } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteDevice: async (deviceSn: string) => {
|
||||
const res = await request(`/api-device/device/${deviceSn}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export const filesApi = {
|
||||
list: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-file/files', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
delete: async (id: string) => {
|
||||
const res = await request(`/api-file/files/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface GeneratorItem {
|
||||
engine?: string;
|
||||
tableName?: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export const generatorApi = {
|
||||
list: async (params: { current?: number; pageSize?: number; tableName?: string }) => {
|
||||
const res = await request('/api-generator/generator/list', {
|
||||
method: 'GET',
|
||||
params: { page: params.current, limit: params.pageSize, tableName: params.tableName },
|
||||
});
|
||||
const data = (res as any).data;
|
||||
const total = (res as any).count ?? data?.length ?? 0;
|
||||
return { data, total } as { data: GeneratorItem[]; total: number };
|
||||
},
|
||||
export: async (tables: string) => {
|
||||
const res = await request('/api-generator/generator/code', {
|
||||
method: 'GET',
|
||||
params: { tables },
|
||||
responseType: 'blob',
|
||||
getResponse: true,
|
||||
});
|
||||
const blob = res.data as Blob;
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${tables}.zip`;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { request } from 'umi';
|
||||
import { encryptPassword } from '@/utils/rsaUtil';
|
||||
|
||||
export interface LoginParams {
|
||||
username: string;
|
||||
password: string;
|
||||
tenantId?: string;
|
||||
deviceId?: string;
|
||||
clientId?: string;
|
||||
clientSecret?: string;
|
||||
validCode?: string;
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
export async function currentUser(): Promise<any> {
|
||||
const res = await request('/api-user/users/current', { method: 'GET' });
|
||||
const mapped: any = res as any;
|
||||
if (typeof mapped?.success !== 'undefined') {
|
||||
if (mapped.success) return mapped.data;
|
||||
return { resp_msg: mapped.msg } as any;
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// 获取当前用户菜单
|
||||
export async function fetchMenuData(): Promise<any[]> {
|
||||
const res = await request('/api-user/menus/current', { method: 'GET' });
|
||||
const mapped: any = res as any;
|
||||
if (typeof mapped?.data !== 'undefined') return (mapped.data ?? []) as any[];
|
||||
return ((res as any) ?? []) as any[];
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
export async function outLogin(): Promise<any> {
|
||||
return request('/api-uaa/oauth/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
// 生成 Basic Token(备用)
|
||||
const generateBasicToken = (clientId: string, clientSecret?: string) => {
|
||||
const token = `${clientId}:${clientSecret || clientId}`;
|
||||
const encoded = btoa(unescape(encodeURIComponent(token)));
|
||||
return `Basic ${encoded}`;
|
||||
};
|
||||
|
||||
// 登录
|
||||
export async function login(body: LoginParams): Promise<any> {
|
||||
// 前端进行 RSA 加密,后端解密
|
||||
const encPwd = encryptPassword(body.password || '');
|
||||
|
||||
if (!encPwd) {
|
||||
throw new Error('密码加密失败,请刷新页面重试');
|
||||
}
|
||||
|
||||
const grantType = 'password_code';
|
||||
|
||||
// 构建请求数据
|
||||
const requestData = {
|
||||
userName: body.username,
|
||||
password: encPwd,
|
||||
grantType,
|
||||
clientId: body.clientId,
|
||||
validCode: body.validCode,
|
||||
deviceId: body.deviceId,
|
||||
};
|
||||
|
||||
const res = await request('/api-uaa/oauth/login', {
|
||||
method: 'POST',
|
||||
data: requestData,
|
||||
});
|
||||
const mapped: any = res as any;
|
||||
if (typeof mapped?.success !== 'undefined') {
|
||||
if (mapped.success) return mapped.data;
|
||||
return { resp_msg: mapped.msg } as any;
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface MenuItem {
|
||||
id?: number;
|
||||
pId?: number;
|
||||
parentId?: number;
|
||||
name: string;
|
||||
url?: string;
|
||||
path?: string;
|
||||
css?: string; // icon
|
||||
hidden?: boolean;
|
||||
type?: 1 | 2; // 1菜单,2按钮
|
||||
pathMethod?: 'GET'|'POST'|'PUT'|'DELETE';
|
||||
sort?: number;
|
||||
children?: MenuItem[];
|
||||
}
|
||||
|
||||
export const menuApi = {
|
||||
list: async (tenantId: string) => {
|
||||
const res = await request('/api-user/menus/findAlls', { method: 'GET', params: { tenantId } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
simpleList: async () => {
|
||||
const res = await request('/api-user/menus/findOnes', { method: 'GET' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
saveOrUpdate: async (data: Partial<MenuItem>) => {
|
||||
const res = await request('/api-user/menus/saveOrUpdate', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
delete: async (id: number) => {
|
||||
const res = await request(`/api-user/menus/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface MessageItem {
|
||||
id: number;
|
||||
type: number;
|
||||
title: string;
|
||||
content: string;
|
||||
status: number; // 0未读 1已读
|
||||
createTime?: string;
|
||||
relatedId?: string | number;
|
||||
}
|
||||
|
||||
export const messageApi = {
|
||||
list: async (params: any) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/messages', { method: 'GET', params: { page: current || 1, limit: pageSize || 20, ...rest } });
|
||||
return { data: (res as any).data?.data || (res as any).data, total: (res as any).data?.total || (res as any).total || 0 } as { data: MessageItem[]; total: number };
|
||||
},
|
||||
markAsRead: async (id: number) => request(`/api-order/messages/${id}/read`, { method: 'PUT' }),
|
||||
markAllAsRead: async () => request('/api-order/messages/read/all', { method: 'PUT' }),
|
||||
delete: async (id: number) => request(`/api-order/messages/${id}`, { method: 'DELETE' }),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface MiniAppItem {
|
||||
id?: number;
|
||||
type: 'MP' | 'MINI' | 'PAY' | 'MA' | string;
|
||||
tenantId?: string;
|
||||
merchantId?: string;
|
||||
appId?: string;
|
||||
appSecret?: string;
|
||||
isServiceMode?: boolean;
|
||||
serviceMchId?: string;
|
||||
serviceAppId?: string;
|
||||
subMchId?: string;
|
||||
subAppId?: string;
|
||||
subMchName?: string;
|
||||
subMchDescription?: string;
|
||||
status?: number; // 0/1
|
||||
remark?: string;
|
||||
asyncEnabled?: boolean;
|
||||
asyncPoolSize?: number;
|
||||
}
|
||||
|
||||
export const miniAppApi = {
|
||||
list: async (params: { page?: number; limit?: number; searchKey?: string; searchValue?: string }) => {
|
||||
const res = await request('/api-user/wechat/config/list', { method: 'GET', params });
|
||||
return {
|
||||
data: (res as any).data?.data || [],
|
||||
total: (res as any).data?.count || 0,
|
||||
resp_code: (res as any).resp_code,
|
||||
resp_msg: (res as any).resp_msg,
|
||||
};
|
||||
},
|
||||
create: async (data: MiniAppItem) => {
|
||||
const res = await request('/api-user/wechat/config', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
update: async (data: MiniAppItem) => {
|
||||
const res = await request('/api-user/wechat/config', { method: 'PUT', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
remove: async (id: number) => {
|
||||
const res = await request(`/api-user/wechat/config/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface OrderItem {
|
||||
id: number;
|
||||
orderNo: string;
|
||||
amount?: number;
|
||||
payType?: number;
|
||||
orderStatus?: number;
|
||||
tourismId?: number;
|
||||
tourismName?: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export const ordersApi = {
|
||||
order: async (params: { current?: number; pageSize?: number; orderNo?: string; orderStatus?: number; tourismId?: number; payType?: number }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/list', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: OrderItem[]; total: number };
|
||||
},
|
||||
updateOrder: async (data: Partial<OrderItem>) => {
|
||||
const res = await request('/api-order/update/order', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 订单文件相关接口
|
||||
orderFiles: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/files', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
deleteOrderFile: async (id: number) => {
|
||||
const res = await request(`/api-order/files/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
qrcodeList: async (params: { current?: number; pageSize?: number }) => {
|
||||
const { current, pageSize } = params || {};
|
||||
const res = await request('/api-order/qrcode', { method: 'GET', params: { page: current, limit: pageSize } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
saveOrUpdateQrcode: async (data: any) => {
|
||||
const res = await request('/api-order/qrcode', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteQrcode: async (id: number) => {
|
||||
const res = await request(`/api-order/qrcode/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 鏃呮父鏅尯
|
||||
tourism: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/tourism', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
saveOrUpdateTourism: async (data: any) => {
|
||||
const res = await request('/api-order/tourism', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteTourism: async (id: number) => {
|
||||
const res = await request(`/api-order/tourism/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 棣栭〉杞挱
|
||||
homeCarousel: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/home/carousel', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
saveOrUpdateHomeCarousel: async (data: any) => {
|
||||
const res = await request('/api-order/home/carousel', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteHomeCarousel: async (id: number) => {
|
||||
const res = await request(`/api-order/home/carousel/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 景区素材(图片/视频等)
|
||||
tourismFile: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/tourism/files', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
saveOrUpdateTourismFile: async (data: any) => {
|
||||
const res = await request('/api-order/tourism/files', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteTourismFile: async (id: number) => {
|
||||
const res = await request(`/api-order/tourism/files/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 退款
|
||||
refund: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/refund', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
updateRefund: async (data: any) => {
|
||||
const res = await request('/api-order/refund/approve', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
createRefund: async (payload: { orderNo: string }) => {
|
||||
const res = await request('/api-order/refund/auto', { method: 'PUT', data: payload });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 仪表盘统计
|
||||
dashboard: async (params?: any) => {
|
||||
const res = await request('/api-order/dashboard/statistics', { method: 'GET', params });
|
||||
return res as any;
|
||||
},
|
||||
// 分账
|
||||
getProfitSharingDetail: async (orderNo: string) => {
|
||||
const res = await request('/api-order/profitSharing/detail', { method: 'GET', params: { orderNo } });
|
||||
return res as any;
|
||||
},
|
||||
executeProfitSharing: async (orderNo: string) => {
|
||||
const res = await request('/api-order/profitSharing/execute', { method: 'POST', params: { orderNo } });
|
||||
return res as any;
|
||||
},
|
||||
getProfitSharingStatistics: async (params?: any) => {
|
||||
const res = await request('/api-order/profitSharing/statistics', { method: 'GET', params });
|
||||
return res as any;
|
||||
},
|
||||
// 视频模板
|
||||
getVideoTemplateList: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/videoTemplate/list', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
saveVideoTemplate: async (data: any) => {
|
||||
const res = await request('/api-order/videoTemplate', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
updateVideoTemplate: async (data: any) => {
|
||||
const res = await request('/api-order/videoTemplate', { method: 'PUT', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteVideoTemplate: async (id: number) => {
|
||||
const res = await request(`/api-order/videoTemplate/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
updateVideoTemplateStatus: async (id: number, status: number) => {
|
||||
const res = await request(`/api-order/videoTemplate/${id}/status`, { method: 'PUT', params: { status } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 编辑任务
|
||||
getEditTaskList: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/editTask/list', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
saveOrUpdateEditTask: async (data: any) => {
|
||||
const res = await request('/api-order/editTask', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteEditTask: async (id: number) => {
|
||||
const res = await request(`/api-order/editTask/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
generateEditTask: async (orderNo: string) => {
|
||||
const res = await request('/api-order/auto/cut/generate', { method: 'POST', params: { orderNo } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 微信消息
|
||||
getWxMessageRecords: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/wx/message/records', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
getWxMessageStatistics: async (params: { startTime?: string; endTime?: string }) => {
|
||||
const res = await request('/api-order/wx/message/statistics', { method: 'GET', params });
|
||||
return res as any;
|
||||
},
|
||||
// 优惠券
|
||||
getCouponList: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-order/coupon', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
getCouponById: async (id: number) => {
|
||||
const res = await request(`/api-order/coupon/${id}`, { method: 'GET' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
createCoupon: async (data: any) => {
|
||||
const res = await request('/api-order/coupon', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
updateCoupon: async (id: number, data: any) => {
|
||||
const res = await request(`/api-order/coupon/${id}`, { method: 'PUT', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
deleteCoupon: async (id: number) => {
|
||||
const res = await request(`/api-order/coupon/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
getCouponsByUserPhone: async (userPhone: string) => {
|
||||
const res = await request(`/api-order/coupon/user/${userPhone}`, { method: 'GET' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
getAvailableCouponsByUserPhone: async (userPhone: string) => {
|
||||
const res = await request(`/api-order/coupon/user/${userPhone}/available`, { method: 'GET' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
useCoupon: async (id: number, orderNo: string) => {
|
||||
const res = await request(`/api-order/coupon/${id}/use`, { method: 'POST', params: { orderNo } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
createCouponFromCtrip: async (params: any) => {
|
||||
const res = await request('/api-order/coupon/ctrip/create', { method: 'POST', params });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
verifyCtripCoupon: async (ctripCouponId: string, orderNo: string) => {
|
||||
const res = await request('/api-order/coupon/ctrip/verify', { method: 'POST', params: { ctripCouponId, orderNo } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
updateExpiredCoupons: async () => {
|
||||
const res = await request('/api-order/coupon/update-expired', { method: 'POST' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface RoleItem {
|
||||
id?: number;
|
||||
name: string;
|
||||
code: string;
|
||||
dataScope?: 'ALL' | 'CREATOR';
|
||||
}
|
||||
|
||||
export const roleApi = {
|
||||
page: async (params: { current?: number; pageSize?: number; tenantId?: string; searchKey?: string; searchValue?: string }) => {
|
||||
if (!params?.tenantId) return { data: [], total: 0 };
|
||||
const res = await request('/api-user/roles', {
|
||||
method: 'GET',
|
||||
params: { page: params.current, limit: params.pageSize, tenantId: params.tenantId, searchKey: params.searchKey, searchValue: params.searchValue },
|
||||
});
|
||||
const data = (res as any).data;
|
||||
const total = (res as any).count ?? data?.length ?? 0;
|
||||
return { data, total } as { data: RoleItem[]; total: number };
|
||||
},
|
||||
saveOrUpdate: async (data: RoleItem) => {
|
||||
const res = await request('/api-user/roles/saveOrUpdate', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
delete: async (id: number) => {
|
||||
const res = await request(`/api-user/roles/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
apps: async () => {
|
||||
const res = await request('/api-uaa/clients/all', { method: 'GET' });
|
||||
return (res as any).data || [];
|
||||
},
|
||||
menuForAuth: async (roleId: number, tenantId: string) => {
|
||||
const res = await request(`/api-user/menus/${roleId}/menus`, { method: 'GET', params: { tenantId } });
|
||||
return res as any[];
|
||||
},
|
||||
assignMenu: async (payload: { roleId: number; menuIds: (string|number)[] }) => {
|
||||
const res = await request('/api-user/menus/granted', { method: 'POST', data: payload });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export const searchApi = {
|
||||
// 索引列表
|
||||
indice: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-search/admin/indices', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data } as { data: any[] };
|
||||
},
|
||||
// 索引详情
|
||||
index: async (indexName: string) => {
|
||||
const res = await request('/api-search/admin/index', { method: 'GET', params: { indexName } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 系统日志
|
||||
syslog: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-log/sysLog', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
// 链路日志
|
||||
tracelog: async (traceId: string) => {
|
||||
const p = { queryStr: `traceId:${traceId}`, sortCol: 'timestamp', sortOrder: 'ASC' };
|
||||
const res = await request('/api-log/traceLog', { method: 'GET', params: p });
|
||||
return (res as any).data || [];
|
||||
},
|
||||
// 审计日志
|
||||
auditlog: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-log/auditLog', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
// 慢 SQL 日志
|
||||
slowQueryLog: async (params?: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-log/slowQueryLog', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: any[]; total: number };
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { request } from 'umi';
|
||||
import { download } from '@/utils/download';
|
||||
|
||||
export interface UserItem {
|
||||
id?: number;
|
||||
username: string;
|
||||
nickname?: string;
|
||||
mobile?: string;
|
||||
sex?: number; // 0/1
|
||||
enabled?: boolean;
|
||||
createTime?: string;
|
||||
roleId?: string; // 角色ID(逗号分隔)
|
||||
roles?: Array<{ id: number; name: string; code: string }>;
|
||||
}
|
||||
|
||||
export interface PageParams {
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
[k: string]: any;
|
||||
}
|
||||
|
||||
export const systemApi = {
|
||||
// 用户分页
|
||||
users: async (params?: PageParams) => {
|
||||
const res = await request('/api-user/users', {
|
||||
method: 'GET',
|
||||
params: { page: params?.current, limit: params?.pageSize, ...params },
|
||||
});
|
||||
// 兼容两种分页返回结构
|
||||
const data = (res as any).data?.data || (res as any).data;
|
||||
const total = (res as any).data?.count || (res as any).count || data?.length || 0;
|
||||
return { data, total } as { data: UserItem[]; total: number };
|
||||
},
|
||||
|
||||
// 保存/更新
|
||||
saveOrUpdateUser: async (data: UserItem) => {
|
||||
const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
|
||||
// 启用/禁用
|
||||
updateEnabled: async (id: number, enabled: boolean) => {
|
||||
const res = await request('/api-user/users/updateEnabled', { method: 'GET', params: { id, enabled } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
|
||||
// 重置密码
|
||||
resetPassword: async (id: number) => {
|
||||
const res = await request(`/api-user/users/${id}/password`, { method: 'PUT' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
|
||||
// 删除用户
|
||||
deleteUser: async (id: number) => {
|
||||
const res = await request(`/api-user/users/${id}`, { method: 'DELETE' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
|
||||
// 导出(支持从 Content-Disposition 读取文件名,默认 user.xls)
|
||||
exportUser: async (params?: any) => {
|
||||
const res: any = await request('/api-user/users/export', {
|
||||
method: 'POST',
|
||||
params,
|
||||
responseType: 'blob',
|
||||
getResponse: true,
|
||||
});
|
||||
download(res, 'user.xls');
|
||||
},
|
||||
|
||||
// 导入
|
||||
importUser: async (formData: FormData) => {
|
||||
const res = await request('/api-user/users/import', { method: 'POST', requestType: 'form', data: formData });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
|
||||
// 搜索用户(全量)
|
||||
searchUsers: async (params?: PageParams) => {
|
||||
const res = await request('/api-user/users/search', {
|
||||
method: 'GET',
|
||||
params: { page: params?.current, limit: params?.pageSize, ...params },
|
||||
});
|
||||
const data = (res as any).data?.data || (res as any).data;
|
||||
const total = (res as any).data?.count || (res as any).count || data?.length || 0;
|
||||
return { data, total } as { data: UserItem[]; total: number };
|
||||
},
|
||||
|
||||
// 角色列表(下拉)
|
||||
roles: async () => {
|
||||
const res = await request('/api-user/roles', { method: 'GET' });
|
||||
const list = (res as any).data || [];
|
||||
return list.map((r: any) => ({ label: r.name, value: r.id }));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface TenantTreeNode {
|
||||
tenantId: string;
|
||||
tenantName: string;
|
||||
parentTenantId?: string;
|
||||
tenantType: string;
|
||||
tenantLevel: number;
|
||||
status: number;
|
||||
enabled: boolean;
|
||||
description?: string;
|
||||
children?: TenantTreeNode[];
|
||||
hasChildren?: boolean;
|
||||
childrenCount?: number;
|
||||
}
|
||||
|
||||
export interface TenantInfo {
|
||||
tenantId: string;
|
||||
tenantName: string;
|
||||
parentTenantId?: string;
|
||||
parentTenantName?: string;
|
||||
tenantLevel: number;
|
||||
tenantPath: string;
|
||||
tenantType: string;
|
||||
tenantCode?: string;
|
||||
contactPerson?: string;
|
||||
contactPhone?: string;
|
||||
address?: string;
|
||||
description?: string;
|
||||
status: number;
|
||||
statusText: string;
|
||||
hasChildren?: boolean;
|
||||
childrenCount?: number;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
creatorId?: number;
|
||||
creatorName?: string;
|
||||
}
|
||||
|
||||
export const tenantApi = {
|
||||
getAccessibleTenants: () => request('/tenant/accessible', { method: 'GET' }),
|
||||
switchTenant: (tenantId: string) => request('/tenant/switch', { method: 'POST', params: { tenantId } }),
|
||||
getCurrentTenant: () => request('/tenant/current', { method: 'GET' }),
|
||||
resetToDefaultTenant: () => request('/tenant/reset', { method: 'POST' }),
|
||||
createTenant: (data: Partial<TenantInfo>) => request('/tenant/hierarchy/create', { method: 'POST', data }),
|
||||
updateTenant: (data: Partial<TenantInfo>) => request('/tenant/hierarchy/update', { method: 'PUT', data }),
|
||||
deleteTenant: (tenantId: string) => request(`/tenant/hierarchy/delete`, { method: 'DELETE', params: { tenantId } }),
|
||||
getTenantList: (params: { parentTenantId?: string; tenantName?: string; status?: number; current?: number; pageSize?: number; }) =>
|
||||
request('/tenant/hierarchy/list', {
|
||||
method: 'GET',
|
||||
params: { ...params, page: params.current, size: params.pageSize },
|
||||
}),
|
||||
getTenantDetail: (tenantId: string) => request(`/tenant/hierarchy/detail/${tenantId}`, { method: 'GET' }),
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace API {
|
||||
interface ResponseStructure<T = any> {
|
||||
success: boolean;
|
||||
code?: number;
|
||||
msg?: string;
|
||||
data: T;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface TokenItem {
|
||||
tokenValue: string;
|
||||
expiration?: string;
|
||||
username?: string;
|
||||
grantType?: string;
|
||||
clientId?: string;
|
||||
accountType?: string;
|
||||
}
|
||||
|
||||
export const tokenApi = {
|
||||
page: async (params: { current?: number; pageSize?: number; tenantId: string; username?: string }) => {
|
||||
if (!params?.tenantId) return { data: [], total: 0 };
|
||||
const res = await request('/api-uaa/tokens', { method: 'GET', params: { page: params.current, limit: params.pageSize, ...params } });
|
||||
const data = (res as any).data;
|
||||
const total = (res as any).count ?? data?.length ?? 0;
|
||||
return { data, total } as { data: TokenItem[]; total: number };
|
||||
},
|
||||
delete: async (token: string) => {
|
||||
const res = await request('/api-uaa/oauth/remove/token', { method: 'DELETE', params: { token } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
export type ThemeMode = 'light' | 'dark';
|
||||
|
||||
type ThemeContextValue = {
|
||||
mode: ThemeMode;
|
||||
toggle: () => void;
|
||||
setMode: (m: ThemeMode) => void;
|
||||
};
|
||||
|
||||
const ThemeContext = createContext<ThemeContextValue>({ mode: 'light', toggle: () => {}, setMode: () => {} });
|
||||
|
||||
export const ThemeProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
|
||||
const [mode, setMode] = useState<ThemeMode>(() => (localStorage.getItem('theme_mode') as ThemeMode) || 'light');
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (mode === 'dark') {
|
||||
root.setAttribute('data-theme', 'dark');
|
||||
} else {
|
||||
root.removeAttribute('data-theme');
|
||||
}
|
||||
localStorage.setItem('theme_mode', mode);
|
||||
}, [mode]);
|
||||
|
||||
const value = useMemo(() => ({ mode, toggle: () => setMode(mode === 'dark' ? 'light' : 'dark'), setMode }), [mode]);
|
||||
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
|
||||
};
|
||||
|
||||
export const useTheme = () => useContext(ThemeContext);
|
||||
|
||||
@@ -0,0 +1,621 @@
|
||||
/* Go-Fly Admin 鐜颁唬绉戞妧鎰熶富棰?*/
|
||||
|
||||
/* CSS鍙橀噺瀹氫箟 */
|
||||
:root {
|
||||
/* 涓昏壊璋?*/
|
||||
/* 红绿主色 + 渐变,提升科技感 */
|
||||
--primary-color: #52c41a;
|
||||
--primary-gradient: linear-gradient(135deg, #95de64 0%, #52c41a 100%);
|
||||
--tech-gradient: linear-gradient(135deg, #b7eb8f 0%, #95de64 100%);
|
||||
|
||||
|
||||
/* 统一操作链接颜色(编辑/删除等) */
|
||||
--action-link-color: #1677ff;
|
||||
--action-link-hover-color: #4096ff;
|
||||
|
||||
/* 鑳屾櫙鑹?*/
|
||||
--bg-primary: #f5f7fb;
|
||||
--bg-secondary: #ffffff;
|
||||
--bg-tertiary: #f5f5f5;
|
||||
--bg-card: #ffffff;
|
||||
--bg-glass: rgba(0, 0, 0, 0.04);
|
||||
|
||||
/* 鏂囧瓧棰滆壊 */
|
||||
--text-primary: #1f2329;
|
||||
--text-secondary: #4e5969;
|
||||
--text-tertiary: #86909c;
|
||||
|
||||
/* 杈规鍜屽垎鍓茬嚎 */
|
||||
--border-color: rgba(0, 0, 0, 0.1);
|
||||
--divider-color: rgba(0, 0, 0, 0.08);
|
||||
|
||||
/* 闃村奖 */
|
||||
--shadow-card: 0 8px 24px rgba(0, 0, 0, 0.06);
|
||||
--shadow-hover: 0 12px 36px rgba(0, 0, 0, 0.12);
|
||||
--shadow-glow: 0 0 20px rgba(255, 77, 79, 0.25);
|
||||
|
||||
/* 鍔ㄧ敾鏇茬嚎 */
|
||||
--ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
|
||||
--ease-in-out-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
||||
}
|
||||
|
||||
/* 鍏ㄥ眬鏍峰紡閲嶇疆 */
|
||||
body {
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* 布局基础:统一背景为页面底色,避免底部白条 */
|
||||
html, body, #root, .ant-pro, .ant-layout, .ant-layout-content {
|
||||
background: var(--bg-primary) !important;
|
||||
}
|
||||
.ant-pro-layout, .ant-pro-layout .ant-layout, .ant-pro-layout-content {
|
||||
background: var(--bg-primary) !important;
|
||||
}
|
||||
/* 兜底:内容区的直接子容器默认透明,避免出现白底容器 */
|
||||
.ant-pro-layout-content > div {
|
||||
background: transparent !important;
|
||||
}
|
||||
.ant-layout { min-height: 100vh; }
|
||||
.ant-layout-footer, .ant-pro-global-footer {
|
||||
background: var(--bg-primary) !important;
|
||||
border: none !important;
|
||||
}
|
||||
.ant-pro-grid-content,
|
||||
.ant-pro-basicLayout-content,
|
||||
.ant-pro-grid-content-children,
|
||||
.ant-pro-page-container-children-content,
|
||||
.ant-pro-page-container-warp,
|
||||
.ant-pro-page-container {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
/* 鐜荤拑璐ㄦ劅鏁堟灉 */
|
||||
.glass-effect {
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
/* 鍗$墖鎮仠鏁堟灉 */
|
||||
.modern-card {
|
||||
background: var(--bg-card);
|
||||
border-radius: 16px;
|
||||
padding: 24px;
|
||||
box-shadow: var(--shadow-card);
|
||||
border: 1px solid var(--border-color);
|
||||
transition: all 0.3s var(--ease-out-quart);
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: var(--shadow-hover);
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
/* 绉戞妧鎰熸寜閽?*/
|
||||
.tech-button {
|
||||
background: var(--tech-gradient);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
color: white;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s var(--ease-out-quart);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -100%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
|
||||
transition: left 0.5s;
|
||||
}
|
||||
|
||||
&:hover::before {
|
||||
left: 100%;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--shadow-glow);
|
||||
}
|
||||
}
|
||||
|
||||
/* 渚ц竟鏍忔牱寮?*/
|
||||
.ant-layout-sider {
|
||||
background: var(--sider-bg) !important;
|
||||
border-right: 1px solid var(--border-color) !important;
|
||||
|
||||
.ant-layout-sider-trigger {
|
||||
background: var(--bg-tertiary) !important;
|
||||
border-top: 1px solid var(--border-color) !important;
|
||||
color: var(--text-secondary) !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* 鑿滃崟鏍峰紡 */
|
||||
.ant-menu {
|
||||
background: transparent !important;
|
||||
border: none !important;
|
||||
|
||||
.ant-menu-item {
|
||||
color: var(--text-secondary) !important;
|
||||
border-radius: 8px !important;
|
||||
margin: 4px 8px !important;
|
||||
height: 48px !important;
|
||||
line-height: 48px !important;
|
||||
transition: all 0.3s var(--ease-out-quart) !important;
|
||||
|
||||
&:hover {
|
||||
background: var(--bg-glass) !important;
|
||||
color: var(--text-primary) !important;
|
||||
transform: translateX(4px);
|
||||
}
|
||||
|
||||
&.ant-menu-item-selected {
|
||||
background: var(--primary-gradient) !important;
|
||||
color: white !important;
|
||||
box-shadow: var(--shadow-glow);
|
||||
|
||||
&::after {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu-submenu-title {
|
||||
color: var(--text-secondary) !important;
|
||||
border-radius: 8px !important;
|
||||
margin: 4px 8px !important;
|
||||
height: 48px !important;
|
||||
line-height: 48px !important;
|
||||
|
||||
&:hover {
|
||||
background: var(--bg-glass) !important;
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 澶撮儴鏍峰紡 */
|
||||
.ant-layout-header {
|
||||
background: var(--header-bg) !important;
|
||||
border-bottom: 1px solid var(--border-color) !important;
|
||||
backdrop-filter: blur(10px);
|
||||
|
||||
.ant-btn {
|
||||
color: var(--text-secondary) !important;
|
||||
border: 1px solid var(--border-color) !important;
|
||||
background: transparent !important;
|
||||
|
||||
&:hover {
|
||||
color: var(--text-primary) !important;
|
||||
border-color: var(--primary-color) !important;
|
||||
background: var(--bg-glass) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 鍐呭鍖哄煙 */
|
||||
.ant-layout-content {
|
||||
background: var(--bg-primary) !important;
|
||||
|
||||
/* 娣诲姞娓愬彉鑳屾櫙 */
|
||||
&::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: radial-gradient(ellipse at top, rgba(102, 126, 234, 0.1) 0%, transparent 50%);
|
||||
pointer-events: none;
|
||||
z-index: -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ant Design 缁勪欢閲嶅啓 */
|
||||
.ant-table {
|
||||
background: var(--bg-card) !important;
|
||||
border-radius: 12px !important;
|
||||
overflow: hidden;
|
||||
|
||||
.ant-table-thead > tr > th {
|
||||
background: var(--bg-tertiary) !important;
|
||||
color: var(--text-primary) !important;
|
||||
border-color: var(--border-color) !important;
|
||||
}
|
||||
|
||||
|
||||
/* 统一操作链接颜色为蓝色 */
|
||||
.ant-space a,
|
||||
.ant-table-cell a,
|
||||
.ant-pro-table .ant-table-cell a,
|
||||
.ant-popover .ant-popconfirm-buttons a {
|
||||
color: var(--action-link-color) !important;
|
||||
}
|
||||
.ant-space a:hover,
|
||||
.ant-table-cell a:hover,
|
||||
.ant-pro-table .ant-table-cell a:hover,
|
||||
.ant-popover .ant-popconfirm-buttons a:hover {
|
||||
color: var(--action-link-hover-color) !important;
|
||||
}
|
||||
|
||||
/* 统一操作链接颜色为蓝色 */
|
||||
.ant-space a {
|
||||
color: #1677ff !important;
|
||||
}
|
||||
.ant-space a:hover {
|
||||
color: #4096ff !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* 表格粘性头与底部滚动条区域默认是白色,这里统一适配主题 */
|
||||
.ant-table-sticky-holder,
|
||||
.ant-table-sticky-scroll {
|
||||
background: var(--bg-card) !important;
|
||||
}
|
||||
|
||||
/* ProCard(ProTable内部大量使用)默认背景为白色,这里统一为主题卡片背景 */
|
||||
.ant-pro-card {
|
||||
background: var(--bg-card) !important;
|
||||
border-color: var(--border-color) !important;
|
||||
}
|
||||
.ant-pro-card-ghost,
|
||||
.ant-pro-card .ant-pro-card-body {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
/* ProLayout 顶部导航容器覆盖,确保与 token 一致 */
|
||||
.ant-pro-global-header,
|
||||
.ant-pro-top-nav-header {
|
||||
background: var(--header-bg) !important;
|
||||
border-bottom: 1px solid var(--border-color) !important;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.ant-card {
|
||||
background: var(--bg-card) !important;
|
||||
border: 1px solid var(--border-color) !important;
|
||||
border-radius: 16px !important;
|
||||
|
||||
.ant-card-head {
|
||||
background: transparent !important;
|
||||
border-color: var(--border-color) !important;
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
.ant-card-body {
|
||||
color: var(--text-secondary) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-form-item-label > label {
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
.ant-input {
|
||||
background: var(--bg-tertiary) !important;
|
||||
border-color: var(--border-color) !important;
|
||||
color: var(--text-primary) !important;
|
||||
|
||||
&:hover, &:focus {
|
||||
border-color: var(--primary-color) !important;
|
||||
box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-select:not(.ant-select-disabled):hover .ant-select-selector {
|
||||
border-color: var(--primary-color) !important;
|
||||
}
|
||||
|
||||
/* 统一“操作链接/按钮”为蓝色(如 编辑/删除/重置 等) */
|
||||
/* 表格单元格与 ProTable 操作列 */
|
||||
.ant-pro-table .ant-table-cell a,
|
||||
.ant-table .ant-table-cell a {
|
||||
color: var(--action-link-color) !important;
|
||||
}
|
||||
.ant-pro-table .ant-table-cell a:hover,
|
||||
.ant-table .ant-table-cell a:hover {
|
||||
color: var(--action-link-hover-color) !important;
|
||||
}
|
||||
|
||||
/* link 类型按钮 */
|
||||
.ant-btn-link {
|
||||
color: var(--action-link-color) !important;
|
||||
}
|
||||
.ant-btn-link:hover,
|
||||
.ant-btn-link:focus {
|
||||
color: var(--action-link-hover-color) !important;
|
||||
}
|
||||
|
||||
/* Popconfirm 底部的链接按钮 */
|
||||
.ant-popover .ant-popconfirm-buttons a,
|
||||
.ant-popover .ant-popconfirm-buttons .ant-btn-link {
|
||||
color: var(--action-link-color) !important;
|
||||
}
|
||||
.ant-popover .ant-popconfirm-buttons a:hover,
|
||||
.ant-popover .ant-popconfirm-buttons .ant-btn-link:hover {
|
||||
color: var(--action-link-hover-color) !important;
|
||||
}
|
||||
|
||||
/* 闈㈠寘灞戜笌鏍囩绛夋绾х粍浠惰壊褰╃粺涓€ */
|
||||
.ant-breadcrumb a { color: var(--text-secondary) !important; }
|
||||
.ant-breadcrumb a:hover { color: var(--text-primary) !important; }
|
||||
.ant-tag { border-color: var(--border-color) !important; }
|
||||
.ant-tag-blue { color: #9bbcff; background: rgba(22,119,255,.12); border-color: rgba(22,119,255,.24) !important; }
|
||||
|
||||
/* Tooltip/Popover 鐜荤拑璐ㄦ劅 */
|
||||
.ant-tooltip .ant-tooltip-inner,
|
||||
.ant-popover .ant-popover-inner {
|
||||
background: var(--bg-tertiary) !important;
|
||||
backdrop-filter: blur(6px);
|
||||
border: 1px solid var(--border-color) !important;
|
||||
}
|
||||
|
||||
/* Modal/Drawer 閫傞厤鏆楄壊 */
|
||||
.ant-modal-content, .ant-drawer-content {
|
||||
background: var(--bg-secondary) !important;
|
||||
color: var(--text-primary) !important;
|
||||
border: 1px solid var(--border-color) !important;
|
||||
}
|
||||
.ant-modal-header, .ant-drawer-header {
|
||||
background: var(--bg-tertiary) !important;
|
||||
border-bottom: 1px solid var(--border-color) !important;
|
||||
}
|
||||
|
||||
/* Tabs 椋庢牸浼樺寲 */
|
||||
.ant-tabs-nav::before { border-color: var(--border-color) !important; }
|
||||
.ant-tabs-tab { color: var(--text-secondary) !important; }
|
||||
.ant-tabs-tab-active .ant-tabs-tab-btn { color: var(--text-primary) !important; }
|
||||
.ant-tabs-ink-bar { background: var(--primary-color) !important; }
|
||||
|
||||
/* Button 鏋佺畝鎻忚竟涓庢偓娴厜鏅?*/
|
||||
.ant-btn-default {
|
||||
background: transparent !important;
|
||||
border-color: var(--border-color) !important;
|
||||
color: var(--text-secondary) !important;
|
||||
}
|
||||
.ant-btn-default:hover {
|
||||
color: var(--text-primary) !important;
|
||||
border-color: var(--primary-color) !important;
|
||||
box-shadow: var(--shadow-glow) !important;
|
||||
}
|
||||
|
||||
/* 鏄庝寒娓愬彉涓绘寜閽紙鏇村惛鐫涳級 */
|
||||
.ant-btn-primary {
|
||||
background: linear-gradient(135deg, #ff4d4f 0%, #52c41a 100%) !important;
|
||||
border: none !important;
|
||||
box-shadow: 0 6px 16px rgba(255, 77, 79, 0.25) !important;
|
||||
}
|
||||
.ant-btn-primary:hover,
|
||||
.ant-btn-primary:focus {
|
||||
filter: brightness(1.05);
|
||||
box-shadow: 0 8px 20px rgba(82, 196, 26, 0.35) !important;
|
||||
}
|
||||
.ant-btn-primary:hover,
|
||||
.ant-btn-primary:focus {
|
||||
filter: brightness(1.05);
|
||||
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.35) !important;
|
||||
}
|
||||
|
||||
/* 娓愬彉鎸夐挳绫伙紙缁勪欢 GradientButton 涔熶細鐢ㄥ埌锛?*/
|
||||
.gf-gradient-btn.ant-btn-primary {
|
||||
background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 40%, #52c41a 100%) !important
|
||||
}
|
||||
.ant-btn-primary:hover,
|
||||
.ant-btn-primary:focus {
|
||||
filter: brightness(1.05);
|
||||
box-shadow: 0 8px 20px rgba(82, 196, 26, 0.35) !important;
|
||||
}
|
||||
|
||||
/* 缁熶竴鍔ㄤ綔鏍忔牱寮?*/
|
||||
.gf-action-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.gf-action-bar-left,
|
||||
.gf-action-bar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* ProTable 椤堕儴宸ュ叿鏍忓拰琛ㄥご缁嗚妭浼樺寲 */
|
||||
.ant-pro-table-list-toolbar-container {
|
||||
background: transparent !important;
|
||||
}
|
||||
.ant-pro-table .ant-pro-table-list-toolbar-title {
|
||||
color: var(--text-primary) !important;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* 琛ㄥ崟鏍¢獙鑹插湪娣辫壊涓嬬殑瀵规瘮搴?*/
|
||||
.ant-form-item-explain-error { color: #ff7875 !important; }
|
||||
|
||||
/* ================= 涓婚鍙橀噺锛歀ight 榛樿 + Dark 瑕嗙洊 ================= */
|
||||
/* Light 榛樿鍙橀噺锛氫綔涓烘渶缁堣鐩栵紝渚夸簬鏃犲睘鎬ф椂涓轰寒鑹蹭富棰?*/
|
||||
:root {
|
||||
--primary-color: #52c41a;
|
||||
--primary-gradient: linear-gradient(135deg, #95de64 0%, #52c41a 100%);
|
||||
--tech-gradient: linear-gradient(135deg, #b7eb8f 0%, #95de64 100%);
|
||||
--logo-initial-color: #0f5132;
|
||||
|
||||
|
||||
/* 统一操作链接颜色(编辑/删除等) */
|
||||
--action-link-color: #1677ff;
|
||||
--action-link-hover-color: #4096ff;
|
||||
|
||||
--bg-primary: #f6ffed; /* 绿系浅背景 */
|
||||
--bg-secondary: #ffffff;
|
||||
/* 顶部/侧边栏单独色,采用浅绿色系 */
|
||||
--header-bg: linear-gradient(135deg, #f6ffed 0%, #eafff0 100%);
|
||||
--sider-bg: #f6ffed;
|
||||
--bg-tertiary: #f5f5f5;
|
||||
--bg-card: #ffffff;
|
||||
--bg-glass: rgba(0, 0, 0, 0.04);
|
||||
|
||||
--text-primary: #1f2329;
|
||||
--text-secondary: #4e5969;
|
||||
--text-tertiary: #86909c;
|
||||
|
||||
--border-color: rgba(0, 0, 0, 0.1);
|
||||
--divider-color: rgba(0, 0, 0, 0.08);
|
||||
|
||||
--shadow-card: 0 8px 24px rgba(0, 0, 0, 0.06);
|
||||
--shadow-hover: 0 12px 36px rgba(0, 0, 0, 0.12);
|
||||
--shadow-glow: 0 0 20px rgba(102, 126, 234, 0.25);
|
||||
}
|
||||
|
||||
/* Dark 妯″紡鍙橀噺锛氶€氳繃 data-theme="dark" 鐢熸晥锛屼紭鍏堢骇鏇撮珮 */
|
||||
[data-theme='dark'] {
|
||||
--primary-color: #52c41a;
|
||||
--primary-gradient: linear-gradient(135deg, #3fbf3a 0%, #52c41a 100%);
|
||||
--tech-gradient: linear-gradient(135deg, #3fbf3a 0%, #52c41a 100%);
|
||||
--logo-initial-color: #e6f4ea;
|
||||
|
||||
|
||||
/* 统一操作链接颜色(编辑/删除等) */
|
||||
--action-link-color: #1677ff;
|
||||
--action-link-hover-color: #4096ff;
|
||||
|
||||
--bg-primary: #0e1625; /* 深色主背景 */
|
||||
--bg-secondary: #0b1220; /* 导航/容器背景 */
|
||||
--header-bg: #0b1f14; /* 顶部深绿调 */
|
||||
--sider-bg: #0b1f14; /* 侧边深绿调 */
|
||||
--bg-tertiary: #121a2a;
|
||||
--bg-card: #121a2a;
|
||||
--bg-glass: rgba(255, 255, 255, 0.06);
|
||||
|
||||
--text-primary: #e6f4ea; /* 主文淡绿白 */
|
||||
--text-secondary: #cfe7d6;
|
||||
--text-tertiary: #a8c2af;
|
||||
|
||||
--border-color: rgba(255, 255, 255, 0.12);
|
||||
--divider-color: rgba(255, 255, 255, 0.16);
|
||||
|
||||
--shadow-card: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||
--shadow-hover: 0 12px 36px rgba(0, 0, 0, 0.6);
|
||||
--shadow-glow: 0 0 20px rgba(82, 196, 26, 0.35);
|
||||
}
|
||||
|
||||
.ant-select-focused .ant-select-selector {
|
||||
border-color: var(--primary-color) !important;
|
||||
box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
|
||||
}
|
||||
|
||||
/* 婊氬姩鏉℃牱寮?*/
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--primary-color);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #4096ff;
|
||||
}
|
||||
|
||||
/* 鍔犺浇鍔ㄧ敾 */
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
@keyframes slideInFromLeft {
|
||||
from {
|
||||
transform: translateX(-100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from {
|
||||
transform: translateY(20px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 椤甸潰杩涘叆鍔ㄧ敾 */
|
||||
.page-enter {
|
||||
animation: fadeInUp 0.6s var(--ease-out-quart);
|
||||
}
|
||||
|
||||
.menu-enter {
|
||||
animation: slideInFromLeft 0.4s var(--ease-out-quart);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ================= 暗色模式:文本可读性增强 ================= */
|
||||
[data-theme='dark'] body { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .modern-card { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-typography { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-page-header, [data-theme='dark'] .ant-pro-page-container { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-card, [data-theme='dark'] .ant-card-head-title { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-table { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-table-tbody > tr > td { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-table-thead > tr > th { color: var(--text-secondary) !important; }
|
||||
[data-theme='dark'] .ant-descriptions, [data-theme='dark'] .ant-descriptions-item-label, [data-theme='dark'] .ant-descriptions-item-content { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-breadcrumb { color: var(--text-secondary) !important; }
|
||||
[data-theme='dark'] .ant-breadcrumb a { color: var(--text-secondary) !important; }
|
||||
[data-theme='dark'] .ant-breadcrumb a:hover { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-form label { color: var(--text-secondary) !important; }
|
||||
[data-theme='dark'] .ant-pagination { color: var(--text-primary) !important; }
|
||||
[data-theme='dark'] .ant-tabs-tab .ant-tabs-tab-btn { color: var(--text-secondary) !important; }
|
||||
[data-theme='dark'] .ant-tabs-tab-active .ant-tabs-tab-btn { color: var(--text-primary) !important; }
|
||||
|
||||
/* 布局内容容器:透明背景,避免底部出现大片白色 */
|
||||
.layout-content-wrapper {
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
/* 暗色模式:表格行高亮/悬停对比度修复 */
|
||||
[data-theme='dark'] .ant-table-tbody > tr:hover > td,
|
||||
[data-theme='dark'] .ant-table-tbody > tr.ant-table-row:hover > td,
|
||||
[data-theme='dark'] .ant-pro-table .ant-table-tbody > tr:hover > td {
|
||||
background: var(--bg-glass) !important; /* 半透明浅色,提高对比度而不变白 */
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
[data-theme='dark'] .ant-table-tbody > tr.ant-table-row-selected > td {
|
||||
background: rgba(82, 196, 26, 0.16) !important; /* 选中态使用绿色浅底 */
|
||||
color: var(--text-primary) !important;
|
||||
}
|
||||
|
||||
[data-theme='dark'] .ant-table-tbody > tr > td.ant-table-cell-row-hover {
|
||||
background: var(--bg-glass) !important;
|
||||
}
|
||||
|
||||
/* 暗色模式:PageContainer 左上角标题(菜单名称)置为白色,提升可读性 */
|
||||
[data-theme='dark'] .ant-pro-page-container .ant-page-header-heading-title,
|
||||
[data-theme='dark'] .ant-page-header-heading-title {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
declare module 'umi' {
|
||||
export const request: any;
|
||||
export const history: any;
|
||||
export type Request = any;
|
||||
export const Link: any;
|
||||
export const useLocation: any;
|
||||
export type IRouteComponentProps = any;
|
||||
}
|
||||
|
||||
declare module 'umi-request' {
|
||||
const req: any;
|
||||
export default req;
|
||||
export const extend: any;
|
||||
}
|
||||
|
||||
declare module 'uuid' {
|
||||
export function v4(): string;
|
||||
}
|
||||
|
||||
// 静态资源模块声明(用于 TS 识别图片导入)
|
||||
declare module '*.png' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
declare module '*.jpg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
declare module '*.jpeg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
declare module '*.svg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
# 前端RSA加密使用指南
|
||||
|
||||
## 概述
|
||||
|
||||
本项目提供了与后端RSAUtil对应的前端RSA加密解决方案,确保敏感数据在传输过程中的安全性。
|
||||
|
||||
## 核心文件
|
||||
|
||||
- `rsaUtil.ts` - RSA加密核心工具类
|
||||
- `securityUtil.ts` - 安全辅助工具类
|
||||
- `useSecurity.ts` - React Hook,提供安全操作
|
||||
- `SecureLoginForm` - 安全登录表单组件
|
||||
|
||||
## 基本使用
|
||||
|
||||
### 1. 密码加密
|
||||
|
||||
```typescript
|
||||
import RSAUtil from '@/utils/rsaUtil';
|
||||
|
||||
// 加密密码
|
||||
const encryptedPassword = RSAUtil.encryptPassword('user123456');
|
||||
|
||||
// 或使用便捷导入
|
||||
import { encryptPassword } from '@/utils/rsaUtil';
|
||||
const encrypted = encryptPassword('user123456');
|
||||
```
|
||||
|
||||
### 2. 登录表单处理
|
||||
|
||||
```typescript
|
||||
import { useSecurity } from '@/hooks/useSecurity';
|
||||
|
||||
const LoginPage = () => {
|
||||
const { secureLogin } = useSecurity();
|
||||
|
||||
const handleLogin = async (values) => {
|
||||
const secureData = await secureLogin(values);
|
||||
if (secureData) {
|
||||
// 发送到后端
|
||||
api.login(secureData);
|
||||
}
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
### 3. 批量敏感字段加密
|
||||
|
||||
```typescript
|
||||
import SecurityUtil from '@/utils/securityUtil';
|
||||
|
||||
const userForm = {
|
||||
username: 'admin',
|
||||
password: '123456',
|
||||
email: 'admin@example.com'
|
||||
};
|
||||
|
||||
// 只加密密码字段
|
||||
const secureForm = SecurityUtil.processFormData(userForm, ['password']);
|
||||
```
|
||||
|
||||
### 4. 使用安全登录组件
|
||||
|
||||
```typescript
|
||||
import SecureLoginForm from '@/components/SecureLoginForm';
|
||||
|
||||
const LoginPage = () => {
|
||||
const handleLogin = async (loginData) => {
|
||||
// loginData.password 已经被自动加密
|
||||
const response = await api.login(loginData);
|
||||
// 处理登录响应
|
||||
};
|
||||
|
||||
return (
|
||||
<SecureLoginForm
|
||||
onLogin={handleLogin}
|
||||
showPasswordStrength={true}
|
||||
/>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
## 安全最佳实践
|
||||
|
||||
### 1. 加密时机
|
||||
- ✅ 在发送请求前立即加密
|
||||
- ✅ 在表单提交时加密
|
||||
- ❌ 不要在组件状态中存储加密数据
|
||||
- ❌ 不要过早加密(影响用户体验)
|
||||
|
||||
### 2. 错误处理
|
||||
```typescript
|
||||
const encryptedData = RSAUtil.encrypt(sensitiveData);
|
||||
if (!encryptedData) {
|
||||
// 处理加密失败
|
||||
message.error('数据加密失败,请重试');
|
||||
return;
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 加密前验证
|
||||
```typescript
|
||||
// 密码强度验证
|
||||
const strength = SecurityUtil.validatePasswordStrength(password);
|
||||
if (strength.level === 'weak') {
|
||||
// 提示用户增强密码
|
||||
}
|
||||
|
||||
// 输入安全过滤
|
||||
const safeInput = SecurityUtil.sanitizeInput(userInput);
|
||||
```
|
||||
|
||||
### 4. 敏感数据脱敏
|
||||
```typescript
|
||||
// 显示时脱敏
|
||||
const maskedPhone = SecurityUtil.maskSensitiveData('13812345678', 'phone');
|
||||
// 结果: 138****5678
|
||||
```
|
||||
|
||||
## 与后端对接
|
||||
|
||||
### 后端解密示例
|
||||
你的后端使用 `RSAUtil.decryptOne()` 方法解密:
|
||||
|
||||
```java
|
||||
// Java后端
|
||||
String rawPassword = RSAUtil.decryptOne(req.getPassword());
|
||||
```
|
||||
|
||||
### 前后端数据流程
|
||||
1. 前端: 用户输入密码 `"123456"`
|
||||
2. 前端: RSA加密 → `"LBS9qzlDcBQ..."`(Base64 + URL编码)
|
||||
3. 后端: 接收加密数据
|
||||
4. 后端: `RSAUtil.decryptOne()` 解密 → `"123456"`
|
||||
|
||||
## 安全注意事项
|
||||
|
||||
### 1. 公钥管理
|
||||
- 公钥已硬编码在代码中(与后端保持一致)
|
||||
- 生产环境建议通过API动态获取公钥
|
||||
- 定期轮换密钥对
|
||||
|
||||
### 2. HTTPS传输
|
||||
```typescript
|
||||
// 确保API请求使用HTTPS
|
||||
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
||||
? 'https://your-domain.com/api'
|
||||
: 'http://localhost:9900';
|
||||
```
|
||||
|
||||
### 3. 内存安全
|
||||
```typescript
|
||||
// 避免在控制台输出敏感信息
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
console.log = () => {};
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 输入验证
|
||||
```typescript
|
||||
// 在加密前验证输入
|
||||
if (!password || password.trim() === '') {
|
||||
throw new Error('密码不能为空');
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
throw new Error('密码长度不能少于6位');
|
||||
}
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q: 加密失败怎么办?
|
||||
A: 检查输入数据是否为空,确认jsencrypt库已正确安装
|
||||
|
||||
### Q: 前后端加密解密不匹配?
|
||||
A: 确认公钥私钥对是否一致,检查Base64编码格式
|
||||
|
||||
### Q: 性能优化建议?
|
||||
A:
|
||||
- RSA加密较慢,只加密敏感字段
|
||||
- 考虑使用Web Worker处理大量数据加密
|
||||
- 合理使用缓存
|
||||
|
||||
## 测试
|
||||
|
||||
```typescript
|
||||
// 简单测试
|
||||
const testData = 'test123';
|
||||
const encrypted = RSAUtil.encrypt(testData);
|
||||
console.log('加密结果:', encrypted);
|
||||
console.log('是否已加密:', RSAUtil.isEncrypted(encrypted));
|
||||
```
|
||||
|
||||
## 升级指南
|
||||
|
||||
如需更新加密算法或密钥:
|
||||
|
||||
1. 与后端协调更新时间
|
||||
2. 更新 `rsaUtil.ts` 中的公钥
|
||||
3. 测试前后端对接
|
||||
4. 发布更新
|
||||
@@ -0,0 +1,69 @@
|
||||
// 通用下载工具(中文注释)
|
||||
// 使用方式:
|
||||
// const res = await request(url, { responseType: 'blob', getResponse: true });
|
||||
// download(res, '默认文件名.xlsx');
|
||||
|
||||
// 解析 Content-Disposition,优先 filename*,其次 filename
|
||||
function getFilenameFromHeaders(headers?: Headers, fallback = 'download') {
|
||||
try {
|
||||
const cd = headers?.get('content-disposition') || headers?.get('Content-Disposition') || '';
|
||||
// filename*="UTF-8''xxx"
|
||||
const star = /filename\*=(?:UTF-8'')?"?([^";]+)"?/i.exec(cd);
|
||||
if (star && star[1]) {
|
||||
try {
|
||||
return decodeURIComponent(star[1]);
|
||||
} catch {
|
||||
return star[1];
|
||||
}
|
||||
}
|
||||
// filename="xxx"
|
||||
const normal = /filename="?([^";]+)"?/i.exec(cd);
|
||||
if (normal && normal[1]) return normal[1];
|
||||
} catch {}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function download(
|
||||
result: { data?: any; response?: Response } | Blob | Response,
|
||||
defaultName = 'download'
|
||||
) {
|
||||
let blob: Blob | null = null;
|
||||
let headers: Headers | undefined = undefined;
|
||||
|
||||
if (result instanceof Blob) {
|
||||
blob = result;
|
||||
} else if (result instanceof Response) {
|
||||
// 假设调用侧已传入 getResponse:true + responseType:'blob' 时不会走到这里
|
||||
// 如果走到这里,说明未读出 blob,此处放弃自动读取,交由调用侧修正
|
||||
// 为避免未读流引发问题,直接返回
|
||||
return;
|
||||
} else if (result && typeof result === 'object') {
|
||||
blob = (result as any).data as Blob;
|
||||
headers = (result as any).response?.headers as Headers;
|
||||
}
|
||||
|
||||
if (!blob) return;
|
||||
|
||||
const filename = getFilenameFromHeaders(headers, defaultName);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
// 通过 URL 直接触发浏览器下载(不读取内容,兼容无 CORS 的场景)
|
||||
export function downloadByUrl(url: string, filename?: string) {
|
||||
if (!url) return;
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
if (filename) a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// 前端 Excel 导出工具(中文注释)
|
||||
// 用于将页面内存数据导出为 xlsx 文件(与老项目保持一致 API)
|
||||
import { saveAs } from 'file-saver';
|
||||
import * as XLSX from 'xlsx';
|
||||
|
||||
export interface ExportHeader {
|
||||
title: string; // 表头名
|
||||
dataIndex: string; // 对应数据字段
|
||||
}
|
||||
|
||||
export interface ExportExcelParams {
|
||||
data: any[]; // 原始数据数组
|
||||
header: ExportHeader[]; // 表头定义
|
||||
fileName: string; // 文件名(不含扩展名)
|
||||
}
|
||||
|
||||
export const exportExcel = ({ data, header, fileName }: ExportExcelParams) => {
|
||||
try {
|
||||
const excelData = (data || []).map((item) => {
|
||||
const row: Record<string, any> = {};
|
||||
header.forEach((h) => {
|
||||
row[h.title] = (item as any)[h.dataIndex];
|
||||
});
|
||||
return row;
|
||||
});
|
||||
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.json_to_sheet(excelData, { header: header.map((h) => h.title) });
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
||||
|
||||
const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
||||
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
saveAs(blob, `${fileName}.xlsx`);
|
||||
} catch (e) {
|
||||
// 仅记录错误,避免阻断页面
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('导出 Excel 失败: ', e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { extend } from 'umi-request';
|
||||
|
||||
const client = extend({
|
||||
timeout: 20000,
|
||||
});
|
||||
|
||||
client.interceptors.response.use(async (response: any) => {
|
||||
const data = await response.clone().json().catch(() => undefined);
|
||||
if (data && typeof data.resp_code !== 'undefined') {
|
||||
// 兼容后端 Result 结构
|
||||
return {
|
||||
success: data.resp_code === 0,
|
||||
code: data.resp_code,
|
||||
msg: data.resp_msg,
|
||||
data: data.data,
|
||||
} as any;
|
||||
}
|
||||
return response;
|
||||
});
|
||||
|
||||
export default client;
|
||||
@@ -0,0 +1,206 @@
|
||||
import * as JSEncryptLib from 'jsencrypt';
|
||||
|
||||
// 确定正确的JSEncrypt构造函数
|
||||
const JSEncrypt = JSEncryptLib.JSEncrypt || JSEncryptLib.default || JSEncryptLib;
|
||||
|
||||
/**
|
||||
* RSA加密工具类 - 与后端RSAUtil对应
|
||||
* 用于前端敏感数据加密,后端解密
|
||||
*/
|
||||
export class RSAUtil {
|
||||
// 与后端genKeyPair()方法中固定的公钥保持一致
|
||||
private static readonly PUBLIC_KEY_RAW =
|
||||
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGu7lYGfEtMICO8kREJrObu0Hy' +
|
||||
'pF7R9iEIefyxApmB6wJ/y3Rg/eBO6kLDCo18hYZ3ZNxKp5CMymZvXDh5j+sd7IHm' +
|
||||
'tUh6sEZzpXExQJIzT8gA1SULd+iXe4V9zt2AcbROIi94vA6lOfmtON28Ex+uAlLK' +
|
||||
'N/iJDXFFXdEOmfdqhwIDAQAB';
|
||||
|
||||
// 格式化为PEM格式的公钥
|
||||
private static readonly PUBLIC_KEY =
|
||||
'-----BEGIN PUBLIC KEY-----\n' +
|
||||
RSAUtil.PUBLIC_KEY_RAW +
|
||||
'\n-----END PUBLIC KEY-----';
|
||||
|
||||
// 由于 jsencrypt 未提供完善的类型定义,这里使用 any 规避类型问题
|
||||
private static jsEncrypt: any = null;
|
||||
|
||||
/**
|
||||
* 获取或创建JSEncrypt实例
|
||||
*/
|
||||
private static getJSEncryptInstance(): any {
|
||||
try {
|
||||
// 每次都创建新实例,避免缓存问题
|
||||
const jsEncrypt: any = new JSEncrypt();
|
||||
|
||||
console.log('创建新的JSEncrypt实例');
|
||||
|
||||
// 首先尝试PEM格式
|
||||
jsEncrypt.setPublicKey(this.PUBLIC_KEY);
|
||||
|
||||
if (!jsEncrypt.getPublicKey()) {
|
||||
console.log('PEM格式失败,尝试原始格式');
|
||||
jsEncrypt.setPublicKey(this.PUBLIC_KEY_RAW);
|
||||
}
|
||||
|
||||
// 最终验证
|
||||
if (!jsEncrypt.getPublicKey()) {
|
||||
throw new Error('公钥设置失败');
|
||||
}
|
||||
|
||||
// 验证encrypt方法是否存在
|
||||
if (typeof jsEncrypt.encrypt !== 'function') {
|
||||
throw new Error('JSEncrypt实例的encrypt方法不存在');
|
||||
}
|
||||
|
||||
console.log('JSEncrypt实例创建成功,encrypt方法类型:', typeof jsEncrypt.encrypt);
|
||||
return jsEncrypt;
|
||||
} catch (error) {
|
||||
console.error('JSEncrypt实例创建失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用公钥加密数据
|
||||
* @param data 要加密的明文数据
|
||||
* @returns 加密后的Base64字符串,已进行URL编码处理(将"/"替换为"%2F")
|
||||
*/
|
||||
public static encrypt(data: string): string | null {
|
||||
try {
|
||||
console.log('开始创建JSEncrypt实例...');
|
||||
const jsEncryptInstance = this.getJSEncryptInstance();
|
||||
|
||||
console.log('开始执行加密操作...');
|
||||
const encrypted = jsEncryptInstance.encrypt(data);
|
||||
|
||||
if (!encrypted) {
|
||||
console.error('RSA加密失败,encrypt方法返回null或false');
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('加密成功,原始结果长度:', encrypted.length);
|
||||
// 与后端encryptOne方法保持一致,将"/"替换为"%2F"
|
||||
const result = encrypted.replace(/\//g, '%2F');
|
||||
console.log('URL编码后长度:', result.length);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('RSA加密异常:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接加密方法 - 绕过类方法调用
|
||||
*/
|
||||
public static directEncrypt(data: string): string | null {
|
||||
try {
|
||||
console.log('直接加密方法,数据长度:', data.length);
|
||||
console.log('JSEncrypt类型:', typeof JSEncrypt);
|
||||
|
||||
if (typeof JSEncrypt !== 'function') {
|
||||
console.error('JSEncrypt不是函数');
|
||||
return null;
|
||||
}
|
||||
|
||||
const crypt = new JSEncrypt();
|
||||
console.log('JSEncrypt实例创建成功,实例类型:', typeof crypt);
|
||||
console.log('encrypt方法类型:', typeof crypt.encrypt);
|
||||
|
||||
// 设置公钥
|
||||
crypt.setPublicKey(this.PUBLIC_KEY_RAW);
|
||||
console.log('公钥设置完成');
|
||||
|
||||
// 执行加密
|
||||
const encrypted = crypt.encrypt(data);
|
||||
console.log('加密结果:', encrypted ? '成功' : '失败');
|
||||
|
||||
if (encrypted) {
|
||||
return encrypted.replace(/\//g, '%2F');
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('直接加密异常:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密密码 - 专门用于密码字段的加密
|
||||
* @param password 原始密码
|
||||
* @returns 加密后的密码字符串
|
||||
*/
|
||||
public static encryptPassword(password: string): string | null {
|
||||
if (!password || password.trim() === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof JSEncrypt !== 'function') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const crypt = new JSEncrypt();
|
||||
crypt.setPublicKey(RSAUtil.PUBLIC_KEY_RAW);
|
||||
const encrypted = crypt.encrypt(password);
|
||||
|
||||
if (encrypted) {
|
||||
return encrypted.replace(/\//g, '%2F');
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('RSA加密失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量加密对象中的敏感字段
|
||||
* @param data 包含敏感字段的对象
|
||||
* @param sensitiveFields 需要加密的字段名数组
|
||||
* @returns 处理后的对象(敏感字段已加密)
|
||||
*/
|
||||
public static encryptSensitiveFields<T extends Record<string, any>>(
|
||||
data: T,
|
||||
sensitiveFields: (keyof T)[]
|
||||
): T {
|
||||
const result = { ...data };
|
||||
|
||||
sensitiveFields.forEach(field => {
|
||||
if (result[field] && typeof result[field] === 'string') {
|
||||
const encrypted = this.encrypt(result[field] as string);
|
||||
if (encrypted) {
|
||||
result[field] = encrypted as T[keyof T];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已加密(简单判断是否包含Base64字符和%2F)
|
||||
* @param data 要检查的数据
|
||||
* @returns 是否已加密
|
||||
*/
|
||||
public static isEncrypted(data: string): boolean {
|
||||
if (!data) return false;
|
||||
// 简单判断:包含%2F且长度较长且符合Base64模式
|
||||
return data.includes('%2F') && data.length > 100 && /^[A-Za-z0-9+%=\/]+$/.test(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公钥(仅用于调试,生产环境不建议暴露)
|
||||
* @returns 公钥字符串
|
||||
*/
|
||||
public static getPublicKey(): string {
|
||||
return this.PUBLIC_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认导出
|
||||
export default RSAUtil;
|
||||
|
||||
// 便捷方法导出
|
||||
export const encryptPassword = RSAUtil.encryptPassword;
|
||||
export const encryptData = RSAUtil.encrypt;
|
||||
export const encryptSensitiveFields = RSAUtil.encryptSensitiveFields;
|
||||
@@ -0,0 +1,172 @@
|
||||
import RSAUtil from './rsaUtil';
|
||||
|
||||
/**
|
||||
* 安全工具类 - 提供常用的安全操作
|
||||
*/
|
||||
export class SecurityUtil {
|
||||
|
||||
/**
|
||||
* 安全登录请求处理
|
||||
* @param loginData 登录数据
|
||||
* @returns 处理后的登录数据(密码已加密)
|
||||
*/
|
||||
public static processLoginData(loginData: {
|
||||
username: string;
|
||||
password: string;
|
||||
[key: string]: any;
|
||||
}) {
|
||||
const processedData = { ...loginData };
|
||||
|
||||
// 加密密码
|
||||
if (processedData.password) {
|
||||
const encryptedPassword = RSAUtil.encryptPassword(processedData.password);
|
||||
if (encryptedPassword) {
|
||||
processedData.password = encryptedPassword;
|
||||
} else {
|
||||
throw new Error('密码加密失败,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
return processedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全表单数据处理
|
||||
* @param formData 表单数据
|
||||
* @param sensitiveFields 敏感字段列表
|
||||
* @returns 处理后的表单数据
|
||||
*/
|
||||
public static processFormData<T extends Record<string, any>>(
|
||||
formData: T,
|
||||
sensitiveFields: (keyof T)[] = ['password', 'confirmPassword', 'oldPassword', 'newPassword']
|
||||
): T {
|
||||
return RSAUtil.encryptSensitiveFields(formData, sensitiveFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码强度
|
||||
* @param password 密码
|
||||
* @returns 密码强度等级和提示信息
|
||||
*/
|
||||
public static validatePasswordStrength(password: string): {
|
||||
level: 'weak' | 'medium' | 'strong';
|
||||
score: number;
|
||||
suggestions: string[];
|
||||
} {
|
||||
const suggestions: string[] = [];
|
||||
let score = 0;
|
||||
|
||||
// 长度检查
|
||||
if (password.length >= 8) {
|
||||
score += 25;
|
||||
} else {
|
||||
suggestions.push('密码长度至少8位');
|
||||
}
|
||||
|
||||
// 包含小写字母
|
||||
if (/[a-z]/.test(password)) {
|
||||
score += 15;
|
||||
} else {
|
||||
suggestions.push('包含小写字母');
|
||||
}
|
||||
|
||||
// 包含大写字母
|
||||
if (/[A-Z]/.test(password)) {
|
||||
score += 15;
|
||||
} else {
|
||||
suggestions.push('包含大写字母');
|
||||
}
|
||||
|
||||
// 包含数字
|
||||
if (/\d/.test(password)) {
|
||||
score += 15;
|
||||
} else {
|
||||
suggestions.push('包含数字');
|
||||
}
|
||||
|
||||
// 包含特殊字符
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
|
||||
score += 20;
|
||||
} else {
|
||||
suggestions.push('包含特殊字符(!@#$%^&*等)');
|
||||
}
|
||||
|
||||
// 长度奖励
|
||||
if (password.length >= 12) {
|
||||
score += 10;
|
||||
}
|
||||
|
||||
let level: 'weak' | 'medium' | 'strong';
|
||||
if (score >= 70) {
|
||||
level = 'strong';
|
||||
} else if (score >= 50) {
|
||||
level = 'medium';
|
||||
} else {
|
||||
level = 'weak';
|
||||
}
|
||||
|
||||
return { level, score, suggestions };
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的输入过滤(基础XSS防护)
|
||||
* @param input 用户输入
|
||||
* @returns 过滤后的输入
|
||||
*/
|
||||
public static sanitizeInput(input: string): string {
|
||||
if (!input) return '';
|
||||
|
||||
return input
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/\//g, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机盐值(用于额外安全性)
|
||||
* @param length 盐值长度
|
||||
* @returns 随机盐值
|
||||
*/
|
||||
public static generateSalt(length: number = 16): string {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let salt = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
salt += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 敏感信息脱敏显示
|
||||
* @param data 敏感数据
|
||||
* @param type 数据类型
|
||||
* @returns 脱敏后的数据
|
||||
*/
|
||||
public static maskSensitiveData(data: string, type: 'phone' | 'email' | 'idcard' | 'bankcard'): string {
|
||||
if (!data) return '';
|
||||
|
||||
switch (type) {
|
||||
case 'phone':
|
||||
return data.length >= 11 ? data.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : data;
|
||||
case 'email':
|
||||
const [username, domain] = data.split('@');
|
||||
if (username && domain) {
|
||||
const maskedUsername = username.length > 2
|
||||
? username[0] + '*'.repeat(username.length - 2) + username[username.length - 1]
|
||||
: username;
|
||||
return `${maskedUsername}@${domain}`;
|
||||
}
|
||||
return data;
|
||||
case 'idcard':
|
||||
return data.length >= 15 ? data.replace(/(\d{6})\d{8}(\d{4})/, '$1********$2') : data;
|
||||
case 'bankcard':
|
||||
return data.length >= 16 ? data.replace(/(\d{4})\d{8}(\d{4})/, '$1********$2') : data;
|
||||
default:
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default SecurityUtil;
|
||||
@@ -0,0 +1,24 @@
|
||||
export interface TreeNode<T=any> {
|
||||
key: string | number;
|
||||
title: string;
|
||||
children?: TreeNode<T>[];
|
||||
raw?: T;
|
||||
}
|
||||
|
||||
export function buildTree<T extends { id: any; pId?: any; name?: string }>(list: T[]): TreeNode<T>[] {
|
||||
const map = new Map<any, TreeNode<T>>();
|
||||
const roots: TreeNode<T>[] = [];
|
||||
list.forEach(item => {
|
||||
map.set(item.id, { key: item.id, title: (item as any).title || item.name || String(item.id), raw: item, children: [] });
|
||||
});
|
||||
list.forEach(item => {
|
||||
const node = map.get(item.id)!;
|
||||
if (item.pId && map.has(item.pId)) {
|
||||
map.get(item.pId)!.children!.push(node);
|
||||
} else {
|
||||
roots.push(node);
|
||||
}
|
||||
});
|
||||
return roots;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user