Merge branch 'pre_dev_military' of https://code.gitlink.org.cn/Gitlink/forgeplus-react into pre_dev_military

This commit is contained in:
何童崇 2022-12-12 17:13:14 +08:00
commit 03a8e054cf
3 changed files with 28 additions and 40 deletions

View File

@ -25,7 +25,7 @@ if (isDev) {
}
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
window.location.search.indexOf('debug=s') !== -1 ? 'student' :
window.location.search.indexOf('debug=a') !== -1 ? 'a' : parsed.debug || ''
window.location.search.indexOf('debug=a') !== -1 ? 'a' : parsed.debug || 'admin'
}
window._debugType = debugType;
export function initAxiosInterceptors(props) {

View File

@ -6,6 +6,7 @@ import "./index.css";
import { turnbar , returnbar } from 'educoder';
import axios from "axios";
import { Base64 } from "js-base64";
const TextArea = Input.TextArea;
class UserSubmitComponent extends Component {
@ -63,7 +64,7 @@ class UserSubmitComponent extends Component {
filepath: filename ? filename : path,
branch: returnbar(branch),
new_branch: submitType === "1" ? values.branchname : undefined,
content,
content:editor_type === "upload" ? content : Base64.encode(content),
message: values.desc,
})
.then((result) => {

View File

@ -1,8 +1,5 @@
import React, { Component } from "react";
import { Upload, Icon } from "antd";
import { getUploadActionUrl, appendFileSizeToUploadFileAll } from "educoder";
import axios from "axios";
const { Dragger } = Upload;
class Read extends Component {
constructor(props) {
@ -22,53 +19,43 @@ class Read extends Component {
});
};
handleChange = (info) => {
let reader = new FileReader();
reader.readAsText(info.fileList[0].originFileObj, "UTF-8");
reader.onload = (e) => {
this.state.fileContent = e.target.result;
this.props.load && this.props.load(this.state);
};
};
beforeUpload = (file) => {
const forbidden_type = [
"jpg",
"jpeg",
"png",
"ico",
"bmp",
"gif",
"pdf",
"csv",
"xlsx",
"xls",
"tif",
"svg",
"psd",
"cdr",
"webp",
];
const { fileList } = this.state;
const { size } = this.props;
const isLt100M = file.size / 1024 / 1024 < size;
const file_type = file.type.split("/").slice(-1)[0];
if (fileList && fileList.length > 0) {
this.props.showNotification("文件已存在, 请删除后再上传");
return false;
} else if (!isLt100M) {
this.props.showNotification(`文件大小必须小于${size}MB!`);
} else if (file_type && forbidden_type.indexOf(file_type) !== -1) {
this.props.showNotification(`不支持${file_type}类型`);
return false;
} else {
this.setState({
fileList: [file],
fileName: file.name,
})
}
return false;
};
// 上传 文件转base64
customRequest = (option) =>{
const formData = new FormData();
formData.append('files[]', option.file);
const reader = new FileReader();
reader.readAsDataURL(option.file);
const {load} = this.props;
reader.onloadend = function(e){
if(e.target.result){
option.onSuccess();
const base64 = e.target.result.substring(e.target.result.indexOf('base64')+7, e.target.result.length);
load({
fileName: option.file.name,
fileContent: base64
});
}
}
}
render() {
//判断是否已经提交,如已提交评论则上一条评论数据清除
const { icon, size } = this.props;
@ -76,10 +63,10 @@ class Read extends Component {
const upload = {
name: "file",
fileList: fileList,
onChange: this.handleChange,
customRequest: this.customRequest,
onRemove: this.onAttachmentRemove,
beforeUpload: this.beforeUpload
};
beforeUpload: this.beforeUpload,
};
return (
<Dragger {...upload} className={this.props.className}>
@ -92,7 +79,7 @@ class Read extends Component {
拖动文件或<span className="color-blue">点击此处上传</span>
</p>
{/* <p className="mt10">
暂仅支持文格式不支持图片,excel等不可以txt读取的文件
暂仅支持文格式不支持图片,excel等不可以txt读取的文件
</p> */}
<p className="mt10">
文件名请使用英文且不得超过{size}MB