|
|
@@ -1,70 +1,58 @@
|
|
|
-import { Modal } from '@/components';
|
|
|
-import { Form, Input } from 'antd';
|
|
|
-import TriggerWay from '@/pages/rule-engine/Scene/Save/components/TriggerWay';
|
|
|
-import type { SceneItem } from '@/pages/rule-engine/Scene/typings';
|
|
|
-import { useEffect } from 'react';
|
|
|
-import { getMenuPathByCode } from '@/utils/menu';
|
|
|
-import useHistory from '@/hooks/route/useHistory';
|
|
|
+import { PageContainer } from '@ant-design/pro-layout';
|
|
|
+import { Button, Card, Form, Input } from 'antd';
|
|
|
+import useLocation from '@/hooks/route/useLocation';
|
|
|
+import Device from '../Save/device/index';
|
|
|
+import Manual from '../Save/manual/index';
|
|
|
+import Timer from '../Save/timer/index';
|
|
|
+import { TitleComponent } from '@/components';
|
|
|
|
|
|
-interface Props {
|
|
|
- close: () => void;
|
|
|
- data: Partial<SceneItem>;
|
|
|
-}
|
|
|
+export default () => {
|
|
|
+ const location = useLocation();
|
|
|
+ const triggerType = location?.query?.triggerType || '';
|
|
|
|
|
|
-export default (props: Props) => {
|
|
|
- const [form] = Form.useForm();
|
|
|
- const history = useHistory();
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- form.setFieldsValue({
|
|
|
- ...props.data,
|
|
|
- });
|
|
|
- }, [props.data]);
|
|
|
+ const triggerRender = (type: string) => {
|
|
|
+ switch (type) {
|
|
|
+ case 'device':
|
|
|
+ return (
|
|
|
+ <Form.Item label={<TitleComponent style={{ fontSize: 14 }} data={'设备触发'} />}>
|
|
|
+ <Device />
|
|
|
+ </Form.Item>
|
|
|
+ );
|
|
|
+ case 'manual':
|
|
|
+ return (
|
|
|
+ <Form.Item label={<TitleComponent style={{ fontSize: 14 }} data={'手动触发'} />}>
|
|
|
+ <Manual />
|
|
|
+ </Form.Item>
|
|
|
+ );
|
|
|
+ case 'timer':
|
|
|
+ return (
|
|
|
+ <Form.Item label={<TitleComponent style={{ fontSize: 14 }} data={'定时触发'} />}>
|
|
|
+ <Timer />
|
|
|
+ </Form.Item>
|
|
|
+ );
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
return (
|
|
|
- <Modal
|
|
|
- title={props.data?.id ? '编辑' : '新增'}
|
|
|
- maskClosable={false}
|
|
|
- visible
|
|
|
- onCancel={() => {
|
|
|
- props.close();
|
|
|
- }}
|
|
|
- onOk={async () => {
|
|
|
- const values = await form.validateFields();
|
|
|
- props.close();
|
|
|
- const url = getMenuPathByCode('rule-engine/Scene/Detail');
|
|
|
- history.push(`${url}?type=${values.trigger?.type}`);
|
|
|
- }}
|
|
|
- width={700}
|
|
|
- >
|
|
|
- <Form name="scene-save" layout={'vertical'} form={form} autoComplete="off">
|
|
|
- <Form.Item
|
|
|
- name={'name'}
|
|
|
- label={'名称'}
|
|
|
- rules={[
|
|
|
- { required: true, message: '请输入名称' },
|
|
|
- {
|
|
|
- max: 64,
|
|
|
- message: '最多输入64个字符',
|
|
|
- },
|
|
|
- ]}
|
|
|
- >
|
|
|
- <Input placeholder={'请输入名称'} />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item
|
|
|
- label={'触发方式'}
|
|
|
- name={['trigger', 'type']}
|
|
|
- rules={[{ required: true, message: '请选择触发方式' }]}
|
|
|
- initialValue={'device'}
|
|
|
- >
|
|
|
- <TriggerWay
|
|
|
- // onSelect={(val) => {
|
|
|
- // // console.log(val);
|
|
|
- // }}
|
|
|
- disabled={!!props.data?.id}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- </Form>
|
|
|
- </Modal>
|
|
|
+ <PageContainer>
|
|
|
+ <Card>
|
|
|
+ <Form name="timer" layout={'vertical'}>
|
|
|
+ {triggerRender(triggerType)}
|
|
|
+ <Form.Item
|
|
|
+ label={<TitleComponent style={{ fontSize: 14 }} data={'说明'} />}
|
|
|
+ name="description"
|
|
|
+ >
|
|
|
+ <Input.TextArea showCount maxLength={200} placeholder={'请输入说明'} rows={4} />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item>
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 保存
|
|
|
+ </Button>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </Card>
|
|
|
+ </PageContainer>
|
|
|
);
|
|
|
};
|