tinymce优化

pull/7199/head v3.7.0_all_last
JEECG 3 months ago
parent 824f3c2b90
commit 39ca47d2ef

@ -5,6 +5,7 @@
<ImgUpload <ImgUpload
:fullscreen="fullscreen" :fullscreen="fullscreen"
@uploading="handleImageUploading" @uploading="handleImageUploading"
@loading="handleLoading"
@done="handleDone" @done="handleDone"
v-show="editorRef" v-show="editorRef"
:disabled="disabled" :disabled="disabled"
@ -13,6 +14,7 @@
<!-- update-end--author:liaozhiyang---date:20240517---forTV360X-35富文本图片上传遮挡其他按钮 --> <!-- update-end--author:liaozhiyang---date:20240517---forTV360X-35富文本图片上传遮挡其他按钮 -->
<Editor :id="tinymceId" ref="elRef" :disabled="disabled" :init="initOptions" :style="{ visibility: 'hidden' }" v-if="!initOptions.inline"></Editor> <Editor :id="tinymceId" ref="elRef" :disabled="disabled" :init="initOptions" :style="{ visibility: 'hidden' }" v-if="!initOptions.inline"></Editor>
<slot v-else></slot> <slot v-else></slot>
<ProcessMask ref="processMaskRef" :show="showUploadMask"/>
</div> </div>
</template> </template>
@ -33,6 +35,7 @@
import 'tinymce/plugins/image'; import 'tinymce/plugins/image';
import { defineComponent, computed, nextTick, ref, unref, watch, onDeactivated, onBeforeUnmount, onMounted } from 'vue'; import { defineComponent, computed, nextTick, ref, unref, watch, onDeactivated, onBeforeUnmount, onMounted } from 'vue';
import ImgUpload from './ImgUpload.vue'; import ImgUpload from './ImgUpload.vue';
import ProcessMask from './ProcessMask.vue';
import {simpleToolbar, menubar, simplePlugins} from './tinymce'; import {simpleToolbar, menubar, simplePlugins} from './tinymce';
import { buildShortUUID } from '/@/utils/uuid'; import { buildShortUUID } from '/@/utils/uuid';
import { bindHandlers } from './helper'; import { bindHandlers } from './helper';
@ -82,6 +85,10 @@
type: Boolean, type: Boolean,
default: true, default: true,
}, },
showUploadMask: {
type: Boolean,
default: false,
},
// //
autoFocus:{ autoFocus:{
type: Boolean, type: Boolean,
@ -91,9 +98,9 @@
export default defineComponent({ export default defineComponent({
name: 'Tinymce', name: 'Tinymce',
components: { ImgUpload,Editor }, components: { ImgUpload,Editor,ProcessMask },
inheritAttrs: false, inheritAttrs: false,
props: tinymceProps, props: tinymceProps as any,
emits: ['change', 'update:modelValue', 'inited', 'init-error'], emits: ['change', 'update:modelValue', 'inited', 'init-error'],
setup(props, { emit, attrs }) { setup(props, { emit, attrs }) {
console.log("---Tinymce---初始化---") console.log("---Tinymce---初始化---")
@ -103,6 +110,7 @@
const tinymceId = ref<string>(buildShortUUID('tiny-vue')); const tinymceId = ref<string>(buildShortUUID('tiny-vue'));
const elRef = ref<Nullable<HTMLElement>>(null); const elRef = ref<Nullable<HTMLElement>>(null);
const editorRootRef = ref<Nullable<HTMLElement>>(null); const editorRootRef = ref<Nullable<HTMLElement>>(null);
const processMaskRef = ref<any>(null);
const imgUploadShow = ref(false); const imgUploadShow = ref(false);
const targetElem = ref<null | HTMLDivElement>(null); const targetElem = ref<null | HTMLDivElement>(null);
@ -325,6 +333,20 @@
setValue(editor, val); setValue(editor, val);
} }
/**
* 上传进度计算
* @param file
* @param fileList
*/
function handleLoading(fileLength,showMask){
if(fileLength && fileLength > 0){
setTimeout(() => {
props?.showUploadMask && processMaskRef.value.calcProcess(fileLength)
},100)
}else{
props?.showUploadMask && (processMaskRef.value.showMask = showMask);
}
}
function getUploadingImgName(name: string) { function getUploadingImgName(name: string) {
return `[uploading:${name}]`; return `[uploading:${name}]`;
} }
@ -397,6 +419,9 @@
editorRootRef, editorRootRef,
imgUploadShow, imgUploadShow,
targetElem, targetElem,
handleLoading,
processMaskRef
}; };
}, },
}); });
@ -428,6 +453,7 @@
} }
// update-end--author:liaozhiyang---date:20240527---forTV360X-329 // update-end--author:liaozhiyang---date:20240527---forTV360X-329
} }
html[data-theme='dark'] { html[data-theme='dark'] {
.@{prefix-cls} { .@{prefix-cls} {
.tox .tox-edit-area__iframe {background-color: #141414;} .tox .tox-edit-area__iframe {background-color: #141414;}

@ -8,6 +8,7 @@
:showUploadList="false" :showUploadList="false"
:data="getBizData()" :data="getBizData()"
:headers="getheader()" :headers="getheader()"
:before-upload="beforeUpload"
accept=".jpg,.jpeg,.gif,.png,.webp" accept=".jpg,.jpeg,.gif,.png,.webp"
> >
<a-button type="primary" v-bind="{ ...getButtonProps }"> <a-button type="primary" v-bind="{ ...getButtonProps }">
@ -37,10 +38,8 @@
default: false, default: false,
}, },
}, },
emits: ['uploading', 'done', 'error'], emits: ['uploading', 'done', 'error', 'loading'],
setup(props, { emit }) { setup(props, { emit }) {
let uploading = false;
//update-begin-author:taoyan date:2022-5-13 for: //update-begin-author:taoyan date:2022-5-13 for:
function getheader() { function getheader() {
return getHeaders(); return getHeaders();
@ -67,33 +66,37 @@
}; };
}); });
let uploadLength = 0;
function handleChange({ file, fileList }) { function handleChange({ file, fileList }) {
if (file.status === 'error') { //
emit('error'); fileList = fileList.filter((file) => {
uploading = false; const existFile = uploadFileList.value.find(({ uid }) => uid === file.uid);
return existFile ? false : true;
});
uploadLength == 0 && (uploadLength = fileList.length);
if (file.status != 'uploading') {
emit('loading', uploadLength, true);
} }
let files = [] as any; //
let noUploadingFileCount = 0;
if (file.status != 'uploading') { if (file.status != 'uploading') {
fileList.forEach((file) => { fileList.forEach((file) => {
if (file.status === 'done' && file.response.success) { if (file.status === 'done' && file.response.success) {
files.push(file); const name = file?.name;
} let realUrl = getFileAccessHttpUrl(file.response.message);
if (file.status != 'uploading') { uploadFileList.value.push(file);
noUploadingFileCount++; emit('done', name, realUrl);
} }
}); });
} }
if (noUploadingFileCount == fileList.length) {
fileList.forEach((file) => {
const name = file?.name;
let realUrl = getFileAccessHttpUrl(file.response.message);
emit('done', name, realUrl);
});
}
} }
//
function beforeUpload() {
uploadLength = 0;
emit('loading', null, true);
setTimeout(() => {
emit('loading', null, false);
}, 10000);
}
return { return {
prefixCls, prefixCls,
handleChange, handleChange,
@ -102,7 +105,8 @@
getBizData, getBizData,
t, t,
getButtonProps, getButtonProps,
uploadFileList uploadFileList,
beforeUpload,
}; };
}, },
}); });

@ -0,0 +1,99 @@
<template>
<div class="mask" v-if="showMask && show">
<div class="progress-bar-rear">
<div class="progress-bar-front" :style="{ width: progressBarWidth }"></div>
</div>
<div class="value">{{ percentage }}</div>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
const props = defineProps({
backColor: {
type: [String],
default: 'white',
},
processColor: {
type: String,
default: '#018FFB',
},
show: {
type: Boolean,
default: false,
},
});
//
const showMask = ref(false);
//
const progressValue = ref<any>(0);
//
const currentNum = ref(0);
//
const progressBarWidth = computed(() => {
return progressValue.value > 0 ? `${progressValue.value}px` : '0px';
});
//
const percentage = computed(() => {
return `${progressValue.value}%`;
});
//
const frontColor = computed(() => {
return props.processColor;
});
//
const rearColor = computed(() => {
return props.backColor;
});
function calcProcess(totalNum) {
!showMask.value && (showMask.value = true);
currentNum.value += 1;
progressValue.value = ((currentNum.value / totalNum) * 100).toFixed(2);
console.log('currentNum.value', currentNum.value);
console.log('totalNum.value', totalNum);
if (currentNum.value == totalNum) {
showMask.value = false;
currentNum.value = 0;
progressValue.value = 0;
}
}
defineExpose({
calcProcess,
showMask,
});
</script>
<style lang="less">
.mask {
position: absolute; /* 或者使用固定定位等其他方式 */
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5); /* 半透明遮罩 */
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
z-index: 99;
}
.progress-bar-rear {
width: 100px; /* 进度条宽度 */
height: 10px; /* 进度条高度 */
background-color: v-bind(rearColor); /* 进度条颜色 */
border-radius: 4px;
}
.progress-bar-front {
height: 10px; /* 进度条高度 */
background-color: v-bind(frontColor); /* 进度条颜色 */
border-radius: 4px;
}
.value {
color: #fff;
margin-left: 5px;
font-size: 16px;
font-weight: 600;
}
</style>
Loading…
Cancel
Save