react_hsbc_teller 2.0.54 → 2.0.56

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.
Files changed (54) hide show
  1. package/.babelrc +39 -39
  2. package/README.en.md +36 -36
  3. package/README.md +329 -323
  4. package/config/webpack.config.js +119 -119
  5. package/config/webpack.dev.js +108 -108
  6. package/config/webpack.prod.js +104 -104
  7. package/lib/hsbc.js +1 -1
  8. package/lib/hsbc.js.LICENSE.txt +13 -16
  9. package/package.json +110 -110
  10. package/packages/api/api.js +818 -818
  11. package/packages/api/server.js +50 -50
  12. package/packages/common/index.esm.js +374 -374
  13. package/packages/demo/demo.js +306 -306
  14. package/packages/demo/index.js +3 -3
  15. package/packages/demo/pdf.js +94 -94
  16. package/packages/envconfig/envconfig.js +12 -12
  17. package/packages/index.js +2 -2
  18. package/packages/pages/components/step/step.jsx +32 -31
  19. package/packages/pages/foot/foot.jsx +235 -235
  20. package/packages/pages/foot/foot.less +85 -85
  21. package/packages/pages/header/header.jsx +15 -15
  22. package/packages/pages/header/header.less +51 -51
  23. package/packages/pages/index.jsx +52 -52
  24. package/packages/pages/multiModule/components/copy/agree.jsx +115 -115
  25. package/packages/pages/multiModule/components/copy/agree.less +105 -105
  26. package/packages/pages/multiModule/components/copy/copyTwo.jsx +682 -682
  27. package/packages/pages/multiModule/components/copy/copyTwo.less +180 -180
  28. package/packages/pages/multiModule/components/copy/copy_en.jsx +368 -368
  29. package/packages/pages/multiModule/components/copy/copy_en.less +145 -145
  30. package/packages/pages/multiModule/components/copy/copylist.jsx +291 -291
  31. package/packages/pages/multiModule/components/copy/copylist.less +83 -83
  32. package/packages/pages/multiModule/components/copy/risk.jsx +296 -296
  33. package/packages/pages/multiModule/components/copy/risk.less +123 -123
  34. package/packages/pages/multiModule/components/sign/signMy.jsx +308 -308
  35. package/packages/pages/multiModule/components/sign/signMy.less +127 -127
  36. package/packages/pages/multiModule/components/subscribe/subscribe.jsx +113 -113
  37. package/packages/pages/multiModule/components/subscribe/subscribe.less +82 -82
  38. package/packages/pages/multiModule/multiModule.jsx +26 -26
  39. package/packages/pages/multiModule/multiModule.less +19 -19
  40. package/packages/pages/sign/signMy.jsx +223 -223
  41. package/packages/pages/sign/signMy.less +129 -129
  42. package/packages/pages/video/video.jsx +7746 -7745
  43. package/packages/pages/video/video.less +715 -715
  44. package/packages/style/index.less +1 -1
  45. package/packages/style/reset.less +345 -345
  46. package/packages/utils/asrController.js +259 -259
  47. package/packages/utils/asyncComponent.jsx +26 -26
  48. package/packages/utils/mixin.js +27 -27
  49. package/packages/utils/setRem.js +10 -10
  50. package/packages/utils/utils.js +199 -199
  51. package/public/index.html +77 -77
  52. package/src/index.js +11 -11
  53. package/src/index.less +5 -5
  54. package/tsconfig.json +11 -11
@@ -1,368 +1,368 @@
1
- import React, { Component } from 'react';
2
- import { FormattedMessage } from 'react-intl';
3
- import './copy_en.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
- state = {
10
- finalImage: "",
11
- pics: [],
12
- isFinish: false,
13
- canvasCtx: null,
14
- stageInfo: '',
15
- isDown: false,
16
- startY: '',
17
- startX: '',
18
- isModalVisibleEnd: false,
19
- isSignOk: false,
20
- isModalVisibleSave: false
21
- };
22
-
23
- componentDidMount() {
24
- const canvas = this.refs.canvasF;
25
- canvas.height = this.refs.canvasHW.offsetHeight - 0;
26
- canvas.width = this.refs.canvasHW.offsetWidth - 0;
27
- this.state.canvasCtx = canvas.getContext('2d');
28
- this.state.stageInfo = canvas.getBoundingClientRect();
29
- this.state.canvasCtx.lineWidth = 6;
30
- this.state.canvasCtx.lineCap = "round";
31
- this.state.isSignOk = false
32
-
33
- canvas.addEventListener('touchstart', this.touchStart, { passive: false });
34
- canvas.addEventListener('touchmove', this.touchMove, { passive: false });
35
- canvas.addEventListener('touchend', this.touchEnd, { passive: false });
36
- }
37
- componentWillUnmount () {
38
- const canvas = this.refs.canvasF;
39
- canvas.removeEventListener('touchstart', this.touchStart);
40
- canvas.removeEventListener('touchmove', this.touchMove);
41
- canvas.removeEventListener('touchend', this.touchEnd);
42
- }
43
- // 清空画布
44
- clearCanvas = () => {
45
- this.state.isSignOk = false
46
- const canvas = this.refs.canvasF;
47
- // 清除画布
48
- this.state.canvasCtx.clearRect(
49
- 0,
50
- 0,
51
- canvas.width,
52
- canvas.height,
53
- );
54
- }
55
- touchStart=(ev)=> {
56
- this.state.isSignOk = true
57
- ev = ev || event
58
- ev.preventDefault()
59
- if (ev.touches.length == 1) {
60
- let obj = {
61
- x: ev.targetTouches[0].clientX,
62
- y: ev.targetTouches[0].clientY,
63
- }
64
- this.state.startX = obj.x
65
- this.state.startY = obj.y
66
- this.state.canvasCtx.beginPath()
67
- const canvas = this.refs.canvasF;
68
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
69
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
70
- this.state.canvasCtx.stroke()
71
- this.state.canvasCtx.closePath()
72
- // this.points.push(obj)
73
-
74
- }
75
- }
76
- touchMove=(ev)=>{
77
- ev = ev || event
78
- ev.preventDefault()
79
- if (ev.touches.length == 1) {
80
- let obj = {
81
- x: ev.targetTouches[0].clientX,
82
- y: ev.targetTouches[0].clientY
83
- }
84
- this.state.canvasCtx.beginPath()
85
- const canvas = this.refs.canvasF;
86
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
87
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
88
- this.state.canvasCtx.stroke()
89
- this.state.canvasCtx.closePath()
90
- this.state.startY = obj.y
91
- this.state.startX = obj.x
92
- // this.points.push(obj)
93
- }
94
- }
95
- touchEnd=(ev)=> {
96
- ev = ev || event
97
- ev.preventDefault()
98
- if (ev.touches.length == 1) {
99
- let obj = {
100
- x: ev.targetTouches[0].clientX ,
101
- y: ev.targetTouches[0].clientY
102
- }
103
- this.state.canvasCtx.beginPath()
104
- const canvas = this.refs.canvasF;
105
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
106
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
107
- this.state.canvasCtx.stroke()
108
- this.state.canvasCtx.closePath()
109
- // this.points.push(obj)
110
- }
111
- }
112
- // pc
113
- mouseDown=(ev) =>{
114
- this.state.isSignOk = true
115
- ev.preventDefault();
116
- const obj = {
117
- x: ev.pageX,
118
- y: ev.pageY,
119
- };
120
- const canvas = this.refs.canvasF;
121
- this.state.startX = obj.x;
122
- this.state.startY = obj.y;
123
- this.state.canvasCtx.beginPath();
124
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
125
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
126
- this.state.canvasCtx.stroke();
127
- this.state.canvasCtx.closePath();
128
- this.state.isDown = true;
129
-
130
- }
131
- mouseMove=(ev)=> {
132
- ev.preventDefault();
133
- if (this.state.isDown) {
134
- const obj = {
135
- x: ev.pageX,
136
- y: ev.pageY,
137
- };
138
- const canvas = this.refs.canvasF;
139
- 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) {
140
- this.state.isDown = false;
141
- }
142
- this.state.moveY = obj.y;
143
- this.state.moveX = obj.x;
144
- this.state.canvasCtx.beginPath();
145
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
146
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
147
- this.state.canvasCtx.stroke();
148
- this.state.canvasCtx.closePath();
149
- this.state.startY = obj.y;
150
- this.state.startX = obj.x;
151
- }
152
- }
153
- mouseUp=(ev)=> {
154
- if (!this.state.isDown) return;
155
- ev.preventDefault();
156
- const obj = {
157
- x: ev.pageX,
158
- y: ev.pageY,
159
- };
160
- const canvas = this.refs.canvasF;
161
- this.state.canvasCtx.beginPath();
162
- this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
163
- this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
164
- this.state.canvasCtx.stroke();
165
- this.state.canvasCtx.closePath();
166
- this.state.isDown = false;
167
-
168
- }
169
- // 提交
170
- commit = async () =>{
171
- if(this.state.isSignOk) {
172
- this.save()
173
- }
174
-
175
- const file = await this.getFinalImage()
176
- const item = this.props.item;
177
- this.props.next({
178
- type: item.type,
179
- file: file, //.replace('data:image/png;base64,',''),
180
- sequence: item.sequence
181
- })
182
- }
183
- // 合成最终图片
184
- getFinalImage = () => {
185
- return new Promise(resolve => {
186
- let canvas = document.createElement('canvas');
187
- let ctx = canvas.getContext('2d');
188
- const rate = parseFloat(this.props.rate)
189
- // console.log('rate',rate)
190
- const num = this.state.pics.length
191
- const blockWidth = 300; // 单字宽
192
- const blockHeight = this.refs.canvasF.height * blockWidth / this.refs.canvasF.width; // 单字高
193
- var wordsPerLine = this.props.item.cell || 8 // 每行图片数
194
- // 计算每行个数 以适应整个图片比例
195
- for (let n=1;n<20;n++){
196
- let width = blockWidth * n;
197
- let height = width/rate;
198
- // console.log(n, width, height)
199
- // console.log(Math.ceil(num/n) * blockHeight, (Math.ceil(num/n)+1) * blockHeight)
200
- if(Math.ceil(num/n) * blockHeight <= height && (Math.ceil(num/n)+1) * blockHeight > height){
201
- wordsPerLine = n;
202
- break
203
- } else if((Math.ceil(num/n)+1) * blockHeight <= height){
204
- wordsPerLine = n;
205
- break
206
- }
207
- }
208
- const canvasWidth = blockWidth * wordsPerLine;
209
- const canvasHeight = canvasWidth / rate
210
- // console.log(canvasWidth, canvasHeight)
211
- // const canvasHeight = this.props.item.row? this.props.item.row*blockHeight: (Math.ceil( this.state.pics.length / wordsPerLine) * blockHeight)
212
-
213
- canvas.width = canvasWidth;
214
- canvas.height = canvasHeight;
215
- // 画背景
216
- // ctx.fillStyle = 'white';
217
- // ctx.fillRect(0, 0, canvasWidth, canvasHeight);
218
-
219
- // 拼接图片绘制
220
- let pics = this.state.pics
221
- for (let i = 0;i< pics.length; i++){
222
-
223
- let rowIndex = Math.floor( i / wordsPerLine)
224
- let colIndex = Math.floor( i % wordsPerLine)
225
-
226
- // 画图
227
- let img = new Image()
228
- img.src = pics[i]
229
- img.onload = () =>{
230
- ctx.drawImage(img, colIndex*blockWidth,(rowIndex)*blockHeight, blockWidth, blockHeight);
231
- if(i===pics.length-1) {
232
- console.log(canvas.toDataURL())
233
- resolve(canvas.toDataURL())
234
- }
235
- }
236
-
237
- }
238
- })
239
- }
240
- // 回退一个
241
- back = () => {
242
- this.state.pics.pop()
243
- this.setState({
244
- pics: this.state.pics
245
- })
246
- this.clearCanvas()
247
- }
248
-
249
- // 保存一屏
250
- save = () => {
251
- if(this.state.isSignOk) {
252
- this.state.pics.push(this.refs.canvasF.toDataURL());
253
- this.setState({
254
- pics: this.state.pics
255
- },()=>{
256
- const $div = document.getElementById('scrollDiv');
257
- $div.scrollTop = $div.scrollHeight;
258
- })
259
-
260
- this.clearCanvas()
261
- } else {
262
- this.setState({
263
- isModalVisibleSave: true
264
- })
265
- }
266
- }
267
- handleOkSave=()=>{
268
- this.setState({
269
- isModalVisibleSave: false
270
- })
271
- }
272
- exit = () => {
273
- this.setState({
274
- isModalVisibleEnd: true
275
- })
276
- }
277
- handleCancelEnd = () => {
278
- this.setState({
279
- isModalVisibleEnd: false
280
- })
281
- }
282
- handleOkEnd = () => {
283
- this.setState({
284
- isModalVisibleEnd: false
285
- })
286
- this.props.exit()
287
- }
288
- render() {
289
- const {item} = this.props;
290
- return (
291
- <div className="copy">
292
- <div className="thehead">
293
- <div className="title">
294
- <div className="title-color"></div>
295
- <div className="title-text">{this.props.title}</div>
296
- </div>
297
-
298
- <div className="btnsEN">
299
- <div className="buttonEN gray" onClick={this.exit}><FormattedMessage id="exit" /></div>
300
- {
301
- this.state.pics.length > 0? <div className="buttonEN" onClick={this.commit}><FormattedMessage id="commit" /></div>: null
302
- }
303
- </div>
304
- </div>
305
- <div className="contents">
306
- <div className='content-desc'>{item.subContent[0].desc}</div>
307
- <div className='copy-desc' id="scrollDiv">
308
- {
309
- this.state.pics.map((pic,index)=>{
310
- return (
311
- <img key={index} className="pic" src={pic}></img>
312
- )
313
- })
314
- }
315
- </div>
316
- </div>
317
-
318
- <div className="copy-area">
319
- <div className="right" ref="canvasHW">
320
- <canvas
321
- id="canvasF"
322
- ref="canvasF"
323
- onMouseDown={this.mouseDown}
324
- onMouseMove={this.mouseMove}
325
- onMouseUp={this.mouseUp}
326
- onMouseLeave={() => { this.state.isDown = false }}
327
- ></canvas>
328
- </div>
329
- <div className="btnsEN footEN">
330
- <div className="buttonEN gray" onClick={this.back}><FormattedMessage id="back" /></div>
331
- <div className="buttonEN gray" onClick={this.clearCanvas}><FormattedMessage id="clearScreen" /></div>
332
- <div className="buttonEN" onClick={this.save}><FormattedMessage id="ok" /></div>
333
-
334
- </div>
335
- </div>
336
-
337
- <Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleSave} footer={[<div key='end'>
338
- <Button className="modelButtonOk" type="primary" danger onClick={this.handleOkSave}><FormattedMessage id="ok" /></Button>
339
- </div>
340
- ]}>
341
- <div className='endModal'>
342
- <div className='modalEndTitle'>提示</div>
343
- <div className='modalEnd'>
344
- <FormattedMessage id="noCopy" />
345
- </div>
346
- </div>
347
- </Modal>
348
- <Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleEnd} footer={[<div key='end'>
349
- <Button className="modelButtonCancel" onClick={this.handleCancelEnd}><FormattedMessage id="cancel" /></Button>
350
- <Button className="modelButtonOk" type="primary" danger onClick={this.handleOkEnd}><FormattedMessage id="ok" /></Button>
351
- </div>
352
- ]}>
353
- <div className='endModal'>
354
- <div className='modalEndTitle'>
355
- <FormattedMessage id="whether" />
356
- </div>
357
- <div className='modalEnd'>
358
- <FormattedMessage id="progress" />
359
- </div>
360
- </div>
361
- </Modal>
362
- </div>
363
- );
364
- }
365
-
366
- }
367
-
368
- export default Copy;
1
+ import React, { Component } from 'react';
2
+ import { FormattedMessage } from 'react-intl';
3
+ import './copy_en.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
+ state = {
10
+ finalImage: "",
11
+ pics: [],
12
+ isFinish: false,
13
+ canvasCtx: null,
14
+ stageInfo: '',
15
+ isDown: false,
16
+ startY: '',
17
+ startX: '',
18
+ isModalVisibleEnd: false,
19
+ isSignOk: false,
20
+ isModalVisibleSave: false
21
+ };
22
+
23
+ componentDidMount() {
24
+ const canvas = this.refs.canvasF;
25
+ canvas.height = this.refs.canvasHW.offsetHeight - 0;
26
+ canvas.width = this.refs.canvasHW.offsetWidth - 0;
27
+ this.state.canvasCtx = canvas.getContext('2d');
28
+ this.state.stageInfo = canvas.getBoundingClientRect();
29
+ this.state.canvasCtx.lineWidth = 6;
30
+ this.state.canvasCtx.lineCap = "round";
31
+ this.state.isSignOk = false
32
+
33
+ canvas.addEventListener('touchstart', this.touchStart, { passive: false });
34
+ canvas.addEventListener('touchmove', this.touchMove, { passive: false });
35
+ canvas.addEventListener('touchend', this.touchEnd, { passive: false });
36
+ }
37
+ componentWillUnmount () {
38
+ const canvas = this.refs.canvasF;
39
+ canvas.removeEventListener('touchstart', this.touchStart);
40
+ canvas.removeEventListener('touchmove', this.touchMove);
41
+ canvas.removeEventListener('touchend', this.touchEnd);
42
+ }
43
+ // 清空画布
44
+ clearCanvas = () => {
45
+ this.state.isSignOk = false
46
+ const canvas = this.refs.canvasF;
47
+ // 清除画布
48
+ this.state.canvasCtx.clearRect(
49
+ 0,
50
+ 0,
51
+ canvas.width,
52
+ canvas.height,
53
+ );
54
+ }
55
+ touchStart=(ev)=> {
56
+ this.state.isSignOk = true
57
+ ev = ev || event
58
+ ev.preventDefault()
59
+ if (ev.touches.length == 1) {
60
+ let obj = {
61
+ x: ev.targetTouches[0].clientX,
62
+ y: ev.targetTouches[0].clientY,
63
+ }
64
+ this.state.startX = obj.x
65
+ this.state.startY = obj.y
66
+ this.state.canvasCtx.beginPath()
67
+ const canvas = this.refs.canvasF;
68
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
69
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
70
+ this.state.canvasCtx.stroke()
71
+ this.state.canvasCtx.closePath()
72
+ // this.points.push(obj)
73
+
74
+ }
75
+ }
76
+ touchMove=(ev)=>{
77
+ ev = ev || event
78
+ ev.preventDefault()
79
+ if (ev.touches.length == 1) {
80
+ let obj = {
81
+ x: ev.targetTouches[0].clientX,
82
+ y: ev.targetTouches[0].clientY
83
+ }
84
+ this.state.canvasCtx.beginPath()
85
+ const canvas = this.refs.canvasF;
86
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
87
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
88
+ this.state.canvasCtx.stroke()
89
+ this.state.canvasCtx.closePath()
90
+ this.state.startY = obj.y
91
+ this.state.startX = obj.x
92
+ // this.points.push(obj)
93
+ }
94
+ }
95
+ touchEnd=(ev)=> {
96
+ ev = ev || event
97
+ ev.preventDefault()
98
+ if (ev.touches.length == 1) {
99
+ let obj = {
100
+ x: ev.targetTouches[0].clientX ,
101
+ y: ev.targetTouches[0].clientY
102
+ }
103
+ this.state.canvasCtx.beginPath()
104
+ const canvas = this.refs.canvasF;
105
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
106
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
107
+ this.state.canvasCtx.stroke()
108
+ this.state.canvasCtx.closePath()
109
+ // this.points.push(obj)
110
+ }
111
+ }
112
+ // pc
113
+ mouseDown=(ev) =>{
114
+ this.state.isSignOk = true
115
+ ev.preventDefault();
116
+ const obj = {
117
+ x: ev.pageX,
118
+ y: ev.pageY,
119
+ };
120
+ const canvas = this.refs.canvasF;
121
+ this.state.startX = obj.x;
122
+ this.state.startY = obj.y;
123
+ this.state.canvasCtx.beginPath();
124
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
125
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
126
+ this.state.canvasCtx.stroke();
127
+ this.state.canvasCtx.closePath();
128
+ this.state.isDown = true;
129
+
130
+ }
131
+ mouseMove=(ev)=> {
132
+ ev.preventDefault();
133
+ if (this.state.isDown) {
134
+ const obj = {
135
+ x: ev.pageX,
136
+ y: ev.pageY,
137
+ };
138
+ const canvas = this.refs.canvasF;
139
+ 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) {
140
+ this.state.isDown = false;
141
+ }
142
+ this.state.moveY = obj.y;
143
+ this.state.moveX = obj.x;
144
+ this.state.canvasCtx.beginPath();
145
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
146
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
147
+ this.state.canvasCtx.stroke();
148
+ this.state.canvasCtx.closePath();
149
+ this.state.startY = obj.y;
150
+ this.state.startX = obj.x;
151
+ }
152
+ }
153
+ mouseUp=(ev)=> {
154
+ if (!this.state.isDown) return;
155
+ ev.preventDefault();
156
+ const obj = {
157
+ x: ev.pageX,
158
+ y: ev.pageY,
159
+ };
160
+ const canvas = this.refs.canvasF;
161
+ this.state.canvasCtx.beginPath();
162
+ this.state.canvasCtx.moveTo(this.state.startX - canvas.getBoundingClientRect().left, this.state.startY - canvas.getBoundingClientRect().top);
163
+ this.state.canvasCtx.lineTo(obj.x - canvas.getBoundingClientRect().left, obj.y - canvas.getBoundingClientRect().top);
164
+ this.state.canvasCtx.stroke();
165
+ this.state.canvasCtx.closePath();
166
+ this.state.isDown = false;
167
+
168
+ }
169
+ // 提交
170
+ commit = async () =>{
171
+ if(this.state.isSignOk) {
172
+ this.save()
173
+ }
174
+
175
+ const file = await this.getFinalImage()
176
+ const item = this.props.item;
177
+ this.props.next({
178
+ type: item.type,
179
+ file: file, //.replace('data:image/png;base64,',''),
180
+ sequence: item.sequence
181
+ })
182
+ }
183
+ // 合成最终图片
184
+ getFinalImage = () => {
185
+ return new Promise(resolve => {
186
+ let canvas = document.createElement('canvas');
187
+ let ctx = canvas.getContext('2d');
188
+ const rate = parseFloat(this.props.rate)
189
+ // console.log('rate',rate)
190
+ const num = this.state.pics.length
191
+ const blockWidth = 300; // 单字宽
192
+ const blockHeight = this.refs.canvasF.height * blockWidth / this.refs.canvasF.width; // 单字高
193
+ var wordsPerLine = this.props.item.cell || 8 // 每行图片数
194
+ // 计算每行个数 以适应整个图片比例
195
+ for (let n=1;n<20;n++){
196
+ let width = blockWidth * n;
197
+ let height = width/rate;
198
+ // console.log(n, width, height)
199
+ // console.log(Math.ceil(num/n) * blockHeight, (Math.ceil(num/n)+1) * blockHeight)
200
+ if(Math.ceil(num/n) * blockHeight <= height && (Math.ceil(num/n)+1) * blockHeight > height){
201
+ wordsPerLine = n;
202
+ break
203
+ } else if((Math.ceil(num/n)+1) * blockHeight <= height){
204
+ wordsPerLine = n;
205
+ break
206
+ }
207
+ }
208
+ const canvasWidth = blockWidth * wordsPerLine;
209
+ const canvasHeight = canvasWidth / rate
210
+ // console.log(canvasWidth, canvasHeight)
211
+ // const canvasHeight = this.props.item.row? this.props.item.row*blockHeight: (Math.ceil( this.state.pics.length / wordsPerLine) * blockHeight)
212
+
213
+ canvas.width = canvasWidth;
214
+ canvas.height = canvasHeight;
215
+ // 画背景
216
+ // ctx.fillStyle = 'white';
217
+ // ctx.fillRect(0, 0, canvasWidth, canvasHeight);
218
+
219
+ // 拼接图片绘制
220
+ let pics = this.state.pics
221
+ for (let i = 0;i< pics.length; i++){
222
+
223
+ let rowIndex = Math.floor( i / wordsPerLine)
224
+ let colIndex = Math.floor( i % wordsPerLine)
225
+
226
+ // 画图
227
+ let img = new Image()
228
+ img.src = pics[i]
229
+ img.onload = () =>{
230
+ ctx.drawImage(img, colIndex*blockWidth,(rowIndex)*blockHeight, blockWidth, blockHeight);
231
+ if(i===pics.length-1) {
232
+ console.log(canvas.toDataURL())
233
+ resolve(canvas.toDataURL())
234
+ }
235
+ }
236
+
237
+ }
238
+ })
239
+ }
240
+ // 回退一个
241
+ back = () => {
242
+ this.state.pics.pop()
243
+ this.setState({
244
+ pics: this.state.pics
245
+ })
246
+ this.clearCanvas()
247
+ }
248
+
249
+ // 保存一屏
250
+ save = () => {
251
+ if(this.state.isSignOk) {
252
+ this.state.pics.push(this.refs.canvasF.toDataURL());
253
+ this.setState({
254
+ pics: this.state.pics
255
+ },()=>{
256
+ const $div = document.getElementById('scrollDiv');
257
+ $div.scrollTop = $div.scrollHeight;
258
+ })
259
+
260
+ this.clearCanvas()
261
+ } else {
262
+ this.setState({
263
+ isModalVisibleSave: true
264
+ })
265
+ }
266
+ }
267
+ handleOkSave=()=>{
268
+ this.setState({
269
+ isModalVisibleSave: false
270
+ })
271
+ }
272
+ exit = () => {
273
+ this.setState({
274
+ isModalVisibleEnd: true
275
+ })
276
+ }
277
+ handleCancelEnd = () => {
278
+ this.setState({
279
+ isModalVisibleEnd: false
280
+ })
281
+ }
282
+ handleOkEnd = () => {
283
+ this.setState({
284
+ isModalVisibleEnd: false
285
+ })
286
+ this.props.exit()
287
+ }
288
+ render() {
289
+ const {item} = this.props;
290
+ return (
291
+ <div className="copy">
292
+ <div className="thehead">
293
+ <div className="title">
294
+ <div className="title-color"></div>
295
+ <div className="title-text">{this.props.title}</div>
296
+ </div>
297
+
298
+ <div className="btnsEN">
299
+ <div className="buttonEN gray" onClick={this.exit}><FormattedMessage id="exit" /></div>
300
+ {
301
+ this.state.pics.length > 0? <div className="buttonEN" onClick={this.commit}><FormattedMessage id="commit" /></div>: null
302
+ }
303
+ </div>
304
+ </div>
305
+ <div className="contents">
306
+ <div className='content-desc'>{item.subContent[0].desc}</div>
307
+ <div className='copy-desc' id="scrollDiv">
308
+ {
309
+ this.state.pics.map((pic,index)=>{
310
+ return (
311
+ <img key={index} className="pic" src={pic}></img>
312
+ )
313
+ })
314
+ }
315
+ </div>
316
+ </div>
317
+
318
+ <div className="copy-area">
319
+ <div className="right" ref="canvasHW">
320
+ <canvas
321
+ id="canvasF"
322
+ ref="canvasF"
323
+ onMouseDown={this.mouseDown}
324
+ onMouseMove={this.mouseMove}
325
+ onMouseUp={this.mouseUp}
326
+ onMouseLeave={() => { this.state.isDown = false }}
327
+ ></canvas>
328
+ </div>
329
+ <div className="btnsEN footEN">
330
+ <div className="buttonEN gray" onClick={this.back}><FormattedMessage id="back" /></div>
331
+ <div className="buttonEN gray" onClick={this.clearCanvas}><FormattedMessage id="clearScreen" /></div>
332
+ <div className="buttonEN" onClick={this.save}><FormattedMessage id="ok" /></div>
333
+
334
+ </div>
335
+ </div>
336
+
337
+ <Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleSave} footer={[<div key='end'>
338
+ <Button className="modelButtonOk" type="primary" danger onClick={this.handleOkSave}><FormattedMessage id="ok" /></Button>
339
+ </div>
340
+ ]}>
341
+ <div className='endModal'>
342
+ <div className='modalEndTitle'>提示</div>
343
+ <div className='modalEnd'>
344
+ <FormattedMessage id="noCopy" />
345
+ </div>
346
+ </div>
347
+ </Modal>
348
+ <Modal transitionName="" maskTransitionName="" getContainer={document.getElementById('multiModule')} destroyOnClose={true} closable={false} centered={true} visible={this.state.isModalVisibleEnd} footer={[<div key='end'>
349
+ <Button className="modelButtonCancel" onClick={this.handleCancelEnd}><FormattedMessage id="cancel" /></Button>
350
+ <Button className="modelButtonOk" type="primary" danger onClick={this.handleOkEnd}><FormattedMessage id="ok" /></Button>
351
+ </div>
352
+ ]}>
353
+ <div className='endModal'>
354
+ <div className='modalEndTitle'>
355
+ <FormattedMessage id="whether" />
356
+ </div>
357
+ <div className='modalEnd'>
358
+ <FormattedMessage id="progress" />
359
+ </div>
360
+ </div>
361
+ </Modal>
362
+ </div>
363
+ );
364
+ }
365
+
366
+ }
367
+
368
+ export default Copy;