Commit ae8a8eef authored by Bill's avatar Bill

fix: 上传token 问题

parent defe2f20
......@@ -39,6 +39,10 @@
margin-right: @margin-sm;
}
.error {
color: '#ff4d4f';
}
> a {
flex: 1;
.textOverflow();
......
......@@ -6,6 +6,7 @@ import { Upload, Progress, Button } from 'antd';
import { CloudUploadOutlined, DeleteOutlined } from '@ant-design/icons';
import styles from './UploadFiles.less';
import pdf_icon from '@/assets/imgs/pdf_icon.png';
import { getAuth } from '@/utils/auth';
type PickProps = "headers" | "action" | "accept" | "beforeUpload" | "onChange" | "fileList"
......@@ -35,6 +36,7 @@ const UploadFiles: React.FC<PickUploadProps> = (props: PickUploadProps) => {
fileContainerClassName
} = props;
const hasFileListProps = "fileList" in props;
const auth = getAuth();
const [files, setFiles] = useState<UploadFile[]>(() => props.fileList || []);
// const renderFiles = hasFileListProps ? props.fileList : files;
useEffect(() => {
......@@ -53,7 +55,7 @@ const UploadFiles: React.FC<PickUploadProps> = (props: PickUploadProps) => {
fileList: files,
accept: accept,
action: action,
headers: headers,
headers: { ...headers, token: auth.token },
data: {
fileType: UPLOAD_TYPE
},
......@@ -102,7 +104,7 @@ const UploadFiles: React.FC<PickUploadProps> = (props: PickUploadProps) => {
<div className={styles.renderFileItem} >
<div className={styles['fileItem-left']}>
<img className={styles.img} src={pdf_icon} />
<a href={_item.url} target="_blank">{_item.name}</a>
<a className={cx({[styles.error]: _item.status === 'error'})} href={_item.url} target="_blank">{_item.name}</a>
</div>
{
!disable && (
......
......@@ -13,6 +13,7 @@ import { UploadFile, UploadChangeParam } from 'antd/lib/upload/interface';
import { UPLOAD_TYPE } from '@/constants'
import { VoucherFileProps } from '../../common/type';
import { PublicApi } from '@/services/api';
import { getAuth } from '@/utils/auth';
interface Iprops {
fileList?: VoucherFileProps[],
......@@ -31,6 +32,7 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
const [fileList, setFileList] = useState([]);
const [loading, setLoading] = useState(false);
const [accountInfo, setAccountInfo] = useState<AccountInfo>(null)
const auth = getAuth();
// 进来设置fileList
// useEffect(() => {
......@@ -70,7 +72,7 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
const uploadProps = {
name: 'file',
action: '/api/file/file/upload',
headers: {},
headers: {token: auth.token},
data: {
fileType: UPLOAD_TYPE, // 指定类型是本地还是线上,
},
......
......@@ -4,10 +4,12 @@ import { Upload, Button, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons'
import { UPLOAD_TYPE } from '@/constants'
import FileListItem from './FileList';
import { getAuth } from '@/utils/auth';
const UploadFile = (props) => {
const { fileList = [], onChange, fileMaxSize = 20 } = props
const [loading, setLoading] = useState<boolean>(false)
const auth = getAuth();
const beforeUpload = (file) => {
const isSizeLimit = file.size / 1024 < fileMaxSize;
if (!isSizeLimit) {
......@@ -19,7 +21,7 @@ const UploadFile = (props) => {
const uploadProps = {
name: 'file',
action: '/api/file/file/upload',
headers: {},
headers: {token: auth.token},
data: {
fileType: UPLOAD_TYPE
},
......
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