1:首页优化 2:首页适配手机
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Space, Button, TreeSelect, Checkbox, message } from 'antd';
|
||||
import { Space, Button, TreeSelect, Checkbox, message, Grid } from 'antd';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
|
||||
interface TenantNode {
|
||||
@@ -19,6 +19,8 @@ interface Props {
|
||||
}
|
||||
|
||||
const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false, autoApply = false }) => {
|
||||
const screens = Grid.useBreakpoint();
|
||||
const isMobile = !screens.md;
|
||||
const [tree, setTree] = useState<TenantNode[]>([]);
|
||||
const [tenantId, setTenantId] = useState<string | undefined>();
|
||||
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
||||
@@ -41,7 +43,7 @@ const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false
|
||||
const curId = curRes?.data?.tenantId || (curRes?.resp_code === 0 ? curRes?.data?.tenantId : undefined);
|
||||
if (curId) setTenantId(curId);
|
||||
} catch {
|
||||
// 忽略错误,展示空树
|
||||
// 忽略错误,展示空
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -82,13 +84,15 @@ const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false
|
||||
};
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Space direction={isMobile ? 'vertical' : 'horizontal'} style={{ width: isMobile ? '100%' : 'auto' }}>
|
||||
<TreeSelect
|
||||
style={{ minWidth: 260 }}
|
||||
style={{ minWidth: isMobile ? 0 : 260, width: isMobile ? '100%' : undefined }}
|
||||
showSearch
|
||||
loading={loading}
|
||||
treeNodeFilterProp="title"
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
dropdownMatchSelectWidth
|
||||
getPopupContainer={(trigger) => (trigger?.parentElement as HTMLElement) || document.body}
|
||||
placeholder="选择租户(含子租户)"
|
||||
value={tenantId}
|
||||
onChange={(val) => setTenantId(val)}
|
||||
@@ -96,11 +100,10 @@ const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false
|
||||
/>
|
||||
<Checkbox checked={includeChildren} onChange={(e) => setIncludeChildren(e.target.checked)}>包含子租户</Checkbox>
|
||||
{!autoApply && (
|
||||
<Button type="primary" onClick={handleApply}>应用</Button>
|
||||
<Button type="primary" size={isMobile ? 'small' : 'middle'} onClick={handleApply}>应用</Button>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantScopeFilter;
|
||||
|
||||
|
||||
@@ -56,6 +56,12 @@ html, body, #root { height: 100%; }
|
||||
.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-picker-dropdown { max-width: 100vw; }
|
||||
.ant-picker-dropdown .ant-picker-panels { display: flex; flex-direction: column; }
|
||||
.ant-select-dropdown { max-width: 100vw; }
|
||||
/* TreeSelect 节点文案允许换行,避免横向挤出 */
|
||||
.ant-select-tree .ant-select-tree-node-content-wrapper { white-space: normal; }
|
||||
}
|
||||
|
||||
/* 更友好的表单间距 */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic } from 'antd';
|
||||
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic, Grid } from 'antd';
|
||||
import { ReloadOutlined } from '@ant-design/icons';
|
||||
import { Line, Pie } from '@ant-design/plots';
|
||||
import TenantScopeFilter from '@/components/TenantScopeFilter';
|
||||
@@ -22,7 +22,7 @@ const computeRangeByType = (type: RangeType, anchor?: Moment): [Moment, Moment]
|
||||
const STATUS_OPTIONS: { value: number; label: string; color?: string }[] = [
|
||||
{ value: 0, label: '待支付' },
|
||||
{ value: 1, label: '排队中', color: 'gold' },
|
||||
{ value: 2, label: '已取消', color: 'red' },
|
||||
{ value: 2, label: '已取号', color: 'red' },
|
||||
{ value: 3, label: '设备执行完成', color: 'green' },
|
||||
{ value: 4, label: '正在服务', color: 'blue' },
|
||||
{ value: 5, label: '素材上传', color: 'geekblue' },
|
||||
@@ -63,8 +63,9 @@ const Welcome: React.FC = () => {
|
||||
const handleRangeTypeChange = (val: any) => {
|
||||
const t = (val as RangeType) || 'date';
|
||||
setRangeType(t);
|
||||
const anchor = range?.[0] || moment();
|
||||
setRange(computeRangeByType(t, anchor));
|
||||
// 切换粒度时,以“当前时间”为锚点,确保切回日/周/月回到“当前日/当前周/当前月”
|
||||
const anchorNow = moment();
|
||||
setRange(computeRangeByType(t, anchorNow));
|
||||
};
|
||||
|
||||
const handleRangeChange = (vals: any) => {
|
||||
@@ -86,7 +87,7 @@ const Welcome: React.FC = () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { startTime, endTime } = getTimeParams();
|
||||
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day'|'month'|'year';
|
||||
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day' | 'month' | 'year';
|
||||
const res: any = await dashboardApi.statistics({ tenantId, includeChildren, startTime, endTime, statType, includeTestQrcodes: false });
|
||||
setStat(res?.data || res);
|
||||
|
||||
@@ -108,7 +109,6 @@ const Welcome: React.FC = () => {
|
||||
setOrdersLoading(false);
|
||||
}
|
||||
|
||||
// 刷新折线(刷新按钮也会触发到这里)
|
||||
try { await loadAggregations(); } catch {}
|
||||
} catch (e) {
|
||||
message.error('加载统计失败');
|
||||
@@ -144,14 +144,14 @@ const Welcome: React.FC = () => {
|
||||
const seriesRes: any = await ordersApi.getOrderSeries({ tenantId, includeChildren, startTime, endTime, statType: rangeType, includeTestQrcodes: false });
|
||||
const seriesData: any[] = seriesRes?.data || [];
|
||||
|
||||
// 构建数据映射表
|
||||
// 构建数据映射
|
||||
const dataMap: Record<string, Record<string, number>> = {
|
||||
'订单创建': {},
|
||||
'完成': {},
|
||||
'退款': {}
|
||||
};
|
||||
|
||||
// 将后端数据填充到映射表
|
||||
// 将后端数据填充到映射
|
||||
seriesData.forEach((item: any) => {
|
||||
const date = item.date || '';
|
||||
const type = item.type || '';
|
||||
@@ -161,7 +161,7 @@ const Welcome: React.FC = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// 填充所有时间点,缺失的补0
|
||||
// 填充所有时间点,缺失的补 0
|
||||
const lineSeries: { date: string; value: number; type: string }[] = [];
|
||||
labels.forEach((label) => {
|
||||
lineSeries.push({ date: label, type: '订单创建', value: dataMap['订单创建'][label] || 0 });
|
||||
@@ -187,17 +187,18 @@ const Welcome: React.FC = () => {
|
||||
return colorMapping[type] || '#1890ff';
|
||||
};
|
||||
|
||||
const screens = Grid.useBreakpoint();
|
||||
const isMobile = !screens.md; // 小于 md 视为移动端
|
||||
const orderLineConfig: any = {
|
||||
data: orderLineSeries,
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
smooth: true,
|
||||
height: 220,
|
||||
legend: { position: 'top' as const },
|
||||
color: (datum: any) => {
|
||||
return getColorByType(datum.type);
|
||||
},
|
||||
autoFit: true,
|
||||
height: isMobile ? 180 : 220,
|
||||
legend: { position: 'top' },
|
||||
color: (datum: any) => getColorByType(datum.type),
|
||||
};
|
||||
|
||||
// 饼图配置
|
||||
@@ -211,7 +212,7 @@ const Welcome: React.FC = () => {
|
||||
colorField: 'type',
|
||||
radius: 0.9,
|
||||
color: distributionPalette,
|
||||
legend: { position: 'right' },
|
||||
legend: { position: (isMobile ? 'bottom' : 'right') as 'top' | 'right' | 'bottom' | 'left' },
|
||||
label: false,
|
||||
animation: false,
|
||||
};
|
||||
@@ -230,16 +231,18 @@ const Welcome: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="page-enter" style={{ padding: 24 }}>
|
||||
{/* 顶部工具栏 */}
|
||||
{/* 顶部工具区 */}
|
||||
<Card className="modern-card" style={{ marginBottom: 16 }}>
|
||||
<Row align="middle" justify="space-between" gutter={[12, 12]}>
|
||||
<Col flex="none"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col>
|
||||
<Col flex="auto">
|
||||
<Space style={{ width: '100%', justifyContent: 'flex-end', flexWrap: 'wrap' }} size={12}>
|
||||
<Space direction={isMobile ? 'vertical' : 'horizontal'} style={{ width: '100%', justifyContent: 'flex-end', flexWrap: 'wrap' }} size={12}>
|
||||
<TenantScopeFilter autoApply onChanged={(tid, inc) => { setTenantId(tid); setIncludeChildren(!!inc); }} />
|
||||
<Space>
|
||||
<Space direction={isMobile ? 'vertical' : 'horizontal'} wrap>
|
||||
<span>统计时间</span>
|
||||
<Segmented
|
||||
block={isMobile}
|
||||
size={isMobile ? 'small' : 'middle'}
|
||||
options={[{ label: '日', value: 'date' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }, { label: '年', value: 'year' }]}
|
||||
value={rangeType}
|
||||
onChange={handleRangeTypeChange}
|
||||
@@ -250,8 +253,12 @@ const Welcome: React.FC = () => {
|
||||
value={range as any}
|
||||
picker={rangeType as any}
|
||||
onChange={handleRangeChange}
|
||||
size={isMobile ? 'small' : 'middle'}
|
||||
getPopupContainer={(trigger: any) => (trigger?.parentElement || document.body)}
|
||||
placement={isMobile ? 'bottomLeft' : 'bottomRight'}
|
||||
style={{ width: isMobile ? '100%' : undefined, minWidth: isMobile ? 220 : undefined }}
|
||||
/>
|
||||
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} onClick={() => { load(); }}>刷新</Button>
|
||||
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} size={isMobile ? 'small' : 'middle'} onClick={() => { load(); }}>刷新</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
</Col>
|
||||
|
||||
@@ -65,7 +65,10 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
|
||||
// 当外部查询参数变更时,自动触发请求
|
||||
params={extraParams}
|
||||
request={async (p) => {
|
||||
const { data, total } = await systemApi.users({ ...(p as any), ...(extraParams || {}) } as any);
|
||||
// 过滤用于强制刷新的内部标记,避免传给后端
|
||||
const { __refresh: _r1, ...safeP } = (p || {}) as any;
|
||||
const { __refresh: _r2, ...safeExtra } = (extraParams || {}) as any;
|
||||
const { data, total } = await systemApi.users({ ...(safeP as any), ...(safeExtra as any) } as any);
|
||||
return { data, total, success: true };
|
||||
}}
|
||||
pagination={{ pageSize: 10 }}
|
||||
|
||||
@@ -10,6 +10,8 @@ import UserForm from './components/UserForm';
|
||||
const UsersPage: React.FC = () => {
|
||||
const tableRef = useRef<UserTableRef>(null);
|
||||
const [params, setParams] = useState<Record<string, any>>({ type: 'BACKEND' });
|
||||
// 每次点击查询自增,配合 ProTable params 触发强制请求
|
||||
const [refreshKey, setRefreshKey] = useState<number>(0);
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
const [editVisible, setEditVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
|
||||
@@ -89,7 +91,10 @@ const UsersPage: React.FC = () => {
|
||||
onFinish={async (values) => {
|
||||
const v: any = { ...(values || {}) };
|
||||
if (v?.type === 'APP') { delete v.tenantId; delete v.includeChildren; }
|
||||
setParams(v); // 交由 ProTable(params) 触发请求
|
||||
// 更新查询参数
|
||||
setParams(v);
|
||||
// 自增刷新标记,确保即使参数未变化也会触发一次请求
|
||||
setRefreshKey((k) => k + 1);
|
||||
}}
|
||||
>
|
||||
<ProFormSelect name="type" label="用户类型" valueEnum={{ BACKEND: '系统用户', APP: 'C端用户' }} initialValue="BACKEND" />
|
||||
@@ -103,7 +108,8 @@ const UsersPage: React.FC = () => {
|
||||
onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }}
|
||||
onResetPassword={(r) => resetPwd(r)}
|
||||
onDelete={(r) => delUser(r)}
|
||||
extraParams={listParams}
|
||||
// 通过 __refresh 强制区分每次点击
|
||||
extraParams={{ ...(listParams || {}), __refresh: refreshKey }}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user