Commit 2a72e52a by end

上传多文件优化

parent f3dbebb5
......@@ -11,10 +11,8 @@ class UploadUtil extends Component {
constructor(props) {
super(props);
this.state = {
uploadParams: {},
uploadAction: {},
originalFileName: "",
originalFileUrl: "",
fileList: [],
newFileList: [],
key: "",
......@@ -23,20 +21,12 @@ class UploadUtil extends Component {
}
//修改一
componentDidMount() {
//上传阿里云
// this.props.gupfetch();
}
beforeUpload = (file, fileList) => {
const time = new Date().getTime();
const regEn = /[`~!@#$%^&*()_+<>?: "{},\/;'[\]]/im,
regCn = /[·!#¥(——):;“”‘、 ,|《。》?、【】[\]]/im;
// 文件大小判断 图片小于3M 文件小于200M
if (file.type.indexOf("image") !== -1) {
// if(regEn.test(file.name) || regCn.test(file.name)) {
// message.info("文件名不能使用特殊字符");
// return false;
// }
if (file.size > 10 * 1024 * 1024) {
message.info("请上传小于10M的图片");
return false;
......@@ -54,7 +44,6 @@ class UploadUtil extends Component {
} else {
this.props.gupList([]);
}
//判断类型 学习营销名片只用上传图片`
let reg = ""; //正则匹配格式
this.props.extra === "markeCardExtra"
? (reg = /(mp4|png|jpg|gif|mp3|pdf|jpeg|doc|docx|pdf|PDF|wps)$/g)
......@@ -64,20 +53,10 @@ class UploadUtil extends Component {
return false;
}
this.setState({ fileList: fileList });
const { param } = this.props;
const fileLength = file.name.split(".").length;
this.setState(
{
uploadParams: {},
uploadAction: `${services.uploadApi}`,
originalFileName: file.name,
originalFileUrl: "",
},
() => {
// 修改bug 6378 【UAT】【管理端】-名片配置-上传新图片修改时-名片预览未显示
// if(this.props.getUrl){
// this.props.getUrl(param.host + "/" + param.dir + "/" + time + "." +file.name.split(".")[fileLength-1],file.name)
// }
}
);
};
......@@ -87,15 +66,21 @@ class UploadUtil extends Component {
this.setState({
processNum: info.file.percent ? info.file.percent : 0,
});
console.log(info, "info")
if (info.file.status === "done") {
fileList.map(item => {
if (item.status === "done") {
if (this.state.newFileList.indexOf(item.response.data) == -1) {
// 检查 item.response.data 是否存在且不为 undefined
if (item?.response?.data && this.state.newFileList.indexOf(item.response.data) === -1) {
this.state.newFileList.push(item.response.data);
}
console.log("11111111111111", this.state.newFileList);
// 检查 item.url 是否存在且不为 undefined
if (item.url && this.state.newFileList.indexOf(item.url) === -1) {
this.state.newFileList.push(item.url);
}
}
});
console.log(this.state.newFileList, "this.state.newFileList")
message.success("上传成功");
} else if (info.file.status === "error") {
message.error("上传失败,请重新尝试");
......@@ -105,19 +90,6 @@ class UploadUtil extends Component {
this.props.getUrl(this.state.newFileList);
}
this.setState({ fileList });
// if (fileList[0] && fileList[0].status === "done") {
// if (this.props.getUrl) {
// this.props.getUrl(fileList[0].response.data, this.state.originalFileName);
// }
// console.log("检测打印变量=fileList ", fileList);
// this.setState({ fileList });
// message.success("上传成功");
// }
// if (fileList[0] && fileList[0].status === "error") {
// message.error("上传失败,请重新尝试");
// this.setState({ fileList: [] });
// }
};
normFile = e => {
......@@ -128,17 +100,31 @@ class UploadUtil extends Component {
};
fnRemove = e => {
this.state.newFileList.splice(
this.state.newFileList.indexOf(e.response.data),
1
);
if (this.props.defaultUrl) {
// 遍历 defaultUrl 数组,将每个对象的 url 合并到 newFileList 中,避免重复添加
this.props.defaultUrl.forEach(item => {
if (item.url && !this.state.newFileList.includes(item.url)) {
this.state.newFileList.push(item.url);
}
});
}
if (e.url) {
this.state.newFileList.splice(
this.state.newFileList.indexOf(e.url),
1
);
} else {
this.state.newFileList.splice(
this.state.newFileList.indexOf(e.response.data),
1
);
}
this.props.getUrl(this.state.newFileList);
};
render() {
const { uploadAction, uploadParams } = this.state;
const { uploadAction } = this.state;
const { getFieldDecorator } = this.props.form;
// console.log('检测打印变量=this.state.fileList ',this.state.fileList );
return (
<Form>
<FormItem
......@@ -158,7 +144,7 @@ class UploadUtil extends Component {
beforeUpload={this.beforeUpload}
action={uploadAction}
headers={{ authorization: sessionStorage.getItem("mgtk") }}
// data={uploadParams}
multiple={true}
onChange={this.handleChange}
onRemove={this.fnRemove}
>
......@@ -179,7 +165,6 @@ class UploadUtil extends Component {
/>
</p>
)}
{/*//进度条--liyuan*/}
</FormItem>
</Form>
);
......
......@@ -7,7 +7,7 @@ class EditableTagGroup extends React.Component {
if (this.props.init) {
this.props.init(this);
}
console.log(this.props.defaultTags, "回显938");
this.state = {
tags: this.props.defaultTags ? this.props.defaultTags : [],
......@@ -145,7 +145,7 @@ class EditableTagGroup extends React.Component {
tags = [];
}
if (disabled) {
return <div style={{ float: "left" }}>
{
tags.map((tag, index) => {
......
......@@ -413,16 +413,12 @@ class Mailbox extends React.Component {
查看
</a>
</div>
{/* <div style={{ display: "inline" }}>
<a
className={Styles.marr10}
onClick={() => {
this.seeEdit(record.id, "edit");
}}
>
删除
</a>
</div> */}
{/* <Popconfirm
title="是否删除?"
onConfirm={() => this.onDelete(record.id)}
>
<a className={Styles.marr10}>删除</a>
</Popconfirm> */}
</div>
);
},
......
......@@ -384,7 +384,7 @@ class Banner extends Component {
return (
<div className={Styles.mobileBanner}>
<div className={Styles.showAccessContainer}>
{/* <div className={Styles.showAccessContainer}>
<span> 显示访问人次 </span>
<Switch checked={switchState} onChange={this.SwitchOnChange} />
<InputNumber
......@@ -406,7 +406,7 @@ class Banner extends Component {
>
<Icon type="question-circle-o" />
</Tooltip>
</div>
</div> */}
<Carousel autoplay>
{ListBanner.map((item, index) => {
return (
......
......@@ -116,10 +116,10 @@ class Banner extends React.Component {
return (
<SpinUtil loadState={false}>
<div className={Styles.pcIndexBanner}>
<div className={Styles.showAccessContainer}>
{/* <div className={Styles.showAccessContainer}>
<span> 显示访问人次 </span>
<Switch
checked={switchState}
<Switch
checked={switchState}
onChange={this.SwitchOnChange}
disabled={!this.props.location.query.lookState ? false : true} //bug-12136-liyuan
/>
......@@ -143,7 +143,7 @@ class Banner extends React.Component {
>
<Icon type="question-circle-o" />
</Tooltip>
</div>
</div> */}
{/*走马灯 有值循环*/}
{pcBannerSelectList.length ? (
<Carousel autoplay className={Styles.BannerLamp}>
......
......@@ -373,7 +373,7 @@ class Banner extends Component {
return (
<div className={Styles.mobileBanner}>
<div className={Styles.showAccessContainer}>
{/* <div className={Styles.showAccessContainer}>
<span> 显示访问人次 </span>
<Switch
checked={switchState}
......@@ -399,7 +399,7 @@ class Banner extends Component {
>
<Icon type="question-circle-o" />
</Tooltip>
</div>
</div> */}
<Carousel autoplay>
{ListBanner.map((item, index) => {
return (
......
......@@ -4,7 +4,6 @@ import TestModal from "./TestModal";
import {
insertTestFetch,
getTestListFetch,
addTest,
editTestFetch,
jumpTestFetch,
jumpReset,
......@@ -12,11 +11,8 @@ import {
import {
Button,
Table,
Popconfirm,
Modal,
Pagination,
message,
Empty,
} from "antd";
import styles from "./index.less";
import { DragDropContext, DragSource, DropTarget } from "react-dnd";
......@@ -87,19 +83,10 @@ const rowTarget = {
drop(props, monitor) {
const dragIndex = monitor.getItem().index;
const hoverIndex = props.index;
// Don't replace items with themselves
if (dragIndex === hoverIndex) {
return;
}
// Time to actually perform the action
props.moveRow(dragIndex, hoverIndex);
// Note: we're mutating the monitor item here!
// Generally it's better to avoid mutations,
// but it's good here for the sake of performance
// to avoid expensive index searches.
monitor.getItem().index = hoverIndex;
},
};
......@@ -127,6 +114,7 @@ class AddTest extends Component {
order: 1,
selectedRowKeys: [],
checkArr: [],
defaultFileList: [],
testItem: {},
pageNo: 1,
pageSize: 20,
......@@ -161,7 +149,6 @@ class AddTest extends Component {
},
],
};
// console.log(temp)
this.props.edit(temp, surid, this.state.pageNo, this.state.pageSize);
};
......@@ -171,12 +158,10 @@ class AddTest extends Component {
visible: true,
});
}
componentDidMount() {}
componentDidMount() { }
handleOk() {
const { surid, tlist } = this.props;
const { order, editstate, editid } = this.state;
console.log(11111, this.addother.state);
// console.log(surid)
this.props.jumpreset();
this.setState({
confirmLoading: true,
......@@ -193,7 +178,6 @@ class AddTest extends Component {
if (values.type === 1) {
for (let i = 0; i < values.cont.length; i++) {
if (values.cont[i] == null) continue;
console.log(values, 11111);
objs.push({
content: values.cont[i],
//correct:values.correct[i]?1:0,
......@@ -204,7 +188,6 @@ class AddTest extends Component {
keywords: this.addother.state.keywords,
});
}
console.log("单选题其他", objs);
}
if (values.type === 2) {
for (let i = 0; i < values.cont.length; i++) {
......@@ -247,8 +230,8 @@ class AddTest extends Component {
attachmentUrl: this.state.fileUrl
? this.state.fileUrl
: this.state.testItem.attachmentUrl
? this.state.testItem.attachmentUrl
: [],
? this.state.testItem.attachmentUrl
: [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
......@@ -375,14 +358,32 @@ class AddTest extends Component {
message.info("请勾选要删除的题目");
}
}
handleData(data) {
if (data) {
data.forEach((item, index) => {
this.state.defaultFileList.push({
uid: index + 1,
status: "done",
url: item,
name: item.split('prefix=')[1],
})
})
console.log(this.state.defaultFileList, "查看文件上传")
} else {
this.state.defaultFileList = []
}
}
handleTestView(item) {
// console.log(item)
console.log(item)
this.setState({
testItem: item,
visible: true,
editstate: true,
editid: item.id,
defaultFileList:[]
}, ()=>{
this.handleData(item.attachmentUrl)
});
this.props.jump({ id: item.id });
}
......@@ -430,10 +431,8 @@ class AddTest extends Component {
fileUrl,
});
},
defaultUrl: this.state.testItem.attachmentUrl,
defaultUrl: this.state.defaultFileList
};
// console.log('检测打印变量1 ',this.state.fileUrl,'检测打印变量2 ',this.state.fileName);
const columns = [
{
title: "编号",
......
......@@ -67,7 +67,6 @@ class TestModal extends Component {
}
componentDidMount() {
const { defaultValue } = this.props;
console.log(defaultValue,'22222222')
if (defaultValue.options && defaultValue.options.length) {
let cach = defaultValue.options;
uuid1 = cach[cach.length - 1]["no"] + 1;
......
......@@ -50,6 +50,7 @@ class Details extends Component {
visible: false,
confirmLoading: false,
data: [],
defaultFileList: [],
pageNo: 1,
isdanxuan: false,
danxuanid: "",
......@@ -75,6 +76,7 @@ class Details extends Component {
}
componentDidMount() {
let param = location.pathname.split("/");
this.type = param.pop();
this.id = param.pop();
......@@ -236,10 +238,10 @@ class Details extends Component {
if (res === "1000") {
this.props.history.push(
"/" +
companyCode +
"/" +
siteCode +
"/index/tool/question/question-management"
companyCode +
"/" +
siteCode +
"/index/tool/question/question-management"
);
}
});
......@@ -264,7 +266,11 @@ class Details extends Component {
editstate: true,
editid: item.id,
canEdit: true,
defaultFileList:[]
}, ()=>{
this.handleData(item.attachmentUrl,true)
});
this.props.jump({ id: item.id });
}
handleTestView1(item) {
......@@ -274,6 +280,9 @@ class Details extends Component {
editstate: true,
editid: item.id,
canEdit: false,
defaultFileList:[]
}, ()=>{
this.handleData(item.attachmentUrl,true)
});
this.props.jump({ id: item.id });
}
......@@ -350,6 +359,7 @@ class Details extends Component {
}
if (editstate) {
console.log(this.state.fileUrl,this.state.testItem.attachmentUrl,'888888')
const param = {
type: values.type,
content: values.content,
......@@ -357,13 +367,12 @@ class Details extends Component {
attachmentUrl: this.state.fileUrl
? this.state.fileUrl
: this.state.testItem.attachmentUrl
? this.state.testItem.attachmentUrl
: [],
? this.state.testItem.attachmentUrl
: [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
minSelectItem: values.needAnswer1 ? values.minSelectItem : "",
//no:this.state.testItem.no,
hasOther: this.addother.state.addother ? 1 : 0,
otherOption: {
content: this.addother.state.other,
......@@ -376,7 +385,7 @@ class Details extends Component {
researchId: surid,
};
this.props.edit(temp, surid, this.state.pageNo, this.state.pageSize);
this.setState({ fileUrl: "" });
this.setState({ fileUrl: [] });
} else {
const param = {
keywords: this.addother.state.keywords,
......@@ -397,7 +406,7 @@ class Details extends Component {
},
};
this.props.insert(param, this.state.pageNo, this.state.pageSize);
this.setState({ fileUrl: "" });
this.setState({ fileUrl: [] });
}
setTimeout(() => {
this.setState({
......@@ -417,7 +426,21 @@ class Details extends Component {
});
this.props.jumpreset();
}
handleData(data,statu) {
if (this.state.testItem.attachmentUrl&&statu) {
data.forEach((item, index) => {
this.state.defaultFileList.push({
uid: index + 1,
status: "done",
url: item,
name: item.split('prefix=')[1],
})
})
} else {
this.state.defaultFileList = []
}
}
render() {
const {
visibleQuestion,
......@@ -432,15 +455,13 @@ class Details extends Component {
const { details, tlist, newsList, jumptests, surid } = this.props;
const uploadProps = {
uploadUtilName: "上传图片/文件",
getUrl: (fileUrl, fileName) => {
getUrl: (fileUrl) => {
this.setState({
fileUrl,
fileName,
});
},
defaultUrl: this.state.testItem.attachmentUrl,
defaultUrl: this.state.defaultFileList
};
const children = [];
for (let i = 0; i < jumptests.length; i++) {
children.push(
......@@ -497,8 +518,8 @@ class Details extends Component {
record.jumpNum
? `跳转至编号${record.jumpNum}题目`
: record.jumpType == 1
? -1
: -2
? -1
: -2
}
disabled
onChange={value => this.handleSelectChange(value, record)}
......@@ -672,25 +693,24 @@ class Details extends Component {
disabled={this.state.isupdata == 1 ? "block" : "none"}
/>
</FormItem>
{/* <Remind ref={(obj) => this.remind = obj} {...remindProps} newsList={newsList} /> */}
{// 修改
details.remind ? (
<MessageRemind
formItemLayout={formItemLayout}
style={{ marginLeft: "170px" }}
relationId={this.id}
remind={details.remind}
relationType={3}
wrappedComponentRef={form => (this.messageRemind = form)}
/>
) : (
<MessageRemind
formItemLayout={formItemLayout}
style={{ marginLeft: "170px" }}
relationType={3}
wrappedComponentRef={form => (this.messageRemind = form)}
/>
)}
details.remind ? (
<MessageRemind
formItemLayout={formItemLayout}
style={{ marginLeft: "170px" }}
relationId={this.id}
remind={details.remind}
relationType={3}
wrappedComponentRef={form => (this.messageRemind = form)}
/>
) : (
<MessageRemind
formItemLayout={formItemLayout}
style={{ marginLeft: "170px" }}
relationType={3}
wrappedComponentRef={form => (this.messageRemind = form)}
/>
)}
<Task
taskValue={details.enableTask}
type={0}
......@@ -710,6 +730,7 @@ class Details extends Component {
onClick={() => {
this.setState({
visibleQuestion: true,
defaultFileList:[],
testItem: {},
editstate: false,
editid: "",
......@@ -730,15 +751,6 @@ class Details extends Component {
scroll={{ y: 500 }}
pagination={false}
/>
{/*<Pagination className="survey-details-pagination"
size="small" total={tlist.total}
showTotal={this.showTotal}
showSizeChanger
showQuickJumper
pageSizeOptions={["10","20","30","40"]}
onChange={this.handlePageChange}
onShowSizeChange={this.handlePageSizeChange}
/>*/}
</div>
<div style={{ marginTop: 10, textAlign: "center" }}>
<Link
......@@ -774,7 +786,7 @@ class Details extends Component {
<LinkUser
type={this.type == "2" ? "look" : ""}
invisible={false}
getData={() => {}}
getData={() => { }}
initData={details.authorizes}
types={"research"}
groupTypes={"research"}
......
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