feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -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';
|
||||
Reference in New Issue
Block a user