Преглед изворни кода

设置富文本默认仿宋GB2312与20pt

新文章正文初始化时应用仿宋_GB2312及20pt默认格式,后续段落继承该字体和字号。\n\nWord 导入优先保留文档中明确设置的字体与字号,仅对未指定格式的文字补仿宋_GB2312、20pt,避免覆盖 Word 原有排版。更新文章新增、变动、修改页面编辑器脚本缓存版本。\n\nValidation:\n- node --check WebRoot/apps/space/js/space.vue.subassembly.js\n- git diff --cached --check
非繁 пре 2 недеља
родитељ
комит
a06e96cd68

+ 37 - 4
WebRoot/apps/space/js/space.vue.subassembly.js

@@ -398,6 +398,8 @@ Vue.component('spaceEditor', {
 			_emitEditorHtmlTimer: undefined,
 			_enhancePdfTimer: undefined,
 			_pdfEnhancing: false,
+			defaultEditorFontFamily: "'仿宋_GB2312', 'FangSong_GB2312', FangSong, serif",
+			defaultEditorFontSize: "20pt",
 		}
 	},
 	name: "spaceEditor",
@@ -2477,7 +2479,7 @@ Vue.component('spaceEditor', {
 						if (result.messages && result.messages.length) {
 							wordUi.showMessage('warning', 'Word 已导入,少量复杂格式可能需要人工检查。');
 						} else {
-							wordUi.showMessage('success', 'Word 文件已导入正文,并尽量保留原文档格式。');
+							wordUi.showMessage('success', 'Word 文件已导入正文,原有字体和字号已尽量保留;未指定格式的文字使用仿宋_GB2312、20pt。');
 						}
 					}.bind(this))
 					.catch(function (error) {
@@ -2580,10 +2582,22 @@ Vue.component('spaceEditor', {
 						return;
 					}
 					var computed = window.getComputedStyle(parent);
+					var explicitFontFamily = "";
+					var explicitFontSize = "";
+					var fontNode = parent;
+					while (fontNode && fontNode != wrapper) {
+						if (!explicitFontFamily && fontNode.style && fontNode.style.fontFamily) {
+							explicitFontFamily = fontNode.style.fontFamily;
+						}
+						if (!explicitFontSize && fontNode.style && fontNode.style.fontSize) {
+							explicitFontSize = fontNode.style.fontSize;
+						}
+						fontNode = fontNode.parentElement;
+					}
 					var formattedSpan = document.createElement('span');
 					formattedSpan.setAttribute('data-word-format', 'true');
-					formattedSpan.style.fontFamily = computed.fontFamily;
-					formattedSpan.style.fontSize = computed.fontSize;
+					formattedSpan.style.fontFamily = explicitFontFamily || this.defaultEditorFontFamily;
+					formattedSpan.style.fontSize = explicitFontSize || this.defaultEditorFontSize;
 					formattedSpan.style.color = computed.color;
 					if (computed.fontWeight && computed.fontWeight !== '400' && computed.fontWeight !== 'normal') {
 						formattedSpan.style.fontWeight = computed.fontWeight;
@@ -2599,7 +2613,7 @@ Vue.component('spaceEditor', {
 					}
 					formattedSpan.appendChild(textNode.cloneNode(true));
 					textNode.parentNode.replaceChild(formattedSpan, textNode);
-				});
+				}.bind(this));
 
 				var inlineNodes = wrapper.querySelectorAll('span, font, b, strong, i, em, u, s, strike, sub, sup');
 				for (var inlineIndex = inlineNodes.length - 1; inlineIndex >= 0; inlineIndex--) {
@@ -2621,6 +2635,22 @@ Vue.component('spaceEditor', {
 				this.$emit('input', this.getEditorSaveHtml());
 				this.deferSyncEditorPlayableVideos();
 			},
+			applyDefaultEditorTypography: function (editor) {
+				if (!editor || !editor.model || !editor.model.document) {
+					return;
+				}
+
+				var root = editor.model.document.getRoot();
+				var firstBlock = root.getChild(0);
+				editor.model.change(function (writer) {
+					if (!firstBlock) {
+						firstBlock = writer.appendElement('paragraph', root);
+					}
+					writer.setSelection(firstBlock, 'in');
+				});
+				editor.execute('fontFamily', { value: this.defaultEditorFontFamily });
+				editor.execute('fontSize', { value: this.defaultEditorFontSize });
+			},
 			convertWordWithServer: function (file) {
 				var formData = new FormData();
 				var convertUrl = this.wordconverturl;
@@ -3567,6 +3597,9 @@ Vue.component('spaceEditor', {
 
 				if (_this.htmlContent != undefined) {
 					_this.editor.setData(_this.normalizeVideoHtmlForEditor(_this.htmlContent));
+					if (!String(_this.htmlContent || '').trim()) {
+						_this.applyDefaultEditorTypography(_this.editor);
+					}
 					_this.upgradePdfLinksToViewers();
 					_this.deferSyncEditorPlayableVideos();
 					_this.enhanceEditorPdfViewers();

+ 1 - 1
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=20261110-line-height"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261110-default-typography"></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?v=20261110-title-submit-v2" type="text/javascript" charset="utf-8"></script>

+ 1 - 1
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=20261110-line-height"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261110-default-typography"></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?v=20261110-title-submit-v2" type="text/javascript" charset="utf-8"></script>

+ 1 - 1
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=20261110-line-height"></script>
+ <script src="/js/space.vue.pc.subassembly.js?v=20261110-default-typography"></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?v=20261110-title-submit-v2" type="text/javascript" charset="utf-8"></script>