上传xml文件

dev
陈博文 3 years ago
parent 3e5033d403
commit 795a06679e

@ -39,3 +39,7 @@
width: 388px;
}
}
.colorBlue {
color: @primary-color;
}

@ -8,33 +8,37 @@ import {
message,
Empty,
Table,
InputNumber,
Upload,
Input,
Col,
} from 'antd';
import Fetch from '@/utils/fetch';
import { useEffect, useState, FC, useRef, Fragment } from 'react';
import React, { useEffect, useState, FC, useRef, Fragment } from 'react';
import { downLoadLink } from '@/utils/download';
import url from '@/utils/url';
import { ColumnsType } from 'antd/lib/table';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
const { Dragger } = Upload;
interface PageProps {}
const Page: FC<PageProps> = () => {
const [data, setData] = useState<any>([]);
const [firmList, setFirmList] = useState<any[]>([]);
const [fileList, setFileList] = useState<any[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [total, setTotal] = useState<number>(0);
const [value, setValue] = useState<string>('');
const [visible, setVisible] = useState<boolean>(false);
const [visible, setVisible] = useState<any>(false);
const [form] = Form.useForm();
const [formAdd] = Form.useForm();
const [params, setParams] = useState<any>({
pageNumber: 1,
pageSize: 20,
keywords: '',
});
const editId = useRef(null);
const savedFileList = useRef<any>([]);
useEffect(() => {
getData(params);
@ -117,6 +121,11 @@ const Page: FC<PageProps> = () => {
};
const handleFinish = async (v: any) => {
console.log(v, 22222);
if (!v?.producerIdList?.length) {
message.warn('厂商不能为空');
return;
}
const res = await Fetch(`/openi/deviceType/editOrAdd`, {
method: 'post',
data: {
@ -132,18 +141,31 @@ const Page: FC<PageProps> = () => {
}
};
const handleAddFinish = async (v: any) => {
console.log(v, 22);
const res = await Fetch(`/openi/deviceType/addList`, {
method: 'post',
data: v.sights || [],
});
if (res.result === 'success') {
params.pageNumber = editId.current ? params.pageNumber : 1;
setParams({ ...params });
getData(params);
setVisible(false);
}
};
const handleEdit = (param: any) => {
form.setFieldsValue({
...param,
producerIdList: param?.producerList?.map((e: any) => e.id),
});
editId.current = param.id;
setVisible(true);
setVisible('编辑');
};
const handleAdd = () => {
form.setFieldsValue({ producerIdList: [''] });
setVisible(true);
setVisible('新增');
};
const handleDelete = (id: any) => {
@ -169,6 +191,73 @@ const Page: FC<PageProps> = () => {
});
};
const handleRemoveFile = async (info: any) => {
const newFileList = fileList.filter((item) => item.uid !== info.uid);
setFileList(newFileList);
savedFileList.current = [...newFileList];
message.info('删除成功');
};
const handleBeforeUpload = (info: any) => {
if (fileList?.some((e: any) => e.name === info.name)) {
message.info(`${info.name}文件已存在`);
return false;
}
let fileText = info?.name?.substring(
info?.name?.lastIndexOf('.'),
info?.name?.length,
);
fileText = fileText?.toLowerCase();
if (fileText !== '.xml' && fileText !== '.XML') {
message.error('只能上传.xml,.XML格式的文档');
return false;
}
const param = { name: info.name, uid: info.uid, file: info, percent: 0 };
fileList.push(param);
savedFileList.current = [...fileList];
setFileList([...fileList]);
return false;
};
const draggerProps = {
height: 40,
multiple: true,
withCredentials: true,
fileList,
disabled: fileList.length > 10,
maxCount: 10,
accept: '.xml, .XML',
// action: `${ENV.API_SERVER}/api/attachments.json`,
// onChange: handleChangeFile,
onRemove: handleRemoveFile,
beforeUpload: handleBeforeUpload,
};
const returnDom = () => {
return (
<div style={{ marginTop: -8 }} className={`font14`}>
<span className={`${styles.colorBlue} ml5`}></span>
</div>
);
};
const handleLoad = () => {
const k = [
{
name: 'U盘',
typeNumber: '8782',
pattern: '国家保密机',
secretLevel: '3级',
managementLevel: '公司 ',
producerIdList: [''],
},
];
formAdd.setFieldsValue({
sights: k,
});
};
return (
<div className={styles.page}>
<div className={styles.title}>
@ -224,8 +313,192 @@ const Page: FC<PageProps> = () => {
/>
<Modal
centered
title={`${editId.current ? '编辑' : '新建'}设备型号`}
visible={visible}
title={`新增设备型号`}
visible={visible === '新增'}
okText="保存"
width={924}
afterClose={() => {
formAdd.resetFields();
editId.current = null;
setFileList([]);
savedFileList.current = [];
}}
cancelText="取消"
onOk={() => {
formAdd.submit();
}}
onCancel={() => {
setVisible(false);
}}
>
<Dragger {...draggerProps}> {returnDom()}</Dragger>
<Row align="middle" justify="center" className="mt10">
<Button
type="dashed"
disabled={fileList.length === 0}
onClick={handleLoad}
style={{ width: 400 }}
>
</Button>
</Row>
<Form
form={formAdd}
colon={false}
layout="horizontal"
onFinish={handleAddFinish}
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
style={{
maxHeight: 500,
overflow: 'auto',
marginTop: 10,
}}
>
<Form.List name="sights">
{(fields) =>
fields.map(({ key, name, ...restField }: any, index: number) => {
return (
<div key={key}>
<b>{index + 1}</b>
<Row align="middle">
<Col span={12}>
<Form.Item
{...restField}
label="装备名称"
name={[name, 'name']}
rules={[
{
required: true,
message: `请输入装备名称`,
},
]}
>
<Input disabled />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
{...restField}
label="装备代号"
name={[name, 'typeNumber']}
rules={[
{
required: true,
message: `请输入装备代号`,
},
]}
>
<Input disabled />
</Form.Item>
</Col>
</Row>
<Row align="middle">
<Col span={12}>
<Form.Item
{...restField}
label="工作模式"
name={[name, 'pattern']}
rules={[
{
required: true,
message: `请输入工作模式`,
},
]}
>
<Input disabled />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
{...restField}
label="装备密级"
name={[name, 'secretLevel']}
rules={[
{
required: true,
message: `请输入装备密级`,
},
]}
>
<Input disabled />
</Form.Item>
</Col>
</Row>
<Row align="middle">
<Col span={12}>
<Form.Item
{...restField}
label="管理层级"
name={[name, 'managementLevel']}
rules={[
{
required: true,
message: `请输入管理层级`,
},
]}
>
<Input disabled />
</Form.Item>
</Col>
</Row>
<Form.List name={[name, 'producerIdList']}>
{(fields, { add, remove }, { errors }) => (
<>
{fields.map(({ key, name, ...restField }, index) => (
<Row align="middle" key={key}>
<Form.Item
className={styles.li}
{...restField}
label="厂商"
name={[name]}
rules={[
{
required: true,
message: '请输入厂商',
},
]}
>
<Select>
{firmList?.map((e) => (
<Select.Option value={e.id} key={e.id}>
{e.name}
</Select.Option>
))}
</Select>
</Form.Item>
{fields.length > 1 ? (
<MinusCircleOutlined
style={{ margin: '0px 0px 23px 10px' }}
onClick={() => remove(name)}
/>
) : null}
</Row>
))}
<Row align="middle" justify="center">
<Button
type="dashed"
onClick={() => add()}
style={{ width: 400 }}
icon={<PlusOutlined />}
>
</Button>
</Row>
</>
)}
</Form.List>
</div>
);
})
}
</Form.List>
</Form>
</Modal>
<Modal
centered
title={'编辑设备型号'}
visible={visible === '编辑'}
okText="保存"
width={924}
afterClose={() => {
@ -264,7 +537,7 @@ const Page: FC<PageProps> = () => {
},
]}
>
<Input />
<Input disabled />
</Form.Item>
</Col>
<Col span={12}>
@ -278,7 +551,7 @@ const Page: FC<PageProps> = () => {
},
]}
>
<Input />
<Input disabled />
</Form.Item>
</Col>
</Row>
@ -294,7 +567,7 @@ const Page: FC<PageProps> = () => {
},
]}
>
<Input />
<Input disabled />
</Form.Item>
</Col>
<Col span={12}>
@ -308,7 +581,7 @@ const Page: FC<PageProps> = () => {
},
]}
>
<Input />
<Input disabled />
</Form.Item>
</Col>
</Row>
@ -324,7 +597,7 @@ const Page: FC<PageProps> = () => {
},
]}
>
<Input />
<Input disabled />
</Form.Item>
</Col>
</Row>

@ -12,11 +12,11 @@ const Header = ({ ...props }) => {
const res = await Fetch('/openi/localManager/isOpen');
if (res.result === 'success') {
document.title = '管理基础设施';
if (!res?.data?.[0]) {
message.warn('当前本地管理终端未开通,已为你跳转至终端界面!');
history.replace('/terminal');
return;
}
// if (!res?.data?.[0]) {
// message.warn('当前本地管理终端未开通,已为你跳转至终端界面!');
// history.replace('/terminal');
// return;
// }
}
};

@ -107,7 +107,7 @@ const Progress = ({ item, onFinish, start, setVisible }: any) => {
<div className={styles.s1}>{data.deviceId}</div>
<div className={styles.s2}>{data.name}</div>
<div className={styles.s0}>
{data.type === 4 ? (
{data.type !== 3 ? (
<i
onClick={() => setVisible(data)}
className="iconfont icon-bianji10"
@ -146,7 +146,7 @@ const Progress = ({ item, onFinish, start, setVisible }: any) => {
<div className={styles.s0}>
{data.type === 1 ? (
<i
onClick={() => setVisible(data)}
// onClick={() => setVisible(data)}
className="iconfont icon-bianji10"
/>
) : (
@ -171,7 +171,7 @@ const Progress = ({ item, onFinish, start, setVisible }: any) => {
<div className={styles.s0}>
{data.type === 2 ? (
<i
onClick={() => setVisible(data)}
// onClick={() => setVisible(data)}
className="iconfont icon-bianji10"
/>
) : (

Loading…
Cancel
Save