更新 upload 示例

This commit is contained in:
icssoa 2021-03-28 18:19:32 +08:00
parent 2c1c679446
commit 5b903d76bd
4 changed files with 41 additions and 25 deletions

View File

@ -12,7 +12,7 @@
"@vue/composition-api": "^1.0.0-rc.5", "@vue/composition-api": "^1.0.0-rc.5",
"axios": "^0.21.1", "axios": "^0.21.1",
"cl-admin": "^1.5.3", "cl-admin": "^1.5.3",
"cl-admin-crud": "^1.6.5", "cl-admin-crud": "^1.6.8",
"cl-admin-theme": "^0.0.5", "cl-admin-theme": "^0.0.5",
"clipboard": "^2.0.7", "clipboard": "^2.0.7",
"codemirror": "^5.59.4", "codemirror": "^5.59.4",

View File

@ -6,7 +6,7 @@
ref="upload-space" ref="upload-space"
detail-data detail-data
:show-button="false" :show-button="false"
@confirm="onUploadSpaceConfirm" @confirm="onFileConfirm"
> >
</cl-upload-space> </cl-upload-space>
</div> </div>
@ -15,6 +15,7 @@
<script> <script>
import Quill from "quill"; import Quill from "quill";
import "quill/dist/quill.snow.css"; import "quill/dist/quill.snow.css";
import { isNumber } from "cl-admin/utils";
export default { export default {
name: "cl-editor-quill", name: "cl-editor-quill",
@ -28,7 +29,6 @@ export default {
data() { data() {
return { return {
uploadURL: "",
content: "", content: "",
quill: null, quill: null,
cursorIndex: 0 cursorIndex: 0
@ -37,20 +37,12 @@ export default {
computed: { computed: {
style() { style() {
let h = this.height; const height = isNumber(this.height) ? this.height + "px" : this.height;
let w = this.width; const width = isNumber(this.width) ? this.width + "px" : this.width;
if (!isNaN(Number(h))) {
h += "px";
}
if (!isNaN(Number(w))) {
h += "px";
}
return { return {
height: h, height,
width: w width
}; };
} }
}, },
@ -72,6 +64,7 @@ export default {
}, },
mounted() { mounted() {
//
this.quill = new Quill(this.$el.querySelector(".editor"), { this.quill = new Quill(this.$el.querySelector(".editor"), {
theme: "snow", theme: "snow",
placeholder: "输入内容", placeholder: "输入内容",
@ -96,18 +89,23 @@ export default {
...this.options ...this.options
}); });
this.quill.getModule("toolbar").addHandler("image", this.uploadFileHandler); //
this.quill.getModule("toolbar").addHandler("image", this.uploadHandler);
//
this.quill.on("text-change", () => { this.quill.on("text-change", () => {
this.content = this.quill.root.innerHTML; this.content = this.quill.root.innerHTML;
}); });
//
this.setContent(this.value); this.setContent(this.value);
//
this.$emit("load", this.quill); this.$emit("load", this.quill);
}, },
methods: { methods: {
uploadFileHandler() { uploadHandler() {
const selection = this.quill.getSelection(); const selection = this.quill.getSelection();
if (selection) { if (selection) {
@ -117,8 +115,9 @@ export default {
this.$refs["upload-space"].open(); this.$refs["upload-space"].open();
}, },
onUploadSpaceConfirm(files) { onFileConfirm(files) {
if (files.length > 0) { if (files.length > 0) {
//
files.forEach((file, i) => { files.forEach((file, i) => {
let [type] = file.type.split("/"); let [type] = file.type.split("/");
@ -129,6 +128,9 @@ export default {
Quill.sources.USER Quill.sources.USER
); );
}); });
//
this.quill.setSelection(this.cursorIndex + files.length);
} }
}, },

View File

@ -1,5 +1,19 @@
<template> <template>
<div class="demo-upload scroller1"> <div class="demo-upload scroller1">
<div class="demo-upload__item">
<p>文件空间</p>
<cl-upload-space v-model="urls"></cl-upload-space>
<p style="margin-top: 10px">选择的文件</p>
<el-image
v-for="(item, index) in urlList"
:key="index"
:src="item"
:style="{ width: '100px', marginRight: '10px' }"
></el-image>
</div>
<div class="demo-upload__item"> <div class="demo-upload__item">
<p>普通上传</p> <p>普通上传</p>
<cl-upload :before-upload="onBeforeUpload"></cl-upload> <cl-upload :before-upload="onBeforeUpload"></cl-upload>
@ -33,13 +47,6 @@
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div> <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
</cl-upload> </cl-upload>
</div> </div>
<div class="demo-upload__item">
<p>文件空间</p>
<cl-upload-space v-model="urls"></cl-upload-space>
<p style="margin-top: 10px">选择的文件{{ urls }}</p>
</div>
</div> </div>
</template> </template>
@ -51,6 +58,12 @@ export default {
}; };
}, },
computed: {
urlList() {
return this.urls.split(",").filter(Boolean);
}
},
methods: { methods: {
onBeforeUpload(file, { done }) { onBeforeUpload(file, { done }) {
done(); done();

View File

@ -9,6 +9,7 @@
title="文件空间" title="文件空间"
height="630px" height="630px"
width="1000px" width="1000px"
keep-alive
:visible.sync="visible" :visible.sync="visible"
:props="{ :props="{
'close-on-click-modal': false, 'close-on-click-modal': false,