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.
- package/.babelrc +39 -39
- package/README.en.md +36 -36
- package/README.md +329 -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,374 +1,374 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function _defineProperties(target, props) {
|
|
8
|
-
for (var i = 0; i < props.length; i++) {
|
|
9
|
-
var descriptor = props[i];
|
|
10
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
11
|
-
descriptor.configurable = true;
|
|
12
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
13
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
18
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
19
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
20
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
21
|
-
writable: false
|
|
22
|
-
});
|
|
23
|
-
return Constructor;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* canvas 画板
|
|
30
|
-
*/
|
|
31
|
-
var BoardOperate = /*#__PURE__*/function () {
|
|
32
|
-
function BoardOperate(canvas, _ref) {
|
|
33
|
-
var _ref$drawType = _ref.drawType,
|
|
34
|
-
drawType = _ref$drawType === void 0 ? 'pen' : _ref$drawType,
|
|
35
|
-
_ref$drawColor = _ref.drawColor,
|
|
36
|
-
drawColor = _ref$drawColor === void 0 ? 'rgba(19, 206, 102, 1)' : _ref$drawColor,
|
|
37
|
-
_ref$lineWidth = _ref.lineWidth,
|
|
38
|
-
lineWidth = _ref$lineWidth === void 0 ? 5 : _ref$lineWidth,
|
|
39
|
-
_ref$sides = _ref.sides,
|
|
40
|
-
sides = _ref$sides === void 0 ? 3 : _ref$sides,
|
|
41
|
-
_ref$fillStyle = _ref.fillStyle,
|
|
42
|
-
fillStyle = _ref$fillStyle === void 0 ? null : _ref$fillStyle,
|
|
43
|
-
allowCallback = _ref.allowCallback,
|
|
44
|
-
moveCallback = _ref.moveCallback;
|
|
45
|
-
|
|
46
|
-
_classCallCheck(this, BoardOperate);
|
|
47
|
-
|
|
48
|
-
this.canvas = canvas; // 画板DOM
|
|
49
|
-
|
|
50
|
-
this.width = canvas.width; // 宽
|
|
51
|
-
|
|
52
|
-
this.height = canvas.height; // 高
|
|
53
|
-
|
|
54
|
-
this.ratio = canvas.width > canvas.clientWidth ? canvas.width / canvas.clientWidth : 1; // 比例(width和clientWidth不一致可调整比例)
|
|
55
|
-
|
|
56
|
-
this.ctx = canvas.getContext('2d');
|
|
57
|
-
this.isClickCanvas = false; // 是否点击canvas内部
|
|
58
|
-
|
|
59
|
-
this.isMoveCanvas = false; // 鼠标是否有移动
|
|
60
|
-
|
|
61
|
-
this.imgData = []; // 存储上一次的图像,用于撤回
|
|
62
|
-
|
|
63
|
-
this.index = 0; // 记录当前显示的是第几帧
|
|
64
|
-
|
|
65
|
-
this.x = 0; // 鼠标按下时的 x 坐标
|
|
66
|
-
|
|
67
|
-
this.y = 0; // 鼠标按下时的 y 坐标
|
|
68
|
-
|
|
69
|
-
this.last = [this.x, this.y]; // 鼠标按下及每次移动后的坐标
|
|
70
|
-
|
|
71
|
-
this.drawType = drawType; // 绘制形状
|
|
72
|
-
|
|
73
|
-
this.drawColor = drawColor; // 绘制颜色
|
|
74
|
-
|
|
75
|
-
this.lineWidth = lineWidth; // 线条宽度
|
|
76
|
-
|
|
77
|
-
this.sides = sides; // 多边形边数
|
|
78
|
-
|
|
79
|
-
this.fillStyle = fillStyle; // 初始填充颜色
|
|
80
|
-
|
|
81
|
-
this.allowCallback = allowCallback || function () {}; // 允许操作的回调
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.moveCallback = moveCallback || function () {}; // 鼠标移动的回调
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.bindMousemove = function () {}; // 解决 eventlistener 不能bind
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.bindMousedown = function () {}; // 解决 eventlistener 不能bind
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.bindMouseup = function () {}; // 解决 eventlistener 不能bind
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.init();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
_createClass(BoardOperate, [{
|
|
100
|
-
key: "init",
|
|
101
|
-
value: function init() {
|
|
102
|
-
if (this.fillStyle) {
|
|
103
|
-
this.ctx.fillStyle = 'transparent';
|
|
104
|
-
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.gatherImage();
|
|
108
|
-
this.bindMousemove = this.onmousemove.bind(this); // 解决 eventlistener 不能bind
|
|
109
|
-
|
|
110
|
-
this.bindMousedown = this.onmousedown.bind(this);
|
|
111
|
-
this.bindMouseup = this.onmouseup.bind(this);
|
|
112
|
-
var eventNameDown = 'mousedown',
|
|
113
|
-
eventNameUp = 'mouseup';
|
|
114
|
-
|
|
115
|
-
if ('ontouchstart' in this.canvas) {
|
|
116
|
-
// 移动端适配
|
|
117
|
-
this.isTouch = true;
|
|
118
|
-
eventNameDown = 'touchstart';
|
|
119
|
-
eventNameUp = 'touchend';
|
|
120
|
-
} else {
|
|
121
|
-
// PC 端鼠标事件
|
|
122
|
-
this.isTouch = false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.canvas.addEventListener(eventNameDown, this.bindMousedown);
|
|
126
|
-
this.canvas.addEventListener(eventNameUp, this.bindMouseup);
|
|
127
|
-
} // 获取当前位置
|
|
128
|
-
|
|
129
|
-
}, {
|
|
130
|
-
key: "getPoint",
|
|
131
|
-
value: function getPoint(e) {
|
|
132
|
-
// const { pageX, pageY, target } = e.changedTouches[0];
|
|
133
|
-
var _e$changedTouches$ = e.changedTouches[0],
|
|
134
|
-
clientX = _e$changedTouches$.clientX,
|
|
135
|
-
clientY = _e$changedTouches$.clientY,
|
|
136
|
-
target = _e$changedTouches$.target;
|
|
137
|
-
|
|
138
|
-
var _target$getBoundingCl = target.getBoundingClientRect(),
|
|
139
|
-
top = _target$getBoundingCl.top,
|
|
140
|
-
left = _target$getBoundingCl.left; // 获取当前节点到视口顶部和左边的距离
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var x = (clientX - left) * this.ratio;
|
|
144
|
-
var y = (clientY - top) * this.ratio;
|
|
145
|
-
return {
|
|
146
|
-
x: x,
|
|
147
|
-
y: y
|
|
148
|
-
};
|
|
149
|
-
} // 鼠标按下
|
|
150
|
-
|
|
151
|
-
}, {
|
|
152
|
-
key: "onmousedown",
|
|
153
|
-
value: function onmousedown(e) {
|
|
154
|
-
e.preventDefault();
|
|
155
|
-
var eventName = 'mousemove';
|
|
156
|
-
|
|
157
|
-
if (this.isTouch) {
|
|
158
|
-
var _this$getPoint = this.getPoint(e),
|
|
159
|
-
x = _this$getPoint.x,
|
|
160
|
-
y = _this$getPoint.y;
|
|
161
|
-
|
|
162
|
-
e.offsetX = x;
|
|
163
|
-
e.offsetY = y;
|
|
164
|
-
eventName = 'touchmove';
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.canvas.addEventListener(eventName, this.bindMousemove);
|
|
168
|
-
this.isClickCanvas = true;
|
|
169
|
-
this.x = e.offsetX;
|
|
170
|
-
this.y = e.offsetY;
|
|
171
|
-
this.last = [this.x, this.y];
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "gatherImage",
|
|
175
|
-
value: function gatherImage() {
|
|
176
|
-
// 采集图像
|
|
177
|
-
this.imgData = this.imgData.slice(0, this.index + 1); // 每次鼠标抬起时,将储存的imgdata截取至index处
|
|
178
|
-
|
|
179
|
-
var imgData = this.ctx.getImageData(0, 0, this.width, this.height);
|
|
180
|
-
this.imgData.push(imgData);
|
|
181
|
-
this.index = this.imgData.length - 1; // 储存完后将 index 重置为 imgData 最后一位
|
|
182
|
-
|
|
183
|
-
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
184
|
-
}
|
|
185
|
-
}, {
|
|
186
|
-
key: "reSetImage",
|
|
187
|
-
value: function reSetImage() {
|
|
188
|
-
// 重置为上一帧
|
|
189
|
-
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
190
|
-
|
|
191
|
-
if (this.imgData.length >= 1) {
|
|
192
|
-
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
193
|
-
}
|
|
194
|
-
} // 鼠标移动
|
|
195
|
-
|
|
196
|
-
}, {
|
|
197
|
-
key: "onmousemove",
|
|
198
|
-
value: function onmousemove(e) {
|
|
199
|
-
if (this.isTouch) {
|
|
200
|
-
e.preventDefault();
|
|
201
|
-
|
|
202
|
-
var _this$getPoint2 = this.getPoint(e),
|
|
203
|
-
x = _this$getPoint2.x,
|
|
204
|
-
y = _this$getPoint2.y;
|
|
205
|
-
|
|
206
|
-
e.offsetX = x;
|
|
207
|
-
e.offsetY = y;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
this.isMoveCanvas = true;
|
|
211
|
-
var endx = e.offsetX;
|
|
212
|
-
var endy = e.offsetY;
|
|
213
|
-
var width = endx - this.x;
|
|
214
|
-
var height = endy - this.y;
|
|
215
|
-
var now = [endx, endy]; // 当前移动到的位置
|
|
216
|
-
|
|
217
|
-
switch (this.drawType) {
|
|
218
|
-
case 'pen':
|
|
219
|
-
{
|
|
220
|
-
var params = [this.last, now, this.lineWidth, this.drawColor, true];
|
|
221
|
-
this.moveCallback.apply(this, ['pen'].concat(params));
|
|
222
|
-
this.line.apply(this, params);
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
|
|
226
|
-
case 'eraser':
|
|
227
|
-
{
|
|
228
|
-
var _params = [endx, endy, this.lineWidth];
|
|
229
|
-
this.moveCallback.apply(this, ['eraser'].concat(_params));
|
|
230
|
-
this.eraser.apply(this, _params);
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
} // 鼠标抬起
|
|
235
|
-
|
|
236
|
-
}, {
|
|
237
|
-
key: "onmouseup",
|
|
238
|
-
value: function onmouseup(e) {
|
|
239
|
-
e.preventDefault();
|
|
240
|
-
|
|
241
|
-
if (this.isClickCanvas) {
|
|
242
|
-
this.isClickCanvas = false;
|
|
243
|
-
|
|
244
|
-
if (this.isTouch) {
|
|
245
|
-
this.canvas.removeEventListener('touchmove', this.bindMousemove);
|
|
246
|
-
} else {
|
|
247
|
-
this.canvas.removeEventListener('mousemove', this.bindMousemove);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (this.isMoveCanvas) {
|
|
251
|
-
// 鼠标没有移动不保存
|
|
252
|
-
this.isMoveCanvas = false;
|
|
253
|
-
this.gatherImage();
|
|
254
|
-
this.moveCallback('gatherImage', this.index);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
} // 绘制线性(直线和铅笔)
|
|
258
|
-
|
|
259
|
-
}, {
|
|
260
|
-
key: "line",
|
|
261
|
-
value: function line(last, now, lineWidth, drawColor, isPencil) {
|
|
262
|
-
if (!isPencil) {
|
|
263
|
-
this.reSetImage();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
this.ctx.beginPath();
|
|
267
|
-
this.ctx.lineCap = 'round'; // 设定线条与线条间接合处的样式
|
|
268
|
-
|
|
269
|
-
this.ctx.lineJoin = 'round';
|
|
270
|
-
this.ctx.lineWidth = lineWidth;
|
|
271
|
-
this.ctx.strokeStyle = drawColor;
|
|
272
|
-
this.ctx.moveTo(last[0], last[1]);
|
|
273
|
-
this.ctx.lineTo(now[0], now[1]);
|
|
274
|
-
this.ctx.closePath();
|
|
275
|
-
this.ctx.stroke(); // 进行绘制
|
|
276
|
-
|
|
277
|
-
if (isPencil) {
|
|
278
|
-
// 铅笔需要保存最后一次记录
|
|
279
|
-
this.last = now;
|
|
280
|
-
}
|
|
281
|
-
} // 橡皮擦
|
|
282
|
-
|
|
283
|
-
}, {
|
|
284
|
-
key: "eraser",
|
|
285
|
-
value: function eraser(endx, endy, lineWidth) {
|
|
286
|
-
this.ctx.save();
|
|
287
|
-
this.line(this.last, [endx, endy], lineWidth * 2, '#fff', true);
|
|
288
|
-
} // 撤回
|
|
289
|
-
|
|
290
|
-
}, {
|
|
291
|
-
key: "undo",
|
|
292
|
-
value: function undo() {
|
|
293
|
-
if (--this.index < 0) {
|
|
294
|
-
this.index = 0;
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
299
|
-
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
300
|
-
} // 前进
|
|
301
|
-
|
|
302
|
-
}, {
|
|
303
|
-
key: "redo",
|
|
304
|
-
value: function redo() {
|
|
305
|
-
if (++this.index > this.imgData.length - 1) {
|
|
306
|
-
this.index = this.imgData.length - 1;
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
311
|
-
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
312
|
-
} // 清屏
|
|
313
|
-
|
|
314
|
-
}, {
|
|
315
|
-
key: "clear",
|
|
316
|
-
value: function clear() {
|
|
317
|
-
this.imgData = [];
|
|
318
|
-
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
319
|
-
this.gatherImage();
|
|
320
|
-
} // 设置画板参数
|
|
321
|
-
|
|
322
|
-
}, {
|
|
323
|
-
key: "changeWay",
|
|
324
|
-
value: function changeWay(_ref2) {
|
|
325
|
-
var type = _ref2.type,
|
|
326
|
-
color = _ref2.color,
|
|
327
|
-
lineWidth = _ref2.lineWidth,
|
|
328
|
-
sides = _ref2.sides;
|
|
329
|
-
|
|
330
|
-
if (type === 'eraser') {
|
|
331
|
-
this.ctx.globalCompositeOperation = 'destination-out'; // 擦除
|
|
332
|
-
} else {
|
|
333
|
-
this.ctx.globalCompositeOperation = 'source-over'; // 画
|
|
334
|
-
} // 绘制条件
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.drawType = type !== 'color' && type || this.drawType; // 绘制形状
|
|
338
|
-
|
|
339
|
-
this.drawColor = color || this.drawColor; // 绘制颜色
|
|
340
|
-
|
|
341
|
-
this.lineWidth = lineWidth || this.lineWidth; // 线宽
|
|
342
|
-
|
|
343
|
-
this.sides = sides || this.sides; // 边数
|
|
344
|
-
} // 销毁画板
|
|
345
|
-
|
|
346
|
-
}, {
|
|
347
|
-
key: "destroy",
|
|
348
|
-
value: function destroy() {
|
|
349
|
-
this.clear();
|
|
350
|
-
this.canvas.removeEventListener('mousedown', this.bindMousedown);
|
|
351
|
-
this.canvas.removeEventListener('mouseup', this.bindMouseup);
|
|
352
|
-
this.canvas = null;
|
|
353
|
-
this.ctx = null;
|
|
354
|
-
} // 保留笔画
|
|
355
|
-
|
|
356
|
-
}, {
|
|
357
|
-
key: "retain",
|
|
358
|
-
value: function retain() {
|
|
359
|
-
var base64 = this.canvas.toDataURL();
|
|
360
|
-
var img = document.createElement('img');
|
|
361
|
-
img.style.position = 'fixed';
|
|
362
|
-
img.style.width = '90vw';
|
|
363
|
-
img.style.height = '95vh';
|
|
364
|
-
img.style.top = '9vh';
|
|
365
|
-
img.style.left = '5vw';
|
|
366
|
-
img.src = base64;
|
|
367
|
-
document.body.appendChild(img);
|
|
368
|
-
}
|
|
369
|
-
}]);
|
|
370
|
-
|
|
371
|
-
return BoardOperate;
|
|
372
|
-
}();
|
|
373
|
-
|
|
374
|
-
export { BoardOperate };
|
|
1
|
+
function _classCallCheck(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) {
|
|
8
|
+
for (var i = 0; i < props.length; i++) {
|
|
9
|
+
var descriptor = props[i];
|
|
10
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
11
|
+
descriptor.configurable = true;
|
|
12
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
13
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
18
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
19
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
20
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
21
|
+
writable: false
|
|
22
|
+
});
|
|
23
|
+
return Constructor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* canvas 画板
|
|
30
|
+
*/
|
|
31
|
+
var BoardOperate = /*#__PURE__*/function () {
|
|
32
|
+
function BoardOperate(canvas, _ref) {
|
|
33
|
+
var _ref$drawType = _ref.drawType,
|
|
34
|
+
drawType = _ref$drawType === void 0 ? 'pen' : _ref$drawType,
|
|
35
|
+
_ref$drawColor = _ref.drawColor,
|
|
36
|
+
drawColor = _ref$drawColor === void 0 ? 'rgba(19, 206, 102, 1)' : _ref$drawColor,
|
|
37
|
+
_ref$lineWidth = _ref.lineWidth,
|
|
38
|
+
lineWidth = _ref$lineWidth === void 0 ? 5 : _ref$lineWidth,
|
|
39
|
+
_ref$sides = _ref.sides,
|
|
40
|
+
sides = _ref$sides === void 0 ? 3 : _ref$sides,
|
|
41
|
+
_ref$fillStyle = _ref.fillStyle,
|
|
42
|
+
fillStyle = _ref$fillStyle === void 0 ? null : _ref$fillStyle,
|
|
43
|
+
allowCallback = _ref.allowCallback,
|
|
44
|
+
moveCallback = _ref.moveCallback;
|
|
45
|
+
|
|
46
|
+
_classCallCheck(this, BoardOperate);
|
|
47
|
+
|
|
48
|
+
this.canvas = canvas; // 画板DOM
|
|
49
|
+
|
|
50
|
+
this.width = canvas.width; // 宽
|
|
51
|
+
|
|
52
|
+
this.height = canvas.height; // 高
|
|
53
|
+
|
|
54
|
+
this.ratio = canvas.width > canvas.clientWidth ? canvas.width / canvas.clientWidth : 1; // 比例(width和clientWidth不一致可调整比例)
|
|
55
|
+
|
|
56
|
+
this.ctx = canvas.getContext('2d');
|
|
57
|
+
this.isClickCanvas = false; // 是否点击canvas内部
|
|
58
|
+
|
|
59
|
+
this.isMoveCanvas = false; // 鼠标是否有移动
|
|
60
|
+
|
|
61
|
+
this.imgData = []; // 存储上一次的图像,用于撤回
|
|
62
|
+
|
|
63
|
+
this.index = 0; // 记录当前显示的是第几帧
|
|
64
|
+
|
|
65
|
+
this.x = 0; // 鼠标按下时的 x 坐标
|
|
66
|
+
|
|
67
|
+
this.y = 0; // 鼠标按下时的 y 坐标
|
|
68
|
+
|
|
69
|
+
this.last = [this.x, this.y]; // 鼠标按下及每次移动后的坐标
|
|
70
|
+
|
|
71
|
+
this.drawType = drawType; // 绘制形状
|
|
72
|
+
|
|
73
|
+
this.drawColor = drawColor; // 绘制颜色
|
|
74
|
+
|
|
75
|
+
this.lineWidth = lineWidth; // 线条宽度
|
|
76
|
+
|
|
77
|
+
this.sides = sides; // 多边形边数
|
|
78
|
+
|
|
79
|
+
this.fillStyle = fillStyle; // 初始填充颜色
|
|
80
|
+
|
|
81
|
+
this.allowCallback = allowCallback || function () {}; // 允许操作的回调
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
this.moveCallback = moveCallback || function () {}; // 鼠标移动的回调
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
this.bindMousemove = function () {}; // 解决 eventlistener 不能bind
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
this.bindMousedown = function () {}; // 解决 eventlistener 不能bind
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
this.bindMouseup = function () {}; // 解决 eventlistener 不能bind
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
this.init();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_createClass(BoardOperate, [{
|
|
100
|
+
key: "init",
|
|
101
|
+
value: function init() {
|
|
102
|
+
if (this.fillStyle) {
|
|
103
|
+
this.ctx.fillStyle = 'transparent';
|
|
104
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.gatherImage();
|
|
108
|
+
this.bindMousemove = this.onmousemove.bind(this); // 解决 eventlistener 不能bind
|
|
109
|
+
|
|
110
|
+
this.bindMousedown = this.onmousedown.bind(this);
|
|
111
|
+
this.bindMouseup = this.onmouseup.bind(this);
|
|
112
|
+
var eventNameDown = 'mousedown',
|
|
113
|
+
eventNameUp = 'mouseup';
|
|
114
|
+
|
|
115
|
+
if ('ontouchstart' in this.canvas) {
|
|
116
|
+
// 移动端适配
|
|
117
|
+
this.isTouch = true;
|
|
118
|
+
eventNameDown = 'touchstart';
|
|
119
|
+
eventNameUp = 'touchend';
|
|
120
|
+
} else {
|
|
121
|
+
// PC 端鼠标事件
|
|
122
|
+
this.isTouch = false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.canvas.addEventListener(eventNameDown, this.bindMousedown);
|
|
126
|
+
this.canvas.addEventListener(eventNameUp, this.bindMouseup);
|
|
127
|
+
} // 获取当前位置
|
|
128
|
+
|
|
129
|
+
}, {
|
|
130
|
+
key: "getPoint",
|
|
131
|
+
value: function getPoint(e) {
|
|
132
|
+
// const { pageX, pageY, target } = e.changedTouches[0];
|
|
133
|
+
var _e$changedTouches$ = e.changedTouches[0],
|
|
134
|
+
clientX = _e$changedTouches$.clientX,
|
|
135
|
+
clientY = _e$changedTouches$.clientY,
|
|
136
|
+
target = _e$changedTouches$.target;
|
|
137
|
+
|
|
138
|
+
var _target$getBoundingCl = target.getBoundingClientRect(),
|
|
139
|
+
top = _target$getBoundingCl.top,
|
|
140
|
+
left = _target$getBoundingCl.left; // 获取当前节点到视口顶部和左边的距离
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
var x = (clientX - left) * this.ratio;
|
|
144
|
+
var y = (clientY - top) * this.ratio;
|
|
145
|
+
return {
|
|
146
|
+
x: x,
|
|
147
|
+
y: y
|
|
148
|
+
};
|
|
149
|
+
} // 鼠标按下
|
|
150
|
+
|
|
151
|
+
}, {
|
|
152
|
+
key: "onmousedown",
|
|
153
|
+
value: function onmousedown(e) {
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
var eventName = 'mousemove';
|
|
156
|
+
|
|
157
|
+
if (this.isTouch) {
|
|
158
|
+
var _this$getPoint = this.getPoint(e),
|
|
159
|
+
x = _this$getPoint.x,
|
|
160
|
+
y = _this$getPoint.y;
|
|
161
|
+
|
|
162
|
+
e.offsetX = x;
|
|
163
|
+
e.offsetY = y;
|
|
164
|
+
eventName = 'touchmove';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.canvas.addEventListener(eventName, this.bindMousemove);
|
|
168
|
+
this.isClickCanvas = true;
|
|
169
|
+
this.x = e.offsetX;
|
|
170
|
+
this.y = e.offsetY;
|
|
171
|
+
this.last = [this.x, this.y];
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
key: "gatherImage",
|
|
175
|
+
value: function gatherImage() {
|
|
176
|
+
// 采集图像
|
|
177
|
+
this.imgData = this.imgData.slice(0, this.index + 1); // 每次鼠标抬起时,将储存的imgdata截取至index处
|
|
178
|
+
|
|
179
|
+
var imgData = this.ctx.getImageData(0, 0, this.width, this.height);
|
|
180
|
+
this.imgData.push(imgData);
|
|
181
|
+
this.index = this.imgData.length - 1; // 储存完后将 index 重置为 imgData 最后一位
|
|
182
|
+
|
|
183
|
+
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "reSetImage",
|
|
187
|
+
value: function reSetImage() {
|
|
188
|
+
// 重置为上一帧
|
|
189
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
190
|
+
|
|
191
|
+
if (this.imgData.length >= 1) {
|
|
192
|
+
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
193
|
+
}
|
|
194
|
+
} // 鼠标移动
|
|
195
|
+
|
|
196
|
+
}, {
|
|
197
|
+
key: "onmousemove",
|
|
198
|
+
value: function onmousemove(e) {
|
|
199
|
+
if (this.isTouch) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
|
|
202
|
+
var _this$getPoint2 = this.getPoint(e),
|
|
203
|
+
x = _this$getPoint2.x,
|
|
204
|
+
y = _this$getPoint2.y;
|
|
205
|
+
|
|
206
|
+
e.offsetX = x;
|
|
207
|
+
e.offsetY = y;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
this.isMoveCanvas = true;
|
|
211
|
+
var endx = e.offsetX;
|
|
212
|
+
var endy = e.offsetY;
|
|
213
|
+
var width = endx - this.x;
|
|
214
|
+
var height = endy - this.y;
|
|
215
|
+
var now = [endx, endy]; // 当前移动到的位置
|
|
216
|
+
|
|
217
|
+
switch (this.drawType) {
|
|
218
|
+
case 'pen':
|
|
219
|
+
{
|
|
220
|
+
var params = [this.last, now, this.lineWidth, this.drawColor, true];
|
|
221
|
+
this.moveCallback.apply(this, ['pen'].concat(params));
|
|
222
|
+
this.line.apply(this, params);
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
case 'eraser':
|
|
227
|
+
{
|
|
228
|
+
var _params = [endx, endy, this.lineWidth];
|
|
229
|
+
this.moveCallback.apply(this, ['eraser'].concat(_params));
|
|
230
|
+
this.eraser.apply(this, _params);
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
} // 鼠标抬起
|
|
235
|
+
|
|
236
|
+
}, {
|
|
237
|
+
key: "onmouseup",
|
|
238
|
+
value: function onmouseup(e) {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
|
|
241
|
+
if (this.isClickCanvas) {
|
|
242
|
+
this.isClickCanvas = false;
|
|
243
|
+
|
|
244
|
+
if (this.isTouch) {
|
|
245
|
+
this.canvas.removeEventListener('touchmove', this.bindMousemove);
|
|
246
|
+
} else {
|
|
247
|
+
this.canvas.removeEventListener('mousemove', this.bindMousemove);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (this.isMoveCanvas) {
|
|
251
|
+
// 鼠标没有移动不保存
|
|
252
|
+
this.isMoveCanvas = false;
|
|
253
|
+
this.gatherImage();
|
|
254
|
+
this.moveCallback('gatherImage', this.index);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} // 绘制线性(直线和铅笔)
|
|
258
|
+
|
|
259
|
+
}, {
|
|
260
|
+
key: "line",
|
|
261
|
+
value: function line(last, now, lineWidth, drawColor, isPencil) {
|
|
262
|
+
if (!isPencil) {
|
|
263
|
+
this.reSetImage();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
this.ctx.beginPath();
|
|
267
|
+
this.ctx.lineCap = 'round'; // 设定线条与线条间接合处的样式
|
|
268
|
+
|
|
269
|
+
this.ctx.lineJoin = 'round';
|
|
270
|
+
this.ctx.lineWidth = lineWidth;
|
|
271
|
+
this.ctx.strokeStyle = drawColor;
|
|
272
|
+
this.ctx.moveTo(last[0], last[1]);
|
|
273
|
+
this.ctx.lineTo(now[0], now[1]);
|
|
274
|
+
this.ctx.closePath();
|
|
275
|
+
this.ctx.stroke(); // 进行绘制
|
|
276
|
+
|
|
277
|
+
if (isPencil) {
|
|
278
|
+
// 铅笔需要保存最后一次记录
|
|
279
|
+
this.last = now;
|
|
280
|
+
}
|
|
281
|
+
} // 橡皮擦
|
|
282
|
+
|
|
283
|
+
}, {
|
|
284
|
+
key: "eraser",
|
|
285
|
+
value: function eraser(endx, endy, lineWidth) {
|
|
286
|
+
this.ctx.save();
|
|
287
|
+
this.line(this.last, [endx, endy], lineWidth * 2, '#fff', true);
|
|
288
|
+
} // 撤回
|
|
289
|
+
|
|
290
|
+
}, {
|
|
291
|
+
key: "undo",
|
|
292
|
+
value: function undo() {
|
|
293
|
+
if (--this.index < 0) {
|
|
294
|
+
this.index = 0;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
299
|
+
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
300
|
+
} // 前进
|
|
301
|
+
|
|
302
|
+
}, {
|
|
303
|
+
key: "redo",
|
|
304
|
+
value: function redo() {
|
|
305
|
+
if (++this.index > this.imgData.length - 1) {
|
|
306
|
+
this.index = this.imgData.length - 1;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
this.allowCallback(this.index > 0, this.index < this.imgData.length - 1);
|
|
311
|
+
this.ctx.putImageData(this.imgData[this.index], 0, 0);
|
|
312
|
+
} // 清屏
|
|
313
|
+
|
|
314
|
+
}, {
|
|
315
|
+
key: "clear",
|
|
316
|
+
value: function clear() {
|
|
317
|
+
this.imgData = [];
|
|
318
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
319
|
+
this.gatherImage();
|
|
320
|
+
} // 设置画板参数
|
|
321
|
+
|
|
322
|
+
}, {
|
|
323
|
+
key: "changeWay",
|
|
324
|
+
value: function changeWay(_ref2) {
|
|
325
|
+
var type = _ref2.type,
|
|
326
|
+
color = _ref2.color,
|
|
327
|
+
lineWidth = _ref2.lineWidth,
|
|
328
|
+
sides = _ref2.sides;
|
|
329
|
+
|
|
330
|
+
if (type === 'eraser') {
|
|
331
|
+
this.ctx.globalCompositeOperation = 'destination-out'; // 擦除
|
|
332
|
+
} else {
|
|
333
|
+
this.ctx.globalCompositeOperation = 'source-over'; // 画
|
|
334
|
+
} // 绘制条件
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
this.drawType = type !== 'color' && type || this.drawType; // 绘制形状
|
|
338
|
+
|
|
339
|
+
this.drawColor = color || this.drawColor; // 绘制颜色
|
|
340
|
+
|
|
341
|
+
this.lineWidth = lineWidth || this.lineWidth; // 线宽
|
|
342
|
+
|
|
343
|
+
this.sides = sides || this.sides; // 边数
|
|
344
|
+
} // 销毁画板
|
|
345
|
+
|
|
346
|
+
}, {
|
|
347
|
+
key: "destroy",
|
|
348
|
+
value: function destroy() {
|
|
349
|
+
this.clear();
|
|
350
|
+
this.canvas.removeEventListener('mousedown', this.bindMousedown);
|
|
351
|
+
this.canvas.removeEventListener('mouseup', this.bindMouseup);
|
|
352
|
+
this.canvas = null;
|
|
353
|
+
this.ctx = null;
|
|
354
|
+
} // 保留笔画
|
|
355
|
+
|
|
356
|
+
}, {
|
|
357
|
+
key: "retain",
|
|
358
|
+
value: function retain() {
|
|
359
|
+
var base64 = this.canvas.toDataURL();
|
|
360
|
+
var img = document.createElement('img');
|
|
361
|
+
img.style.position = 'fixed';
|
|
362
|
+
img.style.width = '90vw';
|
|
363
|
+
img.style.height = '95vh';
|
|
364
|
+
img.style.top = '9vh';
|
|
365
|
+
img.style.left = '5vw';
|
|
366
|
+
img.src = base64;
|
|
367
|
+
document.body.appendChild(img);
|
|
368
|
+
}
|
|
369
|
+
}]);
|
|
370
|
+
|
|
371
|
+
return BoardOperate;
|
|
372
|
+
}();
|
|
373
|
+
|
|
374
|
+
export { BoardOperate };
|