feat: 富文本支持文件上传功能

This commit is contained in:
lbw 2023-03-09 13:45:24 +08:00
parent c39a034fb2
commit 4ecc06b17d
4 changed files with 29 additions and 10 deletions

View File

@ -14,8 +14,8 @@
"@chenfengyuan/vue-qrcode": "^2.0.0", "@chenfengyuan/vue-qrcode": "^2.0.0",
"@element-plus/icons-vue": "^2.0.10", "@element-plus/icons-vue": "^2.0.10",
"@highlightjs/vue-plugin": "^2.1.0", "@highlightjs/vue-plugin": "^2.1.0",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12", "@wangeditor/editor-for-vue": "5.1.12",
"axios": "^1.3.3", "axios": "^1.3.3",
"crypto-js": "^3.1.9-1", "crypto-js": "^3.1.9-1",
"echarts": "^5.4.1", "echarts": "^5.4.1",

View File

@ -19,6 +19,7 @@ import { reactive, shallowRef, watch, onBeforeUnmount } from 'vue';
// @ts-ignore // @ts-ignore
import { IDomEditor } from '@wangeditor/editor'; import { IDomEditor } from '@wangeditor/editor';
import { Toolbar, Editor } from '@wangeditor/editor-for-vue'; import { Toolbar, Editor } from '@wangeditor/editor-for-vue';
import { Session } from '/@/utils/storage';
// //
const props = defineProps({ const props = defineProps({
@ -47,16 +48,41 @@ const props = defineProps({
getHtml: String, getHtml: String,
// editor.getText() // editor.getText()
getText: String, getText: String,
uploadFileUrl: {
type: String,
default: '/admin/sys-file/upload',
},
}); });
// / // /
const emit = defineEmits(['update:getHtml', 'update:getText']); const emit = defineEmits(['update:getHtml', 'update:getText']);
// //
const headers = computed(() => {
return {
Authorization: 'Bearer ' + Session.get('token'),
'TENANT-ID': Session.getTenant(),
};
});
//
const uploadAttr = reactive({
fieldName: 'file',
server: props.uploadFileUrl,
headers: headers,
customInsert(res, insertFn) {
insertFn(res.data.url);
},
});
const editorRef = shallowRef(); const editorRef = shallowRef();
const state = reactive({ const state = reactive({
editorConfig: { editorConfig: {
placeholder: props.placeholder, placeholder: props.placeholder,
MENU_CONF: {
uploadImage: uploadAttr,
uploadVideo: uploadAttr,
},
}, },
editorVal: props.getHtml, editorVal: props.getHtml,
}); });

View File

@ -51,9 +51,6 @@
import { useMessage } from '/@/hooks/message'; import { useMessage } from '/@/hooks/message';
import other from '/@/utils/other'; import other from '/@/utils/other';
import { Session } from '/@/utils/storage'; import { Session } from '/@/utils/storage';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const emit = defineEmits(['sizeChange', 'refreshDataList']); const emit = defineEmits(['sizeChange', 'refreshDataList']);
const prop = defineProps({ const prop = defineProps({

View File

@ -60,10 +60,6 @@
<script setup lang="ts" name="upload-file"> <script setup lang="ts" name="upload-file">
import { useMessage } from '/@/hooks/message'; import { useMessage } from '/@/hooks/message';
import { Local, Session } from '/@/utils/storage'; import { Local, Session } from '/@/utils/storage';
import {useI18n} from 'vue-i18n';
const {t} = useI18n()
const props = defineProps({ const props = defineProps({
modelValue: [String, Array], modelValue: [String, Array],
// //