You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.5 KiB
TypeScript
171 lines
5.5 KiB
TypeScript
1 year ago
|
/*
|
||
|
* @Author: zhoux zhouxia@supervision.ltd
|
||
|
* @Date: 2023-11-01 13:56:33
|
||
|
* @LastEditors: zhoux zhouxia@supervision.ltd
|
||
|
* @LastEditTime: 2023-12-18 17:47:49
|
||
|
* @FilePath: \general-ai-platform-web\src\pages\Device\DeviceCategoryList\components\UpdateForm.tsx
|
||
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||
|
*/
|
||
|
import { putDeviceCategoryUpdateDeviceCategory } from '@/services/device/DeviceCategory';
|
||
|
import {
|
||
|
ModalForm,
|
||
|
ProForm,
|
||
|
ProFormDateTimePicker,
|
||
|
ProFormSelect,
|
||
|
ProFormText,
|
||
|
} from '@ant-design/pro-components';
|
||
|
import { FormattedMessage, useIntl } from '@umijs/max';
|
||
|
import { Form, message } from 'antd';
|
||
|
import React from 'react';
|
||
|
import {
|
||
|
proFormSmallItemStyleProps,
|
||
|
proFormSmallModelWidth,
|
||
|
} from '../../../../../config/defaultForm';
|
||
|
import { postDeviceGroupGetDeviceGroupFkSelect } from '@/services/device/DeviceGroup';
|
||
|
export type FormValueType = {
|
||
|
target?: string;
|
||
|
template?: string;
|
||
|
type?: string;
|
||
|
time?: string;
|
||
|
frequency?: string;
|
||
|
} & Partial<API.DeviceCategory>;
|
||
|
|
||
|
export type UpdateFormProps = {
|
||
|
updateModalOpen: boolean;
|
||
|
handleModal: () => void;
|
||
|
values: Partial<API.DeviceCategory>;
|
||
|
reload: any;
|
||
|
};
|
||
|
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||
|
const intl = useIntl();
|
||
|
const [form] = Form.useForm<API.DeviceCategory>();
|
||
|
|
||
|
return (
|
||
|
<ModalForm<API.DeviceCategory>
|
||
|
width={proFormSmallModelWidth}
|
||
|
title={intl.formatMessage({
|
||
|
id: 'alarm.setting.table.list.update',
|
||
|
defaultMessage: '$$$',
|
||
|
})}
|
||
|
open={props.updateModalOpen}
|
||
|
form={form}
|
||
|
autoFocusFirstInput
|
||
|
modalProps={{
|
||
|
destroyOnClose: true,
|
||
|
onCancel: () => props.handleModal(),
|
||
|
}}
|
||
|
submitTimeout={2000}
|
||
|
onFinish={async (values) => {
|
||
|
putDeviceCategoryUpdateDeviceCategory(values)
|
||
|
.then(() => {
|
||
|
message.success(intl.formatMessage({ id: 'common.success', defaultMessage: '$$$' }));
|
||
|
props.reload();
|
||
|
})
|
||
|
.catch(() => {
|
||
|
message.error(intl.formatMessage({ id: 'common.failure', defaultMessage: '$$$' }));
|
||
|
});
|
||
|
|
||
|
props.handleModal();
|
||
|
return true;
|
||
|
}}
|
||
|
>
|
||
|
<ProForm.Group>
|
||
|
<ProFormText
|
||
|
width={proFormSmallItemStyleProps.width}
|
||
|
name="name"
|
||
|
label={<FormattedMessage id="alarm.setting.table.list.name" defaultMessage="$$$" />}
|
||
|
placeholder={`${intl.formatMessage({
|
||
|
id: 'common.please_input',
|
||
|
defaultMessage: '$$$',
|
||
|
})}${intl.formatMessage({
|
||
|
id: 'alarm.setting.table.list.name',
|
||
|
defaultMessage: '$$$',
|
||
|
})}`}
|
||
|
required={true}
|
||
|
initialValue={props.values.name}
|
||
|
disabled={false}
|
||
|
rules={[
|
||
|
{
|
||
|
required: true,
|
||
|
message: (
|
||
|
<FormattedMessage
|
||
|
id="DCSDeviceList.device_category.table.rule.required.name"
|
||
|
defaultMessage="name is required"
|
||
|
/>
|
||
|
),
|
||
|
},
|
||
|
]}
|
||
|
/>
|
||
|
<ProFormText
|
||
|
width={proFormSmallItemStyleProps.width}
|
||
|
name="code"
|
||
|
label={<FormattedMessage id="alarm.setting.table.list.code" defaultMessage="$$$" />}
|
||
|
placeholder={`${intl.formatMessage({
|
||
|
id: 'common.please_input',
|
||
|
defaultMessage: '$$$',
|
||
|
})}${intl.formatMessage({
|
||
|
id: 'alarm.setting.table.list.code',
|
||
|
defaultMessage: '$$$',
|
||
|
})}`}
|
||
|
required={true}
|
||
|
initialValue={props.values.code}
|
||
|
disabled={false}
|
||
|
rules={[
|
||
|
{
|
||
|
required: true,
|
||
|
message: (
|
||
|
<FormattedMessage
|
||
|
id="alarm.setting.table.rule.required.code"
|
||
|
defaultMessage="code is required"
|
||
|
/>
|
||
|
),
|
||
|
},
|
||
|
]}
|
||
|
/>
|
||
|
<ProFormSelect
|
||
|
width={proFormSmallItemStyleProps.width}
|
||
|
name="level"
|
||
|
label={<FormattedMessage id="alarm.setting.table.list.level" defaultMessage="$$$" />}
|
||
|
placeholder={`${intl.formatMessage({
|
||
|
id: 'common.please_select',
|
||
|
defaultMessage: '$$$',
|
||
|
})}${intl.formatMessage({
|
||
|
id: 'alarm.setting.table.list.level',
|
||
|
defaultMessage: '$$$',
|
||
|
})}`}
|
||
|
required={false}
|
||
|
initialValue={props.values.level}
|
||
|
debounceTime={1000}
|
||
|
request={async (keyWord) => {
|
||
|
// TODO 此处需要使用告警级别接口联调
|
||
|
const resp = await postDeviceGroupGetDeviceGroupFkSelect({});
|
||
|
return resp.data.list.map((v: any) => {
|
||
|
return {
|
||
|
label: v.name,
|
||
|
value: v.id,
|
||
|
};
|
||
|
});
|
||
|
}}
|
||
|
/>
|
||
|
<ProFormText
|
||
|
width={proFormSmallItemStyleProps.width}
|
||
|
name="remark"
|
||
|
label={<FormattedMessage id="alarm.setting.table.list.remark" defaultMessage="$$$" />}
|
||
|
placeholder={`${intl.formatMessage({
|
||
|
id: 'common.please_input',
|
||
|
defaultMessage: '$$$',
|
||
|
})}${intl.formatMessage({
|
||
|
id: 'alarm.setting.table.list.remark',
|
||
|
defaultMessage: '$$$',
|
||
|
})}`}
|
||
|
required={false}
|
||
|
initialValue={props.values.remark}
|
||
|
disabled={false}
|
||
|
/>
|
||
|
|
||
|
</ProForm.Group>
|
||
|
</ModalForm>
|
||
|
);
|
||
|
};
|
||
|
export default UpdateForm;
|