|
@@ -1,23 +1,14 @@
|
|
|
<script lang="ts" setup>
|
|
|
-import { PropType, computed, ref, shallowRef, unref, watch } from 'vue'
|
|
|
+import { PropType, computed, ref, shallowRef, unref, watch, onBeforeUnmount, nextTick } from 'vue'
|
|
|
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
|
|
-import { i18nChangeLanguage, IDomEditor, IEditorConfig } from '@wangeditor/editor'
|
|
|
+import { IDomEditor, IEditorConfig } from '@wangeditor/editor'
|
|
|
import { isNumber } from '@/utils/is'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
-import { useLocaleStore } from '@/store/modules/locale'
|
|
|
-import { getAccessToken, getTenantId } from '@/utils/auth'
|
|
|
-import { getUploadUrl } from '@/components/UploadFile/src/useUpload'
|
|
|
|
|
|
defineOptions({ name: 'Editor' })
|
|
|
|
|
|
type InsertFnType = (url: string, alt: string, href: string) => void
|
|
|
|
|
|
-const localeStore = useLocaleStore()
|
|
|
-
|
|
|
-const currentLocale = computed(() => localeStore.getCurrentLocale)
|
|
|
-
|
|
|
-i18nChangeLanguage(unref(currentLocale).lang)
|
|
|
-
|
|
|
// 使用普通的props定义方式,不使用propTypes
|
|
|
const props = defineProps({
|
|
|
editorId: { type: String, default: 'wangeEditor-1' },
|
|
@@ -87,104 +78,6 @@ const editorConfig = computed((): IEditorConfig => {
|
|
|
},
|
|
|
autoFocus: false,
|
|
|
scroll: true,
|
|
|
- MENU_CONF: {
|
|
|
- ['uploadImage']: {
|
|
|
- server: getUploadUrl(),
|
|
|
- // 单个文件的最大体积限制,默认为 2M
|
|
|
- maxFileSize: 5 * 1024 * 1024,
|
|
|
- // 最多可上传几个文件,默认为 100
|
|
|
- maxNumberOfFiles: 10,
|
|
|
- // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 []
|
|
|
- allowedFileTypes: ['image/*'],
|
|
|
-
|
|
|
- // 自定义增加 http header
|
|
|
- headers: {
|
|
|
- Accept: '*',
|
|
|
- Authorization: 'Bearer ' + getAccessToken(),
|
|
|
- 'tenant-id': getTenantId()
|
|
|
- },
|
|
|
-
|
|
|
- // 超时时间,默认为 10 秒
|
|
|
- timeout: 5 * 1000, // 5 秒
|
|
|
-
|
|
|
- // form-data fieldName,后端接口参数名称,默认值wangeditor-uploaded-image
|
|
|
- fieldName: 'file',
|
|
|
-
|
|
|
- // 上传之前触发
|
|
|
- onBeforeUpload(file: File) {
|
|
|
- // console.log(file)
|
|
|
- return file
|
|
|
- },
|
|
|
- // 上传进度的回调函数
|
|
|
- onProgress(progress: number) {
|
|
|
- // progress 是 0-100 的数字
|
|
|
- console.log('progress', progress)
|
|
|
- },
|
|
|
- onSuccess(file: File, res: any) {
|
|
|
- console.log('onSuccess', file, res)
|
|
|
- },
|
|
|
- onFailed(file: File, res: any) {
|
|
|
- alert(res.message)
|
|
|
- console.log('onFailed', file, res)
|
|
|
- },
|
|
|
- onError(file: File, err: any, res: any) {
|
|
|
- alert(err.message)
|
|
|
- console.error('onError', file, err, res)
|
|
|
- },
|
|
|
- // 自定义插入图片
|
|
|
- customInsert(res: any, insertFn: InsertFnType) {
|
|
|
- insertFn(res.data, 'image', res.data)
|
|
|
- }
|
|
|
- },
|
|
|
- ['uploadVideo']: {
|
|
|
- server: getUploadUrl(),
|
|
|
- // 单个文件的最大体积限制,默认为 10M
|
|
|
- maxFileSize: 10 * 1024 * 1024,
|
|
|
- // 最多可上传几个文件,默认为 100
|
|
|
- maxNumberOfFiles: 10,
|
|
|
- // 选择文件时的类型限制,默认为 ['video/*'] 。如不想限制,则设置为 []
|
|
|
- allowedFileTypes: ['video/*'],
|
|
|
-
|
|
|
- // 自定义增加 http header
|
|
|
- headers: {
|
|
|
- Accept: '*',
|
|
|
- Authorization: 'Bearer ' + getAccessToken(),
|
|
|
- 'tenant-id': getTenantId()
|
|
|
- },
|
|
|
-
|
|
|
- // 超时时间,默认为 30 秒
|
|
|
- timeout: 15 * 1000, // 15 秒
|
|
|
-
|
|
|
- // form-data fieldName,后端接口参数名称,默认值wangeditor-uploaded-image
|
|
|
- fieldName: 'file',
|
|
|
-
|
|
|
- // 上传之前触发
|
|
|
- onBeforeUpload(file: File) {
|
|
|
- // console.log(file)
|
|
|
- return file
|
|
|
- },
|
|
|
- // 上传进度的回调函数
|
|
|
- onProgress(progress: number) {
|
|
|
- // progress 是 0-100 的数字
|
|
|
- console.log('progress', progress)
|
|
|
- },
|
|
|
- onSuccess(file: File, res: any) {
|
|
|
- console.log('onSuccess', file, res)
|
|
|
- },
|
|
|
- onFailed(file: File, res: any) {
|
|
|
- alert(res.message)
|
|
|
- console.log('onFailed', file, res)
|
|
|
- },
|
|
|
- onError(file: File, err: any, res: any) {
|
|
|
- alert(err.message)
|
|
|
- console.error('onError', file, err, res)
|
|
|
- },
|
|
|
- // 自定义插入图片
|
|
|
- customInsert(res: any, insertFn: InsertFnType) {
|
|
|
- insertFn(res.data, 'mp4', res.data)
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
uploadImgShowBase64: true
|
|
|
},
|
|
|
props.editorConfig || {}
|