|
|
@@ -326,10 +326,10 @@ const handleUpdate = async (row?: InfoVO) => {
|
|
|
const res = await getInfo(_id);
|
|
|
iconPreviewUrl.value = res.data.imageUrl;
|
|
|
// 去除content中的style属性里的color设置
|
|
|
- let content = res.data.content;
|
|
|
- if (content) {
|
|
|
+ const content = res.data.content;
|
|
|
+ /* if (content) {
|
|
|
content = content.replace(/<p style="color: rgb\(255, 255, 255\);"/g, '<p');
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
Object.assign(form.value, res.data, { content });
|
|
|
|
|
|
@@ -343,11 +343,11 @@ const submitForm = () => {
|
|
|
if (valid) {
|
|
|
const vals = form.value.content;
|
|
|
console.log(vals);
|
|
|
- let modifiedContent = vals;
|
|
|
+ /* let modifiedContent = vals;
|
|
|
if (vals) {
|
|
|
modifiedContent = vals.replace(/<p/g, '<p style="color: rgb(255, 255, 255);"');
|
|
|
}
|
|
|
- form.value.content = modifiedContent;
|
|
|
+ form.value.content = modifiedContent;*/
|
|
|
buttonLoading.value = true;
|
|
|
if (form.value.id) {
|
|
|
await updateInfo(form.value).finally(() => (buttonLoading.value = false));
|
|
|
@@ -484,61 +484,13 @@ const quillEditorRef = ref();
|
|
|
getList();
|
|
|
loadCategoryOptions();
|
|
|
});*/
|
|
|
-import { onMounted, onUnmounted } from 'vue';
|
|
|
-// 监听粘贴事件
|
|
|
-const handlePaste = (e: ClipboardEvent) => {
|
|
|
- const activeElement = document.activeElement;
|
|
|
-
|
|
|
- // 判断是否在富文本编辑器中(通过 class 或 tagName 判断)
|
|
|
- // 常见富文本编辑器的编辑区通常是 contenteditable 的 div
|
|
|
- const isEditor =
|
|
|
- activeElement?.classList.contains('ql-editor') || // Quill
|
|
|
- activeElement?.getAttribute('contenteditable') === 'true' ||
|
|
|
- (activeElement?.tagName === 'DIV' && activeElement?.parentElement?.classList.contains('my-editor')); // 自定义类名
|
|
|
-
|
|
|
- if (!isEditor) return;
|
|
|
-
|
|
|
- e.preventDefault();
|
|
|
- debugger;
|
|
|
- const clipboardData = e.clipboardData || (e as any).originalEvent.clipboardData;
|
|
|
- const html = clipboardData.getData('text/html');
|
|
|
- const text = clipboardData.getData('text/plain');
|
|
|
-
|
|
|
- // 创建临时元素清理 HTML
|
|
|
- const tempDiv = document.createElement('div');
|
|
|
- tempDiv.innerHTML = html || `<p>${text}</p>`;
|
|
|
-
|
|
|
- // 清理所有 style 和 class
|
|
|
- const walk = (node: Node) => {
|
|
|
- if (node.nodeType === Node.ELEMENT_NODE) {
|
|
|
- const el = node as HTMLElement;
|
|
|
- el.removeAttribute('style');
|
|
|
- el.removeAttribute('class');
|
|
|
- el.removeAttribute('id');
|
|
|
- Array.from(el.childNodes).forEach(walk);
|
|
|
- }
|
|
|
- };
|
|
|
- Array.from(tempDiv.childNodes).forEach(walk);
|
|
|
-
|
|
|
- const cleanHtml = tempDiv.innerHTML;
|
|
|
-
|
|
|
- // ✅ 获取当前光标位置并插入内容(关键:使用 document.execCommand)
|
|
|
- document.execCommand('insertHTML', false, cleanHtml);
|
|
|
-};
|
|
|
+import { onMounted } from 'vue';
|
|
|
|
|
|
onMounted(() => {
|
|
|
- // 绑定全局粘贴事件
|
|
|
- //document.addEventListener('paste', handlePaste);
|
|
|
-
|
|
|
// 其他初始化
|
|
|
getList();
|
|
|
loadCategoryOptions();
|
|
|
});
|
|
|
-
|
|
|
-onUnmounted(() => {
|
|
|
- // 移除事件,防止内存泄漏
|
|
|
- document.removeEventListener('paste', handlePaste);
|
|
|
-});
|
|
|
</script>
|
|
|
<style>
|
|
|
.custom-editor-content .ql-editor {
|