Explorar o código

完善后台富文本编辑与 Word 格式导入

为文章编辑器补充宋体、仿宋、楷体、黑体、微软雅黑等常用中文字体和常用 Word 字号,并允许保留 Word 中的任意字体和字号。

新增“首行缩进两字符”工具栏按钮,将选中段落切换为 text-indent:2em,可再次点击取消;补充 text-indent 的前台/后台双向转换。

优化混合剪贴板处理:同时包含文字和图片时,先上传图片,再将原文字和图片一起插入正文,避免 CKEditor 只保留其中一种内容。

Word 导入优先使用文章页签发的 sys.convert_html 会话地址和 LibreOffice 转换,保留字体、字号、颜色、粗体、对齐、缩进、表格和图片;转换器不可用时回退到增强 Mammoth,并保留标题、列表、粗斜体、表格和图片。

同步更新文章发布、变动、修改页面的脚本缓存版本,并补充 HXCS 发布验收项。

Validation:
- 本地端到端验证常用中文字体下拉存在
- 首行缩进输出 text-indent:2em,取消后移除
- 文字与图片混合粘贴后两者均保留,图片上传成功
- LibreOffice 转换 HTML 插入后保留字体、字号、颜色、粗体、对齐和 2em 首行缩进
- node --check、bash -n、Git diff 检查通过
非繁 hai 1 mes
pai
achega
8a3c60f16b

+ 576 - 16
WebRoot/apps/space/js/space.vue.subassembly.js

@@ -414,7 +414,7 @@ Vue.component('spaceEditor', {
 	 * type:编辑器工具栏类型
 	 * isfullscreen:是否有全屏,
 	 */
-	props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl'],
+		props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl', 'wordconverturl'],
 	computed: {
 		previewFrameStyle: function () {
 			var widthMap = {
@@ -523,6 +523,30 @@ Vue.component('spaceEditor', {
 			}
 			return this.normalizeLocalUploadUrl(url);
 		},
+			getEditorEditableElement: function (editor) {
+				if (!editor) {
+					return null;
+				}
+				if (editor.ui && editor.ui.view && editor.ui.view.editable && editor.ui.view.editable.element) {
+					return editor.ui.view.editable.element;
+				}
+				if (editor.editing && editor.editing.view && typeof editor.editing.view.getDomRoot === 'function') {
+					var domRoot = editor.editing.view.getDomRoot();
+					if (domRoot) {
+						return domRoot;
+					}
+				}
+				if (editor.ui && typeof editor.ui.getEditableElement === 'function') {
+					var editable = editor.ui.getEditableElement();
+					if (editable) {
+						return editable;
+					}
+				}
+				if (editor.ui && editor.ui.view && editor.ui.view.element) {
+					return editor.ui.view.element.querySelector('.ck-editor__editable_inline');
+				}
+				return null;
+			},
 		normalizeVideoHtmlForEditor: function (html) {
 			if (!html || html.indexOf("<video") === -1 || html.indexOf("<source") === -1) {
 				return html || "";
@@ -700,9 +724,7 @@ Vue.component('spaceEditor', {
 			}.bind(this);
 
 			var editorImages = [];
-			var editable = this.editor.ui && this.editor.ui.getEditableElement
-				? this.editor.ui.getEditableElement()
-				: null;
+			var editable = this.getEditorEditableElement(this.editor);
 			if (editable) {
 				var domImages = editable.querySelectorAll("img");
 				for (var i = 0; i < domImages.length; i++) {
@@ -1008,7 +1030,7 @@ Vue.component('spaceEditor', {
 					data.preventDefault();
 				}
 			}, { priority: "high" });
-			var editable = editor.ui.getEditableElement();
+			var editable = _this.getEditorEditableElement(editor);
 			if (editable) {
 				editable.addEventListener("keydown", function (event) {
 					if (event.keyCode !== 8 && event.keyCode !== 46) {
@@ -1674,6 +1696,145 @@ Vue.component('spaceEditor', {
 
 			return toolbar;
 		},
+			installFirstLineIndentPlugin: function (editor) {
+				if (!editor.model.schema.checkAttribute('$block', 'textIndent')) {
+					editor.model.schema.extend('$block', { allowAttributes: ['textIndent'] });
+				}
+
+				editor.conversion.attributeToAttribute({
+					model: { key: 'textIndent', value: '2em' },
+					view: { key: 'style', value: { 'text-indent': '2em' } }
+				});
+			},
+			getSelectedTextBlocks: function (editor) {
+				var blocks = [];
+				var selection = editor.model.document.selection;
+				if (!selection.isCollapsed && typeof selection.getSelectedBlocks === 'function') {
+					blocks = Array.prototype.slice.call(selection.getSelectedBlocks());
+				} else {
+					var node = selection.getFirstPosition().parent;
+					while (node && (!node.is || !node.is('element') || !editor.model.schema.isBlock(node.name))) {
+						node = node.parent;
+					}
+					if (node && node.is('element')) {
+						blocks.push(node);
+					}
+				}
+
+				return blocks.filter(function (block) {
+					return block && editor.model.schema.checkAttribute(block.name, 'textIndent');
+				});
+			},
+			toggleFirstLineIndent: function (editor) {
+				var blocks = this.getSelectedTextBlocks(editor);
+				if (!blocks.length) {
+					return;
+				}
+
+				var removeIndent = blocks.every(function (block) {
+					return block.getAttribute('textIndent') === '2em';
+				});
+				editor.model.change(function (writer) {
+					blocks.forEach(function (block) {
+						if (removeIndent) {
+							writer.removeAttribute('textIndent', block);
+						} else {
+							writer.setAttribute('textIndent', '2em', block);
+						}
+					});
+				});
+				editor.editing.view.focus();
+			},
+			refreshFirstLineIndentButton: function (editor) {
+				if (!editor || !editor.ui || !editor.ui.view || !editor.ui.view.element) {
+					return;
+				}
+
+				var button = editor.ui.view.element.querySelector('[data-space-first-line-indent="true"]');
+				if (!button) {
+					return;
+				}
+
+				var blocks = this.getSelectedTextBlocks(editor);
+				var active = blocks.length > 0 && blocks.every(function (block) {
+					return block.getAttribute('textIndent') === '2em';
+				});
+				button.classList.toggle('ck-on', active);
+				button.classList.toggle('ck-off', !active);
+				button.setAttribute('aria-pressed', active ? 'true' : 'false');
+			},
+			mountFirstLineIndentToolbarButton: function (editor) {
+				if (!editor || !editor.ui || !editor.ui.view || !editor.ui.view.element) {
+					return;
+				}
+
+				var toolbarItems = editor.ui.view.element.querySelector('.ck-toolbar__items');
+				if (!toolbarItems || toolbarItems.querySelector('[data-space-first-line-indent="true"]')) {
+					return;
+				}
+
+				var buttons = toolbarItems.querySelectorAll('.ck-button');
+				var templateButton = null;
+				var outdentButton = null;
+				for (var i = 0; i < buttons.length; i++) {
+					var label = buttons[i].getAttribute('aria-label') || buttons[i].textContent || '';
+					if (!templateButton && buttons[i].querySelector('svg.ck-button__icon')) {
+						templateButton = buttons[i];
+					}
+					if (label.indexOf('减少缩进') !== -1 || label.indexOf('减少縮排') !== -1) {
+						outdentButton = buttons[i];
+						if (!templateButton) {
+							templateButton = buttons[i];
+						}
+					}
+				}
+				if (!templateButton) {
+					return;
+				}
+
+				var button = templateButton.cloneNode(true);
+				button.removeAttribute('aria-disabled');
+				button.removeAttribute('aria-labelledby');
+				button.removeAttribute('aria-haspopup');
+				button.setAttribute('aria-label', '首行缩进两字符');
+				button.setAttribute('aria-pressed', 'false');
+				button.setAttribute('title', '首行缩进两字符');
+				button.setAttribute('data-space-first-line-indent', 'true');
+				button.classList.remove('ck-disabled', 'ck-on');
+				button.classList.add('ck-off');
+				button.tabIndex = 0;
+
+				var tooltipText = button.querySelector('.ck-tooltip__text');
+				if (tooltipText) {
+					tooltipText.textContent = '首行缩进两字符';
+				}
+				var buttonLabel = button.querySelector('.ck-button__label');
+				if (buttonLabel) {
+					buttonLabel.textContent = '首行缩进两字符';
+				}
+
+				var _this = this;
+				button.addEventListener('click', function (event) {
+					event.preventDefault();
+					event.stopPropagation();
+					_this.toggleFirstLineIndent(editor);
+				});
+
+				var referenceButton = outdentButton || templateButton;
+				if (referenceButton && referenceButton.parentNode === toolbarItems) {
+					toolbarItems.insertBefore(button, referenceButton.nextSibling);
+				} else {
+					toolbarItems.appendChild(button);
+				}
+
+				editor.model.document.selection.on('change', function () {
+					_this.refreshFirstLineIndentButton(editor);
+				});
+				editor.model.document.on('change:data', function () {
+					_this.refreshFirstLineIndentButton(editor);
+				});
+				this.refreshFirstLineIndentButton(editor);
+			},
 		alignFullScreenToolbarButton: function () {
 			if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
 				return;
@@ -2111,6 +2272,259 @@ Vue.component('spaceEditor', {
 			this.deferSyncEditorPlayableVideos();
 			space.message.success("正文已完成排版整理");
 		},
+			configureWordUploadPlugin: function (editor) {
+				if (!editor || !editor.plugins) {
+					return;
+				}
+
+				var wordUi = null;
+				try {
+					wordUi = editor.plugins.get('WordUploadUi');
+				} catch (error) {
+					for (var entry of editor.plugins) {
+						var plugin = Array.isArray(entry) ? entry[1] : entry;
+						if (plugin && typeof plugin.importWordFile === 'function') {
+							wordUi = plugin;
+							break;
+						}
+					}
+				}
+				if (!wordUi || wordUi.spaceFormatOverride) {
+					return;
+				}
+
+				var _this = this;
+				wordUi.spaceFormatOverride = true;
+				wordUi.importWordFile = function (targetEditor, file) {
+					return _this.importFormattedWordFile(targetEditor, file, wordUi);
+				};
+			},
+			importFormattedWordFile: function (editor, file, wordUi) {
+				if (!file) {
+					return;
+				}
+
+				var fileName = (file.name || '').toLowerCase();
+				if (!/\.(doc|docx)$/.test(fileName)) {
+					wordUi.showMessage('error', '请选择 .doc 或 .docx 格式的 Word 文件。');
+					return;
+				}
+
+				wordUi.showLoading();
+				this.uploadStatus = '正在导入 Word 文档…';
+				return this.convertWordWithServer(file)
+					.catch(function (error) {
+						if (!/\.docx$/.test(fileName)) {
+							throw new Error('旧版 .doc 转换失败,请在 Word 中另存为 .docx 后再导入。');
+						}
+						console.warn('LibreOffice Word conversion unavailable, fallback to mammoth:', error);
+						return this.convertWordWithMammoth(file, wordUi);
+					}.bind(this))
+					.then(function (result) {
+						var htmlContent = this.normalizeImportedWordHtml(wordUi, result.html);
+						if (!htmlContent) {
+							throw new Error('没有读取到可导入的正文内容。');
+						}
+
+						this.insertFormattedWordHtml(editor, htmlContent);
+						if (result.messages && result.messages.length) {
+							wordUi.showMessage('warning', 'Word 已导入,少量复杂格式可能需要人工检查。');
+						} else {
+							wordUi.showMessage('success', 'Word 文件已导入正文,并尽量保留原文档格式。');
+						}
+					}.bind(this))
+					.catch(function (error) {
+						console.error(error);
+						wordUi.showMessage('error', error && error.message ? error.message : 'Word 文件导入失败,请确认文件未损坏。');
+					})
+					.finally(function () {
+						this.uploadStatus = '';
+						wordUi.closeLoading();
+					}.bind(this));
+			},
+			convertWordWithMammoth: function (file, wordUi) {
+				return wordUi.loadMammoth()
+					.then(function () { return wordUi.readFileAsArrayBuffer(file); })
+					.then(function (arrayBuffer) {
+						return window.mammoth.convertToHtml({ arrayBuffer: arrayBuffer }, {
+							convertImage: window.mammoth.images.imgElement(function (image) {
+								return image.read('base64').then(function (imageBuffer) {
+									return { src: 'data:' + image.contentType + ';base64,' + imageBuffer };
+								});
+							}),
+							styleMap: [
+								"p[style-name='Title'] => h1:fresh",
+								"p[style-name='Subtitle'] => p.subtitle:fresh",
+								"p[style-name='标题'] => h2:fresh",
+								"p[style-name='标题 1'] => h2:fresh",
+								"p[style-name='标题 2'] => h3:fresh",
+								"p[style-name='标题 3'] => h4:fresh",
+								"p[style-name='标题 4'] => h5:fresh",
+								"p[style-name='Heading 1'] => h2:fresh",
+								"p[style-name='Heading 2'] => h3:fresh",
+								"p[style-name='Heading 3'] => h4:fresh",
+								"p[style-name='Heading 4'] => h5:fresh",
+								"p[style-name='正文'] => p:fresh",
+								"p[style-name='Normal'] => p:fresh",
+								"p[style-name='Body Text'] => p:fresh",
+								"p[style-name='Quote'] => blockquote:fresh",
+								"p[style-name='引用'] => blockquote:fresh",
+								"r[style-name='Strong'] => strong",
+								"r[style-name='Emphasis'] => em",
+								"r[style-name='加粗'] => strong",
+								"r[style-name='倾斜'] => em"
+							]
+						});
+					})
+					.then(function (conversion) {
+						return { html: conversion.value, messages: conversion.messages || [] };
+					});
+			},
+			normalizeImportedWordHtml: function (wordUi, html) {
+				var normalized = wordUi.normalizeWordHtml(html || '');
+				if (!normalized) {
+					return '';
+				}
+
+				var wrapper = document.createElement('div');
+				wrapper.innerHTML = normalized;
+				wrapper.style.position = 'absolute';
+				wrapper.style.left = '-99999px';
+				wrapper.style.top = '0';
+				wrapper.style.visibility = 'hidden';
+				document.body.appendChild(wrapper);
+				var nodes = wrapper.querySelectorAll('p, div, blockquote, table, td, th, span, font');
+				for (var i = 0; i < nodes.length; i++) {
+					var node = nodes[i];
+					var styleText = node.getAttribute('style') || '';
+					var keptStyles = styleText.split(';').filter(function (rule) {
+						return rule.trim() && !/^\s*mso-/i.test(rule);
+					}).join(';');
+					if (keptStyles) {
+						node.setAttribute('style', keptStyles);
+					} else {
+						node.removeAttribute('style');
+					}
+
+					var textIndent = node.style && node.style.textIndent;
+					if (textIndent && !/^0(?:px|pt|em|%)?$/i.test(textIndent.trim())) {
+						node.style.textIndent = '2em';
+					}
+					if (node.getAttribute && node.getAttribute('align')) {
+						node.style.textAlign = node.getAttribute('align');
+						node.removeAttribute('align');
+					}
+				}
+
+				var walker = document.createTreeWalker(wrapper, NodeFilter.SHOW_TEXT, {
+					acceptNode: function (textNode) {
+						return textNode.nodeValue && textNode.nodeValue.trim()
+							? NodeFilter.FILTER_ACCEPT
+							: NodeFilter.FILTER_REJECT;
+					}
+				});
+				var textNodes = [];
+				while (walker.nextNode()) {
+					textNodes.push(walker.currentNode);
+				}
+				textNodes.forEach(function (textNode) {
+					var parent = textNode.parentElement;
+					if (!parent || !window.getComputedStyle) {
+						return;
+					}
+					var computed = window.getComputedStyle(parent);
+					var formattedSpan = document.createElement('span');
+					formattedSpan.setAttribute('data-word-format', 'true');
+					formattedSpan.style.fontFamily = computed.fontFamily;
+					formattedSpan.style.fontSize = computed.fontSize;
+					formattedSpan.style.color = computed.color;
+					if (computed.fontWeight && computed.fontWeight !== '400' && computed.fontWeight !== 'normal') {
+						formattedSpan.style.fontWeight = computed.fontWeight;
+					}
+					if (computed.fontStyle && computed.fontStyle !== 'normal') {
+						formattedSpan.style.fontStyle = computed.fontStyle;
+					}
+					if (computed.textDecorationLine && computed.textDecorationLine !== 'none') {
+						formattedSpan.style.textDecoration = computed.textDecorationLine;
+					}
+					if (computed.verticalAlign && computed.verticalAlign !== 'baseline') {
+						formattedSpan.style.verticalAlign = computed.verticalAlign;
+					}
+					formattedSpan.appendChild(textNode.cloneNode(true));
+					textNode.parentNode.replaceChild(formattedSpan, textNode);
+				});
+
+				var inlineNodes = wrapper.querySelectorAll('span, font, b, strong, i, em, u, s, strike, sub, sup');
+				for (var inlineIndex = inlineNodes.length - 1; inlineIndex >= 0; inlineIndex--) {
+					var inlineNode = inlineNodes[inlineIndex];
+					if (inlineNode.getAttribute('data-word-format') === 'true' || !inlineNode.parentNode) {
+						continue;
+					}
+					while (inlineNode.firstChild) {
+						inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
+					}
+					inlineNode.parentNode.removeChild(inlineNode);
+				}
+				var normalizedHtml = wrapper.innerHTML;
+				document.body.removeChild(wrapper);
+				return normalizedHtml;
+			},
+			insertFormattedWordHtml: function (editor, htmlContent) {
+				this.insertHtml(htmlContent);
+				this.$emit('input', this.getEditorSaveHtml());
+				this.deferSyncEditorPlayableVideos();
+			},
+			convertWordWithServer: function (file) {
+				var formData = new FormData();
+				var convertUrl = this.wordconverturl;
+				formData.append('upload', file);
+
+				return fetch('/apps?ark=sys.uploadAjax', {
+					method: 'POST',
+					body: formData,
+					credentials: 'same-origin'
+				}).then(readJsonResponse).then(function (uploadResult) {
+					var uploadData = uploadResult && (uploadResult.data || uploadResult);
+					var path = uploadResult && uploadResult.data && uploadResult.data[0] && uploadResult.data[0].msg;
+					path = path || (uploadData && (uploadData.msg || uploadData.path));
+					if (!path) {
+						throw new Error('Word 文件上传失败。');
+					}
+
+					return fetch(convertUrl, {
+						method: 'POST',
+						headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
+						body: 'path=' + encodeURIComponent(path),
+						credentials: 'same-origin'
+					});
+				}).then(readJsonResponse).then(function (conversionResult) {
+					var data = conversionResult && (conversionResult.data || conversionResult);
+					var html = conversionResult && conversionResult.htmlContent;
+					html = html || (data && data.htmlContent);
+					html = html || (conversionResult && conversionResult.data && conversionResult.data[0] && conversionResult.data[0].htmlContent);
+					if (!html) {
+						throw new Error('服务器没有返回可导入的 Word 内容。');
+					}
+					return { html: html, messages: [] };
+				});
+
+				function readJsonResponse(response) {
+					if (!response || !response.ok) {
+						throw new Error('Word 转换服务不可用。');
+					}
+					return response.text().then(function (text) {
+						try {
+							var json = JSON.parse(text);
+							if (json && json.code && json.code !== 'success') {
+								throw new Error(json.msg || 'Word 转换失败。');
+							}
+							return json;
+						} catch (error) {
+							throw new Error(error && error.message ? error.message : 'Word 转换服务返回异常。');
+						}
+					});
+				}
+			},
 		openWordImporter: function () {
 			if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
 				space.message.warning("编辑器尚未加载完成");
@@ -2406,42 +2820,165 @@ Vue.component('spaceEditor', {
 			}
 		},
 		bindVideoPasteUpload: function () {
-			if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
+			if (!this.editor) {
 				return;
 			}
 
-			var editable = this.editor.ui.getEditableElement();
+			var editable = this.getEditorEditableElement(this.editor);
 			if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
 				return;
 			}
 
-			editable.setAttribute("data-space-video-upload", "true");
+				editable.setAttribute("data-space-video-upload", "true");
 			var _this = this;
 			var handler = function (event) {
 				var dataTransfer = event.clipboardData || event.dataTransfer;
-				if (!dataTransfer || !dataTransfer.files || dataTransfer.files.length == 0) {
+					var files = _this.getClipboardFiles(dataTransfer);
+					if (!files.length) {
 					return;
 				}
 
-				var files = Array.prototype.slice.call(dataTransfer.files);
 				var videoFile = files.find(function (file) {
 					return file && file.type && file.type.indexOf("video/") === 0;
 				});
 				var pdfFile = files.find(function (file) {
 					return _this.isPdfFile(file);
 				});
+					var imageFiles = files.filter(function (file) {
+						return _this.isImageFile(file);
+					});
+					var htmlContent = _this.readClipboardData(dataTransfer, 'text/html');
+					var plainText = _this.readClipboardData(dataTransfer, 'text/plain');
+					var hasTextContent = !!(htmlContent.replace(/\s+/g, '') || plainText.trim());
 
 				if (videoFile) {
 					event.preventDefault();
+						if (event.stopImmediatePropagation) {
+							event.stopImmediatePropagation();
+						}
 					_this.uploadVideoFile(videoFile);
 				} else if (pdfFile) {
 					event.preventDefault();
+						if (event.stopImmediatePropagation) {
+							event.stopImmediatePropagation();
+						}
 					_this.uploadPdfFile(pdfFile);
+					} else if (imageFiles.length && hasTextContent) {
+						event.preventDefault();
+						if (event.stopImmediatePropagation) {
+							event.stopImmediatePropagation();
+						}
+						_this.insertMixedClipboardContent(htmlContent, plainText, imageFiles);
 				}
 			};
 
-			editable.addEventListener("paste", handler);
-			editable.addEventListener("drop", handler);
+				editable.addEventListener("paste", handler, true);
+				editable.addEventListener("drop", handler, true);
+			},
+			getClipboardFiles: function (dataTransfer) {
+				if (!dataTransfer) {
+					return [];
+				}
+				var files = dataTransfer.files ? Array.prototype.slice.call(dataTransfer.files) : [];
+				if (files.length || !dataTransfer.items) {
+					return files;
+				}
+				for (var i = 0; i < dataTransfer.items.length; i++) {
+					var item = dataTransfer.items[i];
+					if (item && item.kind === 'file' && typeof item.getAsFile === 'function') {
+						var file = item.getAsFile();
+						if (file) {
+							files.push(file);
+						}
+					}
+				}
+				return files;
+			},
+			isImageFile: function (file) {
+				return !!(file && ((file.type && file.type.indexOf('image/') === 0)
+					|| /\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i.test(file.name || '')));
+			},
+			readClipboardData: function (dataTransfer, type) {
+				if (!dataTransfer || typeof dataTransfer.getData !== 'function') {
+					return '';
+				}
+				try {
+					return dataTransfer.getData(type) || '';
+				} catch (error) {
+					return '';
+				}
+			},
+			insertMixedClipboardContent: function (htmlContent, plainText, imageFiles) {
+				if (!this.editor || !imageFiles || !imageFiles.length) {
+					return;
+				}
+
+				var _this = this;
+				this.uploadStatus = '正在上传粘贴内容中的图片…';
+				if (window.space && space.plugins && space.plugins.loading) {
+					space.plugins.loading.show();
+				}
+
+				Promise.all(imageFiles.map(function (file) {
+					return _this.uploadPlainFileByAdapter(file, _this.getUploadOptions()).then(function (result) {
+						return result && result.default ? result.default : '';
+					});
+				})).then(function (imageUrls) {
+					var html = _this.buildMixedClipboardHtml(htmlContent, plainText, imageUrls, imageFiles);
+					if (!html) {
+						throw new Error('粘贴内容为空');
+					}
+					_this.insertHtml(html);
+					_this.$emit('input', _this.getEditorSaveHtml());
+					_this.deferSyncEditorPlayableVideos();
+					space.message.success('文字和图片已同时粘贴');
+				}).catch(function (error) {
+					console.error(error);
+					space.message.error(error && error.message ? error.message : '粘贴图片上传失败,请重试');
+				}).finally(function () {
+					_this.uploadStatus = '';
+					if (window.space && space.plugins && space.plugins.loading) {
+						space.plugins.loading.close();
+					}
+				});
+			},
+			buildMixedClipboardHtml: function (htmlContent, plainText, imageUrls, imageFiles) {
+				var safeUrls = imageUrls || [];
+				var wrapper = document.createElement('div');
+				if (htmlContent) {
+					wrapper.innerHTML = htmlContent;
+				} else {
+					var lines = (plainText || '').replace(/\r\n/g, '\n').split('\n');
+					wrapper.innerHTML = lines.map(function (line) {
+						return '<p>' + this.escapeClipboardText(line) + '</p>';
+					}.bind(this)).join('');
+				}
+
+				var images = wrapper.querySelectorAll('img');
+				for (var i = 0; i < images.length && i < safeUrls.length; i++) {
+					if (safeUrls[i]) {
+						images[i].setAttribute('src', safeUrls[i]);
+					}
+				}
+
+				for (var imageIndex = images.length; imageIndex < safeUrls.length; imageIndex++) {
+					if (!safeUrls[imageIndex]) {
+						continue;
+					}
+					var figure = document.createElement('figure');
+					figure.className = 'image';
+					var image = document.createElement('img');
+					image.setAttribute('src', safeUrls[imageIndex]);
+					image.setAttribute('alt', imageFiles[imageIndex] && imageFiles[imageIndex].name ? imageFiles[imageIndex].name : '粘贴图片');
+					figure.appendChild(image);
+					wrapper.appendChild(figure);
+				}
+
+				return wrapper.innerHTML;
+			},
+			escapeClipboardText: function (text) {
+				return String(text || '').replace(/&/g, '&amp;').replace(/</g, '&lt;')
+					.replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
 		},
 		isPdfToolbarControl: function (domTarget) {
 			if (!domTarget || !domTarget.closest) {
@@ -2628,11 +3165,11 @@ Vue.component('spaceEditor', {
 			}
 		},
 		syncEditorPlayableVideos: function () {
-			if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
+			if (!this.editor) {
 				return;
 			}
 
-			var editable = this.editor.ui.getEditableElement();
+			var editable = this.getEditorEditableElement(this.editor);
 			if (!editable) {
 				return;
 			}
@@ -2654,11 +3191,11 @@ Vue.component('spaceEditor', {
 			}, 0);
 		},
 		bindEditorVideoPlayback: function () {
-			if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
+			if (!this.editor) {
 				return;
 			}
 
-			var editable = this.editor.ui.getEditableElement();
+			var editable = this.getEditorEditableElement(this.editor);
 			if (!editable || editable.getAttribute("data-space-playable-media-root") == "true") {
 				this.syncEditorPlayableVideos();
 				return;
@@ -2792,12 +3329,33 @@ Vue.component('spaceEditor', {
 			ClassicEditor.create(document.querySelector("#" + _this.id), {
 				extraPlugins: [function (editor) {
 					_this.installUploadAdapter(editor);
+						_this.installFirstLineIndentPlugin(editor);
 					_this.installVideoViewerPlugin(editor);
 					_this.installPdfViewerPlugin(editor);
 				}], // 添加上传适配器
 				toolbar: toolbar || {},
 				language: 'zh-cn',
 				placeholder: _this.placeholder || '',
+					fontFamily: {
+						supportAllValues: true,
+						options: [
+							'default',
+							{ title: '宋体', model: 'SimSun, serif', view: { name: 'span', styles: { 'font-family': "'SimSun', serif" }, priority: 7 } },
+							{ title: '仿宋', model: 'FangSong, serif', view: { name: 'span', styles: { 'font-family': "'FangSong', serif" }, priority: 7 } },
+							{ title: '楷体', model: 'KaiTi, serif', view: { name: 'span', styles: { 'font-family': "'KaiTi', serif" }, priority: 7 } },
+							{ title: '黑体', model: 'SimHei, sans-serif', view: { name: 'span', styles: { 'font-family': "'SimHei', sans-serif" }, priority: 7 } },
+							{ title: '微软雅黑', model: 'Microsoft YaHei, sans-serif', view: { name: 'span', styles: { 'font-family': "'Microsoft YaHei', sans-serif" }, priority: 7 } },
+							{ title: '等线', model: 'DengXian, sans-serif', view: { name: 'span', styles: { 'font-family': "'DengXian', sans-serif" }, priority: 7 } },
+							{ title: '思源宋体', model: 'Source Han Serif SC, serif', view: { name: 'span', styles: { 'font-family': "'Source Han Serif SC', serif" }, priority: 7 } },
+							{ title: '思源黑体', model: 'Source Han Sans SC, sans-serif', view: { name: 'span', styles: { 'font-family': "'Source Han Sans SC', sans-serif" }, priority: 7 } },
+							{ title: 'Arial', model: 'Arial, Helvetica, sans-serif', view: { name: 'span', styles: { 'font-family': "'Arial', Helvetica, sans-serif" }, priority: 7 } },
+							{ title: 'Times New Roman', model: 'Times New Roman, Times, serif', view: { name: 'span', styles: { 'font-family': "'Times New Roman', Times, serif" }, priority: 7 } }
+						]
+					},
+					fontSize: {
+						supportAllValues: true,
+						options: ['default', '10.5pt', '12pt', '14pt', '16pt', '18pt', '22pt', '26pt', '36pt']
+					},
 				mediaEmbed: {
 					previewsInData: true,
 					providers: [{
@@ -2844,6 +3402,8 @@ Vue.component('spaceEditor', {
 
 				_this.editor = editor;
 				_this.alignFullScreenToolbarButton();
+					_this.mountFirstLineIndentToolbarButton(editor);
+					_this.configureWordUploadPlugin(editor);
 				if (_this.type !== 'flow') {
 					_this.mountVideoUploadToolbarButton();
 					_this.mountPdfUploadToolbarButton();

+ 2 - 2
WebRoot/web/subassembly/app/pc/10021/10104/1002110104_run.jsp

@@ -18,7 +18,7 @@
  <script src="/apps/space/plug-in/element-resize-detector/element-resize-detector.min.js"></script> 
  <script src="/apps/space/plug-in/vue/vue.min.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/apps/space/plug-in/element-ui@2.13.0/index.js" type="text/javascript" charset="utf-8"></script> 
- <script src="/js/space.vue.pc.subassembly.js?v=20260719-image-src"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261027-editor-format"></script>
  <script src="/apps/space/plug-in/layui/dist/layui.all.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.recycle.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.display.js" type="text/javascript" charset="utf-8"></script>
@@ -58,7 +58,7 @@
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
 								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
-								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />" wordconverturl="<app:token name='sys.convert_html' />"></space-editor>
 							</el-form-item>
 						</el-col>
 

+ 2 - 2
WebRoot/web/subassembly/app/pc/10021/10105/1002110105_run.jsp

@@ -18,7 +18,7 @@
  <script src="/apps/space/plug-in/element-resize-detector/element-resize-detector.min.js"></script> 
  <script src="/apps/space/plug-in/vue/vue.min.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/apps/space/plug-in/element-ui@2.13.0/index.js" type="text/javascript" charset="utf-8"></script> 
- <script src="/js/space.vue.pc.subassembly.js?v=20260719-image-src"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261027-editor-format"></script>
  <script src="/apps/space/plug-in/layui/dist/layui.all.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.recycle.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.display.js" type="text/javascript" charset="utf-8"></script>
@@ -59,7 +59,7 @@
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
 								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
-								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />" wordconverturl="<app:token name='sys.convert_html' />"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

+ 2 - 2
WebRoot/web/subassembly/app/pc/10021/10211/1002110211_run.jsp

@@ -18,7 +18,7 @@
  <script src="/apps/space/plug-in/element-resize-detector/element-resize-detector.min.js"></script> 
  <script src="/apps/space/plug-in/vue/vue.min.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/apps/space/plug-in/element-ui@2.13.0/index.js" type="text/javascript" charset="utf-8"></script> 
- <script src="/js/space.vue.pc.subassembly.js?v=20260719-image-src"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261027-editor-format"></script>
  <script src="/apps/space/plug-in/layui/dist/layui.all.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.recycle.js" type="text/javascript" charset="utf-8"></script> 
  <script src="/js/space.display.js" type="text/javascript" charset="utf-8"></script>
@@ -60,7 +60,7 @@
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
 								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
-								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />" wordconverturl="<app:token name='sys.convert_html' />"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

+ 11 - 3
local-run/bin/sync-to-hxcs-prod.sh

@@ -1280,6 +1280,9 @@ WHERE zjid=10149
 	verify_remote_file_contains "网站列表排序 JSP 已部署" "web/subassembly/app/pc/10017/10070/1001710070_run.jsp" "排序序号"
 	verify_remote_file_contains "网站录入排序 JSP 已部署" "web/subassembly/app/pc/10017/10071/1001710071_run.jsp" "排序序号"
 	verify_remote_file_contains "网站变动排序 JSP 已部署" "web/subassembly/app/pc/10017/10073/1001710073_run.jsp" "排序序号"
+	verify_remote_file_contains "文章发布编辑器 Word 转换入口已部署" "web/subassembly/app/pc/10021/10104/1002110104_run.jsp" "wordconverturl"
+	verify_remote_file_contains "文章变动编辑器 Word 转换入口已部署" "web/subassembly/app/pc/10021/10105/1002110105_run.jsp" "wordconverturl"
+	verify_remote_file_contains "文章修改编辑器 Word 转换入口已部署" "web/subassembly/app/pc/10021/10211/1002110211_run.jsp" "wordconverturl"
 
 	verify_http "后台工作台可访问" "https://hxcs.feifan.net/apps/workbench/"
 	verify_http "富文本 CKEditor 资源可访问" "https://hxcs.feifan.net/apps/space/plug-in/ckeditor5/build/ckeditor.js"
@@ -1361,10 +1364,15 @@ SELECT IF(COUNT(*)=0,1,0)
 	  AND (jump_websiteid=10073 OR jump_url LIKE '%xinwen2026.hxcs.feifan.net%');
 "
 
-	if curl -k -s -m 20 "https://hxcs.feifan.net/js/space.vue.pc.subassembly.js" | grep -E "space-editor-wrap|ClassicEditor|图片质量压缩" >/dev/null; then
-		ok "富文本增强脚本内容可识别"
+	local editor_script
+	editor_script="$(curl -k -s -m 20 "https://hxcs.feifan.net/js/space.vue.pc.subassembly.js")"
+	if grep -E "space-editor-wrap|ClassicEditor|图片质量压缩" <<< "${editor_script}" >/dev/null \
+		&& grep -F "installFirstLineIndentPlugin" <<< "${editor_script}" >/dev/null \
+		&& grep -F "insertMixedClipboardContent" <<< "${editor_script}" >/dev/null \
+		&& grep -F "normalizeImportedWordHtml" <<< "${editor_script}" >/dev/null; then
+		ok "富文本编辑器格式、首行缩进、Word 转换和混合粘贴功能已部署"
 	else
-		fail "富文本增强脚本内容未识别"
+		fail "富文本编辑器新增功能未完整部署"
 		VERIFY_FAILED=1
 	fi