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