react_hsbc_teller 2.0.54 → 2.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +39 -39
- package/README.en.md +36 -36
- package/README.md +323 -323
- package/config/webpack.config.js +119 -119
- package/config/webpack.dev.js +108 -108
- package/config/webpack.prod.js +104 -104
- package/lib/hsbc.js +1 -1
- package/lib/hsbc.js.LICENSE.txt +13 -16
- package/package.json +110 -110
- package/packages/api/api.js +818 -818
- package/packages/api/server.js +50 -50
- package/packages/common/index.esm.js +374 -374
- package/packages/demo/demo.js +306 -306
- package/packages/demo/index.js +3 -3
- package/packages/demo/pdf.js +94 -94
- package/packages/envconfig/envconfig.js +12 -12
- package/packages/index.js +2 -2
- package/packages/pages/components/step/step.jsx +32 -31
- package/packages/pages/foot/foot.jsx +235 -235
- package/packages/pages/foot/foot.less +85 -85
- package/packages/pages/header/header.jsx +15 -15
- package/packages/pages/header/header.less +51 -51
- package/packages/pages/index.jsx +52 -52
- package/packages/pages/multiModule/components/copy/agree.jsx +115 -115
- package/packages/pages/multiModule/components/copy/agree.less +105 -105
- package/packages/pages/multiModule/components/copy/copyTwo.jsx +682 -682
- package/packages/pages/multiModule/components/copy/copyTwo.less +180 -180
- package/packages/pages/multiModule/components/copy/copy_en.jsx +368 -368
- package/packages/pages/multiModule/components/copy/copy_en.less +145 -145
- package/packages/pages/multiModule/components/copy/copylist.jsx +291 -291
- package/packages/pages/multiModule/components/copy/copylist.less +83 -83
- package/packages/pages/multiModule/components/copy/risk.jsx +296 -296
- package/packages/pages/multiModule/components/copy/risk.less +123 -123
- package/packages/pages/multiModule/components/sign/signMy.jsx +308 -308
- package/packages/pages/multiModule/components/sign/signMy.less +127 -127
- package/packages/pages/multiModule/components/subscribe/subscribe.jsx +113 -113
- package/packages/pages/multiModule/components/subscribe/subscribe.less +82 -82
- package/packages/pages/multiModule/multiModule.jsx +26 -26
- package/packages/pages/multiModule/multiModule.less +19 -19
- package/packages/pages/sign/signMy.jsx +223 -223
- package/packages/pages/sign/signMy.less +129 -129
- package/packages/pages/video/video.jsx +7746 -7745
- package/packages/pages/video/video.less +715 -715
- package/packages/style/index.less +1 -1
- package/packages/style/reset.less +345 -345
- package/packages/utils/asrController.js +259 -259
- package/packages/utils/asyncComponent.jsx +26 -26
- package/packages/utils/mixin.js +27 -27
- package/packages/utils/setRem.js +10 -10
- package/packages/utils/utils.js +199 -199
- package/public/index.html +77 -77
- package/src/index.js +11 -11
- package/src/index.less +5 -5
- package/tsconfig.json +11 -11
|
@@ -1,682 +1,682 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import { FormattedMessage } from 'react-intl';
|
|
3
|
-
import './copyTwo.less'
|
|
4
|
-
import Modal from "antd/lib/modal";
|
|
5
|
-
import 'antd/lib/modal/style'
|
|
6
|
-
import { Button } from '../../../../../node_modules/antd/lib/index';
|
|
7
|
-
class Copy extends Component {
|
|
8
|
-
signCanvas = React.createRef();
|
|
9
|
-
timer = null;
|
|
10
|
-
state = {
|
|
11
|
-
finalImage: "",
|
|
12
|
-
pics: [],
|
|
13
|
-
isFinish: false,
|
|
14
|
-
ctx: null,
|
|
15
|
-
stageInfo: '',
|
|
16
|
-
isDown: false,
|
|
17
|
-
startY: '',
|
|
18
|
-
startX: '',
|
|
19
|
-
moveX: '',
|
|
20
|
-
moveY: '',
|
|
21
|
-
mask1: false,
|
|
22
|
-
mask2: true,
|
|
23
|
-
imgWidth: '0px',
|
|
24
|
-
imgHeight: '0px',
|
|
25
|
-
isModalVisibleEnd: false,
|
|
26
|
-
isModalVisibleSubmit: false,
|
|
27
|
-
isSignOk: false
|
|
28
|
-
};
|
|
29
|
-
componentWillUnmount() {
|
|
30
|
-
clearTimeout(this.timer)
|
|
31
|
-
const canvas = this.refs.canvas1;
|
|
32
|
-
const canvas2 = this.refs.canvas2;
|
|
33
|
-
canvas.removeEventListener('touchstart', this.touchStart);
|
|
34
|
-
canvas.removeEventListener('touchmove', this.touchMove);
|
|
35
|
-
canvas.removeEventListener('touchend', this.touchEnd);
|
|
36
|
-
canvas2.removeEventListener('touchstart', this.touchStart);
|
|
37
|
-
canvas2.removeEventListener('touchmove', this.touchMove);
|
|
38
|
-
canvas2.removeEventListener('touchend', this.touchEnd);
|
|
39
|
-
}
|
|
40
|
-
componentDidMount() {
|
|
41
|
-
setTimeout(() => {
|
|
42
|
-
let canvas = this.refs.canvas1;
|
|
43
|
-
canvas.height = this.refs.canvasHW.offsetHeight - 0;
|
|
44
|
-
canvas.width = this.refs.canvasHW.offsetWidth - 0;
|
|
45
|
-
this.state.ctx = canvas.getContext('2d');
|
|
46
|
-
this.state.stageInfo = canvas.getBoundingClientRect();
|
|
47
|
-
this.state.ctx.lineWidth = 7;
|
|
48
|
-
this.state.ctx.lineCap = "round";
|
|
49
|
-
|
|
50
|
-
let canvas2 = this.refs.canvas2;
|
|
51
|
-
canvas2.height = this.refs.canvasHW2.offsetHeight - 0;
|
|
52
|
-
canvas2.width = this.refs.canvasHW2.offsetWidth - 0;
|
|
53
|
-
this.state.ctx2 = canvas2.getContext('2d');
|
|
54
|
-
this.state.ctx2.lineWidth = 7;
|
|
55
|
-
this.state.ctx2.lineCap = "round";
|
|
56
|
-
this.state.stageInfo2 = canvas2.getBoundingClientRect();
|
|
57
|
-
this.state.isSignOk = false
|
|
58
|
-
this.drawText()
|
|
59
|
-
this.drawText(1)
|
|
60
|
-
|
|
61
|
-
canvas.addEventListener('touchstart', this.touchStart, { passive: false });
|
|
62
|
-
canvas.addEventListener('touchmove', this.touchMove, { passive: false });
|
|
63
|
-
canvas.addEventListener('touchend', this.touchEnd, { passive: false });
|
|
64
|
-
canvas2.addEventListener('touchstart', this.touchStart, { passive: false });
|
|
65
|
-
canvas2.addEventListener('touchmove', this.touchMove, { passive: false });
|
|
66
|
-
canvas2.addEventListener('touchend', this.touchEnd, { passive: false });
|
|
67
|
-
}, 20);
|
|
68
|
-
var box=document.getElementById("imgLeft");
|
|
69
|
-
if(box){ //此处在加一层判断,更加严密,如果box存在的情况下获取
|
|
70
|
-
this.state.imgWidth = Math.round(Math.sqrt((box.offsetWidth * box.offsetHeight)/70)*10)/10
|
|
71
|
-
this.state.imgHeight = Math.round(Math.sqrt((box.offsetWidth * box.offsetHeight)/70)*10)/10
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// 画背景字
|
|
75
|
-
drawText = (num=0) => {
|
|
76
|
-
if (num==0){
|
|
77
|
-
this.setState({mask2: true, mask1: false})
|
|
78
|
-
} else {
|
|
79
|
-
if (this.state.lastCanvasId === 'canvas2' || (!this.state.lastCanvasId && num ===1)){
|
|
80
|
-
this.setState({mask2: true, mask1: false})
|
|
81
|
-
} else {
|
|
82
|
-
this.setState({mask2: false, mask1: true})
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (this.state.pics.length + num >= this.props.item.subContent[0].desc.length) return;
|
|
86
|
-
let { ctx } = this.state;
|
|
87
|
-
let canvas = this.refs.canvas1;
|
|
88
|
-
if (this.state.lastCanvasId === 'canvas2' || (!this.state.lastCanvasId && num ===1)) {
|
|
89
|
-
ctx = this.state.ctx2;
|
|
90
|
-
canvas = this.refs.canvas2;
|
|
91
|
-
}
|
|
92
|
-
ctx.font = canvas.width/1.5 + 'px "微软雅黑"';
|
|
93
|
-
ctx.fillStyle = "#DADADA";
|
|
94
|
-
ctx.textAlign = "center";
|
|
95
|
-
ctx.textBaseline = "middle";
|
|
96
|
-
ctx.fillText(this.props.item.subContent[0].desc[this.state.pics.length + num], canvas.width/2, canvas.height/2);
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 清空画布
|
|
101
|
-
clearCanvas = () => {
|
|
102
|
-
clearTimeout(this.timer)
|
|
103
|
-
let canvas = this.refs.canvas1;
|
|
104
|
-
// 清除画布
|
|
105
|
-
this.state.ctx.clearRect(
|
|
106
|
-
0,
|
|
107
|
-
0,
|
|
108
|
-
canvas.width,
|
|
109
|
-
canvas.height,
|
|
110
|
-
);
|
|
111
|
-
let canvas2 = this.refs.canvas2;
|
|
112
|
-
// 清除画布2
|
|
113
|
-
this.state.ctx2.clearRect(
|
|
114
|
-
0,
|
|
115
|
-
0,
|
|
116
|
-
canvas2.width,
|
|
117
|
-
canvas2.height,
|
|
118
|
-
);
|
|
119
|
-
this.state.curCanvasId = ''
|
|
120
|
-
this.state.lastCanvasId = ''
|
|
121
|
-
this.drawText()
|
|
122
|
-
this.drawText(1)
|
|
123
|
-
}
|
|
124
|
-
resetTimer = () => {
|
|
125
|
-
clearTimeout(this.timer);
|
|
126
|
-
const curCanvasId = this.state.curCanvasId;
|
|
127
|
-
const ctx = curCanvasId ==='canvas1'?this.state.ctx : this.state.ctx2
|
|
128
|
-
this.timer = setTimeout(() => {
|
|
129
|
-
// 保存另一张图
|
|
130
|
-
if (this.state.curCanvasId) {
|
|
131
|
-
// 新增图片
|
|
132
|
-
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
133
|
-
this.setState({
|
|
134
|
-
pics: this.state.pics
|
|
135
|
-
})
|
|
136
|
-
// 清除画布
|
|
137
|
-
ctx.clearRect(
|
|
138
|
-
0,
|
|
139
|
-
0,
|
|
140
|
-
this.refs[this.state.curCanvasId].width,
|
|
141
|
-
this.refs[this.state.curCanvasId].height,
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
this.state.lastCanvasId = this.state.curCanvasId
|
|
145
|
-
this.state.curCanvasId = '';
|
|
146
|
-
this.drawText(1)
|
|
147
|
-
}, 1000);
|
|
148
|
-
}
|
|
149
|
-
touchStart=(ev)=> {
|
|
150
|
-
this.ableMouse = false;
|
|
151
|
-
// console.log(new Date().toLocaleTimeString(),'触发touchstart---', ev)
|
|
152
|
-
this.state.isSignOk = true
|
|
153
|
-
ev = ev || event
|
|
154
|
-
ev.preventDefault()
|
|
155
|
-
if (ev.touches.length == 1) {
|
|
156
|
-
let obj = {
|
|
157
|
-
x: ev.targetTouches[0].clientX,
|
|
158
|
-
y: ev.targetTouches[0].clientY,
|
|
159
|
-
}
|
|
160
|
-
if (ev.target.id !== this.state.curCanvasId) {
|
|
161
|
-
let curCanvasId = this.state.curCanvasId;
|
|
162
|
-
if (curCanvasId) {
|
|
163
|
-
clearTimeout(this.timer)
|
|
164
|
-
// console.log(this.refs[this.state.curCanvasId].toDataURL()); // 签名img回传后台
|
|
165
|
-
// 新增图片
|
|
166
|
-
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
167
|
-
this.setState({
|
|
168
|
-
pics: this.state.pics
|
|
169
|
-
})
|
|
170
|
-
const $div = document.getElementById('imgLeft');
|
|
171
|
-
$div.scrollTop = $div.scrollHeight;
|
|
172
|
-
// 清除画布
|
|
173
|
-
const ctx = curCanvasId === 'canvas1' ? this.state.ctx : this.state.ctx2;
|
|
174
|
-
ctx.clearRect(
|
|
175
|
-
0,
|
|
176
|
-
0,
|
|
177
|
-
this.refs[curCanvasId].width,
|
|
178
|
-
this.refs[curCanvasId].height,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
this.state.lastCanvasId = this.state.curCanvasId
|
|
182
|
-
this.state.curCanvasId = ev.target.id;
|
|
183
|
-
if (curCanvasId) this.drawText(1)
|
|
184
|
-
}
|
|
185
|
-
let { ctx } = this.state;
|
|
186
|
-
let canvas = this.refs.canvas1;
|
|
187
|
-
if (ev.target.id === 'canvas2') {
|
|
188
|
-
ctx = this.state.ctx2;
|
|
189
|
-
canvas = this.refs.canvas2;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
this.state.startX = obj.x;
|
|
193
|
-
this.state.startY = obj.y;
|
|
194
|
-
ctx.beginPath();
|
|
195
|
-
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
196
|
-
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
197
|
-
ctx.stroke();
|
|
198
|
-
ctx.closePath();
|
|
199
|
-
this.state.isDown = true;
|
|
200
|
-
|
|
201
|
-
if (this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) return
|
|
202
|
-
if(ev.target.id === 'canvas1'){
|
|
203
|
-
this.setState({mask2: false})
|
|
204
|
-
} else {
|
|
205
|
-
this.setState({mask1: false})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// this.resetTimer();
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
touchMove=(ev)=>{
|
|
213
|
-
// console.log(new Date().toLocaleTimeString(),'触发touchmove---', ev)
|
|
214
|
-
ev = ev || event
|
|
215
|
-
ev.preventDefault()
|
|
216
|
-
if (ev.touches.length == 1) {
|
|
217
|
-
let obj = {
|
|
218
|
-
x: ev.targetTouches[0].clientX,
|
|
219
|
-
y: ev.targetTouches[0].clientY
|
|
220
|
-
}
|
|
221
|
-
if (this.state.isDown) {
|
|
222
|
-
if (ev.target.id != this.state.curCanvasId) return
|
|
223
|
-
|
|
224
|
-
let { ctx, stageInfo } = this.state
|
|
225
|
-
let canvas = this.refs.canvas1;
|
|
226
|
-
if (ev.target.id === 'canvas2') {
|
|
227
|
-
ctx = this.state.ctx2;
|
|
228
|
-
stageInfo = this.state.stageInfo2;
|
|
229
|
-
canvas = this.refs.canvas2;
|
|
230
|
-
}
|
|
231
|
-
if(obj.x - canvas.getBoundingClientRect().left<0 || obj.x - canvas.getBoundingClientRect().left> canvas.width || obj.y - canvas.getBoundingClientRect().top< 0 || obj.y - canvas.getBoundingClientRect().top> canvas.height) {
|
|
232
|
-
this.state.isDown = false;
|
|
233
|
-
}
|
|
234
|
-
ctx.beginPath();
|
|
235
|
-
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
236
|
-
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
237
|
-
ctx.stroke();
|
|
238
|
-
ctx.closePath();
|
|
239
|
-
this.state.startY = obj.y;
|
|
240
|
-
this.state.startX = obj.x;
|
|
241
|
-
// this.resetTimer();
|
|
242
|
-
}
|
|
243
|
-
clearTimeout(this.state.touchEndTimer)
|
|
244
|
-
this.state.touchEndTimer = setTimeout(() => {
|
|
245
|
-
// console.log('触发touchEndTimer')
|
|
246
|
-
if (this.state.moveY == obj.y && this.state.moveX == obj.x) {
|
|
247
|
-
console.log('手动关闭')
|
|
248
|
-
this.touchEnd(ev)
|
|
249
|
-
// console.log('更新isDown')
|
|
250
|
-
this.state.isDown = false;
|
|
251
|
-
}
|
|
252
|
-
}, 300)
|
|
253
|
-
this.state.moveY = obj.y;
|
|
254
|
-
this.state.moveX = obj.x;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
touchEnd=(ev)=> {
|
|
258
|
-
// console.log(new Date().toLocaleTimeString(),'触发touchend---', ev)
|
|
259
|
-
ev = ev || event
|
|
260
|
-
ev.preventDefault()
|
|
261
|
-
if (ev.touches.length == 1) {
|
|
262
|
-
let obj = {
|
|
263
|
-
x: ev.targetTouches[0].clientX ,
|
|
264
|
-
y: ev.targetTouches[0].clientY
|
|
265
|
-
}
|
|
266
|
-
let { ctx, stageInfo } = this.state
|
|
267
|
-
let canvas = this.refs.canvas1;
|
|
268
|
-
if (ev.target.id === 'canvas2') {
|
|
269
|
-
ctx = this.state.ctx2;
|
|
270
|
-
stageInfo = this.state.stageInfo2;
|
|
271
|
-
canvas = this.refs.canvas2;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ctx.beginPath();
|
|
275
|
-
// ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
276
|
-
// ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
277
|
-
// ctx.stroke();
|
|
278
|
-
// ctx.closePath();
|
|
279
|
-
this.state.isDown = false;
|
|
280
|
-
|
|
281
|
-
// this.resetTimer();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// pc
|
|
285
|
-
mouseDown=(ev) =>{
|
|
286
|
-
this.ableMouse = true;
|
|
287
|
-
// console.log(new Date().toLocaleTimeString(),'触发mouseDown---', ev)
|
|
288
|
-
this.state.isSignOk = true
|
|
289
|
-
ev.preventDefault();
|
|
290
|
-
// console.log(ev)
|
|
291
|
-
// if (ev.touches.length === 1) {
|
|
292
|
-
// 保存另一张图
|
|
293
|
-
if (ev.target.id !== this.state.curCanvasId) {
|
|
294
|
-
let curCanvasId = this.state.curCanvasId;
|
|
295
|
-
if (curCanvasId) {
|
|
296
|
-
clearTimeout(this.timer)
|
|
297
|
-
// console.log(this.refs[this.state.curCanvasId].toDataURL()); // 签名img回传后台
|
|
298
|
-
// 新增图片
|
|
299
|
-
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
300
|
-
this.setState({
|
|
301
|
-
pics: this.state.pics
|
|
302
|
-
})
|
|
303
|
-
const $div = document.getElementById('imgLeft');
|
|
304
|
-
$div.scrollTop = $div.scrollHeight;
|
|
305
|
-
// 清除画布
|
|
306
|
-
const ctx = curCanvasId === 'canvas1' ? this.state.ctx : this.state.ctx2;
|
|
307
|
-
ctx.clearRect(
|
|
308
|
-
0,
|
|
309
|
-
0,
|
|
310
|
-
this.refs[curCanvasId].width,
|
|
311
|
-
this.refs[curCanvasId].height,
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
this.state.lastCanvasId = this.state.curCanvasId
|
|
315
|
-
this.state.curCanvasId = ev.target.id;
|
|
316
|
-
if (curCanvasId) this.drawText(1)
|
|
317
|
-
}
|
|
318
|
-
let { ctx } = this.state;
|
|
319
|
-
let canvas = this.refs.canvas1;
|
|
320
|
-
if (ev.target.id === 'canvas2') {
|
|
321
|
-
ctx = this.state.ctx2;
|
|
322
|
-
canvas = this.refs.canvas2;
|
|
323
|
-
}
|
|
324
|
-
const obj = {
|
|
325
|
-
x: ev.pageX,
|
|
326
|
-
y: ev.pageY,
|
|
327
|
-
};
|
|
328
|
-
this.state.startX = obj.x;
|
|
329
|
-
this.state.startY = obj.y;
|
|
330
|
-
ctx.beginPath();
|
|
331
|
-
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
332
|
-
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
333
|
-
ctx.stroke();
|
|
334
|
-
ctx.closePath();
|
|
335
|
-
this.state.isDown = true;
|
|
336
|
-
|
|
337
|
-
if (this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) return
|
|
338
|
-
if(ev.target.id === 'canvas1'){
|
|
339
|
-
this.setState({mask2: false})
|
|
340
|
-
} else {
|
|
341
|
-
this.setState({mask1: false})
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// this.resetTimer();
|
|
345
|
-
// }
|
|
346
|
-
}
|
|
347
|
-
mouseMove=(ev)=> {
|
|
348
|
-
// console.log(new Date().toLocaleTimeString(),'触发mouseMove---', ev)
|
|
349
|
-
ev.preventDefault();
|
|
350
|
-
if(!this.ableMouse) {
|
|
351
|
-
// console.log('ableMouse=false阻挡move事件, isdown=', this.state.isDown)
|
|
352
|
-
return
|
|
353
|
-
}
|
|
354
|
-
if (this.state.isDown) {
|
|
355
|
-
if (ev.target.id != this.state.curCanvasId) return
|
|
356
|
-
|
|
357
|
-
let { ctx, stageInfo } = this.state
|
|
358
|
-
let canvas = this.refs.canvas1;
|
|
359
|
-
if (ev.target.id === 'canvas2') {
|
|
360
|
-
ctx = this.state.ctx2;
|
|
361
|
-
stageInfo = this.state.stageInfo2;
|
|
362
|
-
canvas = this.refs.canvas2;
|
|
363
|
-
}
|
|
364
|
-
const obj = {
|
|
365
|
-
x: ev.pageX,
|
|
366
|
-
y: ev.pageY,
|
|
367
|
-
};
|
|
368
|
-
if(obj.x - canvas.getBoundingClientRect().left<0 || obj.x - canvas.getBoundingClientRect().left> canvas.width || obj.y - canvas.getBoundingClientRect().top< 0 || obj.y - canvas.getBoundingClientRect().top> canvas.height) {
|
|
369
|
-
this.state.isDown = false;
|
|
370
|
-
}
|
|
371
|
-
ctx.beginPath();
|
|
372
|
-
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
373
|
-
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
374
|
-
ctx.stroke();
|
|
375
|
-
ctx.closePath();
|
|
376
|
-
this.state.startY = obj.y;
|
|
377
|
-
this.state.startX = obj.x;
|
|
378
|
-
// this.resetTimer();
|
|
379
|
-
clearTimeout(this.state.touchEndTimer)
|
|
380
|
-
this.state.touchEndTimer = setTimeout(() => {
|
|
381
|
-
// console.log('触发mouseEndTimer')
|
|
382
|
-
if (this.state.moveY == obj.y && this.state.moveX == obj.x) {
|
|
383
|
-
console.log('手动关闭')
|
|
384
|
-
this.mouseUp(ev)
|
|
385
|
-
// console.log('更新isDown')
|
|
386
|
-
this.state.isDown = false;
|
|
387
|
-
}
|
|
388
|
-
}, 300)
|
|
389
|
-
this.state.moveY = obj.y;
|
|
390
|
-
this.state.moveX = obj.x;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
mouseUp=(ev)=> {
|
|
394
|
-
// console.log(new Date().toLocaleTimeString(),'触发mouseUp---', ev)
|
|
395
|
-
if (!this.state.isDown) return;
|
|
396
|
-
ev.preventDefault();
|
|
397
|
-
let { ctx, stageInfo } = this.state
|
|
398
|
-
let canvas = this.refs.canvas1;
|
|
399
|
-
if (ev.target.id === 'canvas2') {
|
|
400
|
-
ctx = this.state.ctx2;
|
|
401
|
-
stageInfo = this.state.stageInfo2;
|
|
402
|
-
canvas = this.refs.canvas2;
|
|
403
|
-
}
|
|
404
|
-
const obj = {
|
|
405
|
-
x: ev.pageX,
|
|
406
|
-
y: ev.pageY,
|
|
407
|
-
};
|
|
408
|
-
// ctx.beginPath();
|
|
409
|
-
// ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
410
|
-
// ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
411
|
-
// ctx.stroke();
|
|
412
|
-
// ctx.closePath();
|
|
413
|
-
this.state.isDown = false;
|
|
414
|
-
|
|
415
|
-
// this.resetTimer();
|
|
416
|
-
}
|
|
417
|
-
// 过滤掉背景文字
|
|
418
|
-
filterImgData(canvas, ctx) {
|
|
419
|
-
if (!ctx) ctx = canvas.getContext('2d');
|
|
420
|
-
var imgData=ctx.getImageData(0,0,canvas.width,canvas.height);
|
|
421
|
-
// invert colors
|
|
422
|
-
for (let k=0;k<imgData.data.length;k+=4) {
|
|
423
|
-
if(Math.abs(imgData.data[k]-218)<3 || Math.abs(imgData.data[k+1]-218)<3 ||Math.abs(imgData.data[k+2]-218)<3 ){
|
|
424
|
-
imgData.data[k+3] = 0
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
ctx.putImageData(imgData,0,0);
|
|
428
|
-
return canvas
|
|
429
|
-
}
|
|
430
|
-
// 提交
|
|
431
|
-
commit = async () =>{
|
|
432
|
-
if(this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const curCanvasId = this.state.curCanvasId;
|
|
436
|
-
// 保存另一张图
|
|
437
|
-
if (this.state.curCanvasId) {
|
|
438
|
-
// 新增图片
|
|
439
|
-
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
440
|
-
this.setState({
|
|
441
|
-
pics: this.state.pics
|
|
442
|
-
})
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const file = await this.getFinalImage()
|
|
446
|
-
// console.log(file)
|
|
447
|
-
const item = this.props.item;
|
|
448
|
-
this.props.next({
|
|
449
|
-
type: item.type,
|
|
450
|
-
file: file, //.replace('data:image/png;base64,',''),
|
|
451
|
-
sequence: item.sequence
|
|
452
|
-
})
|
|
453
|
-
} else {
|
|
454
|
-
this.setState({
|
|
455
|
-
isModalVisibleSubmit: true
|
|
456
|
-
})
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
handleSubmit=()=>{
|
|
460
|
-
this.setState({
|
|
461
|
-
isModalVisibleSubmit: false
|
|
462
|
-
})
|
|
463
|
-
}
|
|
464
|
-
// 合成最终图片
|
|
465
|
-
getFinalImage = () => {
|
|
466
|
-
return new Promise(resolve => {
|
|
467
|
-
let canvas = document.createElement('canvas');
|
|
468
|
-
let ctx = canvas.getContext('2d');
|
|
469
|
-
const cell = this.props.item.subContent[0].cell
|
|
470
|
-
const row = this.props.item.subContent[0].row
|
|
471
|
-
|
|
472
|
-
// const blockWidthAndHeight = 40; // 单字宽高
|
|
473
|
-
const blockWidth = 80
|
|
474
|
-
const blockHeight = blockWidth * this.props.height * cell / (this.props.length * row * 2)
|
|
475
|
-
// console.log(blockWidth, blockHeight);
|
|
476
|
-
const wordsPerLine = cell || 10
|
|
477
|
-
|
|
478
|
-
let canvasWidth = blockWidth * wordsPerLine
|
|
479
|
-
let canvasHeight = blockHeight * this.props.item.subContent[0].row * 2 // canvasWidth / this.props.rate
|
|
480
|
-
|
|
481
|
-
canvas.width = canvasWidth;
|
|
482
|
-
canvas.height = canvasHeight;
|
|
483
|
-
// 画背景
|
|
484
|
-
// ctx.fillStyle = 'white';
|
|
485
|
-
// ctx.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
486
|
-
|
|
487
|
-
// 拼接图片绘制
|
|
488
|
-
let pics = this.state.pics
|
|
489
|
-
for (let i = 0;i< this.props.item.subContent[0].desc.length; i++){
|
|
490
|
-
|
|
491
|
-
let rowIndex = Math.floor( i / wordsPerLine)
|
|
492
|
-
let colIndex = Math.floor( i % wordsPerLine)
|
|
493
|
-
// 画字
|
|
494
|
-
// ctx.font = blockWidth/2 + 'px "微软雅黑"';
|
|
495
|
-
// ctx.fillStyle = "#000000";
|
|
496
|
-
// ctx.textAlign = "center";
|
|
497
|
-
// ctx.textBaseline = "middle";
|
|
498
|
-
// ctx.fillText( this.props.item.subContent[0].desc[i], colIndex*blockWidth + blockWidth/2, 2*rowIndex*blockHeight + blockHeight/2 ); //填充文字
|
|
499
|
-
|
|
500
|
-
// 画格子,两条竖线三条横线
|
|
501
|
-
// ctx.beginPath();
|
|
502
|
-
// ctx.strokeStyle = "teal";
|
|
503
|
-
// ctx.moveTo(colIndex*blockWidth, 2*rowIndex*blockHeight); // 竖线
|
|
504
|
-
// ctx.lineTo(colIndex*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
505
|
-
// ctx.stroke();
|
|
506
|
-
|
|
507
|
-
// ctx.moveTo((colIndex+1)*blockWidth, 2*rowIndex*blockHeight);
|
|
508
|
-
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
509
|
-
// ctx.stroke();
|
|
510
|
-
|
|
511
|
-
// ctx.moveTo(colIndex*blockWidth, 2*rowIndex*blockHeight); // 横线
|
|
512
|
-
// ctx.lineTo((colIndex+1)*blockWidth, 2*rowIndex*blockHeight);
|
|
513
|
-
// ctx.stroke();
|
|
514
|
-
|
|
515
|
-
// ctx.moveTo(colIndex*blockWidth, (2*rowIndex+1)*blockHeight);
|
|
516
|
-
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+1)*blockHeight);
|
|
517
|
-
// ctx.stroke();
|
|
518
|
-
|
|
519
|
-
// ctx.moveTo(colIndex*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
520
|
-
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
521
|
-
// ctx.stroke();
|
|
522
|
-
|
|
523
|
-
// 画图
|
|
524
|
-
let img = new Image()
|
|
525
|
-
img.src = pics[i]
|
|
526
|
-
img.onload = () =>{
|
|
527
|
-
ctx.drawImage(img, colIndex*blockWidth-1,(2*rowIndex+1)*blockHeight-1, blockWidth-2, blockHeight-2);
|
|
528
|
-
if(i===this.props.item.subContent[0].desc.length-1) {
|
|
529
|
-
// console.log(canvas.toDataURL())
|
|
530
|
-
console.log('output')
|
|
531
|
-
console.log(canvas.toDataURL())
|
|
532
|
-
resolve(canvas.toDataURL())
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
})
|
|
538
|
-
}
|
|
539
|
-
// 回退一个
|
|
540
|
-
back = () => {
|
|
541
|
-
if(this.state.isSignOk) {
|
|
542
|
-
this.state.isSignOk = false
|
|
543
|
-
this.clearCanvas()
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
} else {
|
|
547
|
-
this.state.pics.pop()
|
|
548
|
-
this.setState({
|
|
549
|
-
pics: this.state.pics
|
|
550
|
-
})
|
|
551
|
-
this.clearCanvas()
|
|
552
|
-
}
|
|
553
|
-
// this.state.pics.pop()
|
|
554
|
-
// this.setState({
|
|
555
|
-
// pics: this.state.pics
|
|
556
|
-
// })
|
|
557
|
-
// this.clearCanvas()
|
|
558
|
-
}
|
|
559
|
-
// 清屏
|
|
560
|
-
clearAll = () => {
|
|
561
|
-
this.state.pics = []
|
|
562
|
-
this.setState({
|
|
563
|
-
pics: this.state.pics
|
|
564
|
-
})
|
|
565
|
-
this.clearCanvas()
|
|
566
|
-
}
|
|
567
|
-
exit = () => {
|
|
568
|
-
this.setState({
|
|
569
|
-
isModalVisibleEnd: true
|
|
570
|
-
})
|
|
571
|
-
}
|
|
572
|
-
handleCancelEnd = () => {
|
|
573
|
-
this.setState({
|
|
574
|
-
isModalVisibleEnd: false
|
|
575
|
-
})
|
|
576
|
-
}
|
|
577
|
-
handleOkEnd = () => {
|
|
578
|
-
this.setState({
|
|
579
|
-
isModalVisibleEnd: false
|
|
580
|
-
})
|
|
581
|
-
this.props.exit()
|
|
582
|
-
}
|
|
583
|
-
render() {
|
|
584
|
-
const {item} = this.props;
|
|
585
|
-
return (
|
|
586
|
-
<div className="copyTwo">
|
|
587
|
-
<div className="thehead">
|
|
588
|
-
<div className="title">
|
|
589
|
-
<div className="title-color"></div>
|
|
590
|
-
<div className="title-text">{this.props.title}</div>
|
|
591
|
-
</div>
|
|
592
|
-
|
|
593
|
-
<div className="btns">
|
|
594
|
-
<div className="button gray" onClick={this.exit}><FormattedMessage id="exit" /></div>
|
|
595
|
-
<div className="button gray" onClick={this.clearAll} ><FormattedMessage id="reset" /></div>
|
|
596
|
-
</div>
|
|
597
|
-
</div>
|
|
598
|
-
<div className="contents">{item.subContent[0].desc}</div>
|
|
599
|
-
<div className="copy-area">
|
|
600
|
-
<div className="left" >
|
|
601
|
-
<div className='imgLeft' id="imgLeft" >
|
|
602
|
-
{
|
|
603
|
-
this.state.pics.map((pic,index)=>{
|
|
604
|
-
return (
|
|
605
|
-
<img key={index} className="pic" src={pic} style={{ width: this.state.imgWidth, height: this.state.imgHeight}}></img>
|
|
606
|
-
)
|
|
607
|
-
})
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
</div>
|
|
611
|
-
<div className="footTwo">
|
|
612
|
-
{/* {
|
|
613
|
-
this.state.pics.length + 1 >= item.subContent[0].desc.length? <div className="button" onClick={this.commit}><FormattedMessage id="commit" /></div>: null
|
|
614
|
-
} */}
|
|
615
|
-
<div className='footThree'>
|
|
616
|
-
<div className="button gray" onClick={this.back}><FormattedMessage id="clearScreen" /></div>
|
|
617
|
-
<div className="button" onClick={this.commit}><FormattedMessage id="commit" /></div>
|
|
618
|
-
</div>
|
|
619
|
-
</div>
|
|
620
|
-
</div>
|
|
621
|
-
<div className="right" ref="canvasHW">
|
|
622
|
-
{this.state.mask1 || this.state.pics.length >= item.subContent[0].desc.length?<div className='mask'></div>:null}
|
|
623
|
-
{/* <div className="current-text">{this.state.pics.length<item.subContent.length? item.subContent[this.state.pics.length] : ''}</div> */}
|
|
624
|
-
<canvas
|
|
625
|
-
style={{display : this.state.pics.length >= item.subContent[0].desc.length ? 'none' : ''}}
|
|
626
|
-
id="canvas1"
|
|
627
|
-
ref="canvas1"
|
|
628
|
-
onMouseDown={this.mouseDown}
|
|
629
|
-
onMouseMove={this.mouseMove}
|
|
630
|
-
onMouseUp={this.mouseUp}
|
|
631
|
-
onMouseLeave={() => { this.state.isDown = false }}
|
|
632
|
-
></canvas>
|
|
633
|
-
|
|
634
|
-
</div>
|
|
635
|
-
<div className="right" ref="canvasHW2">
|
|
636
|
-
{this.state.mask2 || this.state.pics.length >= item.subContent[0].desc.length?<div className='mask'></div>:null}
|
|
637
|
-
{/* <div className="current-text">{this.state.pics.length<item.subContent.length? item.subContent[this.state.pics.length] : ''}</div> */}
|
|
638
|
-
<canvas
|
|
639
|
-
style={{display : this.state.pics.length >= item.subContent[0].desc.length ? 'none' : ''}}
|
|
640
|
-
id="canvas2"
|
|
641
|
-
ref="canvas2"
|
|
642
|
-
onMouseDown={this.mouseDown}
|
|
643
|
-
onMouseMove={this.mouseMove}
|
|
644
|
-
onMouseUp={this.mouseUp}
|
|
645
|
-
onMouseLeave={() => { this.state.isDown = false }}
|
|
646
|
-
></canvas>
|
|
647
|
-
</div>
|
|
648
|
-
</div>
|
|
649
|
-
<Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleEnd} footer={[<div key='end'>
|
|
650
|
-
<Button className="modelButtonCancel" onClick={this.handleCancelEnd}><FormattedMessage id="cancel" /></Button>
|
|
651
|
-
<Button className="modelButtonOk" type="primary" danger onClick={this.handleOkEnd}><FormattedMessage id="ok" /></Button>
|
|
652
|
-
</div>
|
|
653
|
-
]}>
|
|
654
|
-
<div className='endModal'>
|
|
655
|
-
<div className='modalEndTitle'>
|
|
656
|
-
<FormattedMessage id="whether" />
|
|
657
|
-
</div>
|
|
658
|
-
<div className='modalEnd'>
|
|
659
|
-
<FormattedMessage id="progress" />
|
|
660
|
-
</div>
|
|
661
|
-
</div>
|
|
662
|
-
</Modal>
|
|
663
|
-
<Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleSubmit} footer={[<div key='end'>
|
|
664
|
-
<Button className="modelButtonOk" type="primary" danger onClick={this.handleSubmit}><FormattedMessage id="ok" /></Button>
|
|
665
|
-
</div>
|
|
666
|
-
]}>
|
|
667
|
-
<div className='endModal'>
|
|
668
|
-
<div className='modalEndTitle'>
|
|
669
|
-
<FormattedMessage id="message" />
|
|
670
|
-
</div>
|
|
671
|
-
<div className='modalEnd'>
|
|
672
|
-
<FormattedMessage id="signatureNot" />
|
|
673
|
-
</div>
|
|
674
|
-
</div>
|
|
675
|
-
</Modal>
|
|
676
|
-
</div>
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
export default Copy;
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { FormattedMessage } from 'react-intl';
|
|
3
|
+
import './copyTwo.less'
|
|
4
|
+
import Modal from "antd/lib/modal";
|
|
5
|
+
import 'antd/lib/modal/style'
|
|
6
|
+
import { Button } from '../../../../../node_modules/antd/lib/index';
|
|
7
|
+
class Copy extends Component {
|
|
8
|
+
signCanvas = React.createRef();
|
|
9
|
+
timer = null;
|
|
10
|
+
state = {
|
|
11
|
+
finalImage: "",
|
|
12
|
+
pics: [],
|
|
13
|
+
isFinish: false,
|
|
14
|
+
ctx: null,
|
|
15
|
+
stageInfo: '',
|
|
16
|
+
isDown: false,
|
|
17
|
+
startY: '',
|
|
18
|
+
startX: '',
|
|
19
|
+
moveX: '',
|
|
20
|
+
moveY: '',
|
|
21
|
+
mask1: false,
|
|
22
|
+
mask2: true,
|
|
23
|
+
imgWidth: '0px',
|
|
24
|
+
imgHeight: '0px',
|
|
25
|
+
isModalVisibleEnd: false,
|
|
26
|
+
isModalVisibleSubmit: false,
|
|
27
|
+
isSignOk: false
|
|
28
|
+
};
|
|
29
|
+
componentWillUnmount() {
|
|
30
|
+
clearTimeout(this.timer)
|
|
31
|
+
const canvas = this.refs.canvas1;
|
|
32
|
+
const canvas2 = this.refs.canvas2;
|
|
33
|
+
canvas.removeEventListener('touchstart', this.touchStart);
|
|
34
|
+
canvas.removeEventListener('touchmove', this.touchMove);
|
|
35
|
+
canvas.removeEventListener('touchend', this.touchEnd);
|
|
36
|
+
canvas2.removeEventListener('touchstart', this.touchStart);
|
|
37
|
+
canvas2.removeEventListener('touchmove', this.touchMove);
|
|
38
|
+
canvas2.removeEventListener('touchend', this.touchEnd);
|
|
39
|
+
}
|
|
40
|
+
componentDidMount() {
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
let canvas = this.refs.canvas1;
|
|
43
|
+
canvas.height = this.refs.canvasHW.offsetHeight - 0;
|
|
44
|
+
canvas.width = this.refs.canvasHW.offsetWidth - 0;
|
|
45
|
+
this.state.ctx = canvas.getContext('2d');
|
|
46
|
+
this.state.stageInfo = canvas.getBoundingClientRect();
|
|
47
|
+
this.state.ctx.lineWidth = 7;
|
|
48
|
+
this.state.ctx.lineCap = "round";
|
|
49
|
+
|
|
50
|
+
let canvas2 = this.refs.canvas2;
|
|
51
|
+
canvas2.height = this.refs.canvasHW2.offsetHeight - 0;
|
|
52
|
+
canvas2.width = this.refs.canvasHW2.offsetWidth - 0;
|
|
53
|
+
this.state.ctx2 = canvas2.getContext('2d');
|
|
54
|
+
this.state.ctx2.lineWidth = 7;
|
|
55
|
+
this.state.ctx2.lineCap = "round";
|
|
56
|
+
this.state.stageInfo2 = canvas2.getBoundingClientRect();
|
|
57
|
+
this.state.isSignOk = false
|
|
58
|
+
this.drawText()
|
|
59
|
+
this.drawText(1)
|
|
60
|
+
|
|
61
|
+
canvas.addEventListener('touchstart', this.touchStart, { passive: false });
|
|
62
|
+
canvas.addEventListener('touchmove', this.touchMove, { passive: false });
|
|
63
|
+
canvas.addEventListener('touchend', this.touchEnd, { passive: false });
|
|
64
|
+
canvas2.addEventListener('touchstart', this.touchStart, { passive: false });
|
|
65
|
+
canvas2.addEventListener('touchmove', this.touchMove, { passive: false });
|
|
66
|
+
canvas2.addEventListener('touchend', this.touchEnd, { passive: false });
|
|
67
|
+
}, 20);
|
|
68
|
+
var box=document.getElementById("imgLeft");
|
|
69
|
+
if(box){ //此处在加一层判断,更加严密,如果box存在的情况下获取
|
|
70
|
+
this.state.imgWidth = Math.round(Math.sqrt((box.offsetWidth * box.offsetHeight)/70)*10)/10
|
|
71
|
+
this.state.imgHeight = Math.round(Math.sqrt((box.offsetWidth * box.offsetHeight)/70)*10)/10
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// 画背景字
|
|
75
|
+
drawText = (num=0) => {
|
|
76
|
+
if (num==0){
|
|
77
|
+
this.setState({mask2: true, mask1: false})
|
|
78
|
+
} else {
|
|
79
|
+
if (this.state.lastCanvasId === 'canvas2' || (!this.state.lastCanvasId && num ===1)){
|
|
80
|
+
this.setState({mask2: true, mask1: false})
|
|
81
|
+
} else {
|
|
82
|
+
this.setState({mask2: false, mask1: true})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (this.state.pics.length + num >= this.props.item.subContent[0].desc.length) return;
|
|
86
|
+
let { ctx } = this.state;
|
|
87
|
+
let canvas = this.refs.canvas1;
|
|
88
|
+
if (this.state.lastCanvasId === 'canvas2' || (!this.state.lastCanvasId && num ===1)) {
|
|
89
|
+
ctx = this.state.ctx2;
|
|
90
|
+
canvas = this.refs.canvas2;
|
|
91
|
+
}
|
|
92
|
+
ctx.font = canvas.width/1.5 + 'px "微软雅黑"';
|
|
93
|
+
ctx.fillStyle = "#DADADA";
|
|
94
|
+
ctx.textAlign = "center";
|
|
95
|
+
ctx.textBaseline = "middle";
|
|
96
|
+
ctx.fillText(this.props.item.subContent[0].desc[this.state.pics.length + num], canvas.width/2, canvas.height/2);
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 清空画布
|
|
101
|
+
clearCanvas = () => {
|
|
102
|
+
clearTimeout(this.timer)
|
|
103
|
+
let canvas = this.refs.canvas1;
|
|
104
|
+
// 清除画布
|
|
105
|
+
this.state.ctx.clearRect(
|
|
106
|
+
0,
|
|
107
|
+
0,
|
|
108
|
+
canvas.width,
|
|
109
|
+
canvas.height,
|
|
110
|
+
);
|
|
111
|
+
let canvas2 = this.refs.canvas2;
|
|
112
|
+
// 清除画布2
|
|
113
|
+
this.state.ctx2.clearRect(
|
|
114
|
+
0,
|
|
115
|
+
0,
|
|
116
|
+
canvas2.width,
|
|
117
|
+
canvas2.height,
|
|
118
|
+
);
|
|
119
|
+
this.state.curCanvasId = ''
|
|
120
|
+
this.state.lastCanvasId = ''
|
|
121
|
+
this.drawText()
|
|
122
|
+
this.drawText(1)
|
|
123
|
+
}
|
|
124
|
+
resetTimer = () => {
|
|
125
|
+
clearTimeout(this.timer);
|
|
126
|
+
const curCanvasId = this.state.curCanvasId;
|
|
127
|
+
const ctx = curCanvasId ==='canvas1'?this.state.ctx : this.state.ctx2
|
|
128
|
+
this.timer = setTimeout(() => {
|
|
129
|
+
// 保存另一张图
|
|
130
|
+
if (this.state.curCanvasId) {
|
|
131
|
+
// 新增图片
|
|
132
|
+
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
133
|
+
this.setState({
|
|
134
|
+
pics: this.state.pics
|
|
135
|
+
})
|
|
136
|
+
// 清除画布
|
|
137
|
+
ctx.clearRect(
|
|
138
|
+
0,
|
|
139
|
+
0,
|
|
140
|
+
this.refs[this.state.curCanvasId].width,
|
|
141
|
+
this.refs[this.state.curCanvasId].height,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
this.state.lastCanvasId = this.state.curCanvasId
|
|
145
|
+
this.state.curCanvasId = '';
|
|
146
|
+
this.drawText(1)
|
|
147
|
+
}, 1000);
|
|
148
|
+
}
|
|
149
|
+
touchStart=(ev)=> {
|
|
150
|
+
this.ableMouse = false;
|
|
151
|
+
// console.log(new Date().toLocaleTimeString(),'触发touchstart---', ev)
|
|
152
|
+
this.state.isSignOk = true
|
|
153
|
+
ev = ev || event
|
|
154
|
+
ev.preventDefault()
|
|
155
|
+
if (ev.touches.length == 1) {
|
|
156
|
+
let obj = {
|
|
157
|
+
x: ev.targetTouches[0].clientX,
|
|
158
|
+
y: ev.targetTouches[0].clientY,
|
|
159
|
+
}
|
|
160
|
+
if (ev.target.id !== this.state.curCanvasId) {
|
|
161
|
+
let curCanvasId = this.state.curCanvasId;
|
|
162
|
+
if (curCanvasId) {
|
|
163
|
+
clearTimeout(this.timer)
|
|
164
|
+
// console.log(this.refs[this.state.curCanvasId].toDataURL()); // 签名img回传后台
|
|
165
|
+
// 新增图片
|
|
166
|
+
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
167
|
+
this.setState({
|
|
168
|
+
pics: this.state.pics
|
|
169
|
+
})
|
|
170
|
+
const $div = document.getElementById('imgLeft');
|
|
171
|
+
$div.scrollTop = $div.scrollHeight;
|
|
172
|
+
// 清除画布
|
|
173
|
+
const ctx = curCanvasId === 'canvas1' ? this.state.ctx : this.state.ctx2;
|
|
174
|
+
ctx.clearRect(
|
|
175
|
+
0,
|
|
176
|
+
0,
|
|
177
|
+
this.refs[curCanvasId].width,
|
|
178
|
+
this.refs[curCanvasId].height,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
this.state.lastCanvasId = this.state.curCanvasId
|
|
182
|
+
this.state.curCanvasId = ev.target.id;
|
|
183
|
+
if (curCanvasId) this.drawText(1)
|
|
184
|
+
}
|
|
185
|
+
let { ctx } = this.state;
|
|
186
|
+
let canvas = this.refs.canvas1;
|
|
187
|
+
if (ev.target.id === 'canvas2') {
|
|
188
|
+
ctx = this.state.ctx2;
|
|
189
|
+
canvas = this.refs.canvas2;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.state.startX = obj.x;
|
|
193
|
+
this.state.startY = obj.y;
|
|
194
|
+
ctx.beginPath();
|
|
195
|
+
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
196
|
+
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
197
|
+
ctx.stroke();
|
|
198
|
+
ctx.closePath();
|
|
199
|
+
this.state.isDown = true;
|
|
200
|
+
|
|
201
|
+
if (this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) return
|
|
202
|
+
if(ev.target.id === 'canvas1'){
|
|
203
|
+
this.setState({mask2: false})
|
|
204
|
+
} else {
|
|
205
|
+
this.setState({mask1: false})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// this.resetTimer();
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
touchMove=(ev)=>{
|
|
213
|
+
// console.log(new Date().toLocaleTimeString(),'触发touchmove---', ev)
|
|
214
|
+
ev = ev || event
|
|
215
|
+
ev.preventDefault()
|
|
216
|
+
if (ev.touches.length == 1) {
|
|
217
|
+
let obj = {
|
|
218
|
+
x: ev.targetTouches[0].clientX,
|
|
219
|
+
y: ev.targetTouches[0].clientY
|
|
220
|
+
}
|
|
221
|
+
if (this.state.isDown) {
|
|
222
|
+
if (ev.target.id != this.state.curCanvasId) return
|
|
223
|
+
|
|
224
|
+
let { ctx, stageInfo } = this.state
|
|
225
|
+
let canvas = this.refs.canvas1;
|
|
226
|
+
if (ev.target.id === 'canvas2') {
|
|
227
|
+
ctx = this.state.ctx2;
|
|
228
|
+
stageInfo = this.state.stageInfo2;
|
|
229
|
+
canvas = this.refs.canvas2;
|
|
230
|
+
}
|
|
231
|
+
if(obj.x - canvas.getBoundingClientRect().left<0 || obj.x - canvas.getBoundingClientRect().left> canvas.width || obj.y - canvas.getBoundingClientRect().top< 0 || obj.y - canvas.getBoundingClientRect().top> canvas.height) {
|
|
232
|
+
this.state.isDown = false;
|
|
233
|
+
}
|
|
234
|
+
ctx.beginPath();
|
|
235
|
+
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
236
|
+
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
237
|
+
ctx.stroke();
|
|
238
|
+
ctx.closePath();
|
|
239
|
+
this.state.startY = obj.y;
|
|
240
|
+
this.state.startX = obj.x;
|
|
241
|
+
// this.resetTimer();
|
|
242
|
+
}
|
|
243
|
+
clearTimeout(this.state.touchEndTimer)
|
|
244
|
+
this.state.touchEndTimer = setTimeout(() => {
|
|
245
|
+
// console.log('触发touchEndTimer')
|
|
246
|
+
if (this.state.moveY == obj.y && this.state.moveX == obj.x) {
|
|
247
|
+
console.log('手动关闭')
|
|
248
|
+
this.touchEnd(ev)
|
|
249
|
+
// console.log('更新isDown')
|
|
250
|
+
this.state.isDown = false;
|
|
251
|
+
}
|
|
252
|
+
}, 300)
|
|
253
|
+
this.state.moveY = obj.y;
|
|
254
|
+
this.state.moveX = obj.x;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
touchEnd=(ev)=> {
|
|
258
|
+
// console.log(new Date().toLocaleTimeString(),'触发touchend---', ev)
|
|
259
|
+
ev = ev || event
|
|
260
|
+
ev.preventDefault()
|
|
261
|
+
if (ev.touches.length == 1) {
|
|
262
|
+
let obj = {
|
|
263
|
+
x: ev.targetTouches[0].clientX ,
|
|
264
|
+
y: ev.targetTouches[0].clientY
|
|
265
|
+
}
|
|
266
|
+
let { ctx, stageInfo } = this.state
|
|
267
|
+
let canvas = this.refs.canvas1;
|
|
268
|
+
if (ev.target.id === 'canvas2') {
|
|
269
|
+
ctx = this.state.ctx2;
|
|
270
|
+
stageInfo = this.state.stageInfo2;
|
|
271
|
+
canvas = this.refs.canvas2;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ctx.beginPath();
|
|
275
|
+
// ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
276
|
+
// ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
277
|
+
// ctx.stroke();
|
|
278
|
+
// ctx.closePath();
|
|
279
|
+
this.state.isDown = false;
|
|
280
|
+
|
|
281
|
+
// this.resetTimer();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// pc
|
|
285
|
+
mouseDown=(ev) =>{
|
|
286
|
+
this.ableMouse = true;
|
|
287
|
+
// console.log(new Date().toLocaleTimeString(),'触发mouseDown---', ev)
|
|
288
|
+
this.state.isSignOk = true
|
|
289
|
+
ev.preventDefault();
|
|
290
|
+
// console.log(ev)
|
|
291
|
+
// if (ev.touches.length === 1) {
|
|
292
|
+
// 保存另一张图
|
|
293
|
+
if (ev.target.id !== this.state.curCanvasId) {
|
|
294
|
+
let curCanvasId = this.state.curCanvasId;
|
|
295
|
+
if (curCanvasId) {
|
|
296
|
+
clearTimeout(this.timer)
|
|
297
|
+
// console.log(this.refs[this.state.curCanvasId].toDataURL()); // 签名img回传后台
|
|
298
|
+
// 新增图片
|
|
299
|
+
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
300
|
+
this.setState({
|
|
301
|
+
pics: this.state.pics
|
|
302
|
+
})
|
|
303
|
+
const $div = document.getElementById('imgLeft');
|
|
304
|
+
$div.scrollTop = $div.scrollHeight;
|
|
305
|
+
// 清除画布
|
|
306
|
+
const ctx = curCanvasId === 'canvas1' ? this.state.ctx : this.state.ctx2;
|
|
307
|
+
ctx.clearRect(
|
|
308
|
+
0,
|
|
309
|
+
0,
|
|
310
|
+
this.refs[curCanvasId].width,
|
|
311
|
+
this.refs[curCanvasId].height,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
this.state.lastCanvasId = this.state.curCanvasId
|
|
315
|
+
this.state.curCanvasId = ev.target.id;
|
|
316
|
+
if (curCanvasId) this.drawText(1)
|
|
317
|
+
}
|
|
318
|
+
let { ctx } = this.state;
|
|
319
|
+
let canvas = this.refs.canvas1;
|
|
320
|
+
if (ev.target.id === 'canvas2') {
|
|
321
|
+
ctx = this.state.ctx2;
|
|
322
|
+
canvas = this.refs.canvas2;
|
|
323
|
+
}
|
|
324
|
+
const obj = {
|
|
325
|
+
x: ev.pageX,
|
|
326
|
+
y: ev.pageY,
|
|
327
|
+
};
|
|
328
|
+
this.state.startX = obj.x;
|
|
329
|
+
this.state.startY = obj.y;
|
|
330
|
+
ctx.beginPath();
|
|
331
|
+
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
332
|
+
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
333
|
+
ctx.stroke();
|
|
334
|
+
ctx.closePath();
|
|
335
|
+
this.state.isDown = true;
|
|
336
|
+
|
|
337
|
+
if (this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) return
|
|
338
|
+
if(ev.target.id === 'canvas1'){
|
|
339
|
+
this.setState({mask2: false})
|
|
340
|
+
} else {
|
|
341
|
+
this.setState({mask1: false})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// this.resetTimer();
|
|
345
|
+
// }
|
|
346
|
+
}
|
|
347
|
+
mouseMove=(ev)=> {
|
|
348
|
+
// console.log(new Date().toLocaleTimeString(),'触发mouseMove---', ev)
|
|
349
|
+
ev.preventDefault();
|
|
350
|
+
if(!this.ableMouse) {
|
|
351
|
+
// console.log('ableMouse=false阻挡move事件, isdown=', this.state.isDown)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
if (this.state.isDown) {
|
|
355
|
+
if (ev.target.id != this.state.curCanvasId) return
|
|
356
|
+
|
|
357
|
+
let { ctx, stageInfo } = this.state
|
|
358
|
+
let canvas = this.refs.canvas1;
|
|
359
|
+
if (ev.target.id === 'canvas2') {
|
|
360
|
+
ctx = this.state.ctx2;
|
|
361
|
+
stageInfo = this.state.stageInfo2;
|
|
362
|
+
canvas = this.refs.canvas2;
|
|
363
|
+
}
|
|
364
|
+
const obj = {
|
|
365
|
+
x: ev.pageX,
|
|
366
|
+
y: ev.pageY,
|
|
367
|
+
};
|
|
368
|
+
if(obj.x - canvas.getBoundingClientRect().left<0 || obj.x - canvas.getBoundingClientRect().left> canvas.width || obj.y - canvas.getBoundingClientRect().top< 0 || obj.y - canvas.getBoundingClientRect().top> canvas.height) {
|
|
369
|
+
this.state.isDown = false;
|
|
370
|
+
}
|
|
371
|
+
ctx.beginPath();
|
|
372
|
+
ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
373
|
+
ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
374
|
+
ctx.stroke();
|
|
375
|
+
ctx.closePath();
|
|
376
|
+
this.state.startY = obj.y;
|
|
377
|
+
this.state.startX = obj.x;
|
|
378
|
+
// this.resetTimer();
|
|
379
|
+
clearTimeout(this.state.touchEndTimer)
|
|
380
|
+
this.state.touchEndTimer = setTimeout(() => {
|
|
381
|
+
// console.log('触发mouseEndTimer')
|
|
382
|
+
if (this.state.moveY == obj.y && this.state.moveX == obj.x) {
|
|
383
|
+
console.log('手动关闭')
|
|
384
|
+
this.mouseUp(ev)
|
|
385
|
+
// console.log('更新isDown')
|
|
386
|
+
this.state.isDown = false;
|
|
387
|
+
}
|
|
388
|
+
}, 300)
|
|
389
|
+
this.state.moveY = obj.y;
|
|
390
|
+
this.state.moveX = obj.x;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
mouseUp=(ev)=> {
|
|
394
|
+
// console.log(new Date().toLocaleTimeString(),'触发mouseUp---', ev)
|
|
395
|
+
if (!this.state.isDown) return;
|
|
396
|
+
ev.preventDefault();
|
|
397
|
+
let { ctx, stageInfo } = this.state
|
|
398
|
+
let canvas = this.refs.canvas1;
|
|
399
|
+
if (ev.target.id === 'canvas2') {
|
|
400
|
+
ctx = this.state.ctx2;
|
|
401
|
+
stageInfo = this.state.stageInfo2;
|
|
402
|
+
canvas = this.refs.canvas2;
|
|
403
|
+
}
|
|
404
|
+
const obj = {
|
|
405
|
+
x: ev.pageX,
|
|
406
|
+
y: ev.pageY,
|
|
407
|
+
};
|
|
408
|
+
// ctx.beginPath();
|
|
409
|
+
// ctx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
|
|
410
|
+
// ctx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
|
|
411
|
+
// ctx.stroke();
|
|
412
|
+
// ctx.closePath();
|
|
413
|
+
this.state.isDown = false;
|
|
414
|
+
|
|
415
|
+
// this.resetTimer();
|
|
416
|
+
}
|
|
417
|
+
// 过滤掉背景文字
|
|
418
|
+
filterImgData(canvas, ctx) {
|
|
419
|
+
if (!ctx) ctx = canvas.getContext('2d');
|
|
420
|
+
var imgData=ctx.getImageData(0,0,canvas.width,canvas.height);
|
|
421
|
+
// invert colors
|
|
422
|
+
for (let k=0;k<imgData.data.length;k+=4) {
|
|
423
|
+
if(Math.abs(imgData.data[k]-218)<3 || Math.abs(imgData.data[k+1]-218)<3 ||Math.abs(imgData.data[k+2]-218)<3 ){
|
|
424
|
+
imgData.data[k+3] = 0
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
ctx.putImageData(imgData,0,0);
|
|
428
|
+
return canvas
|
|
429
|
+
}
|
|
430
|
+
// 提交
|
|
431
|
+
commit = async () =>{
|
|
432
|
+
if(this.state.pics.length + 1 >= this.props.item.subContent[0].desc.length) {
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
const curCanvasId = this.state.curCanvasId;
|
|
436
|
+
// 保存另一张图
|
|
437
|
+
if (this.state.curCanvasId) {
|
|
438
|
+
// 新增图片
|
|
439
|
+
this.state.pics.push(this.filterImgData(this.refs[curCanvasId]).toDataURL());
|
|
440
|
+
this.setState({
|
|
441
|
+
pics: this.state.pics
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const file = await this.getFinalImage()
|
|
446
|
+
// console.log(file)
|
|
447
|
+
const item = this.props.item;
|
|
448
|
+
this.props.next({
|
|
449
|
+
type: item.type,
|
|
450
|
+
file: file, //.replace('data:image/png;base64,',''),
|
|
451
|
+
sequence: item.sequence
|
|
452
|
+
})
|
|
453
|
+
} else {
|
|
454
|
+
this.setState({
|
|
455
|
+
isModalVisibleSubmit: true
|
|
456
|
+
})
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
handleSubmit=()=>{
|
|
460
|
+
this.setState({
|
|
461
|
+
isModalVisibleSubmit: false
|
|
462
|
+
})
|
|
463
|
+
}
|
|
464
|
+
// 合成最终图片
|
|
465
|
+
getFinalImage = () => {
|
|
466
|
+
return new Promise(resolve => {
|
|
467
|
+
let canvas = document.createElement('canvas');
|
|
468
|
+
let ctx = canvas.getContext('2d');
|
|
469
|
+
const cell = this.props.item.subContent[0].cell
|
|
470
|
+
const row = this.props.item.subContent[0].row
|
|
471
|
+
|
|
472
|
+
// const blockWidthAndHeight = 40; // 单字宽高
|
|
473
|
+
const blockWidth = 80
|
|
474
|
+
const blockHeight = blockWidth * this.props.height * cell / (this.props.length * row * 2)
|
|
475
|
+
// console.log(blockWidth, blockHeight);
|
|
476
|
+
const wordsPerLine = cell || 10
|
|
477
|
+
|
|
478
|
+
let canvasWidth = blockWidth * wordsPerLine
|
|
479
|
+
let canvasHeight = blockHeight * this.props.item.subContent[0].row * 2 // canvasWidth / this.props.rate
|
|
480
|
+
|
|
481
|
+
canvas.width = canvasWidth;
|
|
482
|
+
canvas.height = canvasHeight;
|
|
483
|
+
// 画背景
|
|
484
|
+
// ctx.fillStyle = 'white';
|
|
485
|
+
// ctx.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
486
|
+
|
|
487
|
+
// 拼接图片绘制
|
|
488
|
+
let pics = this.state.pics
|
|
489
|
+
for (let i = 0;i< this.props.item.subContent[0].desc.length; i++){
|
|
490
|
+
|
|
491
|
+
let rowIndex = Math.floor( i / wordsPerLine)
|
|
492
|
+
let colIndex = Math.floor( i % wordsPerLine)
|
|
493
|
+
// 画字
|
|
494
|
+
// ctx.font = blockWidth/2 + 'px "微软雅黑"';
|
|
495
|
+
// ctx.fillStyle = "#000000";
|
|
496
|
+
// ctx.textAlign = "center";
|
|
497
|
+
// ctx.textBaseline = "middle";
|
|
498
|
+
// ctx.fillText( this.props.item.subContent[0].desc[i], colIndex*blockWidth + blockWidth/2, 2*rowIndex*blockHeight + blockHeight/2 ); //填充文字
|
|
499
|
+
|
|
500
|
+
// 画格子,两条竖线三条横线
|
|
501
|
+
// ctx.beginPath();
|
|
502
|
+
// ctx.strokeStyle = "teal";
|
|
503
|
+
// ctx.moveTo(colIndex*blockWidth, 2*rowIndex*blockHeight); // 竖线
|
|
504
|
+
// ctx.lineTo(colIndex*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
505
|
+
// ctx.stroke();
|
|
506
|
+
|
|
507
|
+
// ctx.moveTo((colIndex+1)*blockWidth, 2*rowIndex*blockHeight);
|
|
508
|
+
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
509
|
+
// ctx.stroke();
|
|
510
|
+
|
|
511
|
+
// ctx.moveTo(colIndex*blockWidth, 2*rowIndex*blockHeight); // 横线
|
|
512
|
+
// ctx.lineTo((colIndex+1)*blockWidth, 2*rowIndex*blockHeight);
|
|
513
|
+
// ctx.stroke();
|
|
514
|
+
|
|
515
|
+
// ctx.moveTo(colIndex*blockWidth, (2*rowIndex+1)*blockHeight);
|
|
516
|
+
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+1)*blockHeight);
|
|
517
|
+
// ctx.stroke();
|
|
518
|
+
|
|
519
|
+
// ctx.moveTo(colIndex*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
520
|
+
// ctx.lineTo((colIndex+1)*blockWidth, (2*rowIndex+2)*blockHeight);
|
|
521
|
+
// ctx.stroke();
|
|
522
|
+
|
|
523
|
+
// 画图
|
|
524
|
+
let img = new Image()
|
|
525
|
+
img.src = pics[i]
|
|
526
|
+
img.onload = () =>{
|
|
527
|
+
ctx.drawImage(img, colIndex*blockWidth-1,(2*rowIndex+1)*blockHeight-1, blockWidth-2, blockHeight-2);
|
|
528
|
+
if(i===this.props.item.subContent[0].desc.length-1) {
|
|
529
|
+
// console.log(canvas.toDataURL())
|
|
530
|
+
console.log('output')
|
|
531
|
+
console.log(canvas.toDataURL())
|
|
532
|
+
resolve(canvas.toDataURL())
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
}
|
|
537
|
+
})
|
|
538
|
+
}
|
|
539
|
+
// 回退一个
|
|
540
|
+
back = () => {
|
|
541
|
+
if(this.state.isSignOk) {
|
|
542
|
+
this.state.isSignOk = false
|
|
543
|
+
this.clearCanvas()
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
} else {
|
|
547
|
+
this.state.pics.pop()
|
|
548
|
+
this.setState({
|
|
549
|
+
pics: this.state.pics
|
|
550
|
+
})
|
|
551
|
+
this.clearCanvas()
|
|
552
|
+
}
|
|
553
|
+
// this.state.pics.pop()
|
|
554
|
+
// this.setState({
|
|
555
|
+
// pics: this.state.pics
|
|
556
|
+
// })
|
|
557
|
+
// this.clearCanvas()
|
|
558
|
+
}
|
|
559
|
+
// 清屏
|
|
560
|
+
clearAll = () => {
|
|
561
|
+
this.state.pics = []
|
|
562
|
+
this.setState({
|
|
563
|
+
pics: this.state.pics
|
|
564
|
+
})
|
|
565
|
+
this.clearCanvas()
|
|
566
|
+
}
|
|
567
|
+
exit = () => {
|
|
568
|
+
this.setState({
|
|
569
|
+
isModalVisibleEnd: true
|
|
570
|
+
})
|
|
571
|
+
}
|
|
572
|
+
handleCancelEnd = () => {
|
|
573
|
+
this.setState({
|
|
574
|
+
isModalVisibleEnd: false
|
|
575
|
+
})
|
|
576
|
+
}
|
|
577
|
+
handleOkEnd = () => {
|
|
578
|
+
this.setState({
|
|
579
|
+
isModalVisibleEnd: false
|
|
580
|
+
})
|
|
581
|
+
this.props.exit()
|
|
582
|
+
}
|
|
583
|
+
render() {
|
|
584
|
+
const {item} = this.props;
|
|
585
|
+
return (
|
|
586
|
+
<div className="copyTwo">
|
|
587
|
+
<div className="thehead">
|
|
588
|
+
<div className="title">
|
|
589
|
+
<div className="title-color"></div>
|
|
590
|
+
<div className="title-text">{this.props.title}</div>
|
|
591
|
+
</div>
|
|
592
|
+
|
|
593
|
+
<div className="btns">
|
|
594
|
+
<div className="button gray" onClick={this.exit}><FormattedMessage id="exit" /></div>
|
|
595
|
+
<div className="button gray" onClick={this.clearAll} ><FormattedMessage id="reset" /></div>
|
|
596
|
+
</div>
|
|
597
|
+
</div>
|
|
598
|
+
<div className="contents">{item.subContent[0].desc}</div>
|
|
599
|
+
<div className="copy-area">
|
|
600
|
+
<div className="left" >
|
|
601
|
+
<div className='imgLeft' id="imgLeft" >
|
|
602
|
+
{
|
|
603
|
+
this.state.pics.map((pic,index)=>{
|
|
604
|
+
return (
|
|
605
|
+
<img key={index} className="pic" src={pic} style={{ width: this.state.imgWidth, height: this.state.imgHeight}}></img>
|
|
606
|
+
)
|
|
607
|
+
})
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
</div>
|
|
611
|
+
<div className="footTwo">
|
|
612
|
+
{/* {
|
|
613
|
+
this.state.pics.length + 1 >= item.subContent[0].desc.length? <div className="button" onClick={this.commit}><FormattedMessage id="commit" /></div>: null
|
|
614
|
+
} */}
|
|
615
|
+
<div className='footThree'>
|
|
616
|
+
<div className="button gray" onClick={this.back}><FormattedMessage id="clearScreen" /></div>
|
|
617
|
+
<div className="button" onClick={this.commit}><FormattedMessage id="commit" /></div>
|
|
618
|
+
</div>
|
|
619
|
+
</div>
|
|
620
|
+
</div>
|
|
621
|
+
<div className="right" ref="canvasHW">
|
|
622
|
+
{this.state.mask1 || this.state.pics.length >= item.subContent[0].desc.length?<div className='mask'></div>:null}
|
|
623
|
+
{/* <div className="current-text">{this.state.pics.length<item.subContent.length? item.subContent[this.state.pics.length] : ''}</div> */}
|
|
624
|
+
<canvas
|
|
625
|
+
style={{display : this.state.pics.length >= item.subContent[0].desc.length ? 'none' : ''}}
|
|
626
|
+
id="canvas1"
|
|
627
|
+
ref="canvas1"
|
|
628
|
+
onMouseDown={this.mouseDown}
|
|
629
|
+
onMouseMove={this.mouseMove}
|
|
630
|
+
onMouseUp={this.mouseUp}
|
|
631
|
+
onMouseLeave={() => { this.state.isDown = false }}
|
|
632
|
+
></canvas>
|
|
633
|
+
|
|
634
|
+
</div>
|
|
635
|
+
<div className="right" ref="canvasHW2">
|
|
636
|
+
{this.state.mask2 || this.state.pics.length >= item.subContent[0].desc.length?<div className='mask'></div>:null}
|
|
637
|
+
{/* <div className="current-text">{this.state.pics.length<item.subContent.length? item.subContent[this.state.pics.length] : ''}</div> */}
|
|
638
|
+
<canvas
|
|
639
|
+
style={{display : this.state.pics.length >= item.subContent[0].desc.length ? 'none' : ''}}
|
|
640
|
+
id="canvas2"
|
|
641
|
+
ref="canvas2"
|
|
642
|
+
onMouseDown={this.mouseDown}
|
|
643
|
+
onMouseMove={this.mouseMove}
|
|
644
|
+
onMouseUp={this.mouseUp}
|
|
645
|
+
onMouseLeave={() => { this.state.isDown = false }}
|
|
646
|
+
></canvas>
|
|
647
|
+
</div>
|
|
648
|
+
</div>
|
|
649
|
+
<Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleEnd} footer={[<div key='end'>
|
|
650
|
+
<Button className="modelButtonCancel" onClick={this.handleCancelEnd}><FormattedMessage id="cancel" /></Button>
|
|
651
|
+
<Button className="modelButtonOk" type="primary" danger onClick={this.handleOkEnd}><FormattedMessage id="ok" /></Button>
|
|
652
|
+
</div>
|
|
653
|
+
]}>
|
|
654
|
+
<div className='endModal'>
|
|
655
|
+
<div className='modalEndTitle'>
|
|
656
|
+
<FormattedMessage id="whether" />
|
|
657
|
+
</div>
|
|
658
|
+
<div className='modalEnd'>
|
|
659
|
+
<FormattedMessage id="progress" />
|
|
660
|
+
</div>
|
|
661
|
+
</div>
|
|
662
|
+
</Modal>
|
|
663
|
+
<Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleSubmit} footer={[<div key='end'>
|
|
664
|
+
<Button className="modelButtonOk" type="primary" danger onClick={this.handleSubmit}><FormattedMessage id="ok" /></Button>
|
|
665
|
+
</div>
|
|
666
|
+
]}>
|
|
667
|
+
<div className='endModal'>
|
|
668
|
+
<div className='modalEndTitle'>
|
|
669
|
+
<FormattedMessage id="message" />
|
|
670
|
+
</div>
|
|
671
|
+
<div className='modalEnd'>
|
|
672
|
+
<FormattedMessage id="signatureNot" />
|
|
673
|
+
</div>
|
|
674
|
+
</div>
|
|
675
|
+
</Modal>
|
|
676
|
+
</div>
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export default Copy;
|