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:
@@ -1,4 +1,5 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@import '~antd/es/style/themes/default.less';
|
||||
|
||||
.stat {
|
||||
margin-top: @margin-md;
|
||||
@@ -9,3 +10,104 @@
|
||||
.pie {
|
||||
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 { 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 React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { statistic } from '@/services/welcome/api';
|
||||
import { Area, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
UserOutlined,
|
||||
EyeOutlined,
|
||||
TeamOutlined,
|
||||
LineChartOutlined,
|
||||
BarChartOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import styles from './Welcome.less';
|
||||
|
||||
const { Divider } = StatisticCard;
|
||||
|
||||
const Welcome: React.FC = () => {
|
||||
const [responsive, setResponsive] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [statistics, setStatistics] = useState<WELCOME.Statistic>({});
|
||||
const [weeks, setWeeks] = useState<WELCOME.AreaData[]>([]);
|
||||
const [days, setDays] = useState<WELCOME.AreaData[]>([]);
|
||||
@@ -17,15 +25,18 @@ const Welcome: React.FC = () => {
|
||||
const mapWeek = (result: WELCOME.Statistic) => {
|
||||
const { statWeek_items, statWeek_pv, statWeek_uv } = result;
|
||||
if (statWeek_items && statWeek_pv && statWeek_uv) {
|
||||
const weekData = statWeek_pv
|
||||
.map((pv, index) => {
|
||||
return { type: '访问量(PV)', date: statWeek_items[index], value: pv };
|
||||
})
|
||||
.concat(
|
||||
statWeek_uv.map((uv, index) => {
|
||||
return { type: '独立用户(UV)', date: statWeek_items[index], value: uv };
|
||||
}),
|
||||
);
|
||||
const weekData = [
|
||||
...statWeek_pv.map((pv, index) => ({
|
||||
type: '访问量(PV)',
|
||||
date: statWeek_items[index],
|
||||
value: pv,
|
||||
})),
|
||||
...statWeek_uv.map((uv, index) => ({
|
||||
type: '独立用户(UV)',
|
||||
date: statWeek_items[index],
|
||||
value: uv,
|
||||
})),
|
||||
];
|
||||
setWeeks(weekData);
|
||||
}
|
||||
};
|
||||
@@ -33,195 +44,200 @@ const Welcome: React.FC = () => {
|
||||
const mapDay = (result: WELCOME.Statistic) => {
|
||||
const { statDate_items, statDate_pv, statDate_uv } = result;
|
||||
if (statDate_items && statDate_pv && statDate_uv) {
|
||||
const dayData = statDate_pv
|
||||
.map((pv, index) => {
|
||||
return { type: '访问量(PV)', date: statDate_items[index], value: pv };
|
||||
})
|
||||
.concat(
|
||||
statDate_uv.map((uv, index) => {
|
||||
return { type: '独立用户(UV)', date: statDate_items[index], value: uv };
|
||||
}),
|
||||
);
|
||||
const dayData = [
|
||||
...statDate_pv.map((pv, index) => ({
|
||||
type: '访问量(PV)',
|
||||
date: statDate_items[index],
|
||||
value: pv,
|
||||
})),
|
||||
...statDate_uv.map((uv, index) => ({
|
||||
type: '独立用户(UV)',
|
||||
date: statDate_items[index],
|
||||
value: uv,
|
||||
})),
|
||||
];
|
||||
setDays(dayData);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const result = await statistic();
|
||||
if (result) {
|
||||
setStatistics(result);
|
||||
mapWeek(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 (
|
||||
<PageContainer
|
||||
subTitle="前后端分离的微服务架构"
|
||||
tags={
|
||||
<>
|
||||
<Space>
|
||||
<Tag color="blue">简单</Tag>
|
||||
<Tag color="blue">高效</Tag>
|
||||
</>
|
||||
<Tag color="green">高效</Tag>
|
||||
<Tag color="purple">可扩展</Tag>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<RcResizeObserver
|
||||
key="resize-observer"
|
||||
onResize={(offset) => {
|
||||
setResponsive(offset.width < 596);
|
||||
}}
|
||||
onResize={(offset) => setResponsive(offset.width < 596)}
|
||||
>
|
||||
<StatisticCard.Group direction={responsive ? 'column' : 'row'}>
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: (
|
||||
<Space size="small">
|
||||
在线人数<Tag color="#434343">时</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: statistics.currHour_uv,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: (
|
||||
<Space size="small">
|
||||
PV<Tag color="#52c41a">天</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: statistics.currDate_pv,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: (
|
||||
<Space size="small">
|
||||
UV<Tag color="#52c41a">天</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: statistics.currDate_uv,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: (
|
||||
<Space size="small">
|
||||
周访问量<Tag color="#1890ff">周</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: statistics.currWeek_pv,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: (
|
||||
<Space size="small">
|
||||
月访问量<Tag color="#faad14">月</Tag>
|
||||
</Space>
|
||||
),
|
||||
value: statistics.currMonth_pv,
|
||||
}}
|
||||
/>
|
||||
</StatisticCard.Group>
|
||||
<Skeleton loading={loading} active>
|
||||
<StatisticCard.Group direction={responsive ? 'column' : 'row'}>
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: '在线人数',
|
||||
value: statistics.currHour_uv,
|
||||
icon: <UserOutlined />,
|
||||
description: <Tag color="#434343">实时</Tag>,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: '今日PV',
|
||||
value: statistics.currDate_pv,
|
||||
icon: <EyeOutlined />,
|
||||
description: <Tag color="#52c41a">今日</Tag>,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: '今日UV',
|
||||
value: statistics.currDate_uv,
|
||||
icon: <TeamOutlined />,
|
||||
description: <Tag color="#52c41a">今日</Tag>,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: '本周访问',
|
||||
value: statistics.currWeek_pv,
|
||||
icon: <LineChartOutlined />,
|
||||
description: <Tag color="#1890ff">本周</Tag>,
|
||||
}}
|
||||
/>
|
||||
<Divider type={responsive ? 'horizontal' : 'vertical'} />
|
||||
<StatisticCard
|
||||
statistic={{
|
||||
title: '本月访问',
|
||||
value: statistics.currMonth_pv,
|
||||
icon: <BarChartOutlined />,
|
||||
description: <Tag color="#faad14">本月</Tag>,
|
||||
}}
|
||||
/>
|
||||
</StatisticCard.Group>
|
||||
</Skeleton>
|
||||
|
||||
<Card className={styles.chartCard}>
|
||||
<Tabs defaultActiveKey="1">
|
||||
<Tabs.TabPane tab="周流量趋势" key="1">
|
||||
{weeks.length > 0 ? (
|
||||
<Area {...areaConfig} data={weeks} />
|
||||
) : (
|
||||
<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>
|
||||
<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>
|
||||
);
|
||||
};
|
||||
|
||||
+37
-65
@@ -1,67 +1,51 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
} 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;
|
||||
updateModalVisible: boolean;
|
||||
values?: DEVICE.Device;
|
||||
waylineOptions: any[];
|
||||
tourismOptions: any[];
|
||||
}
|
||||
values: Partial<DEVICE.Device>;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const {
|
||||
onSubmit,
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
waylineOptions,
|
||||
tourismOptions,
|
||||
} = props;
|
||||
|
||||
useEffect(() => {
|
||||
console.log('当前航线选项:', waylineOptions);
|
||||
console.log('当前表单值:', values);
|
||||
}, [waylineOptions, values]);
|
||||
const { updateModalVisible, onVisibleChange, onSubmit, values } = props;
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改设备"
|
||||
width="800px"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
initialValues={{
|
||||
...values,
|
||||
waylineId: values?.waylineId?.toString(), // 确保 waylineId 是字符串
|
||||
}}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={onSubmit}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
forceRender: true,
|
||||
}}
|
||||
initialValues={values}
|
||||
>
|
||||
<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
|
||||
disabled
|
||||
rules={[{ required: true, message: '设备序列号不能为空' }]}
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备序列号"
|
||||
@@ -72,33 +56,21 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '设备昵称不能为空' }]}
|
||||
width="md"
|
||||
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
|
||||
rules={[{ required: true, message: '设备类型不能为空' }]}
|
||||
width="md"
|
||||
name="deviceType"
|
||||
label="设备类型"
|
||||
options={[
|
||||
{ label: '类型1', value: 0 },
|
||||
{ label: '类型2', value: 1 },
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
@@ -106,12 +78,12 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
name="firmwareVersion"
|
||||
label="固件版本"
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
<ProFormTextArea
|
||||
name="deviceDesc"
|
||||
label="设备描述"
|
||||
placeholder="请输入设备描述"
|
||||
/>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
deleteDevice,
|
||||
updateDeviceBoundStatus,
|
||||
} from '@/services/device/api';
|
||||
import { request } from 'umi';
|
||||
import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
@@ -17,27 +16,17 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, message, Popconfirm, Typography, Space, Switch, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import { Button, message, Space, Switch, Upload } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import moment from 'moment';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import { getToken } from '@/utils/authority';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 定义常量对象而不是使用命名空间
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const BOUND_STATUS = {
|
||||
UNBOUND: 0,
|
||||
BOUND: 1,
|
||||
} as const;
|
||||
|
||||
const COMPATIBLE_STATUS = {
|
||||
INCONSISTENT: 0,
|
||||
CONSISTENT: 1,
|
||||
@@ -48,9 +37,7 @@ const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
|
||||
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
|
||||
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
||||
const [currentRow, setCurrentRow] = useState<DEVICE.Device>();
|
||||
|
||||
// 统一的API请求处理函数
|
||||
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 form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = '/api-device/device/export';
|
||||
form.style.display = 'none';
|
||||
|
||||
// 添加token到请求头
|
||||
|
||||
const token = sessionStorage.getItem('access_token');
|
||||
if (token) {
|
||||
const tokenInput = document.createElement('input');
|
||||
tokenInput.type = 'hidden';
|
||||
tokenInput.name = '_token'; // 添加一个隐藏字段携带token
|
||||
tokenInput.name = '_token';
|
||||
tokenInput.value = token;
|
||||
form.appendChild(tokenInput);
|
||||
}
|
||||
@@ -124,70 +95,17 @@ const TableList: React.FC = () => {
|
||||
document.body.removeChild(form);
|
||||
};
|
||||
|
||||
// 修改模板下载函数
|
||||
// 模板下载函数
|
||||
const handleDownloadTemplate = () => {
|
||||
// 直接通过链接下载模板
|
||||
window.location.href = '/api-device/device/template';
|
||||
};
|
||||
|
||||
// 重写获取航线数据的函数
|
||||
const loadWaylineOptions = async () => {
|
||||
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>[] = [
|
||||
// 表格列定义
|
||||
const columns: ProColumns<DEVICE.Device>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '设备序列号',
|
||||
@@ -254,14 +172,14 @@ const TableList: React.FC = () => {
|
||||
title: '操作',
|
||||
dataIndex: 'option',
|
||||
valueType: 'option',
|
||||
fixed: 'right',
|
||||
width: 120,
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
handleUpdateModalVisible(true);
|
||||
// 立即加载航线数据
|
||||
loadWaylineOptions();
|
||||
}}
|
||||
>
|
||||
修改
|
||||
@@ -269,7 +187,15 @@ const TableList: React.FC = () => {
|
||||
<a
|
||||
key="delete"
|
||||
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 },
|
||||
]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="subType"
|
||||
label="设备子类型"
|
||||
options={[
|
||||
// 根据实际需求添加子类型选项
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="firmwareVersion"
|
||||
@@ -328,21 +246,6 @@ const TableList: React.FC = () => {
|
||||
label="设备描述"
|
||||
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>
|
||||
);
|
||||
|
||||
@@ -351,7 +254,6 @@ const TableList: React.FC = () => {
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setSearchParams(values)}
|
||||
>
|
||||
<ProFormSelect
|
||||
@@ -363,9 +265,10 @@ const TableList: React.FC = () => {
|
||||
nickname: '昵称',
|
||||
}}
|
||||
/>
|
||||
<ProFormText name="searchValue" />
|
||||
<ProFormText name="searchValue" placeholder="请输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
|
||||
<ProTable<DEVICE.Device>
|
||||
rowKey="deviceSn"
|
||||
headerTitle="设备管理"
|
||||
actionRef={actionRef}
|
||||
@@ -378,16 +281,10 @@ const TableList: React.FC = () => {
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="template"
|
||||
onClick={handleDownloadTemplate}
|
||||
>
|
||||
<Button key="template" onClick={handleDownloadTemplate}>
|
||||
<DownloadOutlined /> 下载模板
|
||||
</Button>,
|
||||
<Button
|
||||
key="export"
|
||||
onClick={handleExport}
|
||||
>
|
||||
<Button key="export" onClick={handleExport}>
|
||||
<ExportOutlined /> 导出
|
||||
</Button>,
|
||||
<Upload
|
||||
@@ -398,9 +295,6 @@ const TableList: React.FC = () => {
|
||||
action="/api-device/device/import"
|
||||
showUploadList={false}
|
||||
onChange={(info) => {
|
||||
if (info.file.status === 'uploading') {
|
||||
message.loading('正在导入...');
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
if (info.file.response.resp_code === 0) {
|
||||
message.success('导入成功');
|
||||
@@ -417,76 +311,52 @@ const TableList: React.FC = () => {
|
||||
<ImportOutlined /> 导入
|
||||
</Button>
|
||||
</Upload>,
|
||||
<Button
|
||||
type="primary"
|
||||
key="add"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
// 打开新增modal时加载航线数据
|
||||
loadWaylineOptions();
|
||||
}}
|
||||
>
|
||||
<Button type="primary" onClick={() => handleModalVisible(true)}>
|
||||
<PlusOutlined /> 新增
|
||||
</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 && (
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleTableAction('edit', currentRow, values);
|
||||
const success = await handleRequest(
|
||||
() => saveOrUpdateDevice({ ...values, id: currentRow?.id }),
|
||||
'正在更新',
|
||||
'更新成功'
|
||||
);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
if (!visible) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
||||
+35
-25
@@ -7,23 +7,27 @@ import {
|
||||
import React, { useEffect } from 'react';
|
||||
import { STATUS_OPTIONS } from '../index';
|
||||
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: any) => Promise<void>;
|
||||
export type UpdateFormProps = {
|
||||
onSubmit: (values: ORDERS.Qrcode) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Qrcode;
|
||||
waylineOptions: any[]; // 从父组件接收航线选项
|
||||
tourismOptions: any[]; // 从父组件接收景区选项
|
||||
}
|
||||
values: Partial<ORDERS.Qrcode>;
|
||||
waylineOptions: 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(() => {
|
||||
console.log('UpdateForm values:', values);
|
||||
console.log('UpdateForm tourismOptions:', tourismOptions);
|
||||
@@ -36,23 +40,17 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
initialValues={{
|
||||
...values,
|
||||
tourismId: Number(values?.tourismId),
|
||||
waylineId: values?.waylineId,
|
||||
}}
|
||||
onFinish={onSubmit}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<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()),
|
||||
@@ -62,7 +60,6 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
rules={[{ required: true, message: '请选择景区' }]}
|
||||
fieldProps={{
|
||||
@@ -70,20 +67,33 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="price"
|
||||
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
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
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 type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import { wayline } from '@/services/device/api';
|
||||
import { wayline, device } from '@/services/device/api';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
@@ -22,13 +22,6 @@ export const STATUS_OPTIONS = [
|
||||
{ label: '未启用', value: 1 },
|
||||
] as const;
|
||||
|
||||
export const TOURISM_OPTIONS = [
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
] as const;
|
||||
|
||||
export const DEVICE_OPTIONS = [
|
||||
{ label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' },
|
||||
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
|
||||
@@ -106,6 +99,7 @@ const TableList: React.FC = () => {
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
|
||||
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
|
||||
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
||||
const [deviceOptions, setDeviceOptions] = useState<any[]>([]);
|
||||
const formRef = useRef();
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
@@ -139,14 +133,14 @@ const TableList: React.FC = () => {
|
||||
|
||||
const fetchTourismList = useCallback(async () => {
|
||||
try {
|
||||
const result = await tourism({
|
||||
limit: 100,
|
||||
const result = await getTourismList({
|
||||
page: 1,
|
||||
limit: 100,
|
||||
});
|
||||
|
||||
if (result.data) {
|
||||
if (result?.data) {
|
||||
const options = result.data.map(item => ({
|
||||
label: item.tourismName,
|
||||
label: item.tourismName || item.name,
|
||||
value: item.id,
|
||||
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(() => {
|
||||
fetchTourismList();
|
||||
fetchWaylineOptions();
|
||||
}, [fetchTourismList, fetchWaylineOptions]);
|
||||
fetchDeviceList();
|
||||
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList]);
|
||||
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
@@ -289,7 +304,13 @@ const TableList: React.FC = () => {
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="waylineId"
|
||||
@@ -332,9 +353,9 @@ const TableList: React.FC = () => {
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
handleModalVisible(visible);
|
||||
if (!visible) {
|
||||
setWaylineOptions([]);
|
||||
setTourismOptions([]);
|
||||
if (visible) {
|
||||
fetchDeviceList();
|
||||
fetchTourismList();
|
||||
}
|
||||
}}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
@@ -367,6 +388,7 @@ const TableList: React.FC = () => {
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormText
|
||||
@@ -380,9 +402,16 @@ const TableList: React.FC = () => {
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
placeholder="请选择设备编号"
|
||||
options={DEVICE_OPTIONS}
|
||||
rules={[{ required: true, message: '设备不为空' }]}
|
||||
placeholder="请选择设备"
|
||||
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
|
||||
width="md"
|
||||
@@ -397,22 +426,23 @@ const TableList: React.FC = () => {
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
console.log('提交的修改值:', values);
|
||||
return handleTableAction('edit', currentRow, values);
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
console.log('修改弹窗可见性变化:', visible);
|
||||
handleUpdateModalVisible(visible);
|
||||
if (visible) {
|
||||
fetchDeviceList();
|
||||
fetchTourismList();
|
||||
}
|
||||
if (!visible) {
|
||||
setCurrentRow(undefined);
|
||||
setWaylineOptions([]);
|
||||
setTourismOptions([]);
|
||||
}
|
||||
}}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
waylineOptions={waylineOptions}
|
||||
tourismOptions={tourismOptions}
|
||||
deviceOptions={deviceOptions}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
+2
-5
@@ -8,10 +8,8 @@ import {
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Upload, Image, message, Form } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { TOURISM_OPTIONS, TYPE_OPTIONS } from '../constants';
|
||||
import styles from '../index.less';
|
||||
import { tourism } from '@/services/orders/api';
|
||||
import React, { useState } from 'react';
|
||||
import { TYPE_OPTIONS } from '../constants';
|
||||
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: any) => Promise<void>;
|
||||
@@ -57,7 +55,6 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
// 如果上传了新图片,使用新的图片路径
|
||||
if (imagePath) {
|
||||
values.imageUrl = imagePath;
|
||||
}
|
||||
|
||||
@@ -13,3 +13,49 @@
|
||||
.button_view {
|
||||
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,
|
||||
QueryFilter,
|
||||
} 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 React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import { STATUS_CONFIG, TYPE_CONFIG } from './constants';
|
||||
@@ -218,34 +218,110 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
}, [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>[] = [
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
render: (_, record, index) => {
|
||||
// 如果是分组行,不显示序号
|
||||
if (record.children) {
|
||||
return '';
|
||||
}
|
||||
return index + 1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '景区名称',
|
||||
dataIndex: 'tourismId',
|
||||
ellipsis: true,
|
||||
render: (_, record) => {
|
||||
const option = tourismOptions.find(item => item.value === record.tourismId);
|
||||
return option?.label || '-';
|
||||
if (record.children) {
|
||||
return <strong>{record.tourismName}</strong>;
|
||||
}
|
||||
// 对于子项,使用父级的景区名称
|
||||
const parentTourism = tourismOptions.find(item => item.value === record.tourismId);
|
||||
return parentTourism?.label || record.tourismName || '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '素材预览',
|
||||
title: '图片',
|
||||
dataIndex: 'imageUrl',
|
||||
search: false,
|
||||
width: 120,
|
||||
render: (imageUrl) => (
|
||||
<Image
|
||||
src={imageUrl as string}
|
||||
width={80}
|
||||
height={80}
|
||||
style={{ objectFit: 'cover' }}
|
||||
/>
|
||||
),
|
||||
render: (_, record) => {
|
||||
if (record.children) {
|
||||
return null;
|
||||
}
|
||||
return record.imageUrl ? (
|
||||
<Image
|
||||
src={record.imageUrl}
|
||||
alt="素材图片"
|
||||
width={80}
|
||||
height={80}
|
||||
/>
|
||||
) : null;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '页面链接',
|
||||
@@ -346,18 +422,34 @@ const TableList: React.FC = () => {
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable<ORDERS.TourismFile>
|
||||
rowKey="id"
|
||||
rowKey={(record) => record.id || `tourism-${record.tourismId}`}
|
||||
headerTitle="素材列表"
|
||||
request={tourismFile}
|
||||
actionRef={actionRef}
|
||||
request={fetchTableData}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
pageSize: 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={() => [
|
||||
<Button
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
@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 { 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 { ProFormDigit } from '@ant-design/pro-components';
|
||||
import {
|
||||
ProFormDigit,
|
||||
ProFormRadio,
|
||||
ProFormTreeSelect,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
ModalForm,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Space, Tag, Typography, message, Popconfirm } from 'antd';
|
||||
import React, { useRef, useEffect, useState } from 'react';
|
||||
import { Button, Space, Tag, Typography, message, Popconfirm, Tooltip } from 'antd';
|
||||
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = 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 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 TableList: React.FC = () => {
|
||||
// 状态定义
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [tenantId, setTenantId] = useState<string>();
|
||||
const [keyword, setKeyword] = useState<string>();
|
||||
const [apps, setApps] = useState<SYSTEM.App[]>([]);
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<SYSTEM.Menu>();
|
||||
const [data, setData] = useState<SYSTEM.Menu[]>();
|
||||
const [keys, setKeys] = useState<React.Key[]>([]);
|
||||
const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
|
||||
|
||||
const actionRef = useRef<ActionType>();
|
||||
|
||||
const query = async (clientId: string) => {
|
||||
const menus = await menu(clientId);
|
||||
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);
|
||||
};
|
||||
|
||||
// useEffect(() => {
|
||||
|
||||
// query({ tenantId: 'webApp' });
|
||||
// }, []);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const appData = (await appAll()) || [];
|
||||
setApps(appData);
|
||||
if (appData.length > 0) {
|
||||
const clientId = appData[0].clientId;
|
||||
setTenantId(clientId);
|
||||
query(clientId);
|
||||
}
|
||||
})();
|
||||
// 获取菜单数据
|
||||
const fetchMenuData = useCallback(async (clientId: string) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const menus = await menu(clientId);
|
||||
const treeData = treeify(menus, {});
|
||||
menus.forEach((node) => {
|
||||
if (node.children?.length === 0) delete node.children;
|
||||
});
|
||||
setKeys(menus.map((m) => m.id));
|
||||
setData(treeData);
|
||||
} catch (error) {
|
||||
message.error('获取菜单数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 初始化加载应用数据
|
||||
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>[] = [
|
||||
{
|
||||
title: '菜单名称',
|
||||
key: 'name',
|
||||
width: 120,
|
||||
onCell: (record) => {
|
||||
if (keyword && record.name?.includes(keyword)) return { className: 'hightligh' };
|
||||
return {};
|
||||
},
|
||||
render(dom, entity) {
|
||||
if (entity.type === 1) {
|
||||
if (entity.url?.startsWith('javascript')) {
|
||||
return (
|
||||
<Space size="small">
|
||||
<FolderOpenOutlined />
|
||||
{entity.name}
|
||||
</Space>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Space size="small">
|
||||
<MenuOutlined />
|
||||
{entity.name}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return (
|
||||
<Space size="small">
|
||||
<ProfileOutlined />
|
||||
{entity.name}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
},
|
||||
className: (record) => (keyword && record.name?.includes(keyword) ? 'highlight' : ''),
|
||||
render: (_, entity) => (
|
||||
<Space size="small">
|
||||
{entity.type === 1 ? (
|
||||
entity.url?.startsWith('javascript') ? (
|
||||
<FolderOpenOutlined />
|
||||
) : (
|
||||
<MenuOutlined />
|
||||
)
|
||||
) : (
|
||||
<ProfileOutlined />
|
||||
)}
|
||||
<span>{entity.name}</span>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '菜单url',
|
||||
@@ -203,27 +174,21 @@ const Generator: React.FC = () => {
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
width: 80,
|
||||
width: 100,
|
||||
render: (_, entity) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
<Tooltip title="修改菜单">
|
||||
<Link onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
}}>
|
||||
修改
|
||||
</Link>
|
||||
</Tooltip>
|
||||
<Popconfirm
|
||||
title={`确认删除菜单[${entity.name}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
description="删除后不可恢复,请谨慎操作"
|
||||
onConfirm={() => handleMenuOperation('delete', undefined, entity)}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
@@ -231,6 +196,7 @@ const Generator: React.FC = () => {
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '维护系统菜单' }}>
|
||||
<QueryFilter
|
||||
@@ -242,7 +208,6 @@ const Generator: React.FC = () => {
|
||||
setExpandedRowKeys(keys);
|
||||
setKeyword(values.searchValue);
|
||||
}}
|
||||
// onReset={() => setParams({})}
|
||||
>
|
||||
<ProFormSelect
|
||||
name="tenantId"
|
||||
@@ -250,30 +215,27 @@ const Generator: React.FC = () => {
|
||||
fieldProps={{
|
||||
value: tenantId,
|
||||
allowClear: false,
|
||||
onChange: async (values) => {
|
||||
setTenantId(values);
|
||||
query(values);
|
||||
onChange: (value) => {
|
||||
setTenantId(value);
|
||||
fetchMenuData(value);
|
||||
},
|
||||
}}
|
||||
options={apps.map((item) => {
|
||||
return { label: item.clientId, value: item.clientId };
|
||||
})}
|
||||
options={apps.map((item) => ({
|
||||
label: item.clientId,
|
||||
value: item.clientId,
|
||||
}))}
|
||||
/>
|
||||
<ProFormText
|
||||
name="searchValue"
|
||||
placeholder="请输入搜索关键词"
|
||||
/>
|
||||
<ProFormText name="searchValue" />
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable<SYSTEM.Menu>
|
||||
rowKey="id"
|
||||
headerTitle="菜单管理"
|
||||
actionRef={actionRef}
|
||||
request={async () => {
|
||||
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);
|
||||
}}
|
||||
loading={loading}
|
||||
dataSource={data}
|
||||
columns={columns}
|
||||
search={false}
|
||||
@@ -283,45 +245,54 @@ const Generator: React.FC = () => {
|
||||
onExpandedRowsChange: (expandedRows) => setExpandedRowKeys([...expandedRows]),
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setExpandedRowKeys(keys);
|
||||
}}
|
||||
>
|
||||
全部展开
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setExpandedRowKeys([]);
|
||||
}}
|
||||
>
|
||||
全部折叠
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
<Button
|
||||
key="expand"
|
||||
onClick={() => setExpandedRowKeys(keys)}
|
||||
>
|
||||
全部展开
|
||||
</Button>,
|
||||
<Button
|
||||
key="collapse"
|
||||
onClick={() => setExpandedRowKeys([])}
|
||||
>
|
||||
全部折叠
|
||||
</Button>,
|
||||
<Button
|
||||
key="refresh"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => {
|
||||
if (tenantId) {
|
||||
fetchMenuData(tenantId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
刷新
|
||||
</Button>,
|
||||
<Button
|
||||
key="add"
|
||||
type="primary"
|
||||
onClick={() => handleModalVisible(true)}
|
||||
>
|
||||
<PlusOutlined /> 新增
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
|
||||
{/* 新增表单 */}
|
||||
<ModalForm
|
||||
title="添加菜单"
|
||||
// layout="horizontal"
|
||||
title="新增菜单"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true, okText: '保存' }}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
okText: '保存',
|
||||
width: 800,
|
||||
}}
|
||||
onFinish={async (values) => {
|
||||
const success = await handleAdd(values as SYSTEM.Menu);
|
||||
const success = await handleMenuOperation('add', values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -351,8 +322,6 @@ const Generator: React.FC = () => {
|
||||
fieldNames: {
|
||||
label: 'title',
|
||||
},
|
||||
// treeCheckable: true,
|
||||
// showCheckedStrategy: TreeSelect.SHOW_PARENT,
|
||||
placeholder: '选择上级菜单名',
|
||||
}}
|
||||
/>
|
||||
@@ -438,20 +407,24 @@ const Generator: React.FC = () => {
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
{/* 修改表单 */}
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
if (currentRow) {
|
||||
const success = await handleEdit({ ...currentRow, ...values });
|
||||
const success = await handleMenuOperation('edit', values, currentRow);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
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 {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
overflow: auto;
|
||||
background: @layout-body-background;
|
||||
min-height: 100vh;
|
||||
background: #f0f2f5;
|
||||
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 {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
line-height: 44px;
|
||||
text-align: right;
|
||||
:global(.ant-dropdown-trigger) {
|
||||
margin-right: 24px;
|
||||
.timeBox {
|
||||
position: absolute;
|
||||
top: 48px;
|
||||
left: 48px;
|
||||
z-index: 1;
|
||||
|
||||
.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 {
|
||||
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) {
|
||||
.container {
|
||||
background-image: url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center 110px;
|
||||
background-size: 100%;
|
||||
}
|
||||
.loginBox {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
margin-right: 10%;
|
||||
padding: 40px;
|
||||
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 {
|
||||
padding: 32px 0 24px;
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-left: 8px;
|
||||
color: rgba(0, 0, 0, 0.2);
|
||||
font-size: 24px;
|
||||
vertical-align: middle;
|
||||
.welcome {
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
&:hover {
|
||||
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 { login } from '@/services/login/api';
|
||||
import { InfoCircleOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
|
||||
import { LoginForm, ProFormCaptcha, ProFormText } from '@ant-design/pro-components';
|
||||
import { message, Tooltip } from 'antd';
|
||||
import { LoginForm, ProFormCaptcha, ProFormText, ProFormCheckbox } from '@ant-design/pro-components';
|
||||
import { message, Tooltip, Spin } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import { FormattedMessage, history, useIntl, useModel } from 'umi';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -10,87 +10,75 @@ import styles from './index.less';
|
||||
|
||||
const Login: React.FC = () => {
|
||||
const [uuid, setUuid] = useState<string>(uuidv4());
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const { initialState, setInitialState } = useModel('@@initialState');
|
||||
|
||||
const intl = useIntl();
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
const userInfo = await initialState?.fetchUserInfo?.();
|
||||
if (userInfo) {
|
||||
await setInitialState((s) => ({
|
||||
...s,
|
||||
currentUser: userInfo,
|
||||
}));
|
||||
try {
|
||||
const userInfo = await initialState?.fetchUserInfo?.();
|
||||
if (userInfo) {
|
||||
await setInitialState((s) => ({
|
||||
...s,
|
||||
currentUser: userInfo,
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取用户信息失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: API.LoginParams) => {
|
||||
try {
|
||||
// 登录
|
||||
const msg = await login({ ...values });
|
||||
if (msg.resp_code === 0) {
|
||||
const defaultLoginSuccessMessage = intl.formatMessage({
|
||||
id: 'pages.login.success',
|
||||
defaultMessage: '登录成功!',
|
||||
});
|
||||
const loginResult = msg.data;
|
||||
if (loginResult && loginResult.access_token)
|
||||
sessionStorage.setItem('access_token', loginResult.access_token);
|
||||
message.success(defaultLoginSuccessMessage);
|
||||
setLoading(true);
|
||||
const msg = await login({ ...values, deviceId: uuid });
|
||||
|
||||
if (msg.resp_code === 0 && msg.data?.access_token) {
|
||||
sessionStorage.setItem('access_token', msg.data.access_token);
|
||||
message.success('登录成功!');
|
||||
await fetchUserInfo();
|
||||
/** 此方法会跳转到 redirect 参数所在的位置 */
|
||||
if (!history) return;
|
||||
|
||||
const { query } = history.location;
|
||||
const { redirect } = query as { redirect: string };
|
||||
history.push(redirect || '/');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果失败去设置用户错误信息
|
||||
|
||||
message.error(msg.resp_msg || '登录失败');
|
||||
setUuid(uuidv4());
|
||||
} catch (error) {
|
||||
const defaultLoginFailureMessage = intl.formatMessage({
|
||||
id: 'pages.login.failure',
|
||||
defaultMessage: '登录失败,请重试!',
|
||||
});
|
||||
message.error(defaultLoginFailureMessage);
|
||||
message.error('登录失败,请重试!');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const captchaUrl = `/api-uaa/validata/code/${uuid}`;
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
<LoginForm
|
||||
logo={<img alt="logo" src="./logo.png" />}
|
||||
title="microservices-platform"
|
||||
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })}
|
||||
initialValues={{
|
||||
autoLogin: true,
|
||||
}}
|
||||
onFinish={async (values) => {
|
||||
await handleSubmit({ ...values, deviceId: uuid } as API.LoginParams);
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<Spin spinning={loading}>
|
||||
<LoginForm
|
||||
logo={<img alt="logo" src="/logo.png" />}
|
||||
title="microservices-platform"
|
||||
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })}
|
||||
initialValues={{ autoLogin: true }}
|
||||
onFinish={async (values) => {
|
||||
if (!loading) {
|
||||
await handleSubmit(values as API.LoginParams);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="username"
|
||||
fieldProps={{
|
||||
size: 'large',
|
||||
prefix: <UserOutlined className={styles.prefixIcon} />,
|
||||
}}
|
||||
placeholder={intl.formatMessage({
|
||||
id: 'pages.login.username.placeholder',
|
||||
defaultMessage: '账号',
|
||||
})}
|
||||
placeholder="请输入账号"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: (
|
||||
<FormattedMessage
|
||||
id="pages.login.username.required"
|
||||
defaultMessage="请输入账号!"
|
||||
/>
|
||||
),
|
||||
message: '请输入账号!',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@@ -100,19 +88,11 @@ const Login: React.FC = () => {
|
||||
size: 'large',
|
||||
prefix: <LockOutlined className={styles.prefixIcon} />,
|
||||
}}
|
||||
placeholder={intl.formatMessage({
|
||||
id: 'pages.login.password.placeholder',
|
||||
defaultMessage: '密码',
|
||||
})}
|
||||
placeholder="请输入密码"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: (
|
||||
<FormattedMessage
|
||||
id="pages.login.password.required"
|
||||
defaultMessage="请输入密码!"
|
||||
/>
|
||||
),
|
||||
message: '请输入密码!',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@@ -120,22 +100,19 @@ const Login: React.FC = () => {
|
||||
name="validCode"
|
||||
fieldProps={{
|
||||
size: 'large',
|
||||
prefix: <LockOutlined className={'prefixIcon'} />,
|
||||
suffix: (
|
||||
<Tooltip title="不区分大小写">
|
||||
<InfoCircleOutlined style={{ color: 'rgba(0,0,0,.45)' }} />
|
||||
</Tooltip>
|
||||
),
|
||||
prefix: <LockOutlined className={styles.prefixIcon} />,
|
||||
}}
|
||||
captchaProps={{
|
||||
size: 'large',
|
||||
style: { padding: '0 2px' },
|
||||
}}
|
||||
placeholder={'验证码'}
|
||||
placeholder="请输入验证码"
|
||||
captchaTextRender={() => (
|
||||
<span onClick={() => setUuid(uuidv4())}>
|
||||
<img src={captchaUrl} alt="验证码" />
|
||||
</span>
|
||||
<img
|
||||
src={`/api-uaa/validata/code/${uuid}`}
|
||||
alt="验证码"
|
||||
style={{ height: '32px', cursor: 'pointer' }}
|
||||
onClick={() => setUuid(uuidv4())}
|
||||
/>
|
||||
)}
|
||||
rules={[
|
||||
{
|
||||
@@ -143,10 +120,17 @@ const Login: React.FC = () => {
|
||||
message: '请输入验证码!',
|
||||
},
|
||||
]}
|
||||
onGetCaptcha={async () => {}}
|
||||
/>
|
||||
</>
|
||||
</LoginForm>
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<ProFormCheckbox noStyle name="autoLogin">
|
||||
自动登录
|
||||
</ProFormCheckbox>
|
||||
<a style={{ float: 'right' }} href="/user/forgot-password">
|
||||
忘记密码
|
||||
</a>
|
||||
</div>
|
||||
</LoginForm>
|
||||
</Spin>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
@@ -154,13 +154,14 @@ export async function updateRefund(data: ORDERS.Refund): Promise<API.Result<ORDE
|
||||
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',
|
||||
params: {
|
||||
pageSize: params?.pageSize || 100,
|
||||
current: params?.current || 1,
|
||||
},
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user