Commit ff46bff4 authored by cellee's avatar cellee

Signed-off-by: cellee <893264950@qq.com>

parent af1211bb
......@@ -86,15 +86,15 @@ export default {
changeOrigin: true,
pathRewrite: { '^': '' },
},
'/tos/': {
target: 'http://47.74.233.180:8651',
changeOrigin: true,
pathRewrite: { '^': '' },
},
// '/tos/': {
// target: 'http://192.168.1.28:8651',
// target: 'http://47.74.233.180:8651',
// changeOrigin: true,
// pathRewrite: { '^': '' },
// },
'/tos/': {
target: 'http://192.168.1.28:8651',
changeOrigin: true,
pathRewrite: { '^': '' },
},
},
};
/*
* @Author: your name
* @Date: 2021-02-01 14:54:48
* @LastEditTime: 2021-02-06 11:51:58
* @LastEditTime: 2021-02-18 13:54:59
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \tostumi\src\components\Form\PdfUpload.tsx
*/
import React, { useState } from 'react';
import { Input, Upload, message, Button, Spin } from 'antd';
import { LoadingOutlined, PlusOutlined, MinusCircleOutlined } from '@ant-design/icons';
import {
LoadingOutlined,
PlusOutlined,
MinusCircleOutlined,
FilePdfOutlined,
} from '@ant-design/icons';
interface PriceInputProps {
value?: any;
......@@ -19,8 +24,12 @@ interface PriceInputProps {
}
const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled, action, data }) => {
const [loading, setLoading] = useState([false, false, false, false, false]);
const [imgList, setImgList] = useState([] as any);
const [loading, setLoading] = useState([false, false, false, false, false]); // 上传中控制
const [idx, setIdx] = useState(0); // 点击的第几个
const [imgList, setImgList] = useState([] as any); // 列表
const [PdfUrl, setPdfUrl] = useState(null); //地址
const [ModalVisible, setModalVisible] = useState(false); //显示隐藏
// 上传前检测
function beforeUpload(file: any) {
......@@ -38,22 +47,26 @@ const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled,
// 上传成功怎么做
const handleChange = (info: any) => {
console.log(info);
console.log(info.event);
let { status, response } = info.file;
if (status === 'uploading') {
// setLoading();
return;
let v = loading;
v[idx] = true;
setLoading([...v]);
} else {
// setLoading(false);
let v = loading;
v[idx] = false;
setLoading([...v]);
}
if (status === 'done') {
let { fileName, key } = response.data;
console.log('上传成功');
let { fileName, key, fileUrl } = response.data;
let list = JSON.parse(JSON.stringify(imgList));
let obj = {
uid: Math.floor(Math.random() * 100),
name: fileName,
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
url: fileUrl,
};
if (!list[parseInt(key)]) {
// 先判断这个是不是在上传途中被删除掉了
......@@ -74,7 +87,7 @@ const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled,
id: Math.floor(Math.random() * 100),
name: '',
fileList: [],
tip: true,
tip: false,
loading: false,
message: '123',
};
......@@ -97,13 +110,17 @@ const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled,
// 点击预览
const handlePreview = async (file: any) => {
if (!file.url && !file.preview) {
// file.preview = await getBase64(file.originFileObj);
}
console.log(file);
// setpreviewImage(file.url || file.preview);
// setpreviewTitle(file.name);
// setpreviewVisible(true);
setPdfUrl(file);
setModalVisible(true);
};
// 点击上传记录index
const opens = (i: any) => {
setIdx(i);
};
const icons = () => {
return <FilePdfOutlined />;
};
return (
......@@ -124,15 +141,16 @@ const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled,
name="file"
listType="picture-card"
fileList={item.fileList}
// showUploadList={false}
onPreview={handlePreview} // 预览
beforeUpload={beforeUpload}
beforeUpload={beforeUpload} //上传前检测
onChange={handleChange}
id={index}
iconRender={icons}
>
{item.fileList && item.fileList.length >= 5 ? null : (
<div>
<div onClick={() => opens(index)}>
{loading[index] ? <LoadingOutlined /> : <PlusOutlined />}
{/* <PlusOutlined></PlusOutlined> */}
<div style={{ marginTop: 8 }}>Upload</div>
</div>
)}
......@@ -161,6 +179,8 @@ const PdfUpload: React.FC<PriceInputProps> = ({ value = {}, onChange, disabled,
) : (
''
)}
{/* 弹出层 */}
</>
);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment