图表组件封装
This commit is contained in:
@@ -15,26 +15,6 @@ import {
|
||||
Bar,
|
||||
} from 'recharts';
|
||||
|
||||
// =========================
|
||||
// 通用类型定义
|
||||
// =========================
|
||||
|
||||
export interface SeriesConfig {
|
||||
key: string;
|
||||
name: string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
}
|
||||
|
||||
export interface BaseChartProps {
|
||||
width?: number | string;
|
||||
height?: number;
|
||||
showGrid?: boolean;
|
||||
showLegend?: boolean;
|
||||
showTooltip?: boolean;
|
||||
backgroundColor?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// 默认颜色池
|
||||
const DEFAULT_COLORS = [
|
||||
@@ -48,21 +28,9 @@ const DEFAULT_COLORS = [
|
||||
'#2f54eb',
|
||||
];
|
||||
|
||||
// =========================
|
||||
// 折线图组件
|
||||
// =========================
|
||||
|
||||
export interface UniversalLineChartProps extends BaseChartProps {
|
||||
data: Record<string, any>[];
|
||||
xKey: string;
|
||||
series: SeriesConfig[];
|
||||
smooth?: boolean;
|
||||
dot?: boolean;
|
||||
xAxisLabel?: string;
|
||||
yAxisLabel?: string;
|
||||
}
|
||||
|
||||
export const UniversalLineChart: React.FC<UniversalLineChartProps> = ({
|
||||
export const UniversalLineChart = ({
|
||||
data,
|
||||
xKey,
|
||||
series,
|
||||
@@ -117,20 +85,9 @@ export const UniversalLineChart: React.FC<UniversalLineChartProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
// =========================
|
||||
// 柱状图组件
|
||||
// =========================
|
||||
|
||||
export interface UniversalBarChartProps extends BaseChartProps {
|
||||
data: Record<string, any>[];
|
||||
xKey: string;
|
||||
series: SeriesConfig[];
|
||||
barSize?: number;
|
||||
radius?: number | [number, number, number, number];
|
||||
stack?: boolean;
|
||||
}
|
||||
|
||||
export const UniversalBarChart: React.FC<UniversalBarChartProps> = ({
|
||||
export const UniversalBarChart = ({
|
||||
data,
|
||||
xKey,
|
||||
series,
|
||||
@@ -185,25 +142,9 @@ export const UniversalBarChart: React.FC<UniversalBarChartProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
// =========================
|
||||
// 饼图组件
|
||||
// =========================
|
||||
|
||||
export interface PieDataItem {
|
||||
name: string;
|
||||
value: number;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
export interface UniversalPieChartProps extends BaseChartProps {
|
||||
data: PieDataItem[];
|
||||
innerRadius?: number;
|
||||
outerRadius?: number;
|
||||
paddingAngle?: number;
|
||||
showLabel?: boolean;
|
||||
}
|
||||
|
||||
export const UniversalPieChart: React.FC<UniversalPieChartProps> = ({
|
||||
export const UniversalPieChart = ({
|
||||
data,
|
||||
width = '100%',
|
||||
height = 360,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
SelectOutlined, FireOutlined, WarningOutlined, ExclamationCircleOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { Line, Area } from '@ant-design/charts';
|
||||
import { UniversalBarChart, UniversalLineChart } from "../components/recharts"
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
@@ -115,6 +116,7 @@ const generationPerformanceConfig = {
|
||||
legend: { position: 'top' },
|
||||
};
|
||||
|
||||
|
||||
export default function AIDiagnosisPage() {
|
||||
const cardStyle = {
|
||||
borderRadius: 12,
|
||||
@@ -140,6 +142,7 @@ export default function AIDiagnosisPage() {
|
||||
|
||||
return (
|
||||
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '16px 24px', boxSizing: 'border-box', overflowX: 'hidden' }}>
|
||||
|
||||
<style>
|
||||
{`
|
||||
.compact-table .ant-table-thead > tr > th {
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
RobotOutlined, ThunderboltOutlined, AlertOutlined,
|
||||
CheckCircleOutlined
|
||||
} from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { Pie, Line } from '@ant-design/charts';
|
||||
import {
|
||||
ClipboardList,
|
||||
@@ -27,7 +29,7 @@ import {
|
||||
ExternalLink
|
||||
} from 'lucide-react';
|
||||
// 导入工单接口
|
||||
import { getWorkOrderApi, getWorkOrderDetailApi, updateWorkOrder, dispatchWorkOrder } from '../api/workOrder';
|
||||
import { getWorkOrderApi, getWorkOrderDetailApi, updateWorkOrder, dispatchWorkOrder, completeWorkOrder } from '../api/workOrder';
|
||||
|
||||
const { Option } = Select;
|
||||
const { Search } = Input;
|
||||
@@ -73,6 +75,9 @@ const WorkOrderPage = () => {
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [dispatchModalVisible, setDispatchModalVisible] = useState(false);
|
||||
|
||||
const [completeModalVisible, setCompleteModalVisible] = useState(false);
|
||||
const [completeForm] = Form.useForm(); // 完成工单表单
|
||||
|
||||
// 统计数据(保留原模拟不变)
|
||||
const stats = [
|
||||
{ title: '今日新增工单', value: 18, subValue: '+3', subText: '较昨日', icon: <ClipboardList size={24} color="#1890ff" />, bg: '#e6f7ff' },
|
||||
@@ -122,11 +127,45 @@ const WorkOrderPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 打开完成工单弹窗
|
||||
const openCompleteModal = () => {
|
||||
if (!selectedRowKey) return message.warning('请先选择工单');
|
||||
completeForm.setFieldsValue({
|
||||
id: currentDetail?.id,
|
||||
orderNo: currentDetail?.orderNo,
|
||||
handleResult: '已处理完成',
|
||||
handleRemark: '',
|
||||
});
|
||||
setCompleteModalVisible(true);
|
||||
};
|
||||
|
||||
// 提交完成工单
|
||||
const submitComplete = async (values) => {
|
||||
try {
|
||||
// 构造后端需要的参数(只需要传 id + 处理信息)
|
||||
const params = {
|
||||
id: values.id,
|
||||
handleResult: values.handleResult,
|
||||
handleRemark: values.handleRemark,
|
||||
};
|
||||
|
||||
await completeWorkOrder(params);
|
||||
message.success('工单已完成');
|
||||
setCompleteModalVisible(false);
|
||||
// 刷新列表 + 详情
|
||||
getWorkOrderList();
|
||||
getWorkOrderDetail(selectedRowKey);
|
||||
} catch (err) {
|
||||
message.error('工单完成失败');
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取工单详情
|
||||
const getWorkOrderDetail = async (id) => {
|
||||
try {
|
||||
const res = await getWorkOrderDetailApi(id);
|
||||
if (res.code === 0) {
|
||||
if (res.code == 200) {
|
||||
setCurrentDetail(res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -155,15 +194,16 @@ const WorkOrderPage = () => {
|
||||
setEditModalVisible(true);
|
||||
};
|
||||
|
||||
// 打开派发工单弹窗
|
||||
// 打开派发工单弹窗
|
||||
const openDispatchModal = () => {
|
||||
if (!selectedRowKey) return message.warning('请先选择一条工单');
|
||||
form.setFieldsValue({
|
||||
title: currentDetail?.orderTitle,
|
||||
content: currentDetail?.taskDescription,
|
||||
priority: currentDetail?.priorityLevel,
|
||||
type: currentDetail?.orderType,
|
||||
remark: currentDetail?.remark
|
||||
orderId: selectedRowKey, // 自动回填工单ID
|
||||
assigneeName: currentDetail?.assigneeName || '',
|
||||
planStartTime: currentDetail?.planStartTime ? dayjs(currentDetail.planStartTime) : null,
|
||||
planEndTime: currentDetail?.planEndTime ? dayjs(currentDetail.planEndTime) : null,
|
||||
deadlineTime: currentDetail?.deadlineTime ? dayjs(currentDetail.deadlineTime) : null,
|
||||
});
|
||||
setDispatchModalVisible(true);
|
||||
};
|
||||
@@ -188,22 +228,30 @@ const WorkOrderPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 提交派发工单
|
||||
// 提交派发工单
|
||||
const submitDispatch = async (values) => {
|
||||
try {
|
||||
await dispatchWorkOrder({
|
||||
id: selectedRowKey,
|
||||
orderTitle: values.title,
|
||||
taskDescription: values.content,
|
||||
priorityLevel: values.priority,
|
||||
orderType: values.type,
|
||||
remark: values.remark
|
||||
});
|
||||
message.success('派发工单成功');
|
||||
// 拼接接口需要的参数(完全按你给的格式)
|
||||
const params = {
|
||||
orderId: values.orderId,
|
||||
assigneeId: values.assigneeName === '王工' ? 1003 : '', // 你可以自己映射ID
|
||||
assigneeName: values.assigneeName,
|
||||
collaboratorIds: '',
|
||||
collaboratorNames: values.collaboratorNames?.join(',') || '',
|
||||
planStartTime: values.planStartTime ? values.planStartTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
planEndTime: values.planEndTime ? values.planEndTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
deadlineTime: values.deadlineTime ? values.deadlineTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
};
|
||||
|
||||
await dispatchWorkOrder(params);
|
||||
|
||||
message.success('工单派发成功');
|
||||
setDispatchModalVisible(false);
|
||||
getWorkOrderList();
|
||||
getWorkOrderList(); // 刷新列表
|
||||
} catch (error) {
|
||||
message.error('派发工单失败');
|
||||
message.error('工单派发失败');
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -268,7 +316,18 @@ const WorkOrderPage = () => {
|
||||
key: 'action',
|
||||
width: 60,
|
||||
fixed: "right",
|
||||
render: () => <Button type="link" size="small">查看</Button>
|
||||
render: (_, record) => (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
setSelectedRowKey(record.id);
|
||||
getWorkOrderDetail(record.id);
|
||||
}}
|
||||
>
|
||||
查看
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
];
|
||||
|
||||
@@ -596,7 +655,14 @@ const WorkOrderPage = () => {
|
||||
<Col span={6}><Button type="primary" block onClick={openDispatchModal} style={{ borderRadius: 8, height: 36, fontWeight: 600 }}>派发工单</Button></Col>
|
||||
<Col span={6}><Button icon={<ReloadOutlined />} block onClick={openEditModal} style={{ borderRadius: 8, height: 36, fontWeight: 600 }}>转派</Button></Col>
|
||||
<Col span={6}><Button icon={<PauseOutlined />} danger ghost block style={{ borderRadius: 8, height: 36, fontWeight: 600 }}>挂起</Button></Col>
|
||||
<Col span={6}><Button icon={<CheckCircleOutlined />} style={{ background: '#00B42A', color: '#fff', border: 'none', borderRadius: 8, height: 36, fontWeight: 600 }} block>完成工单</Button></Col>
|
||||
<Col span={6}><Button
|
||||
icon={<CheckCircleOutlined />}
|
||||
style={{ background: '#00B42A', color: '#fff', border: 'none', borderRadius: 8, height: 36, fontWeight: 600 }}
|
||||
block
|
||||
onClick={openCompleteModal}
|
||||
>
|
||||
完成工单
|
||||
</Button></Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
@@ -705,34 +771,92 @@ const WorkOrderPage = () => {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
|
||||
{/* 派发工单弹窗 */}
|
||||
<Modal title="派发工单" open={dispatchModalVisible} onCancel={() => setDispatchModalVisible(false)} footer={null} width={520}>
|
||||
<Modal title="派发工单" open={dispatchModalVisible} onCancel={() => setDispatchModalVisible(false)} footer={null} width={550}>
|
||||
<Form form={form} layout="vertical" onFinish={submitDispatch}>
|
||||
<FormItem name="title" label="工单标题">
|
||||
<Input placeholder="请输入工单标题" />
|
||||
<FormItem name="orderId" label="工单ID" hidden>
|
||||
<Input />
|
||||
</FormItem>
|
||||
<FormItem name="content" label="工单内容">
|
||||
<Input.TextArea rows={4} placeholder="请输入工单内容" />
|
||||
</FormItem>
|
||||
<FormItem name="priority" label="优先级">
|
||||
<Select placeholder="请选择优先级">
|
||||
<Option value={1}>高</Option>
|
||||
<Option value={2}>中</Option>
|
||||
<Option value={3}>低</Option>
|
||||
|
||||
<FormItem
|
||||
name="assigneeName"
|
||||
label="负责人"
|
||||
rules={[{ required: true, message: '请选择负责人' }]}
|
||||
>
|
||||
<Select placeholder="请选择负责人">
|
||||
<Option value="王工">王工</Option>
|
||||
<Option value="李工">李工</Option>
|
||||
<Option value="张工">张工</Option>
|
||||
<Option value="陈工">陈工</Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
<FormItem name="type" label="工单类型">
|
||||
<Input placeholder="请输入工单类型" />
|
||||
|
||||
<FormItem name="collaboratorNames" label="协同人员">
|
||||
<Select mode="tags" placeholder="可输入多个,回车确认" />
|
||||
</FormItem>
|
||||
<FormItem name="remark" label="备注">
|
||||
<Input.TextArea rows={2} placeholder="请输入备注" />
|
||||
|
||||
<FormItem name="planStartTime" label="计划开始时间">
|
||||
<DatePicker showTime style={{ width: '100%' }} />
|
||||
</FormItem>
|
||||
|
||||
<FormItem name="planEndTime" label="计划结束时间">
|
||||
<DatePicker showTime style={{ width: '100%' }} />
|
||||
</FormItem>
|
||||
|
||||
<FormItem name="deadlineTime" label="截止时间">
|
||||
<DatePicker showTime style={{ width: '100%' }} />
|
||||
</FormItem>
|
||||
|
||||
<FormItem style={{ textAlign: 'right', marginBottom: 0 }}>
|
||||
<Button onClick={() => setDispatchModalVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>确认派发</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* 完成工单弹窗 */}
|
||||
<Modal
|
||||
title="完成工单"
|
||||
open={completeModalVisible}
|
||||
onCancel={() => setCompleteModalVisible(false)}
|
||||
footer={null}
|
||||
width={500}
|
||||
>
|
||||
<Form form={completeForm} layout="vertical" onFinish={submitComplete}>
|
||||
<Form.Item name="id" hidden>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="orderNo" label="工单编号">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="handleResult"
|
||||
label="处理结果"
|
||||
rules={[{ required: true, message: '请输入处理结果' }]}
|
||||
>
|
||||
<Select placeholder="请选择处理结果">
|
||||
<Option value="已处理完成">已处理完成</Option>
|
||||
<Option value="已修复">已修复</Option>
|
||||
<Option value="无需处理">无需处理</Option>
|
||||
<Option value="问题已闭环">问题已闭环</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="handleRemark" label="处理备注">
|
||||
<Input.TextArea rows={4} placeholder="请填写处理详情、备注信息" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ textAlign: 'right', marginBottom: 0 }}>
|
||||
<Button onClick={() => setCompleteModalVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>
|
||||
确认完成
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user