1:首页优化 2:首页适配手机

This commit is contained in:
2025-10-14 16:27:25 +08:00
parent f6b02a9bd9
commit ba366587f4
6 changed files with 54 additions and 29 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
"build:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test API_PREFIX=http://119.45.169.13:9900 umi build", "build:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test API_PREFIX=http://119.45.169.13:9900 umi build",
"build:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre API_PREFIX=http://119.45.169.13:9900 umi build", "build:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre API_PREFIX=http://119.45.169.13:9900 umi build",
"build:prod": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod umi build", "build:prod": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod umi build",
"build:test:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9900 umi build", "build:test:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9999 umi build",
"build:pre:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9900 umi build", "build:pre:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9900 umi build",
"build:prod:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod APP_BASE=/mgnt umi build", "build:prod:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod APP_BASE=/mgnt umi build",
"lint": "eslint --ext .ts,.tsx src", "lint": "eslint --ext .ts,.tsx src",
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'; 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'; import { tenantApi } from '@/services/tenant';
interface TenantNode { interface TenantNode {
@@ -19,6 +19,8 @@ interface Props {
} }
const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false, autoApply = false }) => { const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false, autoApply = false }) => {
const screens = Grid.useBreakpoint();
const isMobile = !screens.md;
const [tree, setTree] = useState<TenantNode[]>([]); const [tree, setTree] = useState<TenantNode[]>([]);
const [tenantId, setTenantId] = useState<string | undefined>(); const [tenantId, setTenantId] = useState<string | undefined>();
const [includeChildren, setIncludeChildren] = useState<boolean>(true); 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); const curId = curRes?.data?.tenantId || (curRes?.resp_code === 0 ? curRes?.data?.tenantId : undefined);
if (curId) setTenantId(curId); if (curId) setTenantId(curId);
} catch { } catch {
// 忽略错误,展示空树 // 忽略错误,展示空
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -82,13 +84,15 @@ const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false
}; };
return ( return (
<Space> <Space direction={isMobile ? 'vertical' : 'horizontal'} style={{ width: isMobile ? '100%' : 'auto' }}>
<TreeSelect <TreeSelect
style={{ minWidth: 260 }} style={{ minWidth: isMobile ? 0 : 260, width: isMobile ? '100%' : undefined }}
showSearch showSearch
loading={loading} loading={loading}
treeNodeFilterProp="title" treeNodeFilterProp="title"
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
dropdownMatchSelectWidth
getPopupContainer={(trigger) => (trigger?.parentElement as HTMLElement) || document.body}
placeholder="选择租户(含子租户)" placeholder="选择租户(含子租户)"
value={tenantId} value={tenantId}
onChange={(val) => setTenantId(val)} 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> <Checkbox checked={includeChildren} onChange={(e) => setIncludeChildren(e.target.checked)}>包含子租户</Checkbox>
{!autoApply && ( {!autoApply && (
<Button type="primary" onClick={handleApply}>应用</Button> <Button type="primary" size={isMobile ? 'small' : 'middle'} onClick={handleApply}>应用</Button>
)} )}
</Space> </Space>
); );
}; };
export default TenantScopeFilter; export default TenantScopeFilter;
+6
View File
@@ -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-wrapper, .ant-table-wrapper { overflow-x: auto; }
.ant-pro-table .ant-table { min-width: 720px; } .ant-pro-table .ant-table { min-width: 720px; }
.ant-pro-page-container-children-content { padding: 12px; } .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; }
} }
/* 更友好的表单间距 */ /* 更友好的表单间距 */
+26 -19
View File
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react'; 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 { ReloadOutlined } from '@ant-design/icons';
import { Line, Pie } from '@ant-design/plots'; import { Line, Pie } from '@ant-design/plots';
import TenantScopeFilter from '@/components/TenantScopeFilter'; 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 }[] = [ const STATUS_OPTIONS: { value: number; label: string; color?: string }[] = [
{ value: 0, label: '待支付' }, { value: 0, label: '待支付' },
{ value: 1, label: '排队中', color: 'gold' }, { value: 1, label: '排队中', color: 'gold' },
{ value: 2, label: '已取消', color: 'red' }, { value: 2, label: '已取号', color: 'red' },
{ value: 3, label: '设备执行完成', color: 'green' }, { value: 3, label: '设备执行完成', color: 'green' },
{ value: 4, label: '正在服务', color: 'blue' }, { value: 4, label: '正在服务', color: 'blue' },
{ value: 5, label: '素材上传', color: 'geekblue' }, { value: 5, label: '素材上传', color: 'geekblue' },
@@ -63,8 +63,9 @@ const Welcome: React.FC = () => {
const handleRangeTypeChange = (val: any) => { const handleRangeTypeChange = (val: any) => {
const t = (val as RangeType) || 'date'; const t = (val as RangeType) || 'date';
setRangeType(t); setRangeType(t);
const anchor = range?.[0] || moment(); // 切换粒度时,以“当前时间”为锚点,确保切回日/周/月回到“当前日/当前周/当前月”
setRange(computeRangeByType(t, anchor)); const anchorNow = moment();
setRange(computeRangeByType(t, anchorNow));
}; };
const handleRangeChange = (vals: any) => { const handleRangeChange = (vals: any) => {
@@ -86,7 +87,7 @@ const Welcome: React.FC = () => {
setLoading(true); setLoading(true);
try { try {
const { startTime, endTime } = getTimeParams(); 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 }); const res: any = await dashboardApi.statistics({ tenantId, includeChildren, startTime, endTime, statType, includeTestQrcodes: false });
setStat(res?.data || res); setStat(res?.data || res);
@@ -108,7 +109,6 @@ const Welcome: React.FC = () => {
setOrdersLoading(false); setOrdersLoading(false);
} }
// 刷新折线(刷新按钮也会触发到这里)
try { await loadAggregations(); } catch {} try { await loadAggregations(); } catch {}
} catch (e) { } catch (e) {
message.error('加载统计失败'); 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 seriesRes: any = await ordersApi.getOrderSeries({ tenantId, includeChildren, startTime, endTime, statType: rangeType, includeTestQrcodes: false });
const seriesData: any[] = seriesRes?.data || []; const seriesData: any[] = seriesRes?.data || [];
// 构建数据映射表 // 构建数据映射
const dataMap: Record<string, Record<string, number>> = { const dataMap: Record<string, Record<string, number>> = {
'订单创建': {}, '订单创建': {},
'完成': {}, '完成': {},
'退款': {} '退款': {}
}; };
// 将后端数据填充到映射表 // 将后端数据填充到映射
seriesData.forEach((item: any) => { seriesData.forEach((item: any) => {
const date = item.date || ''; const date = item.date || '';
const type = item.type || ''; const type = item.type || '';
@@ -161,7 +161,7 @@ const Welcome: React.FC = () => {
} }
}); });
// 填充所有时间点,缺失的补0 // 填充所有时间点,缺失的补 0
const lineSeries: { date: string; value: number; type: string }[] = []; const lineSeries: { date: string; value: number; type: string }[] = [];
labels.forEach((label) => { labels.forEach((label) => {
lineSeries.push({ date: label, type: '订单创建', value: dataMap['订单创建'][label] || 0 }); lineSeries.push({ date: label, type: '订单创建', value: dataMap['订单创建'][label] || 0 });
@@ -187,17 +187,18 @@ const Welcome: React.FC = () => {
return colorMapping[type] || '#1890ff'; return colorMapping[type] || '#1890ff';
}; };
const screens = Grid.useBreakpoint();
const isMobile = !screens.md; // 小于 md 视为移动端
const orderLineConfig: any = { const orderLineConfig: any = {
data: orderLineSeries, data: orderLineSeries,
xField: 'date', xField: 'date',
yField: 'value', yField: 'value',
seriesField: 'type', seriesField: 'type',
smooth: true, smooth: true,
height: 220, autoFit: true,
legend: { position: 'top' as const }, height: isMobile ? 180 : 220,
color: (datum: any) => { legend: { position: 'top' },
return getColorByType(datum.type); color: (datum: any) => getColorByType(datum.type),
},
}; };
// 饼图配置 // 饼图配置
@@ -211,7 +212,7 @@ const Welcome: React.FC = () => {
colorField: 'type', colorField: 'type',
radius: 0.9, radius: 0.9,
color: distributionPalette, color: distributionPalette,
legend: { position: 'right' }, legend: { position: (isMobile ? 'bottom' : 'right') as 'top' | 'right' | 'bottom' | 'left' },
label: false, label: false,
animation: false, animation: false,
}; };
@@ -230,16 +231,18 @@ const Welcome: React.FC = () => {
return ( return (
<div className="page-enter" style={{ padding: 24 }}> <div className="page-enter" style={{ padding: 24 }}>
{/* 顶部工具栏 */} {/* 顶部工具区 */}
<Card className="modern-card" style={{ marginBottom: 16 }}> <Card className="modern-card" style={{ marginBottom: 16 }}>
<Row align="middle" justify="space-between" gutter={[12, 12]}> <Row align="middle" justify="space-between" gutter={[12, 12]}>
<Col flex="none"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col> <Col flex="none"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col>
<Col flex="auto"> <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); }} /> <TenantScopeFilter autoApply onChanged={(tid, inc) => { setTenantId(tid); setIncludeChildren(!!inc); }} />
<Space> <Space direction={isMobile ? 'vertical' : 'horizontal'} wrap>
<span>统计时间</span> <span>统计时间</span>
<Segmented <Segmented
block={isMobile}
size={isMobile ? 'small' : 'middle'}
options={[{ label: '日', value: 'date' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }, { label: '年', value: 'year' }]} options={[{ label: '日', value: 'date' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }, { label: '年', value: 'year' }]}
value={rangeType} value={rangeType}
onChange={handleRangeTypeChange} onChange={handleRangeTypeChange}
@@ -250,8 +253,12 @@ const Welcome: React.FC = () => {
value={range as any} value={range as any}
picker={rangeType as any} picker={rangeType as any}
onChange={handleRangeChange} 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>
</Space> </Space>
</Col> </Col>
@@ -65,7 +65,10 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
// 当外部查询参数变更时,自动触发请求 // 当外部查询参数变更时,自动触发请求
params={extraParams} params={extraParams}
request={async (p) => { 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 }; return { data, total, success: true };
}} }}
pagination={{ pageSize: 10 }} pagination={{ pageSize: 10 }}
@@ -10,6 +10,8 @@ import UserForm from './components/UserForm';
const UsersPage: React.FC = () => { const UsersPage: React.FC = () => {
const tableRef = useRef<UserTableRef>(null); const tableRef = useRef<UserTableRef>(null);
const [params, setParams] = useState<Record<string, any>>({ type: 'BACKEND' }); const [params, setParams] = useState<Record<string, any>>({ type: 'BACKEND' });
// 每次点击查询自增,配合 ProTable params 触发强制请求
const [refreshKey, setRefreshKey] = useState<number>(0);
const [createVisible, setCreateVisible] = useState(false); const [createVisible, setCreateVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false); const [editVisible, setEditVisible] = useState(false);
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined); const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
@@ -89,7 +91,10 @@ const UsersPage: React.FC = () => {
onFinish={async (values) => { onFinish={async (values) => {
const v: any = { ...(values || {}) }; const v: any = { ...(values || {}) };
if (v?.type === 'APP') { delete v.tenantId; delete v.includeChildren; } 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" /> <ProFormSelect name="type" label="用户类型" valueEnum={{ BACKEND: '系统用户', APP: 'C端用户' }} initialValue="BACKEND" />
@@ -103,7 +108,8 @@ const UsersPage: React.FC = () => {
onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }} onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }}
onResetPassword={(r) => resetPwd(r)} onResetPassword={(r) => resetPwd(r)}
onDelete={(r) => delUser(r)} onDelete={(r) => delUser(r)}
extraParams={listParams} // 通过 __refresh 强制区分每次点击
extraParams={{ ...(listParams || {}), __refresh: refreshKey }}
/> />
</GlassCard> </GlassCard>