Please enter the commit message for your changes. Lines starting

with '#' will be ignored, and an empty message aborts the commit.

On branch develop
Your branch is ahead of 'goflyapp/develop' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
	modified:   zlt-web/react-web/src/main/frontend/src/pages/Welcome.less
	modified:   zlt-web/react-web/src/main/frontend/src/pages/Welcome.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/device/Device/index.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/components/UpdateForm.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/components/UpdateForm.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.less
	modified:   zlt-web/react-web/src/main/frontend/src/pages/orders/TourismFile/index.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/system/Menu/index.less
	modified:   zlt-web/react-web/src/main/frontend/src/pages/system/Menu/index.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.less
	modified:   zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.tsx
	modified:   zlt-web/react-web/src/main/frontend/src/services/orders/api.ts
This commit is contained in:
2025-04-10 11:24:04 +08:00
parent 178ed9fc02
commit 01ae4f909d
14 changed files with 1099 additions and 797 deletions
@@ -1,4 +1,5 @@
@import (reference) '~antd/es/style/themes/index'; @import (reference) '~antd/es/style/themes/index';
@import '~antd/es/style/themes/default.less';
.stat { .stat {
margin-top: @margin-md; margin-top: @margin-md;
@@ -9,3 +10,104 @@
.pie { .pie {
margin-top: @margin-md; margin-top: @margin-md;
} }
.chartCard {
margin: 24px 0;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
:global {
.ant-tabs-nav {
margin-bottom: 16px;
padding: 0 24px;
}
.ant-tabs-tab {
padding: 12px 0;
font-size: 15px;
&:hover {
color: @primary-color;
}
}
.ant-tabs-tab-active {
.ant-tabs-tab-btn {
font-weight: 500;
}
}
.ant-empty {
padding: 32px 0;
}
}
}
.pieRow {
margin-bottom: 24px;
}
.pieCard {
height: 100%;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
:global {
.ant-card-head {
padding: 0 24px;
border-bottom: 1px solid @border-color-split;
.ant-card-head-title {
padding: 16px 0;
font-size: 16px;
font-weight: 500;
}
}
.ant-card-body {
padding: 24px;
}
.ant-empty {
padding: 32px 0;
}
}
}
:global {
.ant-pro-card {
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.ant-statistic-title {
font-size: 15px;
margin-bottom: 8px;
}
.ant-statistic-content {
font-size: 24px;
font-weight: 500;
&-value {
color: @heading-color;
}
}
.ant-pro-card-statistic-description {
margin-top: 8px;
}
.ant-skeleton {
padding: 24px;
}
}
@media screen and (max-width: @screen-md) {
.pieRow {
.pieCard {
margin-bottom: 16px;
}
}
}
@@ -1,15 +1,23 @@
import { PageContainer, StatisticCard } from '@ant-design/pro-components'; import { PageContainer, StatisticCard } from '@ant-design/pro-components';
import { Card, Tag, Space, Tabs, Col, Row } from 'antd'; import { Card, Tag, Space, Tabs, Col, Row, Skeleton, Empty } from 'antd';
import RcResizeObserver from 'rc-resize-observer'; import RcResizeObserver from 'rc-resize-observer';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import { statistic } from '@/services/welcome/api'; import { statistic } from '@/services/welcome/api';
import { Area, Pie } from '@ant-design/plots'; import { Area, Pie } from '@ant-design/plots';
import {
UserOutlined,
EyeOutlined,
TeamOutlined,
LineChartOutlined,
BarChartOutlined,
} from '@ant-design/icons';
import styles from './Welcome.less'; import styles from './Welcome.less';
const { Divider } = StatisticCard; const { Divider } = StatisticCard;
const Welcome: React.FC = () => { const Welcome: React.FC = () => {
const [responsive, setResponsive] = useState<boolean>(false); const [responsive, setResponsive] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(true);
const [statistics, setStatistics] = useState<WELCOME.Statistic>({}); const [statistics, setStatistics] = useState<WELCOME.Statistic>({});
const [weeks, setWeeks] = useState<WELCOME.AreaData[]>([]); const [weeks, setWeeks] = useState<WELCOME.AreaData[]>([]);
const [days, setDays] = useState<WELCOME.AreaData[]>([]); const [days, setDays] = useState<WELCOME.AreaData[]>([]);
@@ -17,15 +25,18 @@ const Welcome: React.FC = () => {
const mapWeek = (result: WELCOME.Statistic) => { const mapWeek = (result: WELCOME.Statistic) => {
const { statWeek_items, statWeek_pv, statWeek_uv } = result; const { statWeek_items, statWeek_pv, statWeek_uv } = result;
if (statWeek_items && statWeek_pv && statWeek_uv) { if (statWeek_items && statWeek_pv && statWeek_uv) {
const weekData = statWeek_pv const weekData = [
.map((pv, index) => { ...statWeek_pv.map((pv, index) => ({
return { type: '访问量(PV)', date: statWeek_items[index], value: pv }; type: '访问量(PV)',
}) date: statWeek_items[index],
.concat( value: pv,
statWeek_uv.map((uv, index) => { })),
return { type: '独立用户(UV)', date: statWeek_items[index], value: uv }; ...statWeek_uv.map((uv, index) => ({
}), type: '独立用户(UV)',
); date: statWeek_items[index],
value: uv,
})),
];
setWeeks(weekData); setWeeks(weekData);
} }
}; };
@@ -33,195 +44,200 @@ const Welcome: React.FC = () => {
const mapDay = (result: WELCOME.Statistic) => { const mapDay = (result: WELCOME.Statistic) => {
const { statDate_items, statDate_pv, statDate_uv } = result; const { statDate_items, statDate_pv, statDate_uv } = result;
if (statDate_items && statDate_pv && statDate_uv) { if (statDate_items && statDate_pv && statDate_uv) {
const dayData = statDate_pv const dayData = [
.map((pv, index) => { ...statDate_pv.map((pv, index) => ({
return { type: '访问量(PV)', date: statDate_items[index], value: pv }; type: '访问量(PV)',
}) date: statDate_items[index],
.concat( value: pv,
statDate_uv.map((uv, index) => { })),
return { type: '独立用户(UV)', date: statDate_items[index], value: uv }; ...statDate_uv.map((uv, index) => ({
}), type: '独立用户(UV)',
); date: statDate_items[index],
value: uv,
})),
];
setDays(dayData); setDays(dayData);
} }
}; };
useEffect(() => { const fetchData = async () => {
(async () => { try {
setLoading(true);
const result = await statistic(); const result = await statistic();
if (result) { if (result) {
setStatistics(result); setStatistics(result);
mapWeek(result); mapWeek(result);
mapDay(result); mapDay(result);
} }
})(); } catch (error) {
console.error('获取统计数据失败:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchData();
// 每5分钟刷新一次数据
const timer = setInterval(fetchData, 5 * 60 * 1000);
return () => clearInterval(timer);
}, []); }, []);
const areaConfig = useMemo(() => ({
smooth: true,
height: 260,
animation: true,
legend: {
layout: 'horizontal',
position: 'top',
},
xField: 'date',
yField: 'value',
seriesField: 'type',
color: ['#1890ff', '#52c41a'],
areaStyle: {
fillOpacity: 0.6,
},
tooltip: {
shared: true,
showCrosshairs: true,
},
}), []);
const pieConfig = useMemo(() => ({
height: 280,
angleField: 'value',
colorField: 'name',
appendPadding: 10,
radius: 0.75,
animation: true,
label: {
type: 'spider',
labelHeight: 28,
content: '{name}\n{percentage}',
},
legend: {
layout: 'horizontal',
position: 'bottom',
},
interactions: [
{ type: 'element-selected' },
{ type: 'element-active' },
],
}), []);
return ( return (
<PageContainer <PageContainer
subTitle="前后端分离的微服务架构" subTitle="前后端分离的微服务架构"
tags={ tags={
<> <Space>
<Tag color="blue">简单</Tag> <Tag color="blue">简单</Tag>
<Tag color="blue">高效</Tag> <Tag color="green">高效</Tag>
</> <Tag color="purple">可扩展</Tag>
</Space>
} }
> >
<RcResizeObserver <RcResizeObserver
key="resize-observer" key="resize-observer"
onResize={(offset) => { onResize={(offset) => setResponsive(offset.width < 596)}
setResponsive(offset.width < 596);
}}
> >
<StatisticCard.Group direction={responsive ? 'column' : 'row'}> <Skeleton loading={loading} active>
<StatisticCard <StatisticCard.Group direction={responsive ? 'column' : 'row'}>
statistic={{ <StatisticCard
title: ( statistic={{
<Space size="small"> title: '在线人数',
在线人数<Tag color="#434343">时</Tag> value: statistics.currHour_uv,
</Space> icon: <UserOutlined />,
), description: <Tag color="#434343">实时</Tag>,
value: statistics.currHour_uv, }}
}} />
/> <Divider type={responsive ? 'horizontal' : 'vertical'} />
<Divider type={responsive ? 'horizontal' : 'vertical'} /> <StatisticCard
<StatisticCard statistic={{
statistic={{ title: '今日PV',
title: ( value: statistics.currDate_pv,
<Space size="small"> icon: <EyeOutlined />,
PV<Tag color="#52c41a">天</Tag> description: <Tag color="#52c41a">今日</Tag>,
</Space> }}
), />
value: statistics.currDate_pv, <Divider type={responsive ? 'horizontal' : 'vertical'} />
}} <StatisticCard
/> statistic={{
<Divider type={responsive ? 'horizontal' : 'vertical'} /> title: '今日UV',
<StatisticCard value: statistics.currDate_uv,
statistic={{ icon: <TeamOutlined />,
title: ( description: <Tag color="#52c41a">今日</Tag>,
<Space size="small"> }}
UV<Tag color="#52c41a">天</Tag> />
</Space> <Divider type={responsive ? 'horizontal' : 'vertical'} />
), <StatisticCard
value: statistics.currDate_uv, statistic={{
}} title: '本周访问',
/> value: statistics.currWeek_pv,
<Divider type={responsive ? 'horizontal' : 'vertical'} /> icon: <LineChartOutlined />,
<StatisticCard description: <Tag color="#1890ff">本周</Tag>,
statistic={{ }}
title: ( />
<Space size="small"> <Divider type={responsive ? 'horizontal' : 'vertical'} />
周访问量<Tag color="#1890ff">周</Tag> <StatisticCard
</Space> statistic={{
), title: '本月访问',
value: statistics.currWeek_pv, value: statistics.currMonth_pv,
}} icon: <BarChartOutlined />,
/> description: <Tag color="#faad14">本月</Tag>,
<Divider type={responsive ? 'horizontal' : 'vertical'} /> }}
<StatisticCard />
statistic={{ </StatisticCard.Group>
title: ( </Skeleton>
<Space size="small">
月访问量<Tag color="#faad14">月</Tag> <Card className={styles.chartCard}>
</Space> <Tabs defaultActiveKey="1">
), <Tabs.TabPane tab="周流量趋势" key="1">
value: statistics.currMonth_pv, {weeks.length > 0 ? (
}} <Area {...areaConfig} data={weeks} />
/> ) : (
</StatisticCard.Group> <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
</Tabs.TabPane>
<Tabs.TabPane tab="日流量趋势" key="2">
{days.length > 0 ? (
<Area {...areaConfig} data={days} />
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
</Tabs.TabPane>
</Tabs>
</Card>
<Row gutter={16} className={styles.pieRow}>
<Col xs={24} sm={24} md={12}>
<Card
title="浏览器分布"
bordered={false}
className={styles.pieCard}
>
{statistics.browser_datas?.length ? (
<Pie {...pieConfig} data={statistics.browser_datas} />
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
</Card>
</Col>
<Col xs={24} sm={24} md={12}>
<Card
title="操作系统分布"
bordered={false}
className={styles.pieCard}
>
{statistics.operatingSystem_datas?.length ? (
<Pie {...pieConfig} data={statistics.operatingSystem_datas} />
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
</Card>
</Col>
</Row>
</RcResizeObserver> </RcResizeObserver>
<Tabs defaultActiveKey="1" className={styles.stat}>
<Tabs.TabPane tab="周流量趋势" key="1">
<Area
data={weeks}
xField="date"
yField="value"
seriesField="type"
smooth
height={200}
legend={{
layout: 'horizontal',
position: 'top',
}}
/>
</Tabs.TabPane>
<Tabs.TabPane tab="天流量趋势" key="2">
<Area
data={days}
xField="date"
yField="value"
seriesField="type"
smooth
height={200}
legend={{
layout: 'horizontal',
position: 'top',
}}
/>
</Tabs.TabPane>
</Tabs>
<Row gutter={16} className={styles.pie}>
<Col span={12}>
<Card
title="浏览器分布"
bordered={false}
size="small"
headStyle={{ textAlign: 'center' }}
>
<Pie
height={240}
data={statistics.browser_datas ?? []}
angleField="value"
colorField="name"
appendPadding={10}
radius={0.75}
label={{
type: 'spider',
labelHeight: 28,
content: '{name}\n{percentage}',
}}
interactions={[
{
type: 'element-selected',
},
{
type: 'element-active',
},
]}
/>
</Card>
</Col>
<Col span={12}>
<Card
title="操作系统分布"
bordered={false}
size="small"
headStyle={{ textAlign: 'center' }}
>
<Pie
height={240}
data={statistics.operatingSystem_datas ?? []}
angleField="value"
colorField="name"
appendPadding={10}
radius={0.75}
label={{
type: 'spider',
labelHeight: 28,
content: '{name}\n{percentage}',
}}
interactions={[
{
type: 'element-selected',
},
{
type: 'element-active',
},
]}
/>
</Card>
</Col>
</Row>
</PageContainer> </PageContainer>
); );
}; };
@@ -1,67 +1,51 @@
import { import {
ModalForm, ModalForm,
ProForm, ProForm,
ProFormSelect,
ProFormText, ProFormText,
ProFormSelect,
ProFormTextArea, ProFormTextArea,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import React, { useEffect } from 'react'; import React from 'react';
interface UpdateFormProps { // 设备类型常量
onSubmit: (values: DEVICE.Device) => Promise<boolean>; const DEVICE_TYPE = {
DOCK: 1,
DRONE: 2,
REMOTE_CONTROL: 3,
} as const;
export type FormValueType = {
id?: string;
deviceSn?: string;
deviceName?: string;
nickname?: string;
deviceType?: number;
firmwareVersion?: string;
deviceDesc?: string;
} & Partial<DEVICE.Device>;
export type UpdateFormProps = {
onSubmit: (values: FormValueType) => Promise<void>;
onVisibleChange: (visible: boolean) => void; onVisibleChange: (visible: boolean) => void;
updateModalVisible: boolean; updateModalVisible: boolean;
values?: DEVICE.Device; values: Partial<DEVICE.Device>;
waylineOptions: any[]; };
tourismOptions: any[];
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => { const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const { const { updateModalVisible, onVisibleChange, onSubmit, values } = props;
onSubmit,
onVisibleChange,
updateModalVisible,
values,
waylineOptions,
tourismOptions,
} = props;
useEffect(() => {
console.log('当前航线选项:', waylineOptions);
console.log('当前表单值:', values);
}, [waylineOptions, values]);
return ( return (
<ModalForm <ModalForm
title="修改设备" title="修改设备"
width="800px"
visible={updateModalVisible} visible={updateModalVisible}
onVisibleChange={onVisibleChange} onVisibleChange={onVisibleChange}
initialValues={{ modalProps={{ destroyOnClose: true }}
...values,
waylineId: values?.waylineId?.toString(), // 确保 waylineId 是字符串
}}
onFinish={onSubmit} onFinish={onSubmit}
modalProps={{ initialValues={values}
destroyOnClose: true,
forceRender: true,
}}
> >
<ProForm.Group> <ProForm.Group>
<ProFormSelect
name="waylineId"
label="航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
showSearch: true,
loading: !waylineOptions?.length,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
}}
/>
<ProFormText <ProFormText
disabled rules={[{ required: true, message: '设备序列号不能为空' }]}
width="md" width="md"
name="deviceSn" name="deviceSn"
label="设备序列号" label="设备序列号"
@@ -72,33 +56,21 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
name="deviceName" name="deviceName"
label="设备名称" label="设备名称"
/> />
</ProForm.Group>
<ProForm.Group>
<ProFormText <ProFormText
rules={[{ required: true, message: '设备昵称不能为空' }]}
width="md" width="md"
name="nickname" name="nickname"
label="昵称" label="设备昵称"
/> />
<ProFormSelect
rules={[{ required: true, message: '工作区不能为空' }]}
width="md"
name="workspaceId"
label="工作区"
options={[
{ label: '工作区1', value: '1' },
{ label: '工作区2', value: '2' },
]}
/>
</ProForm.Group>
<ProForm.Group>
<ProFormSelect <ProFormSelect
rules={[{ required: true, message: '设备类型不能为空' }]} rules={[{ required: true, message: '设备类型不能为空' }]}
width="md" width="md"
name="deviceType" name="deviceType"
label="设备类型" label="设备类型"
options={[ options={[
{ label: '类型1', value: 0 }, { label: '机场', value: DEVICE_TYPE.DOCK },
{ label: '类型2', value: 1 }, { label: '无人机', value: DEVICE_TYPE.DRONE },
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
]} ]}
/> />
<ProFormText <ProFormText
@@ -106,12 +78,12 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
name="firmwareVersion" name="firmwareVersion"
label="固件版本" label="固件版本"
/> />
<ProFormTextArea
name="deviceDesc"
label="设备描述"
placeholder="请输入设备描述"
/>
</ProForm.Group> </ProForm.Group>
<ProFormTextArea
name="deviceDesc"
label="设备描述"
placeholder="请输入设备描述"
/>
</ModalForm> </ModalForm>
); );
}; };
@@ -4,7 +4,6 @@ import {
deleteDevice, deleteDevice,
updateDeviceBoundStatus, updateDeviceBoundStatus,
} from '@/services/device/api'; } from '@/services/device/api';
import { request } from 'umi';
import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined } from '@ant-design/icons'; import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { import {
@@ -17,27 +16,17 @@ import {
ProTable, ProTable,
QueryFilter, QueryFilter,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Button, message, Popconfirm, Typography, Space, Switch, Upload } from 'antd'; import { Button, message, Space, Switch, Upload } from 'antd';
import type { RcFile } from 'antd/lib/upload'; import React, { useRef, useState } from 'react';
import React, { useRef, useState, useCallback, useEffect } from 'react';
import moment from 'moment'; import moment from 'moment';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
import { getToken } from '@/utils/authority';
const { Link } = Typography;
// 定义常量对象而不是使用命名空间
const DEVICE_TYPE = { const DEVICE_TYPE = {
DOCK: 1, DOCK: 1,
DRONE: 2, DRONE: 2,
REMOTE_CONTROL: 3, REMOTE_CONTROL: 3,
} as const; } as const;
const BOUND_STATUS = {
UNBOUND: 0,
BOUND: 1,
} as const;
const COMPATIBLE_STATUS = { const COMPATIBLE_STATUS = {
INCONSISTENT: 0, INCONSISTENT: 0,
CONSISTENT: 1, CONSISTENT: 1,
@@ -48,9 +37,7 @@ const TableList: React.FC = () => {
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false); const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false); const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>(); const [currentRow, setCurrentRow] = useState<DEVICE.Device>();
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
// 统一的API请求处理函数 // 统一的API请求处理函数
const handleRequest = async ( const handleRequest = async (
@@ -87,34 +74,18 @@ const TableList: React.FC = () => {
} }
}; };
// 获取认证token // 导出处理函数
const getAuthHeader = () => {
// 从sessionStorage中获取token
const token = sessionStorage.getItem('access_token') || localStorage.getItem('access_token');
return token ? `Bearer ${token}` : '';
};
// 打印token信息用于调试
console.log('当前token:', {
sessionToken: sessionStorage.getItem('access_token'),
localToken: localStorage.getItem('access_token'),
authHeader: getAuthHeader()
});
// 修改导出处理函数
const handleExport = () => { const handleExport = () => {
// 创建一个隐藏的表单
const form = document.createElement('form'); const form = document.createElement('form');
form.method = 'POST'; form.method = 'POST';
form.action = '/api-device/device/export'; form.action = '/api-device/device/export';
form.style.display = 'none'; form.style.display = 'none';
// 添加token到请求头
const token = sessionStorage.getItem('access_token'); const token = sessionStorage.getItem('access_token');
if (token) { if (token) {
const tokenInput = document.createElement('input'); const tokenInput = document.createElement('input');
tokenInput.type = 'hidden'; tokenInput.type = 'hidden';
tokenInput.name = '_token'; // 添加一个隐藏字段携带token tokenInput.name = '_token';
tokenInput.value = token; tokenInput.value = token;
form.appendChild(tokenInput); form.appendChild(tokenInput);
} }
@@ -124,70 +95,17 @@ const TableList: React.FC = () => {
document.body.removeChild(form); document.body.removeChild(form);
}; };
// 修改模板下载函数 // 模板下载函数
const handleDownloadTemplate = () => { const handleDownloadTemplate = () => {
// 直接通过链接下载模板
window.location.href = '/api-device/device/template'; window.location.href = '/api-device/device/template';
}; };
// 重写获取航线数据的函数 // 表格列定义
const loadWaylineOptions = async () => { const columns: ProColumns<DEVICE.Device>[] = [
try {
const result = await wayline({
current: 1,
pageSize: 999 // 获取更多数据
});
if (result?.data) {
const options = result.data.map((item: any) => ({
label: item.name || item.waylineId,
value: item.waylineId
}));
setWaylineOptions(options);
console.log('加载的航线选项:', options);
}
} catch (error) {
console.error('加载航线失败:', error);
message.error('获取航线列表失败');
}
};
// 组件挂载时加载数据
useEffect(() => {
loadWaylineOptions();
}, []);
// 添加操作处理函数
const handleTableAction = async (
action: 'add' | 'edit' | 'delete',
record?: ORDERS.Qrcode,
values?: any
) => {
try {
if (action === 'add') {
await addDevice(values);
message.success('添加成功');
} else if (action === 'edit') {
await updateDevice({ ...values, id: record?.id });
message.success('修改成功');
} else if (action === 'delete') {
await deleteDevice({ id: record?.id });
message.success('删除成功');
}
actionRef.current?.reload();
return true;
} catch (error) {
console.error('操作失败:', error);
message.error('操作失败');
return false;
}
};
// 修改列定义,确保操作列正确显示
const columns: ProColumns<ORDERS.Qrcode>[] = [
{ {
dataIndex: 'index', dataIndex: 'index',
valueType: 'indexBorder', valueType: 'indexBorder',
width: 48,
}, },
{ {
title: '设备序列号', title: '设备序列号',
@@ -254,14 +172,14 @@ const TableList: React.FC = () => {
title: '操作', title: '操作',
dataIndex: 'option', dataIndex: 'option',
valueType: 'option', valueType: 'option',
fixed: 'right',
width: 120,
render: (_, record) => [ render: (_, record) => [
<a <a
key="edit" key="edit"
onClick={() => { onClick={() => {
setCurrentRow(record); setCurrentRow(record);
handleUpdateModalVisible(true); handleUpdateModalVisible(true);
// 立即加载航线数据
loadWaylineOptions();
}} }}
> >
修改 修改
@@ -269,7 +187,15 @@ const TableList: React.FC = () => {
<a <a
key="delete" key="delete"
onClick={() => { onClick={() => {
handleTableAction('delete', record); handleRequest(
() => deleteDevice(record.id),
'正在删除',
'删除成功'
).then((success) => {
if (success && actionRef.current) {
actionRef.current.reload();
}
});
}} }}
> >
删除 删除
@@ -310,14 +236,6 @@ const TableList: React.FC = () => {
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL }, { label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
]} ]}
/> />
<ProFormSelect
width="md"
name="subType"
label="设备子类型"
options={[
// 根据实际需求添加子类型选项
]}
/>
<ProFormText <ProFormText
width="md" width="md"
name="firmwareVersion" name="firmwareVersion"
@@ -328,21 +246,6 @@ const TableList: React.FC = () => {
label="设备描述" label="设备描述"
placeholder="请输入设备描述" placeholder="请输入设备描述"
/> />
<ProFormSelect
width="md"
name="waylineId"
label="航线"
placeholder="请选择航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
loading: !waylineOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: waylineOptions.length === 0 ? '暂无数据' : undefined,
}}
/>
</ProForm.Group> </ProForm.Group>
); );
@@ -351,7 +254,6 @@ const TableList: React.FC = () => {
<QueryFilter <QueryFilter
defaultCollapsed defaultCollapsed
split split
className="query-filter"
onFinish={async (values) => setSearchParams(values)} onFinish={async (values) => setSearchParams(values)}
> >
<ProFormSelect <ProFormSelect
@@ -363,9 +265,10 @@ const TableList: React.FC = () => {
nickname: '昵称', nickname: '昵称',
}} }}
/> />
<ProFormText name="searchValue" /> <ProFormText name="searchValue" placeholder="请输入关键字" />
</QueryFilter> </QueryFilter>
<ProTable<ORDERS.Qrcode>
<ProTable<DEVICE.Device>
rowKey="deviceSn" rowKey="deviceSn"
headerTitle="设备管理" headerTitle="设备管理"
actionRef={actionRef} actionRef={actionRef}
@@ -378,16 +281,10 @@ const TableList: React.FC = () => {
showQuickJumper: true, showQuickJumper: true,
}} }}
toolBarRender={() => [ toolBarRender={() => [
<Button <Button key="template" onClick={handleDownloadTemplate}>
key="template"
onClick={handleDownloadTemplate}
>
<DownloadOutlined /> 下载模板 <DownloadOutlined /> 下载模板
</Button>, </Button>,
<Button <Button key="export" onClick={handleExport}>
key="export"
onClick={handleExport}
>
<ExportOutlined /> 导出 <ExportOutlined /> 导出
</Button>, </Button>,
<Upload <Upload
@@ -398,9 +295,6 @@ const TableList: React.FC = () => {
action="/api-device/device/import" action="/api-device/device/import"
showUploadList={false} showUploadList={false}
onChange={(info) => { onChange={(info) => {
if (info.file.status === 'uploading') {
message.loading('正在导入...');
}
if (info.file.status === 'done') { if (info.file.status === 'done') {
if (info.file.response.resp_code === 0) { if (info.file.response.resp_code === 0) {
message.success('导入成功'); message.success('导入成功');
@@ -417,76 +311,52 @@ const TableList: React.FC = () => {
<ImportOutlined /> 导入 <ImportOutlined /> 导入
</Button> </Button>
</Upload>, </Upload>,
<Button <Button type="primary" onClick={() => handleModalVisible(true)}>
type="primary"
key="add"
onClick={() => {
handleModalVisible(true);
// 打开新增modal时加载航线数据
loadWaylineOptions();
}}
>
<PlusOutlined /> 新增 <PlusOutlined /> 新增
</Button>, </Button>,
]} ]}
/> />
<ModalForm
title="新增设备"
visible={createModalVisible}
onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true }}
onFinish={async (values) => {
const success = await handleRequest(
() => saveOrUpdateDevice(values),
'正在添加',
'添加成功'
);
if (success) {
handleModalVisible(false);
actionRef.current?.reload();
}
return success;
}}
>
{renderModalContent()}
</ModalForm>
{updateModalVisible && ( {updateModalVisible && (
<UpdateForm <UpdateForm
onSubmit={async (values) => { onSubmit={async (values) => {
const success = await handleTableAction('edit', currentRow, values); const success = await handleRequest(
() => saveOrUpdateDevice({ ...values, id: currentRow?.id }),
'正在更新',
'更新成功'
);
if (success) { if (success) {
handleUpdateModalVisible(false); handleUpdateModalVisible(false);
setCurrentRow(undefined); setCurrentRow(undefined);
actionRef.current?.reload();
} }
}} }}
onVisibleChange={(visible) => { onVisibleChange={handleUpdateModalVisible}
if (!visible) {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
}
}}
updateModalVisible={updateModalVisible} updateModalVisible={updateModalVisible}
values={currentRow} values={currentRow}
waylineOptions={waylineOptions}
tourismOptions={tourismOptions}
/> />
)} )}
{createModalVisible && (
<ModalForm
title="新增二维码"
visible={createModalVisible}
onVisibleChange={(visible) => {
if (visible) {
loadWaylineOptions();
}
handleModalVisible(visible);
}}
modalProps={{ destroyOnClose: true }}
onFinish={async (values) => {
const success = await handleTableAction('add', undefined, values);
if (success) {
handleModalVisible(false);
}
}}
>
<ProForm.Group>
<ProFormSelect
width="md"
name="waylineId"
label="航线"
placeholder="请选择航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
}}
/>
{renderModalContent()}
</ProForm.Group>
</ModalForm>
)}
</PageContainer> </PageContainer>
); );
}; };
@@ -7,23 +7,27 @@ import {
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { STATUS_OPTIONS } from '../index'; import { STATUS_OPTIONS } from '../index';
interface UpdateFormProps { export type UpdateFormProps = {
onSubmit: (values: any) => Promise<void>; onSubmit: (values: ORDERS.Qrcode) => Promise<void>;
onVisibleChange: (visible: boolean) => void; onVisibleChange: (visible: boolean) => void;
updateModalVisible: boolean; updateModalVisible: boolean;
values?: ORDERS.Qrcode; values: Partial<ORDERS.Qrcode>;
waylineOptions: any[]; // 从父组件接收航线选项 waylineOptions: any[];
tourismOptions: any[]; // 从父组件接收景区选项 tourismOptions: any[];
} deviceOptions: any[]; // 添加设备选项属性
};
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const {
updateModalVisible,
onVisibleChange,
onSubmit,
values,
waylineOptions,
tourismOptions,
deviceOptions, // 解构设备选项
} = props;
const UpdateForm: React.FC<UpdateFormProps> = ({
onSubmit,
onVisibleChange,
updateModalVisible,
values,
waylineOptions,
tourismOptions,
}) => {
useEffect(() => { useEffect(() => {
console.log('UpdateForm values:', values); console.log('UpdateForm values:', values);
console.log('UpdateForm tourismOptions:', tourismOptions); console.log('UpdateForm tourismOptions:', tourismOptions);
@@ -36,23 +40,17 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
visible={updateModalVisible} visible={updateModalVisible}
onVisibleChange={onVisibleChange} onVisibleChange={onVisibleChange}
modalProps={{ destroyOnClose: true }} modalProps={{ destroyOnClose: true }}
initialValues={{
...values,
tourismId: Number(values?.tourismId),
waylineId: values?.waylineId,
}}
onFinish={onSubmit} onFinish={onSubmit}
initialValues={values}
> >
<ProForm.Group> <ProForm.Group>
<ProFormSelect <ProFormSelect
width="md" width="md"
name="waylineId" name="waylineId"
label="航线" label="航线"
placeholder="请选择航线"
options={waylineOptions} options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]} rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{ fieldProps={{
loading: !waylineOptions.length,
showSearch: true, showSearch: true,
filterOption: (input, option) => filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()), (option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
@@ -62,7 +60,6 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
width="md" width="md"
name="tourismId" name="tourismId"
label="景区" label="景区"
placeholder="请选择景区"
options={tourismOptions} options={tourismOptions}
rules={[{ required: true, message: '请选择景区' }]} rules={[{ required: true, message: '请选择景区' }]}
fieldProps={{ fieldProps={{
@@ -70,20 +67,33 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
showSearch: true, showSearch: true,
filterOption: (input, option) => filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()), (option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
}} }}
/> />
<ProFormText <ProFormText
width="md" width="md"
name="price" name="price"
label="景点打卡价格" label="景点打卡价格"
placeholder="输入价格(单位:分)" rules={[{ required: true, message: '价格不能为空' }]}
rules={[{ required: true, message: '价格不为空' }]} />
<ProFormSelect
width="md"
name="deviceSn"
label="设备编号"
options={deviceOptions}
rules={[{ required: true, message: '设备不能为空' }]}
fieldProps={{
loading: !deviceOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: deviceOptions.length === 0 ? '暂无设备数据' : undefined,
}}
/> />
<ProFormSelect <ProFormSelect
width="md" width="md"
name="status" name="status"
label="状态" label="状态"
placeholder="请选择状态"
options={STATUS_OPTIONS} options={STATUS_OPTIONS}
rules={[{ required: true, message: '请选择状态' }]} rules={[{ required: true, message: '请选择状态' }]}
/> />
@@ -1,4 +1,4 @@
import { deleteQrcode, qrcode, saveOrUpdateQrcode, tourism } from '@/services/orders/api'; import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList } from '@/services/orders/api';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { import {
@@ -13,7 +13,7 @@ import {
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd'; import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
import React, { useRef, useState, useCallback, useEffect } from 'react'; import React, { useRef, useState, useCallback, useEffect } from 'react';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
import { wayline } from '@/services/device/api'; import { wayline, device } from '@/services/device/api';
const { Link } = Typography; const { Link } = Typography;
@@ -22,13 +22,6 @@ export const STATUS_OPTIONS = [
{ label: '未启用', value: 1 }, { label: '未启用', value: 1 },
] as const; ] as const;
export const TOURISM_OPTIONS = [
{ label: '北塘古镇', value: 33 },
{ label: '海丝首港', value: 32 },
{ label: '武汉东湖牡丹园', value: 35 },
{ label: '武汉东湖樱花园', value: 36 },
] as const;
export const DEVICE_OPTIONS = [ export const DEVICE_OPTIONS = [
{ label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' }, { label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' },
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' }, { label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
@@ -106,6 +99,7 @@ const TableList: React.FC = () => {
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>(); const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
const [waylineOptions, setWaylineOptions] = useState<any[]>([]); const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
const [tourismOptions, setTourismOptions] = useState<any[]>([]); const [tourismOptions, setTourismOptions] = useState<any[]>([]);
const [deviceOptions, setDeviceOptions] = useState<any[]>([]);
const formRef = useRef(); const formRef = useRef();
const handleTableAction = useCallback(async ( const handleTableAction = useCallback(async (
@@ -139,14 +133,14 @@ const TableList: React.FC = () => {
const fetchTourismList = useCallback(async () => { const fetchTourismList = useCallback(async () => {
try { try {
const result = await tourism({ const result = await getTourismList({
limit: 100,
page: 1, page: 1,
limit: 100,
}); });
if (result.data) { if (result?.data) {
const options = result.data.map(item => ({ const options = result.data.map(item => ({
label: item.tourismName, label: item.tourismName || item.name,
value: item.id, value: item.id,
info: item info: item
})); }));
@@ -172,10 +166,31 @@ const TableList: React.FC = () => {
} }
}, []); }, []);
const fetchDeviceList = useCallback(async () => {
try {
const result = await device({
current: 1,
pageSize: 100,
});
if (result?.data) {
const options = result.data.map((item: DEVICE.Device) => ({
label: `${item.deviceName}(${item.deviceSn})`,
value: item.deviceSn,
info: item
}));
setDeviceOptions(options);
}
} catch (error) {
message.error('获取设备列表失败');
}
}, []);
useEffect(() => { useEffect(() => {
fetchTourismList(); fetchTourismList();
fetchWaylineOptions(); fetchWaylineOptions();
}, [fetchTourismList, fetchWaylineOptions]); fetchDeviceList();
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList]);
const columns: ProColumns<ORDERS.Qrcode>[] = [ const columns: ProColumns<ORDERS.Qrcode>[] = [
{ {
@@ -289,7 +304,13 @@ const TableList: React.FC = () => {
label="景区" label="景区"
placeholder="请选择景区" placeholder="请选择景区"
options={tourismOptions} options={tourismOptions}
showSearch fieldProps={{
loading: !tourismOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
}}
/> />
<ProFormSelect <ProFormSelect
name="waylineId" name="waylineId"
@@ -332,9 +353,9 @@ const TableList: React.FC = () => {
visible={createModalVisible} visible={createModalVisible}
onVisibleChange={(visible) => { onVisibleChange={(visible) => {
handleModalVisible(visible); handleModalVisible(visible);
if (!visible) { if (visible) {
setWaylineOptions([]); fetchDeviceList();
setTourismOptions([]); fetchTourismList();
} }
}} }}
modalProps={{ destroyOnClose: true }} modalProps={{ destroyOnClose: true }}
@@ -367,6 +388,7 @@ const TableList: React.FC = () => {
showSearch: true, showSearch: true,
filterOption: (input, option) => filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()), (option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
}} }}
/> />
<ProFormText <ProFormText
@@ -380,9 +402,16 @@ const TableList: React.FC = () => {
width="md" width="md"
name="deviceSn" name="deviceSn"
label="设备编号" label="设备编号"
placeholder="请选择设备编号" placeholder="请选择设备"
options={DEVICE_OPTIONS} options={deviceOptions}
rules={[{ required: true, message: '设备不为空' }]} rules={[{ required: true, message: '设备不能为空' }]}
fieldProps={{
loading: !deviceOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: deviceOptions.length === 0 ? '暂无设备数据' : undefined,
}}
/> />
<ProFormSelect <ProFormSelect
width="md" width="md"
@@ -397,22 +426,23 @@ const TableList: React.FC = () => {
</ModalForm> </ModalForm>
<UpdateForm <UpdateForm
onSubmit={async (values) => { onSubmit={async (values) => {
console.log('提交的修改值:', values);
return handleTableAction('edit', currentRow, values); return handleTableAction('edit', currentRow, values);
}} }}
onVisibleChange={(visible) => { onVisibleChange={(visible) => {
console.log('修改弹窗可见性变化:', visible);
handleUpdateModalVisible(visible); handleUpdateModalVisible(visible);
if (visible) {
fetchDeviceList();
fetchTourismList();
}
if (!visible) { if (!visible) {
setCurrentRow(undefined); setCurrentRow(undefined);
setWaylineOptions([]);
setTourismOptions([]);
} }
}} }}
updateModalVisible={updateModalVisible} updateModalVisible={updateModalVisible}
values={currentRow} values={currentRow}
waylineOptions={waylineOptions} waylineOptions={waylineOptions}
tourismOptions={tourismOptions} tourismOptions={tourismOptions}
deviceOptions={deviceOptions}
/> />
</PageContainer> </PageContainer>
); );
@@ -8,10 +8,8 @@ import {
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Button, Upload, Image, message, Form } from 'antd'; import { Button, Upload, Image, message, Form } from 'antd';
import type { RcFile } from 'antd/lib/upload'; import type { RcFile } from 'antd/lib/upload';
import React, { useState, useEffect, useCallback } from 'react'; import React, { useState } from 'react';
import { TOURISM_OPTIONS, TYPE_OPTIONS } from '../constants'; import { TYPE_OPTIONS } from '../constants';
import styles from '../index.less';
import { tourism } from '@/services/orders/api';
interface UpdateFormProps { interface UpdateFormProps {
onSubmit: (values: any) => Promise<void>; onSubmit: (values: any) => Promise<void>;
@@ -57,7 +55,6 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
onVisibleChange={props.onVisibleChange} onVisibleChange={props.onVisibleChange}
modalProps={{ destroyOnClose: true }} modalProps={{ destroyOnClose: true }}
onFinish={async (values) => { onFinish={async (values) => {
// 如果上传了新图片,使用新的图片路径
if (imagePath) { if (imagePath) {
values.imageUrl = imagePath; values.imageUrl = imagePath;
} }
@@ -13,3 +13,49 @@
.button_view { .button_view {
margin-top: 16px; margin-top: 16px;
} }
.groupRow {
background-color: #fafafa;
font-weight: bold;
&:hover {
background-color: #f5f5f5 !important;
}
td {
padding: 16px 8px !important;
}
}
// 优化表格样式
:global {
.ant-table-row-expand-icon-cell {
width: 48px;
}
.ant-table-expanded-row {
background-color: #fff;
}
.ant-table-tbody {
> tr.ant-table-row:hover {
> td {
background-color: #f0f5ff;
}
}
}
// 分组标题样式
.group-title {
font-size: 16px;
color: @heading-color;
margin: 0;
.group-count {
font-size: 14px;
color: @text-color-secondary;
margin-left: 8px;
font-weight: normal;
}
}
}
@@ -11,7 +11,7 @@ import {
ProTable, ProTable,
QueryFilter, QueryFilter,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd'; import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload, Spin } from 'antd';
import type { RcFile } from 'antd/lib/upload'; import type { RcFile } from 'antd/lib/upload';
import React, { useRef, useState, useCallback, useEffect } from 'react'; import React, { useRef, useState, useCallback, useEffect } from 'react';
import { STATUS_CONFIG, TYPE_CONFIG } from './constants'; import { STATUS_CONFIG, TYPE_CONFIG } from './constants';
@@ -218,34 +218,110 @@ const TableList: React.FC = () => {
} }
}, [createImagePath]); }, [createImagePath]);
// 修改请求处理函数
const fetchTableData = async (params: any) => {
try {
// 先获取景区列表
const tourismResult = await tourism({
page: params.current || 1,
limit: params.pageSize || 10,
});
if (!tourismResult?.data) {
return {
data: [],
success: true,
total: 0,
};
}
// 获取所有景区的ID列表
const tourismIds = tourismResult.data.map(item => item.id);
// 获取这些景区的素材数据
const fileResult = await tourismFile({
page: 1,
limit: 1000,
tourismIds: tourismIds.join(','),
});
const fileList = fileResult?.data || [];
// 按景区组织数据
const groupedData = tourismResult.data.map(tourism => {
const tourismFiles = fileList.filter(file => file.tourismId === tourism.id);
return {
id: `tourism-${tourism.id}`,
tourismId: tourism.id,
tourismName: tourism.tourismName,
children: tourismFiles.map(file => ({
...file,
key: file.id,
})),
};
});
return {
data: groupedData,
success: true,
total: tourismResult.total || 0,
};
} catch (error) {
console.error('获取数据失败:', error);
message.error('获取数据失败,请稍后重试');
return {
data: [],
success: false,
total: 0,
};
}
};
const columns: ProColumns<ORDERS.TourismFile>[] = [ const columns: ProColumns<ORDERS.TourismFile>[] = [
{ {
title: '序号', title: '序号',
dataIndex: 'index', dataIndex: 'index',
valueType: 'indexBorder', valueType: 'indexBorder',
width: 48, width: 48,
render: (_, record, index) => {
// 如果是分组行,不显示序号
if (record.children) {
return '';
}
return index + 1;
},
}, },
{ {
title: '景区名称', title: '景区名称',
dataIndex: 'tourismId', dataIndex: 'tourismId',
ellipsis: true, ellipsis: true,
render: (_, record) => { render: (_, record) => {
const option = tourismOptions.find(item => item.value === record.tourismId); if (record.children) {
return option?.label || '-'; return <strong>{record.tourismName}</strong>;
}
// 对于子项,使用父级的景区名称
const parentTourism = tourismOptions.find(item => item.value === record.tourismId);
return parentTourism?.label || record.tourismName || '-';
}, },
}, },
{ {
title: '素材预览', title: '图片',
dataIndex: 'imageUrl', dataIndex: 'imageUrl',
search: false,
width: 120, width: 120,
render: (imageUrl) => ( render: (_, record) => {
<Image if (record.children) {
src={imageUrl as string} return null;
width={80} }
height={80} return record.imageUrl ? (
style={{ objectFit: 'cover' }} <Image
/> src={record.imageUrl}
), alt="素材图片"
width={80}
height={80}
/>
) : null;
},
}, },
{ {
title: '页面链接', title: '页面链接',
@@ -346,18 +422,34 @@ const TableList: React.FC = () => {
</QueryFilter> </QueryFilter>
<ProTable<ORDERS.TourismFile> <ProTable<ORDERS.TourismFile>
rowKey="id" rowKey={(record) => record.id || `tourism-${record.tourismId}`}
headerTitle="素材列表" headerTitle="素材列表"
request={tourismFile}
actionRef={actionRef} actionRef={actionRef}
request={fetchTableData}
columns={columns} columns={columns}
search={false} search={false}
params={params} params={params}
pagination={{ pagination={{
showSizeChanger: true, showSizeChanger: true,
showQuickJumper: true, showQuickJumper: true,
pageSize: 10,
defaultPageSize: 10, defaultPageSize: 10,
pageSizeOptions: ['10', '20', '50'], showTotal: (total) => `共 ${total} 个景区`,
}}
expandable={{
defaultExpandAllRows: true,
}}
rowClassName={(record) => {
return record.children ? styles.groupRow : '';
}}
// 添加表格滚动配置
scroll={{ x: 'max-content' }}
// 添加表格大小设置
size="middle"
// 添加表格工具栏配置
toolbar={{
title: '素材列表',
tooltip: '按景区展示所有素材信息',
}} }}
toolBarRender={() => [ toolBarRender={() => [
<Button <Button
@@ -1,2 +1,14 @@
@import (reference) '~antd/es/style/themes/index'; @import (reference) '~antd/es/style/themes/index';
.highlight {
background-color: #ffd591;
}
.ant-pro-table-list-toolbar-container {
padding-bottom: 16px;
}
.ant-pro-query-filter {
margin-bottom: 16px;
}
@@ -1,158 +1,129 @@
import { appAll, deleteMenus, menu, menuOnes, saveOrUpdateMenus } from '@/services/system/api'; import { appAll, deleteMenus, menu, menuOnes, saveOrUpdateMenus } from '@/services/system/api';
import { treeify } from '@/util/treeify'; import { treeify } from '@/util/treeify';
import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined } from '@ant-design/icons'; import { FolderOpenOutlined, MenuOutlined, PlusOutlined, ProfileOutlined, ReloadOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProFormDigit } from '@ant-design/pro-components';
import { import {
ProFormDigit,
ProFormRadio, ProFormRadio,
ProFormTreeSelect, ProFormTreeSelect,
ProForm, ProForm,
ProFormSelect, ProFormSelect,
} from '@ant-design/pro-components';
import {
PageContainer, PageContainer,
ProFormText, ProFormText,
ProTable, ProTable,
QueryFilter, QueryFilter,
ModalForm, ModalForm,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Button, Space, Tag, Typography, message, Popconfirm } from 'antd'; import { Button, Space, Tag, Typography, message, Popconfirm, Tooltip } from 'antd';
import React, { useRef, useEffect, useState } from 'react'; import React, { useRef, useEffect, useState, useCallback } from 'react';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
const { Link } = Typography; const { Link } = Typography;
const handleAdd = async (fields: SYSTEM.Menu) => { const TableList: React.FC = () => {
const hide = message.loading('正在添加'); // 状态定义
try { const [loading, setLoading] = useState(false);
const result = await saveOrUpdateMenus({ ...fields });
hide();
if (result.resp_code === 0) {
message.success('添加菜单成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('添加菜单失败');
return false;
}
};
const handleEdit = async (fields: SYSTEM.Menu) => {
const hide = message.loading('正在更新');
try {
const result = await saveOrUpdateMenus({ ...fields });
hide();
if (result.resp_code === 0) {
message.success('修改菜单成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('修改菜单失败');
return false;
}
};
const handleDelete = async (sysUser: SYSTEM.Menu) => {
const hide = message.loading('正在删除');
try {
const result = await deleteMenus(sysUser.id);
hide();
if (result.resp_code === 0) {
message.success('删除菜单成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('删除菜单失败');
return false;
}
};
const Generator: React.FC = () => {
const [tenantId, setTenantId] = useState<string>(); const [tenantId, setTenantId] = useState<string>();
const [keyword, setKeyword] = useState<string>(); const [keyword, setKeyword] = useState<string>();
const [apps, setApps] = useState<SYSTEM.App[]>([]); const [apps, setApps] = useState<SYSTEM.App[]>([]);
const actionRef = useRef<ActionType>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false); const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false); const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>(); const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>();
const [data, setData] = useState<SYSTEM.Menu[]>(); const [data, setData] = useState<SYSTEM.Menu[]>();
const [keys, setKeys] = useState<React.Key[]>([]); const [keys, setKeys] = useState<React.Key[]>([]);
const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]); const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
const actionRef = useRef<ActionType>();
const query = async (clientId: string) => { // 获取菜单数据
const menus = await menu(clientId); const fetchMenuData = useCallback(async (clientId: string) => {
const treeData = treeify(menus, {}); try {
menus.forEach((node) => { setLoading(true);
if (node.children && node.children.length === 0) delete node.children; const menus = await menu(clientId);
}); const treeData = treeify(menus, {});
setKeys(menus.map((m) => m.id)); menus.forEach((node) => {
setData(treeData); if (node.children?.length === 0) delete node.children;
}; });
setKeys(menus.map((m) => m.id));
// useEffect(() => { setData(treeData);
} catch (error) {
// query({ tenantId: 'webApp' }); message.error('获取菜单数据失败');
// }, []); } finally {
setLoading(false);
useEffect(() => { }
(async () => {
const appData = (await appAll()) || [];
setApps(appData);
if (appData.length > 0) {
const clientId = appData[0].clientId;
setTenantId(clientId);
query(clientId);
}
})();
}, []); }, []);
// 初始化加载应用数据
useEffect(() => {
const loadApps = async () => {
try {
const appData = await appAll();
if (appData?.length > 0) {
setApps(appData);
const defaultClientId = appData[0].clientId;
setTenantId(defaultClientId);
fetchMenuData(defaultClientId);
}
} catch (error) {
message.error('获取应用列表失败');
}
};
loadApps();
}, [fetchMenuData]);
// 处理菜单操作
const handleMenuOperation = async (
operation: 'add' | 'edit' | 'delete',
values?: any,
menuItem?: SYSTEM.Menu
) => {
const operationMap = {
add: { api: saveOrUpdateMenus, successMsg: '添加菜单成功', errorMsg: '添加菜单失败' },
edit: { api: saveOrUpdateMenus, successMsg: '修改菜单成功', errorMsg: '修改菜单失败' },
delete: { api: deleteMenus, successMsg: '删除菜单成功', errorMsg: '删除菜单失败' },
};
const hide = message.loading(`正在${operation === 'delete' ? '删除' : '保存'}...`);
try {
const result = await operationMap[operation].api(
operation === 'delete' ? menuItem?.id : { ...menuItem, ...values }
);
hide();
if (result.resp_code === 0) {
message.success(operationMap[operation].successMsg);
actionRef.current?.reload();
return true;
}
message.error(result.resp_msg);
return false;
} catch (error) {
hide();
message.error(operationMap[operation].errorMsg);
return false;
}
};
// 表格列定义
const columns: ProColumns<SYSTEM.Menu>[] = [ const columns: ProColumns<SYSTEM.Menu>[] = [
{ {
title: '菜单名称', title: '菜单名称',
key: 'name', key: 'name',
width: 120, width: 120,
onCell: (record) => { className: (record) => (keyword && record.name?.includes(keyword) ? 'highlight' : ''),
if (keyword && record.name?.includes(keyword)) return { className: 'hightligh' }; render: (_, entity) => (
return {}; <Space size="small">
}, {entity.type === 1 ? (
render(dom, entity) { entity.url?.startsWith('javascript') ? (
if (entity.type === 1) { <FolderOpenOutlined />
if (entity.url?.startsWith('javascript')) { ) : (
return ( <MenuOutlined />
<Space size="small"> )
<FolderOpenOutlined /> ) : (
{entity.name} <ProfileOutlined />
</Space> )}
); <span>{entity.name}</span>
} else { </Space>
return ( ),
<Space size="small">
<MenuOutlined />
{entity.name}
</Space>
);
}
} else {
return (
<Space size="small">
<ProfileOutlined />
{entity.name}
</Space>
);
}
},
}, },
{ {
title: '菜单url', title: '菜单url',
@@ -203,27 +174,21 @@ const Generator: React.FC = () => {
title: '操作', title: '操作',
key: 'action', key: 'action',
fixed: 'right', fixed: 'right',
width: 80, width: 100,
render: (_, entity) => ( render: (_, entity) => (
<Space> <Space>
<Link <Tooltip title="修改菜单">
onClick={() => { <Link onClick={() => {
setCurrentRow(entity); setCurrentRow(entity);
handleUpdateModalVisible(true); handleUpdateModalVisible(true);
}} }}>
> 修改
修改 </Link>
</Link> </Tooltip>
<Popconfirm <Popconfirm
title={`确认删除菜单[${entity.name}]?`} title={`确认删除菜单[${entity.name}]?`}
onConfirm={async () => { description="删除后不可恢复,请谨慎操作"
const success = await handleDelete(entity); onConfirm={() => handleMenuOperation('delete', undefined, entity)}
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
> >
<Link>删除</Link> <Link>删除</Link>
</Popconfirm> </Popconfirm>
@@ -231,6 +196,7 @@ const Generator: React.FC = () => {
), ),
}, },
]; ];
return ( return (
<PageContainer header={{ subTitle: '维护系统菜单' }}> <PageContainer header={{ subTitle: '维护系统菜单' }}>
<QueryFilter <QueryFilter
@@ -242,7 +208,6 @@ const Generator: React.FC = () => {
setExpandedRowKeys(keys); setExpandedRowKeys(keys);
setKeyword(values.searchValue); setKeyword(values.searchValue);
}} }}
// onReset={() => setParams({})}
> >
<ProFormSelect <ProFormSelect
name="tenantId" name="tenantId"
@@ -250,30 +215,27 @@ const Generator: React.FC = () => {
fieldProps={{ fieldProps={{
value: tenantId, value: tenantId,
allowClear: false, allowClear: false,
onChange: async (values) => { onChange: (value) => {
setTenantId(values); setTenantId(value);
query(values); fetchMenuData(value);
}, },
}} }}
options={apps.map((item) => { options={apps.map((item) => ({
return { label: item.clientId, value: item.clientId }; label: item.clientId,
})} value: item.clientId,
}))}
/>
<ProFormText
name="searchValue"
placeholder="请输入搜索关键词"
/> />
<ProFormText name="searchValue" />
</QueryFilter> </QueryFilter>
<ProTable<SYSTEM.Menu> <ProTable<SYSTEM.Menu>
rowKey="id" rowKey="id"
headerTitle="菜单管理" headerTitle="菜单管理"
actionRef={actionRef} actionRef={actionRef}
request={async () => { loading={loading}
const menus = await menu(params);
const treeData = treeify(menus, {});
menus.forEach((node) => {
if (node.children && node.children.length === 0) delete node.children;
});
setKeys(menus.map((m) => m.id));
setData(treeData);
}}
dataSource={data} dataSource={data}
columns={columns} columns={columns}
search={false} search={false}
@@ -283,45 +245,54 @@ const Generator: React.FC = () => {
onExpandedRowsChange: (expandedRows) => setExpandedRowKeys([...expandedRows]), onExpandedRowsChange: (expandedRows) => setExpandedRowKeys([...expandedRows]),
}} }}
toolBarRender={() => [ toolBarRender={() => [
<> <Button
<Button key="expand"
onClick={() => { onClick={() => setExpandedRowKeys(keys)}
setExpandedRowKeys(keys); >
}} 全部展开
> </Button>,
全部展开 <Button
</Button> key="collapse"
<Button onClick={() => setExpandedRowKeys([])}
onClick={() => { >
setExpandedRowKeys([]); 全部折叠
}} </Button>,
> <Button
全部折叠 key="refresh"
</Button> icon={<ReloadOutlined />}
<Button onClick={() => {
type="primary" if (tenantId) {
onClick={() => { fetchMenuData(tenantId);
handleModalVisible(true); }
}} }}
> >
<PlusOutlined /> 添加 刷新
</Button> </Button>,
</>, <Button
key="add"
type="primary"
onClick={() => handleModalVisible(true)}
>
<PlusOutlined /> 新增
</Button>,
]} ]}
/> />
{/* 新增表单 */}
<ModalForm <ModalForm
title="添加菜单" title="新增菜单"
// layout="horizontal"
visible={createModalVisible} visible={createModalVisible}
onVisibleChange={handleModalVisible} onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true, okText: '保存' }} modalProps={{
destroyOnClose: true,
maskClosable: false,
okText: '保存',
width: 800,
}}
onFinish={async (values) => { onFinish={async (values) => {
const success = await handleAdd(values as SYSTEM.Menu); const success = await handleMenuOperation('add', values);
if (success) { if (success) {
handleModalVisible(false); handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
} }
}} }}
> >
@@ -351,8 +322,6 @@ const Generator: React.FC = () => {
fieldNames: { fieldNames: {
label: 'title', label: 'title',
}, },
// treeCheckable: true,
// showCheckedStrategy: TreeSelect.SHOW_PARENT,
placeholder: '选择上级菜单名', placeholder: '选择上级菜单名',
}} }}
/> />
@@ -438,20 +407,24 @@ const Generator: React.FC = () => {
/> />
</ProForm.Group> </ProForm.Group>
</ModalForm> </ModalForm>
{/* 修改表单 */}
<UpdateForm <UpdateForm
onSubmit={async (values) => { onSubmit={async (values) => {
if (currentRow) { if (currentRow) {
const success = await handleEdit({ ...currentRow, ...values }); const success = await handleMenuOperation('edit', values, currentRow);
if (success) { if (success) {
handleUpdateModalVisible(false); handleUpdateModalVisible(false);
if (actionRef.current) { setCurrentRow(undefined);
actionRef.current.reload();
}
} }
}
}}
onVisibleChange={(visible) => {
handleUpdateModalVisible(visible);
if (!visible) {
setCurrentRow(undefined); setCurrentRow(undefined);
} }
}} }}
onVisibleChange={handleUpdateModalVisible}
updateModalVisible={updateModalVisible} updateModalVisible={updateModalVisible}
values={currentRow} values={currentRow}
/> />
@@ -459,4 +432,4 @@ const Generator: React.FC = () => {
); );
}; };
export default Generator; export default TableList;
@@ -1,50 +1,247 @@
@import (reference) '~antd/es/style/themes/index'; @import '~antd/es/style/themes/default.less';
.container { .container {
position: relative;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100vh; min-height: 100vh;
overflow: auto; background: #f0f2f5;
background: @layout-body-background; overflow: hidden;
&::before {
content: '';
position: absolute;
top: -50%;
right: -50%;
width: 100%;
height: 100%;
background: linear-gradient(45deg, #1890ff20 0%, #722ed120 100%);
transform: rotate(45deg);
z-index: 0;
}
} }
.lang { .timeBox {
width: 100%; position: absolute;
height: 40px; top: 48px;
line-height: 44px; left: 48px;
text-align: right; z-index: 1;
:global(.ant-dropdown-trigger) {
margin-right: 24px; .time {
display: block;
font-size: 48px;
font-weight: 300;
color: @heading-color;
line-height: 1;
margin-bottom: 8px;
}
.date {
font-size: 16px;
color: @text-color-secondary;
} }
} }
.content { .content {
flex: 1; flex: 1;
padding: 32px 0; padding: 32px;
display: flex;
justify-content: flex-end;
align-items: center;
position: relative;
z-index: 1;
} }
@media (min-width: @screen-md-min) { .loginBox {
.container { width: 100%;
background-image: url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg'); max-width: 420px;
background-repeat: no-repeat; margin-right: 10%;
background-position: center 110px; padding: 40px;
background-size: 100%; background: white;
} border-radius: 16px;
box-shadow:
0 4px 6px rgba(0, 0, 0, 0.02),
0 10px 20px rgba(0, 0, 0, 0.04);
transition: transform 0.3s ease;
.content { &:hover {
padding: 32px 0 24px; transform: translateY(-2px);
} }
} }
.icon { .welcome {
margin-left: 8px; text-align: center;
color: rgba(0, 0, 0, 0.2); margin-bottom: 40px;
font-size: 24px;
vertical-align: middle; h2 {
margin-bottom: 8px;
}
}
.errorMessage {
margin-bottom: 24px;
padding: 12px;
background: #fff2f0;
border-radius: 4px;
text-align: center;
}
:global {
.ant-input-affix-wrapper {
border-radius: 8px;
border: 1px solid #e8e8e8;
transition: all 0.3s;
padding: 12px 16px;
&:hover, &:focus {
border-color: @primary-color;
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}
.ant-input {
font-size: 15px;
}
.anticon {
color: @text-color-secondary;
}
}
.ant-form-item {
margin-bottom: 24px;
}
.ant-btn {
height: 48px;
font-size: 16px;
border-radius: 8px;
&.ant-btn-primary {
background: @primary-color;
border: none;
transition: all 0.3s;
&:hover {
background: lighten(@primary-color, 5%);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(24, 144, 255, 0.25);
}
}
}
}
.captchaContainer {
display: flex;
gap: 16px;
align-items: flex-start;
.ant-form-item {
flex: 1;
margin-bottom: 0;
}
}
.captchaImage {
height: 48px;
border-radius: 8px;
overflow: hidden;
cursor: pointer; cursor: pointer;
transition: opacity 0.3s;
&:hover {
opacity: 0.8;
}
img {
height: 100%;
width: auto;
}
}
.loginOptions {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 24px;
}
.forgotPassword {
color: @text-color-secondary;
transition: color 0.3s; transition: color 0.3s;
&:hover { &:hover {
color: @primary-color; color: @primary-color;
} }
} }
// 响应式设计
@media screen and (max-width: @screen-md) {
.timeBox {
position: static;
text-align: center;
padding: 24px 0;
.time {
font-size: 36px;
}
}
.content {
justify-content: center;
padding: 16px;
}
.loginBox {
margin-right: 0;
padding: 24px;
}
}
@media screen and (max-width: @screen-xs) {
.loginBox {
padding: 20px;
}
:global {
.ant-input-affix-wrapper {
padding: 8px 12px;
}
.ant-btn {
height: 40px;
}
}
.captchaImage {
height: 40px;
}
}
// 暗色主题支持
@media (prefers-color-scheme: dark) {
.container {
background: #141414;
&::before {
background: linear-gradient(45deg, #1890ff10 0%, #722ed110 100%);
}
}
.loginBox {
background: #1f1f1f;
box-shadow:
0 4px 6px rgba(0, 0, 0, 0.1),
0 10px 20px rgba(0, 0, 0, 0.2);
}
.errorMessage {
background: #2a1f1f;
}
:global {
.ant-input-affix-wrapper {
background: #141414;
border-color: #434343;
}
}
}
@@ -1,8 +1,8 @@
import Footer from '@/components/Footer'; import Footer from '@/components/Footer';
import { login } from '@/services/login/api'; import { login } from '@/services/login/api';
import { InfoCircleOutlined, LockOutlined, UserOutlined } from '@ant-design/icons'; import { InfoCircleOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
import { LoginForm, ProFormCaptcha, ProFormText } from '@ant-design/pro-components'; import { LoginForm, ProFormCaptcha, ProFormText, ProFormCheckbox } from '@ant-design/pro-components';
import { message, Tooltip } from 'antd'; import { message, Tooltip, Spin } from 'antd';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { FormattedMessage, history, useIntl, useModel } from 'umi'; import { FormattedMessage, history, useIntl, useModel } from 'umi';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@@ -10,87 +10,75 @@ import styles from './index.less';
const Login: React.FC = () => { const Login: React.FC = () => {
const [uuid, setUuid] = useState<string>(uuidv4()); const [uuid, setUuid] = useState<string>(uuidv4());
const [loading, setLoading] = useState<boolean>(false);
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const intl = useIntl(); const intl = useIntl();
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
const userInfo = await initialState?.fetchUserInfo?.(); try {
if (userInfo) { const userInfo = await initialState?.fetchUserInfo?.();
await setInitialState((s) => ({ if (userInfo) {
...s, await setInitialState((s) => ({
currentUser: userInfo, ...s,
})); currentUser: userInfo,
}));
}
} catch (error) {
message.error('获取用户信息失败');
} }
}; };
const handleSubmit = async (values: API.LoginParams) => { const handleSubmit = async (values: API.LoginParams) => {
try { try {
// 登录 setLoading(true);
const msg = await login({ ...values }); const msg = await login({ ...values, deviceId: uuid });
if (msg.resp_code === 0) {
const defaultLoginSuccessMessage = intl.formatMessage({ if (msg.resp_code === 0 && msg.data?.access_token) {
id: 'pages.login.success', sessionStorage.setItem('access_token', msg.data.access_token);
defaultMessage: '登录成功!', message.success('登录成功!');
});
const loginResult = msg.data;
if (loginResult && loginResult.access_token)
sessionStorage.setItem('access_token', loginResult.access_token);
message.success(defaultLoginSuccessMessage);
await fetchUserInfo(); await fetchUserInfo();
/** 此方法会跳转到 redirect 参数所在的位置 */
if (!history) return;
const { query } = history.location; const { query } = history.location;
const { redirect } = query as { redirect: string }; const { redirect } = query as { redirect: string };
history.push(redirect || '/'); history.push(redirect || '/');
return; return;
} }
// 如果失败去设置用户错误信息 message.error(msg.resp_msg || '登录失败');
setUuid(uuidv4());
} catch (error) { } catch (error) {
const defaultLoginFailureMessage = intl.formatMessage({ message.error('登录失败,请重试!');
id: 'pages.login.failure', } finally {
defaultMessage: '登录失败,请重试!', setLoading(false);
});
message.error(defaultLoginFailureMessage);
} }
}; };
const captchaUrl = `/api-uaa/validata/code/${uuid}`;
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div className={styles.content}> <div className={styles.content}>
<LoginForm <Spin spinning={loading}>
logo={<img alt="logo" src="./logo.png" />} <LoginForm
title="microservices-platform" logo={<img alt="logo" src="/logo.png" />}
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })} title="microservices-platform"
initialValues={{ subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })}
autoLogin: true, initialValues={{ autoLogin: true }}
}} onFinish={async (values) => {
onFinish={async (values) => { if (!loading) {
await handleSubmit({ ...values, deviceId: uuid } as API.LoginParams); await handleSubmit(values as API.LoginParams);
}} }
> }}
<> >
<ProFormText <ProFormText
name="username" name="username"
fieldProps={{ fieldProps={{
size: 'large', size: 'large',
prefix: <UserOutlined className={styles.prefixIcon} />, prefix: <UserOutlined className={styles.prefixIcon} />,
}} }}
placeholder={intl.formatMessage({ placeholder="请输入账号"
id: 'pages.login.username.placeholder',
defaultMessage: '账号',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '请输入账号!',
<FormattedMessage
id="pages.login.username.required"
defaultMessage="请输入账号!"
/>
),
}, },
]} ]}
/> />
@@ -100,19 +88,11 @@ const Login: React.FC = () => {
size: 'large', size: 'large',
prefix: <LockOutlined className={styles.prefixIcon} />, prefix: <LockOutlined className={styles.prefixIcon} />,
}} }}
placeholder={intl.formatMessage({ placeholder="请输入密码"
id: 'pages.login.password.placeholder',
defaultMessage: '密码',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '请输入密码!',
<FormattedMessage
id="pages.login.password.required"
defaultMessage="请输入密码!"
/>
),
}, },
]} ]}
/> />
@@ -120,22 +100,19 @@ const Login: React.FC = () => {
name="validCode" name="validCode"
fieldProps={{ fieldProps={{
size: 'large', size: 'large',
prefix: <LockOutlined className={'prefixIcon'} />, prefix: <LockOutlined className={styles.prefixIcon} />,
suffix: (
<Tooltip title="不区分大小写">
<InfoCircleOutlined style={{ color: 'rgba(0,0,0,.45)' }} />
</Tooltip>
),
}} }}
captchaProps={{ captchaProps={{
size: 'large', size: 'large',
style: { padding: '0 2px' },
}} }}
placeholder={'验证码'} placeholder="请输入验证码"
captchaTextRender={() => ( captchaTextRender={() => (
<span onClick={() => setUuid(uuidv4())}> <img
<img src={captchaUrl} alt="验证码" /> src={`/api-uaa/validata/code/${uuid}`}
</span> alt="验证码"
style={{ height: '32px', cursor: 'pointer' }}
onClick={() => setUuid(uuidv4())}
/>
)} )}
rules={[ rules={[
{ {
@@ -143,10 +120,17 @@ const Login: React.FC = () => {
message: '请输入验证码!', message: '请输入验证码!',
}, },
]} ]}
onGetCaptcha={async () => {}}
/> />
</> <div style={{ marginBottom: 24 }}>
</LoginForm> <ProFormCheckbox noStyle name="autoLogin">
自动登录
</ProFormCheckbox>
<a style={{ float: 'right' }} href="/user/forgot-password">
忘记密码
</a>
</div>
</LoginForm>
</Spin>
</div> </div>
<Footer /> <Footer />
</div> </div>
@@ -154,13 +154,14 @@ export async function updateRefund(data: ORDERS.Refund): Promise<API.Result<ORDE
return result; return result;
} }
export async function getTourismList(params?: { pageSize?: number; current?: number }) { /** 获取景区列表 */
return request<API.Response<API.Tourism[]>>('/api-order/tourism', { export async function getTourismList(params: {
page: number;
limit: number;
}) {
return request<API.Response<ORDERS.Tourism[]>>('/api-order/tourism', {
method: 'GET', method: 'GET',
params: { params,
pageSize: params?.pageSize || 100,
current: params?.current || 1,
},
}); });
} }