|
@@ -17,7 +17,7 @@
|
|
|
import {nextTick, computed, inject, shallowRef, onBeforeUnmount, ref} from "vue";
|
|
import {nextTick, computed, inject, shallowRef, onBeforeUnmount, ref} from "vue";
|
|
|
import {IToolbarConfig, IEditorConfig} from "@wangeditor/editor";
|
|
import {IToolbarConfig, IEditorConfig} from "@wangeditor/editor";
|
|
|
import {Editor, Toolbar} from "@wangeditor/editor-for-vue";
|
|
import {Editor, Toolbar} from "@wangeditor/editor-for-vue";
|
|
|
-import {UploadFiles} from "../../api/uploadFile.js";
|
|
|
|
|
|
|
+import {uploadImg} from "../../api/modules/upload.js";
|
|
|
|
|
|
|
|
import "@wangeditor/editor/dist/css/style.css";
|
|
import "@wangeditor/editor/dist/css/style.css";
|
|
|
import {ElNotification, formContextKey, formItemContextKey} from "element-plus";
|
|
import {ElNotification, formContextKey, formItemContextKey} from "element-plus";
|
|
@@ -28,6 +28,10 @@ const editorRef = shallowRef();
|
|
|
// 实列化编辑器
|
|
// 实列化编辑器
|
|
|
const handleCreated = (editor: any) => {
|
|
const handleCreated = (editor: any) => {
|
|
|
editorRef.value = editor;
|
|
editorRef.value = editor;
|
|
|
|
|
+ // 如果需要禁用,在编辑器创建后执行
|
|
|
|
|
+ if (self_disabled.value) {
|
|
|
|
|
+ editor.disable();
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 接收父组件参数,并设置默认值
|
|
// 接收父组件参数,并设置默认值
|
|
@@ -68,8 +72,7 @@ const self_disabled = computed(() => {
|
|
|
return props.disabled || formContext?.disabled;
|
|
return props.disabled || formContext?.disabled;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-// 判断当前富文本编辑器是否禁用
|
|
|
|
|
-if (self_disabled.value) nextTick(() => editorRef.value.disable());
|
|
|
|
|
|
|
+// 注意:禁用逻辑已移至 handleCreated 中处理
|
|
|
|
|
|
|
|
// 富文本的内容监听,触发父组件改变,实现双向数据绑定
|
|
// 富文本的内容监听,触发父组件改变,实现双向数据绑定
|
|
|
const emit = defineEmits<{
|
|
const emit = defineEmits<{
|
|
@@ -97,15 +100,17 @@ props.editorConfig.MENU_CONF!["uploadImage"] = {
|
|
|
async customUpload(file: File, insertFn: InsertFnTypeImg) {
|
|
async customUpload(file: File, insertFn: InsertFnTypeImg) {
|
|
|
if (!uploadImgValidate(file)) return;
|
|
if (!uploadImgValidate(file)) return;
|
|
|
try {
|
|
try {
|
|
|
- const res = await UploadFiles(file);
|
|
|
|
|
- if (res?.res?.requestUrls?.length) {
|
|
|
|
|
- insertFn(res.res.requestUrls[0]);
|
|
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ formData.append("file", file);
|
|
|
|
|
+ const res = await uploadImg(formData);
|
|
|
|
|
+ if (res?.code === 200 && res?.data?.path) {
|
|
|
|
|
+ insertFn(res.data.path);
|
|
|
} else {
|
|
} else {
|
|
|
-
|
|
|
|
|
|
|
+ ElNotification.error(res?.msg || "上传失败");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
|
|
+ ElNotification.error("上传失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -152,20 +157,18 @@ type InsertFnTypeVideo = (url: string, poster?: string) => void;
|
|
|
props.editorConfig.MENU_CONF!["uploadVideo"] = {
|
|
props.editorConfig.MENU_CONF!["uploadVideo"] = {
|
|
|
async customUpload(file: File, insertFn: InsertFnTypeVideo) {
|
|
async customUpload(file: File, insertFn: InsertFnTypeVideo) {
|
|
|
if (!uploadVideoValidate(file)) return;
|
|
if (!uploadVideoValidate(file)) return;
|
|
|
- let formData = new FormData();
|
|
|
|
|
- formData.append("file", file);
|
|
|
|
|
try {
|
|
try {
|
|
|
- //const {data} = await UploadFiles(file);
|
|
|
|
|
- //insertFn(data.fileUrl);
|
|
|
|
|
- const res = await UploadFiles(file);
|
|
|
|
|
- console.log(res, 333)
|
|
|
|
|
- if (res?.res?.requestUrls?.length) {
|
|
|
|
|
- insertFn(res.res.requestUrls[0]);
|
|
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ formData.append("file", file);
|
|
|
|
|
+ const res = await uploadImg(formData);
|
|
|
|
|
+ if (res?.code === 200 && res?.data?.path) {
|
|
|
|
|
+ insertFn(res.data.path);
|
|
|
} else {
|
|
} else {
|
|
|
-
|
|
|
|
|
|
|
+ ElNotification.error(res?.msg || "上传失败");
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
|
|
+ ElNotification.error("上传失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|