zydx-plus 1.32.310 → 1.32.311

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zydx-plus",
3
- "version": "1.32.310",
3
+ "version": "1.32.311",
4
4
  "description": "Vue.js",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -40,7 +40,6 @@
40
40
  "@tiptap/extension-link": "^2.0.3",
41
41
  "@vue-office/docx": "^1.1.3",
42
42
  "@vue-office/excel": "^1.1.3",
43
- "fabric": "^5.3.0",
44
43
  "js-export-word": "^1.0.5",
45
44
  "js-audio-recorder": "^1.0.7"
46
45
  },
package/src/index.js CHANGED
@@ -27,7 +27,6 @@ import time from './components/time/index';
27
27
  import preface from './components/preface/index';
28
28
  import choice from './components/choice/index';
29
29
  import word from './components/word/index';
30
- import sketchpad from './components/sketchpad/index';
31
30
  import pictureViewer from './components/pictureViewer/index';
32
31
  import lessonTemplate from './components/lesson_template/index';
33
32
  import paper from './components/word2/index';
@@ -63,7 +62,6 @@ const components = [
63
62
  preface,
64
63
  choice,
65
64
  word,
66
- sketchpad,
67
65
  pictureViewer,
68
66
  lessonTemplate,
69
67
  paper,
@@ -81,7 +79,7 @@ function install(app) {
81
79
  }
82
80
 
83
81
  export default {
84
- version: '1.32.309',
82
+ version: '1.32.311',
85
83
  install,
86
84
  Calendar,
87
85
  Message,
@@ -112,7 +110,6 @@ export default {
112
110
  preface,
113
111
  choice,
114
112
  word,
115
- sketchpad,
116
113
  pictureViewer,
117
114
  lessonTemplate,
118
115
  paper,
@@ -1,6 +0,0 @@
1
- import main from './src/sketchpad';
2
-
3
- main.install = function(Vue) {
4
- Vue.component(main.name, main);
5
- };
6
- export default main;
@@ -1,525 +0,0 @@
1
- <template>
2
- <div class="sketchpad" ref="sketchpad">
3
- <canvas :id="id"></canvas>
4
- <div class="tool"
5
- @mousedown.stop="mousedown"
6
- :style="{transform: `translate(${x}px, ${y}px)`}">
7
- <div class="tool-list" @click.stop="set">
8
- <img class="img-1" src="./img/shezi.png" alt=""/>
9
- <div v-if="setShow" class="set">
10
- <div class="set-list">
11
- <span>线条粗细</span>
12
- <em v-for="(item,index) in strokeData" @click="strokeTap(item)">{{ item }}</em>
13
- </div>
14
- <div class="set-list">
15
- <span>线条颜色</span>
16
- <i v-for="(item,index) in strokeColor" @click="strokeColTap(item)" :style="{'background-color': item}"></i>
17
- </div>
18
- </div>
19
- </div>
20
- <div class="tool-list" @click.stop="mouse()">
21
- <img class="img-2" src="./img/shubiao.png" alt=""/>
22
- </div>
23
- <div class="tool-list" @click.stop="brush()">
24
- <img class="img-3" src="./img/huabi.png" alt=""/>
25
- </div>
26
- <div class="tool-list" @click.stop="rectangle()">
27
- <img class="img-4" src="./img/juxing.png" alt=""/>
28
- </div>
29
- <div class="tool-list" @click.stop="addTextBox()">
30
- <img class="img-5" src="./img/wenzi.png" alt=""/>
31
- <div v-if="textShow" class="set">
32
- <div class="set-list">
33
- <span>字号</span>
34
- <em style="font-size: 13px;" v-for="(item,index) in textData" @click.stop="sizeTap(item)">{{ item }}</em>
35
- </div>
36
- <div class="set-list" @click.stop="textInputTap">
37
- <span>内容</span>
38
- <input ref="textInput" type="text" v-model="text"/>
39
- </div>
40
- <div class="set-list set-right">
41
- <button class="but" @click="textBox">确认</button>
42
- </div>
43
- </div>
44
- </div>
45
- <div class="tool-list" @click.stop="rotundity()">
46
- <img class="img-6" src="./img/yuan.png" alt=""/>
47
- </div>
48
- <div class="tool-list" @click.stop="addLine()">
49
- <img class="img-7" src="./img/jian.png" alt=""/>
50
- </div>
51
- <div class="tool-list" @click.stop="arrow()">
52
- <img class="img-8" src="./img/jiantou.png" alt=""/>
53
- </div>
54
- <div class="tool-list" @click.stop="save()">
55
- <img class="img-9" src="./img/baocun.png" alt=""/>
56
- </div>
57
- <div class="tool-list" @click.stop="clear()">
58
- <img class="img-10" src="./img/xiangpi.png" alt=""/>
59
- </div>
60
- </div>
61
- </div>
62
- </template>
63
-
64
- <script>
65
- import {fabric} from 'fabric'
66
-
67
- export default {
68
- name: "zydx-sketchpad",
69
- data() {
70
- return {
71
- canvas: null,
72
- strokeWidth: 2, // 线条粗细
73
- color: '#000', // 线条颜色
74
- line: null, // 线条
75
- isDown: false, // 是否按下
76
- state: null, // 状态
77
- rect: null, // 矩形
78
- circle: null, // 圆形
79
- fontSize: 14, // 字体大小
80
- setShow: false, // 设置
81
- strokeData: ['1', '2', '3', '4', '5', '6', '7'], // 画笔数据
82
- strokeColor: ['#000', '#f00', '#0f0', '#00f', '#f0f', '#ff0', '#0ff'], // 画笔颜色
83
- textShow: false, // 文本
84
- textData: ['14', '16', '18', '20', '22', '24', '28', '30'], // 文本数据
85
- text: '',
86
- id: null,
87
- left: 0,
88
- top: 0,
89
- isMove: false,
90
- x: 0,
91
- y: 0,
92
- offLeft: 0,
93
- offTop: 0,
94
- scrollTop: 0
95
- }
96
- },
97
- props: {
98
- data: {
99
- type: Object,
100
- default: () => {
101
- }
102
- },
103
- width: {
104
- type: Number,
105
- default: 800
106
- },
107
- height: {
108
- type: Number,
109
- default: 800
110
- }
111
- },
112
- emits: ['save'],
113
- watch: {
114
- data: {
115
- handler(val) {
116
- this.canvas.loadFromJSON(val)
117
- },
118
- deep: true
119
- }
120
- },
121
- mounted() {
122
- // 生成随机id
123
- this.id = Math.random().toString(36).substr(2)
124
- setTimeout(() => {
125
- this.init()
126
- }, 0)
127
- window.addEventListener('keydown', this.handleKeyEvent)
128
- document.addEventListener('mousemove', (event) => {
129
- if (!this.isMove) return
130
- const ids = this.$refs.sketchpad.getBoundingClientRect()
131
- this.offLeft = ids.left
132
- this.offTop = ids.top
133
- this.x = event.clientX - this.left - this.offLeft
134
- this.y = event.clientY - this.top - this.offTop
135
- })
136
- document.addEventListener('mouseup', (event) => {
137
- this.isMove = false
138
- })
139
- },
140
- beforeDestroy() {
141
- window.removeEventListener('keydown', this.handleKeyEvent)
142
- },
143
- methods: {
144
- mouse() {
145
- this.state = null
146
- this.canvas.isDrawingMode = false
147
- },
148
- textInputTap() {
149
- this.$refs.textInput.focus()
150
- },
151
- mousedown(event) {
152
- const e = event.target || event.srcElement
153
- let x = 0, y = 0
154
- if(e.nodeName === 'IMG') {
155
- const rect = e.getBoundingClientRect()
156
- const index = e.className.split(' ')[0].split('-')[1]
157
- x = event.clientX - rect.left
158
- y = event.clientY - rect.top + 30*index
159
- }else {
160
- x = event.offsetX
161
- y = event.offsetY
162
- }
163
- console.log(x,y)
164
- //鼠标按下事件
165
- this.left = x
166
- this.top = y
167
- this.isMove = true
168
- },
169
- sizeTap(v) {
170
- this.fontSize = Number(v)
171
- },
172
- addTextBox() {
173
- this.state = 'text'
174
- this.setShow = false
175
- this.textShow = !this.textShow
176
- },
177
- strokeColTap(v) {
178
- this.color = v
179
- this.canvas.freeDrawingBrush.color = this.color
180
- },
181
- strokeTap(v) {
182
- this.strokeWidth = Number(v)
183
- this.canvas.freeDrawingBrush.width = this.strokeWidth
184
- },
185
- set() {
186
- this.textShow = false
187
- this.setShow = !this.setShow
188
- },
189
- init() {
190
- this.canvas = new fabric.Canvas(this.id, {
191
- isDrawingMode: false,
192
- width: this.width,
193
- height: this.height,
194
- });
195
- this.canvas.selectionColor = "rgba(255,255,255,0)";
196
- this.canvas.loadFromJSON(this.data)
197
- this.y = (this.height / 2) - 203
198
- },
199
- // 画笔
200
- brush() {
201
- this.state = 'brush'
202
- this.canvas.isDrawingMode = !this.canvas.isDrawingMode
203
- this.canvas.freeDrawingBrush.width = this.strokeWidth
204
- this.canvas.freeDrawingBrush.color = this.color
205
- },
206
- // 直线
207
- addLine() {
208
- this.canvas.isDrawingMode = false
209
- this.state = 'line'
210
- const id = Date.now()
211
- this.canvas.on('mouse:down', (o) => {
212
- if (o.target !== null) return
213
- if (this.state !== 'line') return
214
- this.isDown = true
215
- const pointer = this.canvas.getPointer(o.e)
216
- const points = [pointer.x, pointer.y, pointer.x, pointer.y]
217
- this.line = new fabric.Line(points, {
218
- id: id,
219
- strokeWidth: this.strokeWidth,
220
- fill: this.color,
221
- stroke: this.color,
222
- originX: 'center',
223
- originY: 'center'
224
- })
225
- this.canvas.add(this.line)
226
- })
227
- this.canvas.on('mouse:move', (o) => {
228
- if (this.state !== 'line') return
229
- if (!this.isDown) return
230
- const pointer = this.canvas.getPointer(o.e)
231
- this.line.set({x2: pointer.x, y2: pointer.y})
232
- this.canvas.renderAll()
233
- })
234
-
235
- this.canvas.on('mouse:up', (o) => {
236
- this.isDown = false
237
- this.line?.setCoords()
238
- })
239
- },
240
- // 矩形
241
- rectangle() {
242
- this.canvas.isDrawingMode = false
243
- this.state = 'rectangle'
244
- const id = Date.now()
245
- let origX, origY
246
- this.canvas.on('mouse:down', (o) => {
247
- if (o.target !== null) return
248
- if (this.state !== 'rectangle') return
249
- this.isDown = true
250
- let pointer = this.canvas.getPointer(o.e)
251
- origX = pointer.x
252
- origY = pointer.y
253
- this.rect = new fabric.Rect({
254
- id: id,
255
- left: origX,
256
- top: origY,
257
- originX: 'left',
258
- originY: 'top',
259
- width: pointer.x - origX,
260
- height: pointer.y - origY,
261
- angle: 0,
262
- fill: '',
263
- stroke: this.color,
264
- strokeWidth: this.strokeWidth
265
- })
266
- this.canvas.add(this.rect)
267
- })
268
- this.canvas.on('mouse:move', (o) => {
269
- if (this.state !== 'rectangle') return
270
- if (!this.isDown) return
271
- let pointer = this.canvas.getPointer(o.e)
272
-
273
- if (origX > pointer.x) {
274
- this.rect.set({left: Math.abs(pointer.x)})
275
- }
276
- if (origY > pointer.y) {
277
- this.rect.set({top: Math.abs(pointer.y)})
278
- }
279
- this.rect.set({width: Math.abs(origX - pointer.x)})
280
- this.rect.set({height: Math.abs(origY - pointer.y)})
281
- this.canvas.renderAll()
282
- })
283
- this.canvas.on('mouse:up', (o) => {
284
- this.isDown = false
285
- this.rect?.setCoords()
286
- })
287
- },
288
- // 圆形
289
- rotundity() {
290
- this.canvas.isDrawingMode = false
291
- this.state = 'rotundity'
292
- let origX, origY
293
- this.canvas.on('mouse:down', (o) => {
294
- if (o.target !== null) return
295
- if (this.state !== 'rotundity') return
296
- this.isDown = true
297
- let pointer = this.canvas.getPointer(o.e)
298
- origX = pointer.x
299
- origY = pointer.y
300
- this.circle = new fabric.Circle({
301
- left: origX,
302
- top: origY,
303
- originX: 'left',
304
- originY: 'top',
305
- radius: pointer.x - origX,
306
- angle: 0,
307
- fill: '',
308
- stroke: this.color,
309
- strokeWidth: this.strokeWidth
310
- })
311
- this.canvas.add(this.circle)
312
- })
313
- this.canvas.on('mouse:move', (o) => {
314
- if (this.state !== 'rotundity') return
315
- if (!this.isDown) return
316
- let pointer = this.canvas.getPointer(o.e)
317
- let radius =
318
- Math.max(
319
- Math.abs(origY - pointer.y),
320
- Math.abs(origX - pointer.x)
321
- ) / 2
322
- if (radius > this.circle.strokeWidth) {
323
- radius -= this.circle.strokeWidth / 2
324
- }
325
- this.circle.set({radius: radius})
326
-
327
- if (origX > pointer.x) {
328
- this.circle.set({originX: 'right'})
329
- } else {
330
- this.circle.set({originX: 'left'})
331
- }
332
- if (origY > pointer.y) {
333
- this.circle.set({originY: 'bottom'})
334
- } else {
335
- this.circle.set({originY: 'top'})
336
- }
337
- this.canvas.renderAll()
338
- })
339
- this.canvas.on('mouse:up', () => {
340
- this.isDown = false
341
- this.circle?.setCoords()
342
- })
343
- },
344
- // 箭头
345
- arrow() {
346
- const id = Date.now()
347
- const triangle = new fabric.Triangle({
348
- width: 9,
349
- height: 15,
350
- fill: 'black',
351
- left: 150,
352
- top: 137,
353
- angle: 90
354
- })
355
- const line = new fabric.Rect({
356
- left: 100,
357
- top: 140,
358
- width: 40,
359
- height: 3,
360
- fill: 'black',
361
- originX: 'left',
362
- originY: 'top',
363
- centeredRotation: true
364
- })
365
- const arrow = new fabric.Group([line, triangle], {
366
- id: id,
367
- left: this.canvas.width / 2,
368
- top: this.canvas.height / 2,
369
- angle: 0
370
- })
371
- this.canvas.add(arrow)
372
- },
373
- // 文本框
374
- textBox() {
375
- const id = Date.now()
376
- this.textbox = new fabric.Textbox(this.text, {
377
- id: id,
378
- top: 200,
379
- left: 200,
380
- width: 10,
381
- fill: this.color,
382
- fontSize: this.fontSize,
383
- color: this.color,
384
- fontWeight: 400,
385
- lineHeight: 1.5,
386
- fontFamily: '微软雅黑',
387
- textDecoration: 'none',
388
- textAlign: 'left'
389
- })
390
- this.canvas.add(this.textbox)
391
- },
392
- save() {
393
- this.$emit('save', this.canvas.toJSON())
394
- },
395
- clear() {
396
- this.canvas.clear()
397
- },
398
- handleKeyEvent(e) {
399
- const {key} = e
400
- if (key === 'Backspace' || key === 'Delete') {
401
- const el = this.canvas.getActiveObject()
402
- if (el) this.canvas.remove(el)
403
- }
404
- }
405
- }
406
- }
407
- </script>
408
-
409
- <style scoped>
410
- .sketchpad {
411
- position: relative;
412
- }
413
-
414
- .tool {
415
- position: absolute;
416
- top: 0;
417
- left: 0;
418
- z-index: 1;
419
- width: 50px;
420
- padding: 15px;
421
- border-radius: 10px;
422
- box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.3);
423
- box-sizing: border-box;
424
- background: #fff;
425
- transition-property: transform;
426
- transition-duration: 0ms;
427
- transition-timing-function: linear;
428
- transition-delay: 0ms;
429
- transform: translate(0px, 0px);
430
- cursor: move;
431
- user-select: none;
432
- }
433
-
434
- .tool-list {
435
- width: 100%;
436
- margin-bottom: 20px;
437
- cursor: pointer;
438
- position: relative;
439
- }
440
-
441
- .tool-list:last-child {
442
- margin-bottom: 0;
443
- }
444
-
445
- .tool-list img {
446
- width: 100%;
447
- }
448
-
449
- .set {
450
- position: absolute;
451
- top: 0;
452
- left: 40px;
453
- width: 280px;
454
- background-color: #fff;
455
- border-radius: 10px;
456
- box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.3);
457
- padding: 10px;
458
- z-index: 1;
459
- }
460
-
461
- .set-list {
462
- padding: 5px 0;
463
- font-size: 15px;
464
- }
465
-
466
- .set-list:after {
467
- content: '';
468
- display: block;
469
- clear: both;
470
- }
471
-
472
- .set-list span {
473
- margin-right: 10px;
474
- float: left;
475
- }
476
-
477
- .set-list em {
478
- font-style: normal;
479
- font-size: 15px;
480
- width: 16px;
481
- display: inline-block;
482
- margin-right: 10px;
483
- text-align: center;
484
- }
485
-
486
- .set-list em:hover {
487
- color: #5daf34;
488
- }
489
-
490
- .set-list i {
491
- display: inline-block;
492
- width: 16px;
493
- height: 16px;
494
- background-color: #000;
495
- margin: 2px 10px 0 0;
496
- float: left;
497
- }
498
-
499
- .set-list input {
500
- width: calc(100% - 60px);
501
- height: 22px;
502
- border: 1px solid #ccc;
503
- border-radius: 5px;
504
- padding: 0 10px;
505
- box-sizing: border-box;
506
- float: left;
507
- }
508
-
509
- .but {
510
- margin-left: 5px;
511
- font-size: 12px;
512
- background-color: transparent;
513
- border: 1px solid #000;
514
- border-radius: 3px;
515
- padding: 2px 5px;
516
- cursor: pointer;
517
- min-width: 60px;
518
- height: 21px;
519
- margin-right: 20px;
520
- }
521
-
522
- .set-right {
523
- text-align: right;
524
- }
525
- </style>