Commit 969f9d03275d8d45bec864286d3db829a526eaca

Authored by YunaiV
1 parent 2579e854

v3.7.0 富文本新增上传文件大小限制

yudao-ui-admin/src/components/Editor/index.vue
... ... @@ -2,6 +2,7 @@
2 2 <div>
3 3 <el-upload
4 4 :action="uploadUrl"
  5 + :before-upload="handleBeforeUpload"
5 6 :on-success="handleUploadSuccess"
6 7 :on-error="handleUploadError"
7 8 name="file"
... ... @@ -46,6 +47,11 @@ export default {
46 47 type: Boolean,
47 48 default: false,
48 49 },
  50 + // 上传文件大小限制(MB)
  51 + fileSize: {
  52 + type: Number,
  53 + default: 5,
  54 + },
49 55 /* 类型(base64格式、url格式) */
50 56 type: {
51 57 type: String,
... ... @@ -130,14 +136,6 @@ export default {
130 136 this.quill.format("image", false);
131 137 }
132 138 });
133   - toolbar.addHandler("video", (value) => {
134   - this.uploadType = "video";
135   - if (value) {
136   - this.$refs.upload.$children[0].$refs.input.click();
137   - } else {
138   - this.quill.format("video", false);
139   - }
140   - });
141 139 }
142 140 this.Quill.pasteHTML(this.currentValue);
143 141 this.Quill.on("text-change", (delta, oldDelta, source) => {
... ... @@ -158,6 +156,18 @@ export default {
158 156 this.$emit("on-editor-change", eventName, ...args);
159 157 });
160 158 },
  159 + // 上传前校检格式和大小
  160 + handleBeforeUpload(file) {
  161 + // 校检文件大小
  162 + if (this.fileSize) {
  163 + const isLt = file.size / 1024 / 1024 < this.fileSize;
  164 + if (!isLt) {
  165 + this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
  166 + return false;
  167 + }
  168 + }
  169 + return true;
  170 + },
161 171 handleUploadSuccess(res, file) {
162 172 // 获取富文本组件实例
163 173 let quill = this.Quill;
... ...