|
@@ -13,6 +13,32 @@
|
13
|
13
|
v-if="this.type == 'url'"
|
14
|
14
|
>
|
15
|
15
|
</el-upload>
|
|
16
|
+ <el-upload
|
|
17
|
+ :action="uploadUrl"
|
|
18
|
+ :before-upload="handleBeforeUploadVideo"
|
|
19
|
+ :on-success="handleUploadSuccessVideo"
|
|
20
|
+ :on-error="handleUploadErrorVideo"
|
|
21
|
+ name="file"
|
|
22
|
+ :show-file-list="false"
|
|
23
|
+ :headers="headers"
|
|
24
|
+ style="display: none"
|
|
25
|
+ ref="uploadVideo"
|
|
26
|
+ v-if="this.type == 'url'"
|
|
27
|
+ >
|
|
28
|
+ </el-upload>
|
|
29
|
+ <el-upload
|
|
30
|
+ :action="uploadUrl"
|
|
31
|
+ :before-upload="handleBeforeUploadFile"
|
|
32
|
+ :on-success="handleUploadSuccessFile"
|
|
33
|
+ :on-error="handleUploadErrorFile"
|
|
34
|
+ name="file"
|
|
35
|
+ :show-file-list="false"
|
|
36
|
+ :headers="headers"
|
|
37
|
+ style="display: none"
|
|
38
|
+ ref="uploadFile"
|
|
39
|
+ v-if="this.type == 'url'"
|
|
40
|
+ >
|
|
41
|
+ </el-upload>
|
16
|
42
|
<div class="editor" ref="editor" :style="styles"></div>
|
17
|
43
|
</div>
|
18
|
44
|
</template>
|
|
@@ -24,6 +50,34 @@ import "quill/dist/quill.snow.css";
|
24
|
50
|
import "quill/dist/quill.bubble.css";
|
25
|
51
|
import { getToken } from "@/utils/auth";
|
26
|
52
|
|
|
53
|
+// 源码中是import直接倒入,这里要用Quill.import引入
|
|
54
|
+const Link = Quill.import("formats/link");
|
|
55
|
+// 自定义a链接
|
|
56
|
+class FileBlot extends Link {
|
|
57
|
+
|
|
58
|
+ // 继承Link Blot
|
|
59
|
+ static create (value) {
|
|
60
|
+
|
|
61
|
+ let node = undefined;
|
|
62
|
+ if (value && !value.href) {
|
|
63
|
+
|
|
64
|
+ // 适应原本的Link Blot
|
|
65
|
+ node = super.create(value)
|
|
66
|
+ } else {
|
|
67
|
+
|
|
68
|
+ // 自定义Link Blot
|
|
69
|
+ node = super.create(value.href)
|
|
70
|
+ node.href = value.href
|
|
71
|
+ node.innerText = value.innerText
|
|
72
|
+ // node.setAttribute('download', value.innerText); // 左键点击即下载
|
|
73
|
+ }
|
|
74
|
+ return node;
|
|
75
|
+ }
|
|
76
|
+}
|
|
77
|
+FileBlot.blotName = "link" // 这里不用改,如果需要也可以保留原来的,这里用个新的blot
|
|
78
|
+FileBlot.tagName = "A"
|
|
79
|
+Quill.register(FileBlot) // 注册link
|
|
80
|
+
|
27
|
81
|
export default {
|
28
|
82
|
name: "Editor",
|
29
|
83
|
props: {
|
|
@@ -49,9 +103,18 @@ export default {
|
49
|
103
|
},
|
50
|
104
|
/* 上传文件大小限制(MB) */
|
51
|
105
|
fileSize: {
|
|
106
|
+ type: Number,
|
|
107
|
+ default: 50,
|
|
108
|
+ },
|
|
109
|
+ /* 上传图片大小限制(MB) */
|
|
110
|
+ imageSize: {
|
52
|
111
|
type: Number,
|
53
|
112
|
default: 5,
|
54
|
113
|
},
|
|
114
|
+ videoSize: {
|
|
115
|
+ type: Number,
|
|
116
|
+ default: 500,
|
|
117
|
+ },
|
55
|
118
|
/* 类型(base64格式、url格式) */
|
56
|
119
|
type: {
|
57
|
120
|
type: String,
|
|
@@ -77,7 +140,7 @@ export default {
|
77
|
140
|
["blockquote", "code-block"], // 引用 代码块
|
78
|
141
|
[{ list: "ordered" }, { list: "bullet" }], // 有序、无序列表
|
79
|
142
|
[{ indent: "-1" }, { indent: "+1" }], // 缩进
|
80
|
|
- [{ size: ["small", false, "large", "huge"] }], // 字体大小
|
|
143
|
+ [{ size: ["20px","14px","16px", "large", "huge"] }], // 字体大小
|
81
|
144
|
[{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
|
82
|
145
|
[{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
|
83
|
146
|
[{ align: [] }], // 对齐方式
|
|
@@ -123,8 +186,11 @@ export default {
|
123
|
186
|
},
|
124
|
187
|
methods: {
|
125
|
188
|
init() {
|
|
189
|
+ debugger
|
126
|
190
|
const editor = this.$refs.editor;
|
127
|
191
|
this.Quill = new Quill(editor, this.options);
|
|
192
|
+ var Size = Quill.import("formats/size");
|
|
193
|
+ Size.whitelist = ["14px","16px", "large","20px", "huge"];
|
128
|
194
|
// 如果设置了上传地址则自定义图片上传事件
|
129
|
195
|
if (this.type == 'url') {
|
130
|
196
|
let toolbar = this.Quill.getModule("toolbar");
|
|
@@ -135,6 +201,20 @@ export default {
|
135
|
201
|
this.quill.format("image", false);
|
136
|
202
|
}
|
137
|
203
|
});
|
|
204
|
+ toolbar.addHandler("video", (value) => {
|
|
205
|
+ if (value) {
|
|
206
|
+ this.$refs.uploadVideo.$children[0].$refs.input.click();
|
|
207
|
+ } else {
|
|
208
|
+ this.quill.format("video", false);
|
|
209
|
+ }
|
|
210
|
+ });
|
|
211
|
+ toolbar.addHandler("link", (value) => {
|
|
212
|
+ if (value) {
|
|
213
|
+ this.$refs.uploadFile.$children[0].$refs.input.click();
|
|
214
|
+ } else {
|
|
215
|
+ this.quill.format("link", false);
|
|
216
|
+ }
|
|
217
|
+ });
|
138
|
218
|
}
|
139
|
219
|
this.Quill.pasteHTML(this.currentValue);
|
140
|
220
|
this.Quill.on("text-change", (delta, oldDelta, source) => {
|
|
@@ -164,6 +244,36 @@ export default {
|
164
|
244
|
this.$message.error(`图片格式错误!`);
|
165
|
245
|
return false;
|
166
|
246
|
}
|
|
247
|
+ // 校检文件大小
|
|
248
|
+ if (this.imageSize) {
|
|
249
|
+ const isLt = file.size / 1024 / 1024 < this.imageSize;
|
|
250
|
+ if (!isLt) {
|
|
251
|
+ this.$message.error(`上传文件大小不能超过 ${this.imageSize} MB!`);
|
|
252
|
+ return false;
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+ return true;
|
|
256
|
+ },
|
|
257
|
+ handleBeforeUploadVideo(file) {
|
|
258
|
+ const type = ["video/mp4"];
|
|
259
|
+ const isVideo = type.includes(file.type);
|
|
260
|
+ // 检验文件格式
|
|
261
|
+ if (!isVideo) {
|
|
262
|
+ this.$message.error(`视频格式错误!`);
|
|
263
|
+ return false;
|
|
264
|
+ }
|
|
265
|
+ // 校检文件大小
|
|
266
|
+ if (this.videoSize) {
|
|
267
|
+ const isLt = file.size / 1024 / 1024 < this.videoSize;
|
|
268
|
+ if (!isLt) {
|
|
269
|
+ this.$message.error(`上传文件大小不能超过 ${this.videoSize} MB!`);
|
|
270
|
+ return false;
|
|
271
|
+ }
|
|
272
|
+ }
|
|
273
|
+ return true;
|
|
274
|
+ },
|
|
275
|
+ // 上传前校检格式和大小
|
|
276
|
+ handleBeforeUploadFile(file) {
|
167
|
277
|
// 校检文件大小
|
168
|
278
|
if (this.fileSize) {
|
169
|
279
|
const isLt = file.size / 1024 / 1024 < this.fileSize;
|
|
@@ -175,6 +285,7 @@ export default {
|
175
|
285
|
return true;
|
176
|
286
|
},
|
177
|
287
|
handleUploadSuccess(res, file) {
|
|
288
|
+ debugger
|
178
|
289
|
// 如果上传成功
|
179
|
290
|
if (res.code == 200) {
|
180
|
291
|
// 获取富文本组件实例
|
|
@@ -189,9 +300,50 @@ export default {
|
189
|
300
|
this.$message.error("图片插入失败");
|
190
|
301
|
}
|
191
|
302
|
},
|
|
303
|
+ handleUploadSuccessVideo(res, file) {
|
|
304
|
+ // 如果上传成功
|
|
305
|
+ if (res.code == 200) {
|
|
306
|
+ // 获取富文本组件实例
|
|
307
|
+ let quill = this.Quill;
|
|
308
|
+ // 获取光标所在位置
|
|
309
|
+ let length = quill.getSelection().index;
|
|
310
|
+ // 插入图片 res.url为服务器返回的图片地址
|
|
311
|
+ quill.insertEmbed(length, "video", process.env.VUE_APP_BASE_API + res.fileName);
|
|
312
|
+ // 调整光标到最后
|
|
313
|
+ quill.setSelection(length + 1);
|
|
314
|
+ } else {
|
|
315
|
+ this.$message.error("视频插入失败");
|
|
316
|
+ }
|
|
317
|
+ },
|
|
318
|
+ handleUploadSuccessFile(res, file) {
|
|
319
|
+ // 如果上传成功
|
|
320
|
+ if (res.code == 200) {
|
|
321
|
+ // 获取富文本组件实例
|
|
322
|
+ let quill = this.Quill;
|
|
323
|
+ // 获取光标所在位置
|
|
324
|
+ let length = quill.getSelection().index;
|
|
325
|
+ // 插入文件 res.url为服务器返回的图片地址
|
|
326
|
+ quill.insertEmbed(length, "link",
|
|
327
|
+ {
|
|
328
|
+ href: process.env.VUE_APP_BASE_API + res.fileName,
|
|
329
|
+ innerText: res.originalFilename
|
|
330
|
+ },
|
|
331
|
+ );
|
|
332
|
+ // 调整光标到最后
|
|
333
|
+ quill.setSelection(length + 1);
|
|
334
|
+ } else {
|
|
335
|
+ this.$message.error("文件插入失败");
|
|
336
|
+ }
|
|
337
|
+ },
|
192
|
338
|
handleUploadError() {
|
193
|
339
|
this.$message.error("图片插入失败");
|
194
|
340
|
},
|
|
341
|
+ handleUploadErrorVideo() {
|
|
342
|
+ this.$message.error("视频插入失败");
|
|
343
|
+ },
|
|
344
|
+ handleUploadErrorFile() {
|
|
345
|
+ this.$message.error("文件插入失败");
|
|
346
|
+ },
|
195
|
347
|
},
|
196
|
348
|
};
|
197
|
349
|
</script>
|
|
@@ -204,6 +356,12 @@ export default {
|
204
|
356
|
.quill-img {
|
205
|
357
|
display: none;
|
206
|
358
|
}
|
|
359
|
+.ql-align-right{
|
|
360
|
+ text-align: right;
|
|
361
|
+}
|
|
362
|
+.ql-align-center{
|
|
363
|
+ text-align: center;
|
|
364
|
+}
|
207
|
365
|
.ql-snow .ql-tooltip[data-mode="link"]::before {
|
208
|
366
|
content: "请输入链接地址:";
|
209
|
367
|
}
|
|
@@ -223,14 +381,38 @@ export default {
|
223
|
381
|
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="small"]::before {
|
224
|
382
|
content: "10px";
|
225
|
383
|
}
|
|
384
|
+.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="14px"]::before,
|
|
385
|
+.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="14px"]::before {
|
|
386
|
+ content: "14px";
|
|
387
|
+}
|
|
388
|
+.ql-size-14px {
|
|
389
|
+ font-size: 14px;
|
|
390
|
+}
|
|
391
|
+.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="16px"]::before,
|
|
392
|
+.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="16px"]::before {
|
|
393
|
+ content: "16px";
|
|
394
|
+}
|
|
395
|
+.ql-size-16px {
|
|
396
|
+ font-size: 16px;
|
|
397
|
+}
|
|
398
|
+
|
226
|
399
|
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="large"]::before,
|
227
|
400
|
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="large"]::before {
|
228
|
401
|
content: "18px";
|
229
|
402
|
}
|
|
403
|
+.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="20px"]::before,
|
|
404
|
+.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="20px"]::before {
|
|
405
|
+ content: "20px";
|
|
406
|
+}
|
|
407
|
+.ql-size-20px {
|
|
408
|
+ font-size: 20px;
|
|
409
|
+}
|
230
|
410
|
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="huge"]::before,
|
231
|
411
|
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="huge"]::before {
|
232
|
412
|
content: "32px";
|
233
|
413
|
}
|
|
414
|
+
|
|
415
|
+
|
234
|
416
|
.ql-snow .ql-picker.ql-header .ql-picker-label::before,
|
235
|
417
|
.ql-snow .ql-picker.ql-header .ql-picker-item::before {
|
236
|
418
|
content: "文本";
|
|
@@ -271,4 +453,9 @@ export default {
|
271
|
453
|
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="monospace"]::before {
|
272
|
454
|
content: "等宽字体";
|
273
|
455
|
}
|
|
456
|
+.ql-video {
|
|
457
|
+ width: 100%;
|
|
458
|
+ height: 425px;
|
|
459
|
+}
|
274
|
460
|
</style>
|
|
461
|
+
|