Skip to content

Commit 5b903d7

Browse files
committed
更新 upload 示例
1 parent 2c1c679 commit 5b903d7

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@vue/composition-api": "^1.0.0-rc.5",
1313
"axios": "^0.21.1",
1414
"cl-admin": "^1.5.3",
15-
"cl-admin-crud": "^1.6.5",
15+
"cl-admin-crud": "^1.6.8",
1616
"cl-admin-theme": "^0.0.5",
1717
"clipboard": "^2.0.7",
1818
"codemirror": "^5.59.4",

src/cool/modules/base/components/editor-quill/index.vue

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ref="upload-space"
77
detail-data
88
:show-button="false"
9-
@confirm="onUploadSpaceConfirm"
9+
@confirm="onFileConfirm"
1010
>
1111
</cl-upload-space>
1212
</div>
@@ -15,6 +15,7 @@
1515
<script>
1616
import Quill from "quill";
1717
import "quill/dist/quill.snow.css";
18+
import { isNumber } from "cl-admin/utils";
1819
1920
export default {
2021
name: "cl-editor-quill",
@@ -28,7 +29,6 @@ export default {
2829
2930
data() {
3031
return {
31-
uploadURL: "",
3232
content: "",
3333
quill: null,
3434
cursorIndex: 0
@@ -37,20 +37,12 @@ export default {
3737
3838
computed: {
3939
style() {
40-
let h = this.height;
41-
let w = this.width;
42-
43-
if (!isNaN(Number(h))) {
44-
h += "px";
45-
}
46-
47-
if (!isNaN(Number(w))) {
48-
h += "px";
49-
}
40+
const height = isNumber(this.height) ? this.height + "px" : this.height;
41+
const width = isNumber(this.width) ? this.width + "px" : this.width;
5042
5143
return {
52-
height: h,
53-
width: w
44+
height,
45+
width
5446
};
5547
}
5648
},
@@ -72,6 +64,7 @@ export default {
7264
},
7365
7466
mounted() {
67+
// 实例化
7568
this.quill = new Quill(this.$el.querySelector(".editor"), {
7669
theme: "snow",
7770
placeholder: "输入内容",
@@ -96,18 +89,23 @@ export default {
9689
...this.options
9790
});
9891
99-
this.quill.getModule("toolbar").addHandler("image", this.uploadFileHandler);
92+
// 添加文件上传工具
93+
this.quill.getModule("toolbar").addHandler("image", this.uploadHandler);
10094
95+
// 监听内容变化
10196
this.quill.on("text-change", () => {
10297
this.content = this.quill.root.innerHTML;
10398
});
10499
100+
// 设置默认内容
105101
this.setContent(this.value);
102+
103+
// 加载完回调
106104
this.$emit("load", this.quill);
107105
},
108106
109107
methods: {
110-
uploadFileHandler() {
108+
uploadHandler() {
111109
const selection = this.quill.getSelection();
112110
113111
if (selection) {
@@ -117,8 +115,9 @@ export default {
117115
this.$refs["upload-space"].open();
118116
},
119117
120-
onUploadSpaceConfirm(files) {
118+
onFileConfirm(files) {
121119
if (files.length > 0) {
120+
// 批量插件图片
122121
files.forEach((file, i) => {
123122
let [type] = file.type.split("/");
124123
@@ -129,6 +128,9 @@ export default {
129128
Quill.sources.USER
130129
);
131130
});
131+
132+
// 移动光标到图片后一位
133+
this.quill.setSelection(this.cursorIndex + files.length);
132134
}
133135
},
134136

src/cool/modules/demo/views/upload.vue

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<template>
22
<div class="demo-upload scroller1">
3+
<div class="demo-upload__item">
4+
<p>文件空间</p>
5+
<cl-upload-space v-model="urls"></cl-upload-space>
6+
7+
<p style="margin-top: 10px">选择的文件:</p>
8+
9+
<el-image
10+
v-for="(item, index) in urlList"
11+
:key="index"
12+
:src="item"
13+
:style="{ width: '100px', marginRight: '10px' }"
14+
></el-image>
15+
</div>
16+
317
<div class="demo-upload__item">
418
<p>普通上传</p>
519
<cl-upload :before-upload="onBeforeUpload"></cl-upload>
@@ -33,13 +47,6 @@
3347
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
3448
</cl-upload>
3549
</div>
36-
37-
<div class="demo-upload__item">
38-
<p>文件空间</p>
39-
<cl-upload-space v-model="urls"></cl-upload-space>
40-
41-
<p style="margin-top: 10px">选择的文件:{{ urls }}</p>
42-
</div>
4350
</div>
4451
</template>
4552

@@ -51,6 +58,12 @@ export default {
5158
};
5259
},
5360
61+
computed: {
62+
urlList() {
63+
return this.urls.split(",").filter(Boolean);
64+
}
65+
},
66+
5467
methods: {
5568
onBeforeUpload(file, { done }) {
5669
done();

src/cool/modules/upload/components/space/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
title="文件空间"
1010
height="630px"
1111
width="1000px"
12+
keep-alive
1213
:visible.sync="visible"
1314
:props="{
1415
'close-on-click-modal': false,

0 commit comments

Comments
 (0)