提交 52bde14c authored 作者: 钟是志's avatar 钟是志
上级 ee72e570
...@@ -2,13 +2,21 @@ import React, { useRef, useState, useEffect } from 'react'; ...@@ -2,13 +2,21 @@ import React, { useRef, useState, useEffect } from 'react';
import { List, Switch, Button, Toast, Icon } from 'antd-mobile'; import { List, Switch, Button, Toast, Icon } from 'antd-mobile';
import styles from './styles.less'; import styles from './styles.less';
import { uploadOnestopFile } from '@/H5Public/baseComponents/UploadFile/api'; import { uploadOnestopFile } from '@/H5Public/baseComponents/UploadFile/api';
import systemConfig from '@/config/config';
const Brief = List.Item.Brief; const Brief = List.Item.Brief;
export default function DiyUploadOneStopFile(props) { export default function DiyUploadOneStopFile(props) {
const { config, formValue = [], giveRequiredName, changeValue } = props; const { config, formValue = [], giveRequiredName, changeValue } = props;
const { readOnly } = config;
const [files, setFiles] = useState([]); const [files, setFiles] = useState([]);
const inputRef = useRef(null); const inputRef = useRef(null);
useEffect(() => {
if(formValue[config.key] && Array.isArray(formValue[config.key])){
setFiles(formValue[config.key]);
}
}, [readOnly, formValue]);
const uploadImage = () => { const uploadImage = () => {
Toast.loading('文件上传中', 1); Toast.loading('文件上传中', 1);
const domF = inputRef.current.files; const domF = inputRef.current.files;
...@@ -36,13 +44,13 @@ export default function DiyUploadOneStopFile(props) { ...@@ -36,13 +44,13 @@ export default function DiyUploadOneStopFile(props) {
}; };
useEffect(() => { useEffect(() => {
changeValue(files, config.key); changeValue(files, config.key);
}, [files]); }, [files]);
const deleteItem = (data) => { const deleteItem = (data) => {
setFiles((files) => { setFiles((files) => {
return files.filter((item) => { return files.filter((item) => {
return item.path !== data.path; return item.path !== data.path;
}); });
}); });
}; };
...@@ -53,29 +61,35 @@ export default function DiyUploadOneStopFile(props) { ...@@ -53,29 +61,35 @@ export default function DiyUploadOneStopFile(props) {
className={styles.diyStyle} className={styles.diyStyle}
> >
{giveRequiredName(config)} {giveRequiredName(config)}
<Brief> <Brief>
支持格式:xlsxlsxwpsrarzipdocdocxpdfpngjpgjpeg {
<div className={styles.uploadButton}> !readOnly && <>
<input type="file" 支持格式:xlsxlsxwpsrarzipdocdocxpdfpngjpgjpeg
// accept={'*'} <div className={styles.uploadButton}>
id={config.key} <input type="file"
ref={inputRef} // accept={'*'}
style={{ id={config.key}
opacity: 0, ref={inputRef}
width: '100vw', style={{
height: '50px', opacity: 0,
position: 'absolute', width: '100vw',
zIndex: 2, height: '50px',
}} position: 'absolute',
onChange={uploadImage} zIndex: 2,
/> }}
<Button type={'primary'}>上传文件</Button> onChange={uploadImage}
</div> />
<Button type={'primary'}>上传文件</Button>
</div>
</>
}
<div className={styles.fileList}> <div className={styles.fileList}>
{ {
files.map((g) => { files.map((g) => {
return <div key={g.path} className={styles.fileItem}> return <div key={g.path} className={styles.fileItem}>
<a>{g.name}</a><Icon type={'cross-circle'} onClick={deleteItem.bind(this, g)} /> {/* TODO 加个弹窗的预览功能 */}
<a href={systemConfig.sqlFormsServer + g.path} target={'_blank'}>{g.name}</a> {!readOnly && <Icon type={'cross-circle'} onClick={deleteItem.bind(this, g)} /> }
</div>; </div>;
}) })
} }
......
...@@ -12,7 +12,6 @@ import { ...@@ -12,7 +12,6 @@ import {
} from 'antd-mobile'; } from 'antd-mobile';
import moment from 'moment'; import moment from 'moment';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import FieldList from '@/H5Public/baseComponents/FieldList';
import TextareaItemMultiRows from '../TextareaItemMultiRows'; import TextareaItemMultiRows from '../TextareaItemMultiRows';
import { useState } from 'react'; import { useState } from 'react';
...@@ -69,9 +68,9 @@ const DiyTextarea = props => { ...@@ -69,9 +68,9 @@ const DiyTextarea = props => {
const DiyPicker = props => { const DiyPicker = props => {
let { config, formValue, changeValue } = props; let { config, formValue, changeValue } = props;
if (config.readOnly) { if (config.readOnly) {
config.placeholder = ' '; config.extra = ' ';
} else { } else {
config.placeholder = config.placeholder || '点击输入'; config.extra = config.placeholder || '请选择';
} }
let opt = config.options.map(x => { let opt = config.options.map(x => {
return { return {
...@@ -79,18 +78,18 @@ const DiyPicker = props => { ...@@ -79,18 +78,18 @@ const DiyPicker = props => {
value: x.key, value: x.key,
}; };
}); });
return ( return (
<Picker <Picker
data={opt} data={opt}
cols={1} cols={1}
// extra={' '} // extra={' '}
key={config.key} key={config.key}
value={[formValue[config.key]]} value={formValue[config.key] ? [formValue[config.key]] : undefined}
disabled={config.readOnly} disabled={config.readOnly}
onChange={val => { onChange={val => {
changeValue(val[0], config.key); changeValue(val[0], config.key);
}} }}
extra={config.extra}
{...config.otherProps} {...config.otherProps}
> >
<List.Item arrow={config.readOnly ? '' : 'horizontal'}>{giveRequiredName(config)}</List.Item> <List.Item arrow={config.readOnly ? '' : 'horizontal'}>{giveRequiredName(config)}</List.Item>
...@@ -352,5 +351,5 @@ FormArray.defaultProps = { ...@@ -352,5 +351,5 @@ FormArray.defaultProps = {
}, },
readOnly: false, readOnly: false,
}; };
export { giveRequiredName }
export default FormArray; export default FormArray;
import { getHeaders } from '@/H5Public/utils/2022new/getHeaders';
export default function requestJSON(url, data) {
return fetch(url, {
method: 'post',
body: JSON.stringify({...data}),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
...getHeaders().headers,
}
})
.then(function(res) {
return res.json();
}).then(function(data) {
return data;
})
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论