vdi/web-fe/src/pages/terminal/mod/bindImage/index.tsx

145 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-08-07 10:15:11 +00:00
// index.tsx
2025-08-11 09:19:58 +00:00
import { ERROR_CODE } from '@/constants/constants';
2025-08-11 10:33:13 +00:00
import { getBindImageAdd, getBindImageList } from '@/services/terminal';
2025-08-11 09:19:58 +00:00
import { Button, Form, message, Modal } from 'antd';
2025-08-07 10:15:11 +00:00
import React, { useEffect } from 'react';
import SelectedTable from '../ImageSelectedTable/index';
import styles from './index.less';
interface UserEditModalProps {
onCancel: () => void;
onOk: (values: any) => void;
confirmLoading?: boolean;
dataDetial?: Termial.ModalBaseNode;
selectedOrg?: number;
}
const BindUserModal: React.FC<UserEditModalProps> = ({
onCancel,
onOk,
confirmLoading = false,
dataDetial,
}) => {
const { recordData, visible, selectedOrg } = dataDetial || {};
2025-08-11 10:33:13 +00:00
const { device_id } = recordData || {};
2025-08-07 10:15:11 +00:00
const [form] = Form.useForm();
useEffect(() => {
2025-08-11 09:19:58 +00:00
const params = { device_id: device_id };
getBindImageList(params).then((res: any) => {
const { code, data = [] } = res || {};
if (code === ERROR_CODE) {
if (data && data.length) {
const initialValues = { image_list: data };
form.setFieldsValue(initialValues);
}
}
});
2025-08-07 10:15:11 +00:00
}, [visible, form, recordData, selectedOrg]);
const handleOk = async () => {
try {
const values = await form.validateFields();
2025-08-11 10:33:13 +00:00
const { image_list } = values || {};
if (image_list && image_list.length > 0) {
const list: any[] = [];
image_list.forEach((item: any) => {
list.push({
id: item.id,
device_id: device_id,
image_id: item.record_id,
});
});
const payload: any = {
data: list,
};
getBindImageAdd(payload).then((res: any) => {
const { code } = res || {};
if (code === ERROR_CODE) {
message.success('绑定成功');
onOk();
} else {
message.error('绑定失败');
}
});
} else {
message.info('请先选择绑定的镜像');
}
2025-08-07 10:15:11 +00:00
console.log('values=====', values);
2025-08-11 10:33:13 +00:00
// onOk(values);
2025-08-07 10:15:11 +00:00
} catch (error) {
message.error('请检查表单字段');
}
};
return (
<Modal
title={'绑定镜像'}
open={visible}
onCancel={onCancel}
onOk={handleOk}
confirmLoading={confirmLoading}
width={1200}
maskClosable={false}
centered={true}
destroyOnHidden={true}
cancelText="取消"
okText="确定"
2025-08-11 10:11:44 +00:00
footer={null}
// footer={
// <div style={{ display: 'flex', justifyContent: 'right' }}>
// <Button
// type="primary"
// onClick={handleOk}
// style={{ marginRight: '20px' }}
// >
// 确定
// </Button>
// <Button onClick={onCancel} style={{ marginRight: '20px' }}>
// 取消
// </Button>
// </div>
// }
2025-08-07 10:15:11 +00:00
>
<div className={styles.model_content}>
<Form
form={form}
2025-08-11 10:11:44 +00:00
onFinish={handleOk}
2025-08-07 10:15:11 +00:00
labelCol={{ span: 4 }}
wrapperCol={{ span: 19 }}
layout="horizontal"
style={{ paddingTop: '20px', paddingBottom: '20px' }}
>
<Form.Item
2025-08-11 09:19:58 +00:00
name="image_list"
2025-08-07 10:15:11 +00:00
label="选择镜像"
rules={[{ required: true, message: '请输入终端型号' }]}
>
<SelectedTable />
</Form.Item>
2025-08-11 09:19:58 +00:00
{/* <Form.Item
2025-08-07 10:15:11 +00:00
name="description"
label="描述内容"
rules={[{ required: false, message: '请输入描述内容' }]}
>
<Input.TextArea rows={4} />
2025-08-11 09:19:58 +00:00
</Form.Item> */}
2025-08-11 10:11:44 +00:00
<Form.Item label={null}>
<Button
type="primary"
htmlType="submit"
style={{ marginRight: '20px' }}
>
</Button>
<Button onClick={onCancel}></Button>
</Form.Item>
2025-08-07 10:15:11 +00:00
</Form>
</div>
</Modal>
);
};
export default BindUserModal;