低电量返航增加配置界面,触发规则机器即返航

This commit is contained in:
mmc
2026-11-07 10:02:01 +08:00
parent 25bdaa521f
commit 886e21237d
4 changed files with 288 additions and 109 deletions

View File

@@ -16,6 +16,7 @@ import {
Col, Col,
App, App,
} from 'antd'; } from 'antd';
import type { FormInstance } from 'antd/es/form';
import { import {
SearchOutlined, SearchOutlined,
ReloadOutlined, ReloadOutlined,
@@ -41,67 +42,134 @@ const { Option } = Select;
const AntdCard = Card as any; const AntdCard = Card as any;
// 规则类型 // ====================== TS 类型(和后端实体对齐)======================
type RuleType = 'LOW_BATTERY_RETURN';
type DeviceScope = 'ALL' | 'GROUP' | 'SOME';
type CompareEnum = 'GT' | 'GTE' | 'LT' | 'LTE' | 'EQ' | 'NE' | 'BETWEEN' | 'NOT_BETWEEN';
type ActionType = 'AUTO_TASK' | 'SEND_COMMAND' | 'ALARM' | 'WORK_ORDER';
interface TriggerConditions {
key: string;
operator: CompareEnum;
value: string;
}
interface ActionConfig {
actionType: ActionType;
args: Record<string, any>;
}
interface RuleItem {
id?: number;
ruleName: string;
ruleType: RuleType;
deviceScope: DeviceScope;
conditions: TriggerConditions;
actionConfig: ActionConfig;
enabled: boolean;
// 后端字段:ForceExecute(大驼峰,不规范,建议后端改为 forceExecute)
ForceExecute: boolean;
orgId?: string;
siteId?: string;
}
interface SearchFormValues {
ruleName?: string;
ruleType?: RuleType;
enabled?: number | '';
}
interface RuleFormValues {
ruleName: string;
ruleType: RuleType;
deviceScope: DeviceScope;
key: string;
operator: CompareEnum;
value?: number;
min?: number;
max?: number;
actionType: ActionType;
argsJson: string;
enabled: boolean;
ForceExecute: boolean;
}
// ====================== 常量配置 ======================
const RuleTypeOptions = [ const RuleTypeOptions = [
{ value: 'LOW_BATTERY_RETURN', labelKey: 'ruleTypeLowBatteryReturn' }, { value: 'LOW_BATTERY_RETURN' as RuleType, labelKey: 'ruleTypeLowBatteryReturn' },
]; ];
// 适用范围
const DeviceScopeOptions = [ const DeviceScopeOptions = [
{ value: 'ALL', labelKey: 'deviceScopeAll' }, { value: 'ALL' as DeviceScope, labelKey: 'deviceScopeAll' },
{ value: 'GROUP', labelKey: 'deviceScopeGroup' }, { value: 'GROUP' as DeviceScope, labelKey: 'deviceScopeGroup' },
{ value: 'SOME', labelKey: 'deviceScopeSome' }, { value: 'SOME' as DeviceScope, labelKey: 'deviceScopeSome' },
]; ];
// 触发字段
const TriggerKeyOptions = [ const TriggerKeyOptions = [
{ value: 'battery', labelKey: 'triggerKeyBattery' }, { value: 'battery_percentage', labelKey: 'triggerKeyBattery' },
{ value: 'temperature', labelKey: 'triggerKeyTemperature' }, { value: 'temperature', labelKey: 'triggerKeyTemperature' },
{ value: 'offline_duration', labelKey: 'triggerKeyOfflineDuration' }, { value: 'offline_duration', labelKey: 'triggerKeyOfflineDuration' },
{ value: 'voltage', labelKey: 'triggerKeyVoltage' }, { value: 'voltage', labelKey: 'triggerKeyVoltage' },
]; ];
// 执行动作
const ActionTypeOptions = [ const ActionTypeOptions = [
{ value: 'AUTO_TASK', labelKey: 'actionTypeAutoTask' }, //{ value: 'AUTO_TASK' as ActionType, labelKey: 'actionTypeAutoTask' },
{ value: 'SEND_COMMAND', labelKey: 'actionTypeSendCommand' }, { value: 'BACK_TO_REST' as ActionType, labelKey: 'actionTypeBackToRest' },
{ value: 'ALARM', labelKey: 'actionTypeAlarm' },
{ value: 'WORK_ORDER', labelKey: 'actionTypeWorkOrder' }, //BACK_TO_REST
{ value: 'SEND_COMMAND' as ActionType, labelKey: 'actionTypeSendCommand' },
{ value: 'ALARM' as ActionType, labelKey: 'actionTypeAlarm' },
{ value: 'WORK_ORDER' as ActionType, labelKey: 'actionTypeWorkOrder' },
]; ];
const rangeOperators = ['BETWEEN', 'NOT_BETWEEN']; const rangeOperators: CompareEnum[] = ['BETWEEN', 'NOT_BETWEEN'];
export default function RuleConfigManagement() { export default function RuleConfigManagement() {
const { t } = useTranslation(); const { t } = useTranslation();
const { stationId, currentStation } = useSelector((state: RootState) => state.station); const { stationId, currentStation } = useSelector((state: RootState) => state.station);
const { modal } = App.useApp(); const { modal } = App.useApp();
const [form] = Form.useForm(); const [form] = Form.useForm<RuleFormValues>();
const [searchForm] = Form.useForm(); const [searchForm] = Form.useForm<SearchFormValues>();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [ruleList, setRuleList] = useState<any[]>([]); const [ruleList, setRuleList] = useState<RuleItem[]>([]);
const [filteredList, setFilteredList] = useState<any[]>([]); const [filteredList, setFilteredList] = useState<RuleItem[]>([]);
const [modalVisible, setModalVisible] = useState(false); const [modalVisible, setModalVisible] = useState(false);
const [modalType, setModalType] = useState<'add' | 'edit' | 'view'>('add'); const [modalType, setModalType] = useState<'add' | 'edit' | 'view'>('add');
const [currentRecord, setCurrentRecord] = useState<any>(null); const [currentRecord, setCurrentRecord] = useState<RuleItem | null>(null);
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
// 获取规则列表 const operatorWatch = Form.useWatch('operator', form);
const isRangeOperator = useMemo(() => rangeOperators.includes(operatorWatch), [operatorWatch]);
const disabledForm = modalType === 'view';
// 公共翻译label获取
const getOptionLabel = (options: Array<{ value: string; labelKey: string }>, value: string, ns = 'systemSetting') => {
const item = options.find(o => o.value === value);
return item ? t(`${ns}.${item.labelKey}`) : value;
};
// 获取列表
const fetchRuleList = async () => { const fetchRuleList = async () => {
if (!stationId) return; if (!stationId) return;
setLoading(true); setLoading(true);
try { try {
const res = await selectRuleBySiteId({ siteId: stationId }); const res = await selectRuleBySiteId({ siteId: stationId });
if (res.code == 200) { if (res.code === 200) {
const list = res?.data || res?.rows || []; // 兼容多种后端返回结构:数组直接用 / 分页对象取 records/rows/list / 其他回退空数组
const raw = res?.data;
let list: RuleItem[] = [];
if (Array.isArray(raw)) list = raw;
else if (raw && typeof raw === 'object') list = Array.isArray(raw.records) ? raw.records : Array.isArray(raw.rows) ? raw.rows : Array.isArray(raw.list) ? raw.list : [];
console.log('[selectRuleBySiteId] res.data type:', Array.isArray(raw) ? 'array' : typeof raw, '-> list len:', list.length);
setRuleList(list); setRuleList(list);
console.log(list, "list")
setFilteredList(list); setFilteredList(list);
} else { } else {
setRuleList([]); setRuleList([]);
setFilteredList([]); setFilteredList([]);
} }
} catch (err) { } catch (err) {
utils.message.error(t('systemSetting.operationFailed')); utils.message.error(t('systemSetting.operationFailed'));
} finally { } finally {
@@ -117,7 +185,7 @@ export default function RuleConfigManagement() {
const handleSearch = () => { const handleSearch = () => {
searchForm.validateFields().then(values => { searchForm.validateFields().then(values => {
const next = ruleList.filter(item => { const next = ruleList.filter(item => {
const matchName = !values.ruleName || (item.ruleName || '').toLowerCase().includes(values.ruleName.toLowerCase()); const matchName = !values.ruleName || item.ruleName.toLowerCase().includes(values.ruleName.toLowerCase());
const matchType = !values.ruleType || item.ruleType === values.ruleType; const matchType = !values.ruleType || item.ruleType === values.ruleType;
const matchEnabled = values.enabled === undefined || values.enabled === '' || Number(item.enabled) === Number(values.enabled); const matchEnabled = values.enabled === undefined || values.enabled === '' || Number(item.enabled) === Number(values.enabled);
return matchName && matchType && matchEnabled; return matchName && matchType && matchEnabled;
@@ -132,31 +200,36 @@ export default function RuleConfigManagement() {
}; };
// 打开弹窗 // 打开弹窗
const openModal = (type: 'add' | 'edit' | 'view', record?: any) => { const openModal = (type: 'add' | 'edit' | 'view', record?: RuleItem) => {
setModalType(type); setModalType(type);
setCurrentRecord(record || null); setCurrentRecord(record ?? null);
setModalVisible(true); setModalVisible(true);
form.resetFields(); form.resetFields();
if ((type === 'edit' || type === 'view') && record) { if ((type === 'edit' || type === 'view') && record) {
const conditions = record.conditions || {}; const conditions = record.conditions;
const actionConfig = record.actionConfig || {}; const actionConfig = record.actionConfig;
const isRange = rangeOperators.includes(conditions.operator); const isRange = rangeOperators.includes(conditions.operator);
let min = '';
let max = ''; let min: number | undefined;
let value = conditions.value; let max: number | undefined;
if (isRange && typeof conditions.value === 'string' && conditions.value.includes(',')) { let value: number | undefined;
if (isRange && conditions.value.includes(',')) {
const [a, b] = conditions.value.split(','); const [a, b] = conditions.value.split(',');
min = a; min = Number(a);
max = b; max = Number(b);
value = ''; } else {
value = Number(conditions.value);
} }
let argsJson = ''; let argsJson = '';
try { try {
argsJson = actionConfig.args ? JSON.stringify(actionConfig.args, null, 2) : ''; argsJson = actionConfig.args ? JSON.stringify(actionConfig.args, null, 2) : '';
} catch (e) { } catch (e) {
argsJson = ''; argsJson = '';
} }
form.setFieldsValue({ form.setFieldsValue({
ruleName: record.ruleName, ruleName: record.ruleName,
ruleType: record.ruleType, ruleType: record.ruleType,
@@ -168,10 +241,11 @@ export default function RuleConfigManagement() {
max, max,
actionType: actionConfig.actionType, actionType: actionConfig.actionType,
argsJson, argsJson,
enabled: record.enabled === true || record.enabled === 1, enabled: record.enabled,
ForceExecute: record.ForceExecute === true || record.ForceExecute === 1, ForceExecute: record.ForceExecute,
}); });
} else { } else {
// 新增默认值
form.setFieldsValue({ form.setFieldsValue({
ruleType: 'LOW_BATTERY_RETURN', ruleType: 'LOW_BATTERY_RETURN',
deviceScope: 'ALL', deviceScope: 'ALL',
@@ -184,39 +258,53 @@ export default function RuleConfigManagement() {
} }
}; };
// 保存规则 // ✅ 保存逻辑(重点优化)
const handleSave = async (values: any) => { const handleSave = async (values: RuleFormValues) => {
let argsObj: any = {}; // 1. JSON 参数解析校验
if (values.argsJson) { let argsObj: Record<string, any> = {};
if (values.argsJson?.trim()) {
try { try {
argsObj = JSON.parse(values.argsJson); argsObj = JSON.parse(values.argsJson.trim());
} catch (e) { } catch (e) {
utils.message.error(t('systemSetting.invalidJson')); utils.message.error(t('systemSetting.invalidJson'));
return; return;
} }
} }
const isRange = rangeOperators.includes(values.operator); // 2. 根据运算符拼接 value(后端存字符串)
const value = isRange ? `${values.min},${values.max}` : values.value; let conditionValue: string;
if (isRangeOperator) {
if (values.min === undefined || values.max === undefined) {
utils.message.error(t('systemSetting.pleaseInputTriggerValue'));
return;
}
conditionValue = `${values.min},${values.max}`;
} else {
if (values.value === undefined) {
utils.message.error(t('systemSetting.pleaseInputTriggerValue'));
return;
}
conditionValue = String(values.value);
}
const submitData: any = { const submitData: RuleItem = {
id: modalType === 'edit' ? currentRecord?.id : undefined, id: modalType === 'edit' ? currentRecord?.id : undefined,
ruleName: values.ruleName, ruleName: values.ruleName.trim(),
ruleType: values.ruleType, ruleType: values.ruleType,
deviceScope: values.deviceScope, deviceScope: values.deviceScope,
conditions: { conditions: {
key: values.key, key: values.key,
operator: values.operator, operator: values.operator,
value, value: conditionValue,
}, },
actionConfig: { actionConfig: {
actionType: values.actionType, actionType: values.actionType,
args: argsObj, args: argsObj,
}, },
enabled: values.enabled ? 1 : 0, enabled: values.enabled,
ForceExecute: values.ForceExecute ? 1 : 0, ForceExecute: values.ForceExecute,
orgId: currentStation?.orgId || '', orgId: currentStation?.orgId,
siteId: stationId || '', siteId: stationId,
}; };
setSubmitting(true); setSubmitting(true);
@@ -236,8 +324,8 @@ export default function RuleConfigManagement() {
} }
}; };
// 删除规则 // 删除
const handleDelete = (record: any) => { const handleDelete = (record: RuleItem) => {
modal.confirm({ modal.confirm({
title: t('common.confirmDelete'), title: t('common.confirmDelete'),
content: t('systemSetting.confirmDeleteRule', { name: record.ruleName }), content: t('systemSetting.confirmDeleteRule', { name: record.ruleName }),
@@ -246,7 +334,7 @@ export default function RuleConfigManagement() {
cancelText: t('common.cancel'), cancelText: t('common.cancel'),
onOk: async () => { onOk: async () => {
try { try {
const res = await deleteRule({ ids: [record.id] }); const res = await deleteRule([record.id!]);
if (res?.code === 200) { if (res?.code === 200) {
utils.message.success(t('common.deleteSuccess')); utils.message.success(t('common.deleteSuccess'));
fetchRuleList(); fetchRuleList();
@@ -260,19 +348,16 @@ export default function RuleConfigManagement() {
}); });
}; };
const operatorWatch = Form.useWatch('operator', form); const renderConditions = (record: RuleItem) => {
const isRangeOperator = useMemo(() => rangeOperators.includes(operatorWatch), [operatorWatch]); const c = record.conditions;
// 匹配 key 对应的 labelKey
const keyItem = TriggerKeyOptions.find(o => o.value === c.key);
const keyLabel = keyItem ? t(`systemSetting.${keyItem.labelKey}`) : c.key;
const getLabel = (options: any[], value: string, ns: string = 'systemSetting') => {
const item = options.find(o => o.value === value);
return item ? t(`${ns}.${item.labelKey}`) : value;
};
const renderConditions = (record: any) => {
const c = record.conditions || {};
const opItem = CompareEnumOptions.find(o => o.value === c.operator); const opItem = CompareEnumOptions.find(o => o.value === c.operator);
const opLabel = opItem ? t(`constants.${opItem.label}`) : c.operator; const opLabel = opItem ? t(opItem.label) : c.operator;
return <Text type="secondary">{c.key} {opLabel} {c.value}</Text>;
return <Text type="secondary">{keyLabel} {opLabel} {c.value}</Text>;
}; };
const columns = [ const columns = [
@@ -288,59 +373,71 @@ export default function RuleConfigManagement() {
dataIndex: 'ruleType', dataIndex: 'ruleType',
key: 'ruleType', key: 'ruleType',
width: 140, width: 140,
render: (text: string) => getLabel(RuleTypeOptions, text), render: (text: RuleType) => getOptionLabel(RuleTypeOptions, text),
}, },
{ {
title: t('systemSetting.deviceScope'), title: t('systemSetting.deviceScope'),
dataIndex: 'deviceScope', dataIndex: 'deviceScope',
key: 'deviceScope', key: 'deviceScope',
width: 120, width: 120,
render: (text: string) => getLabel(DeviceScopeOptions, text), render: (text: DeviceScope) => getOptionLabel(DeviceScopeOptions, text),
}, },
{ {
title: t('systemSetting.triggerKey'), title: t('systemSetting.triggerKey'),
key: 'conditions', key: 'conditions',
width: 220, width: 220,
render: (_: any, record: any) => renderConditions(record), render: (_: any, record: RuleItem) => renderConditions(record),
}, },
{ {
title: t('systemSetting.actionType'), title: t('systemSetting.actionType'),
dataIndex: ['actionConfig', 'actionType'], dataIndex: ['actionConfig', 'actionType'],
key: 'actionType', key: 'actionType',
width: 140, width: 140,
render: (text: string) => getLabel(ActionTypeOptions, text), render: (text: ActionType) => getOptionLabel(ActionTypeOptions, text),
}, },
{ {
title: t('systemSetting.enabledLabel'), title: t('systemSetting.enabledLabel'),
dataIndex: 'enabled', dataIndex: 'enabled',
key: 'enabled', key: 'enabled',
width: 100, width: 100,
render: (val: any) => <Tag color={val === 1 || val === true ? 'green' : 'default'}>{val === 1 || val === true ? t('common.enable') : t('common.disable')}</Tag>, render: (val: boolean) => (
}, <Tag color={val ? 'green' : 'default'}>
{ {val ? t('common.enable') : t('common.disable')}
title: t('systemSetting.forceExecute'), </Tag>
dataIndex: 'ForceExecute', ),
key: 'ForceExecute',
width: 100,
render: (val: any) => <Tag color={val === 1 || val === true ? 'orange' : 'default'}>{val === 1 || val === true ? t('common.yes') : t('common.no')}</Tag>,
}, },
//{
// title: t('systemSetting.forceExecute'),
// dataIndex: 'ForceExecute',
// key: 'ForceExecute',
// width: 100,
// render: (val: boolean) => (
// <Tag color={val ? 'orange' : 'default'}>
// {val ? t('common.yes') : t('common.no')}
// </Tag>
// ),
//},
{ {
title: t('common.actions'), title: t('common.actions'),
key: 'action', key: 'action',
width: 220, width: 220,
fixed: 'right' as const, fixed: 'right' as const,
render: (_: any, record: any) => ( render: (_: any, record: RuleItem) => (
<Space> <Space>
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => openModal('view', record)}>{t('common.view')}</Button> <Button type="link" size="small" icon={<EyeOutlined />} onClick={() => openModal('view', record)}>
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => openModal('edit', record)}>{t('common.edit')}</Button> {t('common.view')}
<Button type="link" size="small" danger icon={<DeleteOutlined />} onClick={() => handleDelete(record)}>{t('common.delete')}</Button> </Button>
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => openModal('edit', record)}>
{t('common.edit')}
</Button>
<Button type="link" size="small" danger icon={<DeleteOutlined />} onClick={() => handleDelete(record)}>
{t('common.delete')}
</Button>
</Space> </Space>
), ),
}, },
]; ];
const disabledForm = modalType === 'view';
return ( return (
<div style={{ padding: '0px 0px', background: '#f5f7fa', minHeight: 'calc(100vh - 120px)' }}> <div style={{ padding: '0px 0px', background: '#f5f7fa', minHeight: 'calc(100vh - 120px)' }}>
<AntdCard style={{ borderRadius: 8 }}> <AntdCard style={{ borderRadius: 8 }}>
@@ -351,7 +448,9 @@ export default function RuleConfigManagement() {
<Form.Item name="ruleType" label={t('systemSetting.ruleType')}> <Form.Item name="ruleType" label={t('systemSetting.ruleType')}>
<Select placeholder={t('systemSetting.pleaseSelectRuleType')} style={{ width: 150 }} allowClear> <Select placeholder={t('systemSetting.pleaseSelectRuleType')} style={{ width: 150 }} allowClear>
{RuleTypeOptions.map(option => ( {RuleTypeOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`systemSetting.${option.labelKey}`)}</Option> <Option key={option.value} value={option.value}>
{t(`systemSetting.${option.labelKey}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -363,9 +462,20 @@ export default function RuleConfigManagement() {
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<Space> <Space>
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch}>{t('common.search2')}</Button> <Button type="primary" icon={<SearchOutlined />} onClick={handleSearch}>
<Button icon={<ReloadOutlined />} onClick={handleReset}>{t('common.reset')}</Button> {t('common.search2')}
<Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('add')}>{t('systemSetting.addRule')}</Button> </Button>
<Button icon={<ReloadOutlined />} onClick={handleReset}>
{t('common.reset')}
</Button>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => openModal('add')}
disabled={!stationId}
>
{t('systemSetting.addRule')}
</Button>
</Space> </Space>
</Form.Item> </Form.Item>
</Form> </Form>
@@ -376,12 +486,22 @@ export default function RuleConfigManagement() {
dataSource={filteredList} dataSource={filteredList}
loading={loading} loading={loading}
scroll={{ x: 1100 }} scroll={{ x: 1100 }}
pagination={{ pageSize: 10, showSizeChanger: true, showTotal: total => t('common.total', { total }) }} pagination={{
pageSize: 10,
showSizeChanger: true,
showTotal: total => t('common.total', { total }),
}}
/> />
</AntdCard> </AntdCard>
<Modal <Modal
title={modalType === 'add' ? t('systemSetting.addRule') : modalType === 'edit' ? t('systemSetting.editRule') : t('systemSetting.viewRule')} title={
modalType === 'add'
? t('systemSetting.addRule')
: modalType === 'edit'
? t('systemSetting.editRule')
: t('systemSetting.viewRule')
}
open={modalVisible} open={modalVisible}
width={720} width={720}
maskClosable={false} maskClosable={false}
@@ -393,7 +513,9 @@ export default function RuleConfigManagement() {
) : ( ) : (
<Space> <Space>
<Button onClick={() => setModalVisible(false)}>{t('common.cancel')}</Button> <Button onClick={() => setModalVisible(false)}>{t('common.cancel')}</Button>
<Button type="primary" loading={submitting} onClick={() => form.submit()}>{t('common.save')}</Button> <Button type="primary" loading={submitting} onClick={() => form.submit()}>
{t('common.save')}
</Button>
</Space> </Space>
) )
} }
@@ -406,15 +528,25 @@ export default function RuleConfigManagement() {
> >
<Row gutter={16}> <Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item name="ruleName" label={t('systemSetting.ruleName')} rules={[{ required: true, message: t('systemSetting.pleaseInputRuleName') }]}> <Form.Item
name="ruleName"
label={t('systemSetting.ruleName')}
rules={[{ required: true, message: t('systemSetting.pleaseInputRuleName') }]}
>
<Input placeholder={t('systemSetting.pleaseInputRuleName')} /> <Input placeholder={t('systemSetting.pleaseInputRuleName')} />
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={12}> <Col span={12}>
<Form.Item name="ruleType" label={t('systemSetting.ruleType')} rules={[{ required: true, message: t('systemSetting.pleaseSelectRuleType') }]}> <Form.Item
name="ruleType"
label={t('systemSetting.ruleType')}
rules={[{ required: true, message: t('systemSetting.pleaseSelectRuleType') }]}
>
<Select placeholder={t('systemSetting.pleaseSelectRuleType')}> <Select placeholder={t('systemSetting.pleaseSelectRuleType')}>
{RuleTypeOptions.map(option => ( {RuleTypeOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`systemSetting.${option.labelKey}`)}</Option> <Option key={option.value} value={option.value}>
{t(`systemSetting.${option.labelKey}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -423,19 +555,31 @@ export default function RuleConfigManagement() {
<Row gutter={16}> <Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item name="deviceScope" label={t('systemSetting.deviceScope')} rules={[{ required: true, message: t('systemSetting.pleaseSelectDeviceScope') }]}> <Form.Item
name="deviceScope"
label={t('systemSetting.deviceScope')}
rules={[{ required: true, message: t('systemSetting.pleaseSelectDeviceScope') }]}
>
<Select placeholder={t('systemSetting.pleaseSelectDeviceScope')}> <Select placeholder={t('systemSetting.pleaseSelectDeviceScope')}>
{DeviceScopeOptions.map(option => ( {DeviceScopeOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`systemSetting.${option.labelKey}`)}</Option> <Option key={option.value} value={option.value}>
{t(`systemSetting.${option.labelKey}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={12}> <Col span={12}>
<Form.Item name="key" label={t('systemSetting.triggerKey')} rules={[{ required: true, message: t('systemSetting.pleaseSelectTriggerKey') }]}> <Form.Item
name="key"
label={t('systemSetting.triggerKey')}
rules={[{ required: true, message: t('systemSetting.pleaseSelectTriggerKey') }]}
>
<Select placeholder={t('systemSetting.pleaseSelectTriggerKey')}> <Select placeholder={t('systemSetting.pleaseSelectTriggerKey')}>
{TriggerKeyOptions.map(option => ( {TriggerKeyOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`systemSetting.${option.labelKey}`)}</Option> <Option key={option.value} value={option.value}>
{t(`systemSetting.${option.labelKey}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -444,10 +588,16 @@ export default function RuleConfigManagement() {
<Row gutter={16}> <Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item name="operator" label={t('systemSetting.operator')} rules={[{ required: true, message: t('systemSetting.pleaseSelectOperator') }]}> <Form.Item
name="operator"
label={t('common.operation')}
rules={[{ required: true, message: t('systemSetting.pleaseSelectOperator') }]}
>
<Select placeholder={t('systemSetting.pleaseSelectOperator')}> <Select placeholder={t('systemSetting.pleaseSelectOperator')}>
{CompareEnumOptions.map(option => ( {CompareEnumOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`constants.${option.label}`)}</Option> <Option key={option.value} value={option.value}>
{t(`${option.label}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -456,18 +606,30 @@ export default function RuleConfigManagement() {
{isRangeOperator ? ( {isRangeOperator ? (
<Row gutter={8}> <Row gutter={8}>
<Col span={12}> <Col span={12}>
<Form.Item name="min" label={t('systemSetting.triggerValue')} rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}> <Form.Item
name="min"
label={t('systemSetting.triggerValue')}
rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}
>
<InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} /> <InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} />
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={12}> <Col span={12}>
<Form.Item name="max" label=" " rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}> <Form.Item
name="max"
label=" "
rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}
>
<InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} /> <InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} />
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>
) : ( ) : (
<Form.Item name="value" label={t('systemSetting.triggerValue')} rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}> <Form.Item
name="value"
label={t('systemSetting.triggerValue')}
rules={[{ required: true, message: t('systemSetting.pleaseInputTriggerValue') }]}
>
<InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} /> <InputNumber style={{ width: '100%' }} placeholder={t('systemSetting.pleaseInputTriggerValue')} />
</Form.Item> </Form.Item>
)} )}
@@ -476,10 +638,16 @@ export default function RuleConfigManagement() {
<Row gutter={16}> <Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item name="actionType" label={t('systemSetting.actionType')} rules={[{ required: true, message: t('systemSetting.pleaseSelectActionType') }]}> <Form.Item
name="actionType"
label={t('systemSetting.actionType')}
rules={[{ required: true, message: t('systemSetting.pleaseSelectActionType') }]}
>
<Select placeholder={t('systemSetting.pleaseSelectActionType')}> <Select placeholder={t('systemSetting.pleaseSelectActionType')}>
{ActionTypeOptions.map(option => ( {ActionTypeOptions.map(option => (
<Option key={option.value} value={option.value}>{t(`systemSetting.${option.labelKey}`)}</Option> <Option key={option.value} value={option.value}>
{t(`systemSetting.${option.labelKey}`)}
</Option>
))} ))}
</Select> </Select>
</Form.Item> </Form.Item>
@@ -491,21 +659,21 @@ export default function RuleConfigManagement() {
</Col> </Col>
</Row> </Row>
<Row gutter={16}> {/*<Row gutter={16}>
<Col span={24}> <Col span={24}>
<Form.Item name="argsJson" label={t('systemSetting.actionArgs')}> <Form.Item name="argsJson" label={t('systemSetting.actionArgs')}>
<TextArea rows={4} placeholder={`{\n "routeId": 123\n}`} /> <TextArea rows={4} placeholder={`{\n "routeId": 123\n}`} />
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>*/}
<Row gutter={16}> {/*<Row gutter={16}>
<Col span={12}> <Col span={12}>
<Form.Item name="ForceExecute" label={t('systemSetting.forceExecute')} valuePropName="checked"> <Form.Item name="ForceExecute" label={t('systemSetting.forceExecute')} valuePropName="checked">
<Switch checkedChildren={t('common.yes')} unCheckedChildren={t('common.no')} /> <Switch checkedChildren={t('common.yes')} unCheckedChildren={t('common.no')} />
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>*/}
</Form> </Form>
</Modal> </Modal>
</div> </div>

View File

@@ -100,6 +100,8 @@ export default function MapEditorPage() {
const [obstaclePointConfigList, setObstaclePointConfigList] = useState<any[]>([]); const [obstaclePointConfigList, setObstaclePointConfigList] = useState<any[]>([]);
// 站点地图信息主键 id,编辑/保存时需要带上 // 站点地图信息主键 id,编辑/保存时需要带上
const [siteMapInfoId, setSiteMapInfoId] = useState<number | null>(null); const [siteMapInfoId, setSiteMapInfoId] = useState<number | null>(null);
// getSiteMapInfoFn 并发请求版本号,只接受最新请求的结果,避免旧请求覆盖新数据
const siteMapRequestIdRef = useRef(0);
// 预设路径(供分区的 bindRoutes / defaultRoute 选择) // 预设路径(供分区的 bindRoutes / defaultRoute 选择)
const [presetRoutes, setPresetRoutes] = useState<any[]>([]); const [presetRoutes, setPresetRoutes] = useState<any[]>([]);
const [selectedRouteId, setSelectedRouteId] = useState<string | number | null>(null); const [selectedRouteId, setSelectedRouteId] = useState<string | number | null>(null);
@@ -115,6 +117,7 @@ export default function MapEditorPage() {
// 当前展示的点位列表 // 当前展示的点位列表
const currentList = useMemo(() => { const currentList = useMemo(() => {
//returnPointConfigList
if (activeType === 'returnPoint') return returnPoints; if (activeType === 'returnPoint') return returnPoints;
if (activeType === 'restArea') return restAreas; if (activeType === 'restArea') return restAreas;
if (activeType === 'routeGen') return routePoints; if (activeType === 'routeGen') return routePoints;
@@ -149,7 +152,10 @@ export default function MapEditorPage() {
}, [stationId]); }, [stationId]);
const getSiteMapInfoFn = () => { const getSiteMapInfoFn = () => {
const reqId = ++siteMapRequestIdRef.current;
getSiteMapInfo({ siteId: stationId }).then((res: any) => { getSiteMapInfo({ siteId: stationId }).then((res: any) => {
// 只处理最新一次请求的结果,避免并发竞态覆盖
if (reqId !== siteMapRequestIdRef.current) return;
if (res?.code === 200 && res.data) { if (res?.code === 200 && res.data) {
setSiteMapInfoId(res.data.id ?? null); setSiteMapInfoId(res.data.id ?? null);
@@ -563,8 +569,9 @@ export default function MapEditorPage() {
i === index ? { ...p, alias } : p i === index ? { ...p, alias } : p
); );
// 先更新界面 // 同时更新已配置列表和编辑列表,保证二者一致
setReturnPointConfigList(updated); setReturnPointConfigList(updated);
setReturnPoints(prev => prev.map((p, i) => i === index ? { ...p, name: alias } : p));
const payload: any = { const payload: any = {
restPoints: updated.map((p: any) => ({ restPoints: updated.map((p: any) => ({
@@ -717,6 +724,7 @@ export default function MapEditorPage() {
i === index ? { ...p, bindDeviceId: bindDeviceId || null } : p i === index ? { ...p, bindDeviceId: bindDeviceId || null } : p
); );
setReturnPointConfigList(updated); setReturnPointConfigList(updated);
setReturnPoints(prev => prev.map((p, i) => i === index ? { ...p, deviceId: bindDeviceId || undefined } : p));
const restPoints = updated.map((p: any) => ({ const restPoints = updated.map((p: any) => ({
alias: p.alias, alias: p.alias,

View File

@@ -1060,6 +1060,8 @@
savePathTitle: 'Save Path Title', savePathTitle: 'Save Path Title',
savePlan: 'Save Plan', savePlan: 'Save Plan',
workName: 'Work Name', workName: 'Work Name',
actionTypeBackToRest: 'actionTypeBackToRest',
saving: 'Saving', saving: 'Saving',
searchDeviceName: 'Search Device Name', searchDeviceName: 'Search Device Name',
searchWaylinePlaceholder: 'Search Wayline Placeholder', searchWaylinePlaceholder: 'Search Wayline Placeholder',

View File

@@ -2705,6 +2705,7 @@ const zh = {
triggerValue: '阈值', triggerValue: '阈值',
actionType: '执行动作', actionType: '执行动作',
actionTypeAutoTask: '路径规划任务', actionTypeAutoTask: '路径规划任务',
actionTypeBackToRest: '返航任务',
actionTypeSendCommand: '下发指令', actionTypeSendCommand: '下发指令',
actionTypeAlarm: '告警', actionTypeAlarm: '告警',
actionTypeWorkOrder: '工单下发', actionTypeWorkOrder: '工单下发',