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

移动端签名组件重构

上级 6e93f973
...@@ -5,16 +5,17 @@ ...@@ -5,16 +5,17 @@
*/ */
import React, { Component } from 'react'; import React, { Component } from 'react';
import SignatureCanvas from 'react-signature-canvas'; import SignatureCanvas from 'react-signature-canvas';
import { message, Button } from 'antd'; import { message, Button, Modal } from 'antd';
import config from '@/webPublic/one_stop_public/config'; import config from '@/webPublic/one_stop_public/config';
import reqwest from 'reqwest'; import reqwest from 'reqwest';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token'; import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import { uaaRequest } from '@/webPublic/one_stop_public/utils/request'; import { uaaRequest } from '@/webPublic/one_stop_public/utils/request';
import { getOneStopMyInfo } from '@/webPublic/one_stop_public/utils/utils'; import { getOneStopMyInfo } from '@/webPublic/one_stop_public/utils/utils';
import styles from './mobileSign.less';
// 保存签名 到用户基础信息上 // 保存签名 到用户基础信息上
function saveSign(url){ function saveSign(url) {
if(typeof url !== 'string' || url.length < 15){ if (typeof url !== 'string' || url.length < 15) {
return true; return true;
} }
const userInfo = getUserInfo(); const userInfo = getUserInfo();
...@@ -23,10 +24,11 @@ function saveSign(url){ ...@@ -23,10 +24,11 @@ function saveSign(url){
backgroundImageUrl: userInfo.backgroundImageUrl, backgroundImageUrl: userInfo.backgroundImageUrl,
isUseBackImage: userInfo.isUseBackImage, isUseBackImage: userInfo.isUseBackImage,
userSign: url, userSign: url,
}).then((g) => { })
getOneStopMyInfo(); .then((g) => {
return true; getOneStopMyInfo();
}); return true;
});
} }
function dataURLtoBlob(toDataURL) { function dataURLtoBlob(toDataURL) {
...@@ -53,6 +55,7 @@ export default class Index extends Component { ...@@ -53,6 +55,7 @@ export default class Index extends Component {
const value = props.value; const value = props.value;
this.state = { this.state = {
url: value || getUserInfo().userSign, url: value || getUserInfo().userSign,
showModal: false,
}; };
} }
...@@ -137,20 +140,83 @@ export default class Index extends Component { ...@@ -137,20 +140,83 @@ export default class Index extends Component {
}; };
componentDidMount() { componentDidMount() {
if(!this.props.value && this.state.value){ if (!this.props.value && this.state.value) {
this.triggerChange(this.state.value); this.triggerChange(this.state.value);
} }
} }
changeShowModal = () => {
this.setState({
showModal: !this.state.showModal,
});
};
// 移动端签名组件
MobileSign = () => {
const { url } = this.state;
if (url) {
return <div className={styles.mobileSign}>
</div>;
} else {
return <div className={styles.mobileSign2}>
<Button type={'primary'} onClick={this.changeShowModal}>
点击开始签名
</Button>
</div>;
}
return null;
};
MobileModal = () => {
const { showModal } = this.state;
const height = 300;
const width = window.screen.width - 50;
return (
showModal && <Modal className={styles.mobileModal}
width={'100vw'}
onCancel={this.changeShowModal}
visible={true}
title={'签名'}
bodyStyle={{minHeight: '350px'}}
>
<div className={styles.borderDiv}>
<SignatureCanvas
penColor='black'
ref={(ref) => {
this.sigCanvas = ref;
}}
canvasProps={{
width: width + 'px',
height: height + 'px',
className: 'sigCanvas',
}}
/>
</div>
</Modal>);
};
render() { render() {
// console.log('签名组件'); // console.log('签名组件');
const { const {
width, width,
height, height,
get,
} = this.props; } = this.props;
const { url } = this.state; const { url } = this.state;
if (get === 'mobile') {
const MobileSign = this.MobileSign;
const MobileModal = this.MobileModal;
return <>
<MobileSign />
<MobileModal />
</>;
}
return ( return (
<div id="canvas_signature" style={{ <div id='canvas_signature' style={{
width: '100%', width: '100%',
height: '100%', height: '100%',
marginLeft: 5, marginLeft: 5,
...@@ -167,10 +233,10 @@ export default class Index extends Component { ...@@ -167,10 +233,10 @@ export default class Index extends Component {
<img src={config.httpServer + url} style={{ <img src={config.httpServer + url} style={{
width: width, width: width,
height: height - 20, height: height - 20,
}}/> }} />
) : ( ) : (
<SignatureCanvas <SignatureCanvas
penColor="black" penColor='black'
ref={(ref) => { ref={(ref) => {
this.sigCanvas = ref; this.sigCanvas = ref;
}} }}
...@@ -187,15 +253,15 @@ export default class Index extends Component { ...@@ -187,15 +253,15 @@ export default class Index extends Component {
bottom: 5, bottom: 5,
}}> }}>
{url ? ( {url ? (
<Button type="danger" size="small" onClick={this.delete}> <Button type='danger' size='small' onClick={this.delete}>
重写 重写
</Button> </Button>
) : ( ) : (
<> <>
<Button style={{ marginLeft: 12 }} type="danger" size="small" onClick={this.clear}> <Button style={{ marginLeft: 12 }} type='danger' size='small' onClick={this.clear}>
清除 清除
</Button> </Button>
<Button style={{ marginLeft: 12 }} onClick={this.trim} size="small" type="primary"> <Button style={{ marginLeft: 12 }} onClick={this.trim} size='small' type='primary'>
保存 保存
</Button> </Button>
</> </>
......
.mobileSign2{
text-align: center;
}
.mobileModal{
//width: 100vw;
min-height: 70vh;
}
.borderDiv{
border: 1px solid #555;
margin-top: 20px;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论