@sy-common/wang-editor 1.0.0-beta.15 → 1.0.0-beta.18
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/index.vue +343 -301
package/package.json
CHANGED
package/src/index.vue
CHANGED
|
@@ -1,301 +1,343 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div style="z-index: 999">
|
|
3
|
-
<!-- 工具栏 -->
|
|
4
|
-
<Toolbar
|
|
5
|
-
:editor="editor"
|
|
6
|
-
:defaultConfig="toolbarConfig"
|
|
7
|
-
/>
|
|
8
|
-
<!-- 编辑器 -->
|
|
9
|
-
<Editor
|
|
10
|
-
style="
|
|
11
|
-
:defaultConfig="editorConfig"
|
|
12
|
-
v-model="html"
|
|
13
|
-
@onChange="onChange"
|
|
14
|
-
@onCreated="onCreated"
|
|
15
|
-
/>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script>
|
|
20
|
-
import '@wangeditor-next/editor/dist/css/style.css'
|
|
21
|
-
import {oneOf} from '@lambo-design/shared/utils/platform';
|
|
22
|
-
import {Editor, Toolbar} from '@wangeditor-next/editor-for-vue2'
|
|
23
|
-
|
|
24
|
-
export default {
|
|
25
|
-
name: 'WangEditor',
|
|
26
|
-
components: {Editor, Toolbar},
|
|
27
|
-
props: {
|
|
28
|
-
value: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: ''
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* 绑定的值的类型, enum: ['html', 'text']
|
|
34
|
-
*/
|
|
35
|
-
valueType: {
|
|
36
|
-
type: String,
|
|
37
|
-
default: 'html',
|
|
38
|
-
validator: (val) => {
|
|
39
|
-
return oneOf(val, ['html', 'text'])
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
/**
|
|
43
|
-
* @description 设置change事件触发时间间隔
|
|
44
|
-
*/
|
|
45
|
-
changeInterval: {
|
|
46
|
-
type: Number,
|
|
47
|
-
default: 200
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* @description 是否开启本地存储
|
|
51
|
-
*/
|
|
52
|
-
cache: {
|
|
53
|
-
type: Boolean,
|
|
54
|
-
default: true
|
|
55
|
-
},
|
|
56
|
-
/**
|
|
57
|
-
* @description 是否使用 base64 保存图片
|
|
58
|
-
*/
|
|
59
|
-
uploadImgShowBase64: {
|
|
60
|
-
type: Boolean,
|
|
61
|
-
default: false
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* 上传图片上下文
|
|
65
|
-
*/
|
|
66
|
-
ossServerContext: {
|
|
67
|
-
type: String,
|
|
68
|
-
default: ''
|
|
69
|
-
},
|
|
70
|
-
/**
|
|
71
|
-
* 上传图片Url地址
|
|
72
|
-
*/
|
|
73
|
-
ossFilePutUrl: {
|
|
74
|
-
type: String,
|
|
75
|
-
default: "/oss/file/put"
|
|
76
|
-
},
|
|
77
|
-
/**
|
|
78
|
-
* 获取图片url地址
|
|
79
|
-
*/
|
|
80
|
-
ossFileGetImgUrl: {
|
|
81
|
-
type: String,
|
|
82
|
-
default: "/oss/file/get/"
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* @description 是否保留粘贴内容的样式
|
|
86
|
-
*/
|
|
87
|
-
preservePasteStyle: {
|
|
88
|
-
type: Boolean,
|
|
89
|
-
default: false
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"rgb(
|
|
141
|
-
"rgb(
|
|
142
|
-
"rgb(
|
|
143
|
-
"rgb(
|
|
144
|
-
"rgb(
|
|
145
|
-
"rgb(
|
|
146
|
-
"rgb(
|
|
147
|
-
"rgb(
|
|
148
|
-
"rgb(
|
|
149
|
-
"rgb(
|
|
150
|
-
"rgb(
|
|
151
|
-
"rgb(
|
|
152
|
-
"rgb(
|
|
153
|
-
"rgb(
|
|
154
|
-
"rgb(
|
|
155
|
-
"rgb(
|
|
156
|
-
"rgb(
|
|
157
|
-
"rgb(
|
|
158
|
-
"rgb(
|
|
159
|
-
"rgb(
|
|
160
|
-
"rgb(
|
|
161
|
-
"rgb(
|
|
162
|
-
"rgb(
|
|
163
|
-
"rgb(
|
|
164
|
-
"rgb(
|
|
165
|
-
"rgb(
|
|
166
|
-
"rgb(
|
|
167
|
-
"rgb(
|
|
168
|
-
"rgb(
|
|
169
|
-
"rgb(
|
|
170
|
-
"rgb(
|
|
171
|
-
"rgb(
|
|
172
|
-
"rgb(
|
|
173
|
-
"rgb(
|
|
174
|
-
"rgb(
|
|
175
|
-
"rgb(
|
|
176
|
-
"rgb(
|
|
177
|
-
"rgb(
|
|
178
|
-
"rgb(
|
|
179
|
-
"rgb(
|
|
180
|
-
"rgb(
|
|
181
|
-
"rgb(
|
|
182
|
-
"rgb(
|
|
183
|
-
"rgb(
|
|
184
|
-
"rgb(
|
|
185
|
-
"rgb(
|
|
186
|
-
"rgb(
|
|
187
|
-
"rgb(
|
|
188
|
-
"rgb(
|
|
189
|
-
"rgb(
|
|
190
|
-
"rgb(
|
|
191
|
-
"rgb(
|
|
192
|
-
"rgb(
|
|
193
|
-
"rgb(
|
|
194
|
-
"rgb(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div style="z-index: 999">
|
|
3
|
+
<!-- 工具栏 -->
|
|
4
|
+
<Toolbar
|
|
5
|
+
:editor="editor"
|
|
6
|
+
:defaultConfig="toolbarConfig"
|
|
7
|
+
/>
|
|
8
|
+
<!-- 编辑器 -->
|
|
9
|
+
<Editor
|
|
10
|
+
:style="editorStyle"
|
|
11
|
+
:defaultConfig="editorConfig"
|
|
12
|
+
v-model="html"
|
|
13
|
+
@onChange="onChange"
|
|
14
|
+
@onCreated="onCreated"
|
|
15
|
+
/>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import '@wangeditor-next/editor/dist/css/style.css'
|
|
21
|
+
import {oneOf} from '@lambo-design/shared/utils/platform';
|
|
22
|
+
import {Editor, Toolbar} from '@wangeditor-next/editor-for-vue2'
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
name: 'WangEditor',
|
|
26
|
+
components: {Editor, Toolbar},
|
|
27
|
+
props: {
|
|
28
|
+
value: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: ''
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* 绑定的值的类型, enum: ['html', 'text']
|
|
34
|
+
*/
|
|
35
|
+
valueType: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: 'html',
|
|
38
|
+
validator: (val) => {
|
|
39
|
+
return oneOf(val, ['html', 'text'])
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* @description 设置change事件触发时间间隔
|
|
44
|
+
*/
|
|
45
|
+
changeInterval: {
|
|
46
|
+
type: Number,
|
|
47
|
+
default: 200
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* @description 是否开启本地存储
|
|
51
|
+
*/
|
|
52
|
+
cache: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
default: true
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* @description 是否使用 base64 保存图片
|
|
58
|
+
*/
|
|
59
|
+
uploadImgShowBase64: {
|
|
60
|
+
type: Boolean,
|
|
61
|
+
default: false
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* 上传图片上下文
|
|
65
|
+
*/
|
|
66
|
+
ossServerContext: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: ''
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* 上传图片Url地址
|
|
72
|
+
*/
|
|
73
|
+
ossFilePutUrl: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: "/oss/file/put"
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* 获取图片url地址
|
|
79
|
+
*/
|
|
80
|
+
ossFileGetImgUrl: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: "/oss/file/get/"
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* @description 是否保留粘贴内容的样式
|
|
86
|
+
*/
|
|
87
|
+
preservePasteStyle: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
readOnly: {
|
|
93
|
+
type: Boolean,
|
|
94
|
+
default: false
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* @description: 隐藏菜单
|
|
98
|
+
*/
|
|
99
|
+
hideMenu: {
|
|
100
|
+
type: Array,
|
|
101
|
+
default: () => []
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
height: {
|
|
105
|
+
type: Number,
|
|
106
|
+
default: 400
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
data() {
|
|
110
|
+
return {
|
|
111
|
+
editor: null,
|
|
112
|
+
html: '',
|
|
113
|
+
toolbarConfig: {
|
|
114
|
+
// toolbarKeys: [ /* 显示哪些菜单,如何排序、分组 */ ],
|
|
115
|
+
// excludeKeys: [ /* 隐藏哪些菜单 */ ],
|
|
116
|
+
},
|
|
117
|
+
editorConfig: {
|
|
118
|
+
placeholder: '请输入内容...',
|
|
119
|
+
MENU_CONF: {
|
|
120
|
+
fontFamily: {
|
|
121
|
+
fontFamilyList: [
|
|
122
|
+
"黑体",
|
|
123
|
+
{
|
|
124
|
+
name: "仿宋",
|
|
125
|
+
value: "仿宋"
|
|
126
|
+
},
|
|
127
|
+
"仿宋_GB2312",
|
|
128
|
+
"楷体",
|
|
129
|
+
"楷体_GB2312",
|
|
130
|
+
"标楷体",
|
|
131
|
+
"华文仿宋",
|
|
132
|
+
"华文楷体",
|
|
133
|
+
{
|
|
134
|
+
name: "宋体",
|
|
135
|
+
value: "宋体"
|
|
136
|
+
}, "隶书", "方正小标宋简体", "思源宋体", "微软雅黑", "Arial", "Tahoma", "Verdana", "Times New Roman", "Courier New"]
|
|
137
|
+
},
|
|
138
|
+
color: {
|
|
139
|
+
colors: [
|
|
140
|
+
"rgb(0, 0, 0)",
|
|
141
|
+
"rgb(38, 38, 38)",
|
|
142
|
+
"rgb(89, 89, 89)",
|
|
143
|
+
"rgb(140, 140, 140)",
|
|
144
|
+
"rgb(191, 191, 191)",
|
|
145
|
+
"rgb(217, 217, 217)",
|
|
146
|
+
"rgb(233, 233, 233)",
|
|
147
|
+
"rgb(245, 245, 245)",
|
|
148
|
+
"rgb(250, 250, 250)",
|
|
149
|
+
"rgb(255, 255, 255)",
|
|
150
|
+
"rgb(225, 60, 57)",
|
|
151
|
+
"rgb(231, 95, 51)",
|
|
152
|
+
"rgb(235, 144, 58)",
|
|
153
|
+
"rgb(245, 219, 77)",
|
|
154
|
+
"rgb(114, 192, 64)",
|
|
155
|
+
"rgb(89, 191, 192)",
|
|
156
|
+
"rgb(66, 144, 247)",
|
|
157
|
+
"rgb(54, 88, 226)",
|
|
158
|
+
"rgb(106, 57, 201)",
|
|
159
|
+
"rgb(216, 68, 147)",
|
|
160
|
+
"rgb(251, 233, 230)",
|
|
161
|
+
"rgb(252, 237, 225)",
|
|
162
|
+
"rgb(252, 239, 212)",
|
|
163
|
+
"rgb(252, 251, 207)",
|
|
164
|
+
"rgb(231, 246, 213)",
|
|
165
|
+
"rgb(218, 244, 240)",
|
|
166
|
+
"rgb(217, 237, 250)",
|
|
167
|
+
"rgb(224, 232, 250)",
|
|
168
|
+
"rgb(237, 225, 248)",
|
|
169
|
+
"rgb(246, 226, 234)",
|
|
170
|
+
"rgb(255, 163, 158)",
|
|
171
|
+
"rgb(255, 187, 150)",
|
|
172
|
+
"rgb(255, 213, 145)",
|
|
173
|
+
"rgb(255, 251, 143)",
|
|
174
|
+
"rgb(183, 235, 143)",
|
|
175
|
+
"rgb(135, 232, 222)",
|
|
176
|
+
"rgb(145, 213, 255)",
|
|
177
|
+
"rgb(173, 198, 255)",
|
|
178
|
+
"rgb(211, 173, 247)",
|
|
179
|
+
"rgb(255, 173, 210)",
|
|
180
|
+
"rgb(255, 77, 79)",
|
|
181
|
+
"rgb(255, 122, 69)",
|
|
182
|
+
"rgb(255, 169, 64)",
|
|
183
|
+
"rgb(255, 236, 61)",
|
|
184
|
+
"rgb(115, 209, 61)",
|
|
185
|
+
"rgb(54, 207, 201)",
|
|
186
|
+
"rgb(64, 169, 255)",
|
|
187
|
+
"rgb(89, 126, 247)",
|
|
188
|
+
"rgb(146, 84, 222)",
|
|
189
|
+
"rgb(247, 89, 171)",
|
|
190
|
+
"rgb(207, 19, 34)",
|
|
191
|
+
"rgb(212, 56, 13)",
|
|
192
|
+
"rgb(212, 107, 8)",
|
|
193
|
+
"rgb(212, 177, 6)",
|
|
194
|
+
"rgb(56, 158, 13)",
|
|
195
|
+
"rgb(8, 151, 156)",
|
|
196
|
+
"rgb(9, 109, 217)",
|
|
197
|
+
"rgb(29, 57, 196)",
|
|
198
|
+
"rgb(83, 29, 171)",
|
|
199
|
+
"rgb(196, 29, 127)",
|
|
200
|
+
"rgb(130, 0, 20)",
|
|
201
|
+
"rgb(135, 20, 0)",
|
|
202
|
+
"rgb(135, 56, 0)",
|
|
203
|
+
"rgb(97, 71, 0)",
|
|
204
|
+
"rgb(19, 82, 0)",
|
|
205
|
+
"rgb(0, 71, 79)",
|
|
206
|
+
"rgb(0, 58, 140)",
|
|
207
|
+
"rgb(6, 17, 120)",
|
|
208
|
+
"rgb(34, 7, 94)",
|
|
209
|
+
"rgb(120, 6, 80)",
|
|
210
|
+
"rgb(250,64,6)"
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
uploadImage: {
|
|
214
|
+
//上传图片配置
|
|
215
|
+
server: this.ossServerContext + this.ossFilePutUrl, //上传接口地址
|
|
216
|
+
fieldName: 'file', //上传文件名
|
|
217
|
+
methods: 'post',
|
|
218
|
+
metaWithUrl: true, // 参数拼接到 url 上
|
|
219
|
+
//自定义插入图片
|
|
220
|
+
customInsert: (res, insertFn) => {
|
|
221
|
+
let self = this;
|
|
222
|
+
const imgInfo = res.data[0] || {}
|
|
223
|
+
const {fileId, fileName, contentType} = imgInfo
|
|
224
|
+
insertFn(self.ossServerContext + self.ossFileGetImgUrl + fileId, fileName, self.ossServerContext + self.ossFileGetImgUrl + fileId)
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
watch: {
|
|
233
|
+
value: {
|
|
234
|
+
handler: function (newVal, oldVal) {
|
|
235
|
+
if (oldVal === '') {
|
|
236
|
+
if (this.valueType === 'html') {
|
|
237
|
+
this.editor.setHtml(newVal)
|
|
238
|
+
} else {
|
|
239
|
+
this.editor.insertText(newVal)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
readOnly: {
|
|
246
|
+
handler(newVal){
|
|
247
|
+
this.editorConfig.readOnly = newVal
|
|
248
|
+
if(newVal){
|
|
249
|
+
this.toolbarConfig.toolbarKeys = ['fullScreen']
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
immediate: true,
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
hideMenu: {
|
|
256
|
+
handler(newVal){
|
|
257
|
+
this.toolbarConfig.excludeKeys = newVal
|
|
258
|
+
},
|
|
259
|
+
immediate: true,
|
|
260
|
+
deep: true
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
computed: {
|
|
264
|
+
editorStyle() {
|
|
265
|
+
let finalHeight = this.height;
|
|
266
|
+
// 如果是数字,自动拼接 px 单位
|
|
267
|
+
if (typeof finalHeight === 'number') {
|
|
268
|
+
finalHeight = `${finalHeight}px`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
height: finalHeight,
|
|
273
|
+
'overflow-y': 'hidden'
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
methods: {
|
|
278
|
+
|
|
279
|
+
onCreated(editor) {
|
|
280
|
+
this.editor = Object.seal(editor) // 【注意】一定要用 Object.seal() 否则会报错
|
|
281
|
+
// 如果本地有存储加载本地存储内容
|
|
282
|
+
let html = this.value
|
|
283
|
+
if (html) this.editor.setHtml(html)
|
|
284
|
+
|
|
285
|
+
},
|
|
286
|
+
onChange(editor) {
|
|
287
|
+
let self = this;
|
|
288
|
+
let html = this.editor.getHtml()
|
|
289
|
+
// 创建一个临时的 div 容器来解析 HTML
|
|
290
|
+
const tempDiv = document.createElement('div');
|
|
291
|
+
tempDiv.innerHTML = html;
|
|
292
|
+
|
|
293
|
+
// 处理 table 元素
|
|
294
|
+
const tables = tempDiv.querySelectorAll('table');
|
|
295
|
+
tables.forEach(table => {
|
|
296
|
+
const currentStyle = table.getAttribute('style') || '';
|
|
297
|
+
const newStyle = `${currentStyle}; border-collapse: collapse;`.trim();
|
|
298
|
+
table.setAttribute('class', 'wangeditor-styled-table');
|
|
299
|
+
table.setAttribute('style', newStyle);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// 处理 hr 元素
|
|
303
|
+
const hrs = tempDiv.querySelectorAll('hr');
|
|
304
|
+
hrs.forEach(hr => {
|
|
305
|
+
const currentStyle = hr.getAttribute('style') || '';
|
|
306
|
+
const newStyle = `${currentStyle}; border: 1px solid rgb(250, 64, 6);`.trim();
|
|
307
|
+
hr.setAttribute('style', newStyle);
|
|
308
|
+
});
|
|
309
|
+
// 更新处理后的 HTML
|
|
310
|
+
html = tempDiv.innerHTML;
|
|
311
|
+
console.log("this.editor.getMenuConfig('color')", this.editor.getMenuConfig('color'))
|
|
312
|
+
this.$emit('input', self.valueType === 'html' ? html : editor.getText())
|
|
313
|
+
this.$emit('on-change', html, editor.getText())
|
|
314
|
+
},
|
|
315
|
+
customPaste(editor, event, callback) {
|
|
316
|
+
//console.log('ClipboardEvent 粘贴事件对象', event)
|
|
317
|
+
const html = event.clipboardData.getData('text/html') // 获取粘贴的 html
|
|
318
|
+
const text = event.clipboardData.getData('text/plain') // 获取粘贴的纯文本
|
|
319
|
+
const rtf = event.clipboardData.getData('text/rtf') // 获取 rtf 数据(如从 word wsp 复制粘贴)
|
|
320
|
+
|
|
321
|
+
//console.log("customPaste-html",rtf)
|
|
322
|
+
// 自定义插入内容
|
|
323
|
+
editor.setHtml(html)
|
|
324
|
+
|
|
325
|
+
// 返回 false ,阻止默认粘贴行为
|
|
326
|
+
event.preventDefault()
|
|
327
|
+
callback(false) // 返回值(注意,vue 事件的返回值,不能用 return)
|
|
328
|
+
|
|
329
|
+
// 返回 true ,继续默认的粘贴行为
|
|
330
|
+
// callback(true)
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
mounted() {
|
|
334
|
+
|
|
335
|
+
},
|
|
336
|
+
beforeDestroy() {
|
|
337
|
+
const editor = this.editor
|
|
338
|
+
if (editor == null) return
|
|
339
|
+
editor.destroy() // 组件销毁时,及时销毁 editor ,重要!!!
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
</script>
|