提交 4cfdf202 authored 作者: 钟是志's avatar 钟是志

泸职版本增加自定义表单 增加视频上传组件. 后台接口暂时用的雅职生产

token 获取方式 localstorage('uploadVideoServiceToken')
上级 3face9ee
...@@ -124,6 +124,7 @@ const transLate = { ...@@ -124,6 +124,7 @@ const transLate = {
RangePicker: 'rangePicker', RangePicker: 'rangePicker',
UploadCom: 'buttonUpload', UploadCom: 'buttonUpload',
ImgUploadCom: 'upload', ImgUploadCom: 'upload',
VideoUploadCom: 'upload',
Input: 'input', Input: 'input',
TableSelect: 'tableSelect', // 表格选择 TableSelect: 'tableSelect', // 表格选择
ChildForm: 'childForm', // 最终保存的数据还有问题 ChildForm: 'childForm', // 最终保存的数据还有问题
......
...@@ -5,14 +5,10 @@ ...@@ -5,14 +5,10 @@
*/ */
import React, { Component } from 'react' import React, { Component } from 'react'
import SignatureCanvas from 'react-signature-canvas' import SignatureCanvas from 'react-signature-canvas'
// import Button from '@/components/NewButton';
import { message,Button } from 'antd'; import { message,Button } from 'antd';
import config from '@/webPublic/one_stop_public/config'; import config from '@/webPublic/one_stop_public/config';
import { queryApiActionPath } from "../utils/queryConfig";
import baseX from 'base-x';
const Bs64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const base64 = baseX(Bs64);
import reqwest from 'reqwest'; import reqwest from 'reqwest';
function dataURLtoBlob(toDataURL) { function dataURLtoBlob(toDataURL) {
var arr = toDataURL.split(","), var arr = toDataURL.split(","),
mime = arr[0].match(/:(.*?);/)[1], mime = arr[0].match(/:(.*?);/)[1],
...@@ -37,8 +33,8 @@ export default class index extends Component { ...@@ -37,8 +33,8 @@ export default class index extends Component {
this.state = { this.state = {
url:value, url:value,
} }
} }
triggerChange = (changedValue) => { triggerChange = (changedValue) => {
// Should provide an event to pass value to Form. // Should provide an event to pass value to Form.
...@@ -51,14 +47,15 @@ export default class index extends Component { ...@@ -51,14 +47,15 @@ export default class index extends Component {
// Should be a controlled component. // Should be a controlled component.
if ('value' in nextProps) { if ('value' in nextProps) {
const value = nextProps.value; const value = nextProps.value;
this.setState({url:value}); this.setState({url:value});
// //
} }
} }
sigCanvas = {clear:()=>{},toDataURL:(param)=>{return ""}}; sigCanvas = {clear:()=>{},toDataURL:(param)=>{return ""}};
clear=()=>{ clear=()=>{
this.sigCanvas.clear(); this.sigCanvas.clear();
} }
...@@ -70,10 +67,10 @@ export default class index extends Component { ...@@ -70,10 +67,10 @@ export default class index extends Component {
} }
trim=()=>{ trim=()=>{
const formData = new FormData() const formData = new FormData()
const xx=dataURLtoBlob(this.sigCanvas.toDataURL('image/png')) const xx=dataURLtoBlob(this.sigCanvas.toDataURL('image/png'))
const file = blobToFile(xx,"sign.png") const file = blobToFile(xx,"sign.png")
if(file==null){ if(file==null){
return return
} }
formData.append('file',file,"sign.png") formData.append('file',file,"sign.png")
...@@ -83,12 +80,12 @@ export default class index extends Component { ...@@ -83,12 +80,12 @@ export default class index extends Component {
processData: false, processData: false,
data: formData, data: formData,
success: (url) => { success: (url) => {
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({url:url}); this.setState({url:url});
} }
this.triggerChange(url); this.triggerChange(url);
message.success('保存成功'); message.success('保存成功');
}, },
error: (e) => { error: (e) => {
...@@ -101,7 +98,7 @@ export default class index extends Component { ...@@ -101,7 +98,7 @@ export default class index extends Component {
}else{ }else{
message.error('保存失败'); message.error('保存失败');
} }
}, },
}); });
//let trimmedCanvas = this.sigCanvas.getTrimmedCanvas(); //let trimmedCanvas = this.sigCanvas.getTrimmedCanvas();
...@@ -127,9 +124,9 @@ export default class index extends Component { ...@@ -127,9 +124,9 @@ export default class index extends Component {
<Button style={{marginLeft:12}} onClick={this.trim} size="small" type='primary'>保存</Button></>} <Button style={{marginLeft:12}} onClick={this.trim} size="small" type='primary'>保存</Button></>}
</div> </div>
</div> </div>
</div> </div>
) )
} }
} }
...@@ -7,12 +7,12 @@ export default class ImgUploadCom extends React.Component { ...@@ -7,12 +7,12 @@ export default class ImgUploadCom extends React.Component {
const value = props.value const value = props.value
this.state = { this.state = {
url:value url:value
} }
} }
triggerChange = (changedValue) => { triggerChange = (changedValue) => {
// Should provide an event to pass value to Form. // Should provide an event to pass value to Form.
const onChange = this.props.onChange; const onChange = this.props.onChange;
...@@ -31,7 +31,7 @@ export default class ImgUploadCom extends React.Component { ...@@ -31,7 +31,7 @@ export default class ImgUploadCom extends React.Component {
if (info.file.status === 'done') { if (info.file.status === 'done') {
message.success(`图片上传成功`); message.success(`图片上传成功`);
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({url: info.file.response }); this.setState({url: info.file.response });
} }
...@@ -41,13 +41,13 @@ export default class ImgUploadCom extends React.Component { ...@@ -41,13 +41,13 @@ export default class ImgUploadCom extends React.Component {
} }
} }
changePos=(obj)=>{ changePos=(obj)=>{
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({...obj}); this.setState({...obj});
} }
this.triggerChange({...obj}); this.triggerChange({...obj});
} }
render() { render() {
const{json,disabled}=this.props const{json,disabled}=this.props
...@@ -60,6 +60,6 @@ export default class ImgUploadCom extends React.Component { ...@@ -60,6 +60,6 @@ export default class ImgUploadCom extends React.Component {
</Upload.Dragger> </Upload.Dragger>
); );
} }
} }
\ No newline at end of file
import React from 'react'
import {extend} from 'umi-request';
import queryConfig from "@/utils/queryConfig";
import {Upload, message} from 'antd';
import {isJSON} from "@/webPublic/one_stop_public/copy";
const getToken = () => {
const x = localStorage.getItem('uploadVideoServiceToken');
if(x === "null" || x === "undefined"){
return null;
}
return x;
};
const configService = queryConfig('uploadVideoService');
const token = getToken();
const umiRequest = extend({
// errorHandler, // 默认错误处理
credentials: 'omit', // 默认请求是否带上cookie
mode: 'cors',
});
export default class VideoUploadCom extends React.Component {
constructor(props) {
super(props);
const {value} = props;
let url = value;
if (isJSON(value)) {
url = JSON.parse(value).url;
}
this.state = {
url: url || '',
}
}
triggerChange = (changedValue) => {
// Should provide an event to pass value to Form.
const onChange = this.props.onChange;
if (onChange) {
onChange(changedValue);
}
};
componentWillReceiveProps(nextProps) {
// Should be a controlled component.
if ('value' in nextProps) {
const {value} = nextProps;
if (isJSON(value)) {
this.setState({
url: JSON.parse(value).url,
});
}
}
}
changeUrl = (info, key) => {
if (info.file.status === 'done') {
let filePathThis = info?.file?.response?.data?.filePath;
message.info('视频正在转换中,请稍后');
if (filePathThis) {
setTimeout(() => {
umiRequest(`${configService}/folderApi/findByPath?token=${token}&path=${filePathThis}`, {method: 'GET'}).then((res) => {
if (res && res.data) {
let info = res.data;
const {screenshots, url, createTime, downloadUrl, filePath} = info;
let needInfo = {
screenshots,
url,
createTime,
downloadUrl,
filePath,
};
message.success(`视频上传成功`);
this.triggerChange(JSON.stringify(needInfo));
}
});
}, 5000);
}
} else if (info.file.status === 'error') {
message.error(`视频上传失败`);
}
};
render() {
const {json, disabled} = this.props;
const {url} = this.state;
console.log(url);
return (
<Upload.Dragger disabled={disabled}
accept={'.mp4,.webm,.ogg'}
url={url}
showUploadList={false}
name="file"
action={configService + '/uploadFileApi/upload'}
onChange={this.changeUrl}
multiple={false}
data={{
isConvert: true,
token,
}}
style={{padding: 0}}>
{url ? <video src={url}
controls
style={{
height: json.height,
width: json.width,
}}/> :
<div style={{height: json.height, width: json.width}}>
</div>}
</Upload.Dragger>
);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论