Explorar o código

升级文章富文本编辑器工具

- 新增文章正文工具条样式,保持现有 Element UI 后台风格,支持一键排版、多图上传、视频上传、图片质量选择和三端预览入口。

- 增加上传适配器兼容包装,修复多图上传直接调用旧入口导致的报错,并支持视频粘贴/拖拽上传。

- 新增文章预览查看服务,预览临时文件通过 session key 读取并限制在 web/upload 范围内。

- 更新文章录入、修改、变动页面的静态资源版本号,避免旧弹窗缓存继续加载旧脚本。

Validation:

- ./local-run/bin/status-full-local.sh

- node --check WebRoot/apps/space/js/space.vue.subassembly.js

- node --check WebRoot/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js

- javac -encoding UTF-8 -cp 'WebRoot/WEB-INF/classes:WebRoot/WEB-INF/lib/*' -d /private/tmp/zq-article-compile-check src/space/apps/moudules/website/services/ArticleService.java

- git diff --check --cached

- curl 本地静态资源检查与 uploadPlainFileByAdapter 兼容调用链检查
非繁 hai 5 meses
pai
achega
d4e967711c

+ 1 - 0
WebRoot/WEB-INF/apps/website/config/services/article.service.xml

@@ -60,6 +60,7 @@
 				<service name="article_getIssueNavList" desc="获取可发布的栏目" title="获取可发布的栏目" class="space.apps.moudules.website.services.ArticleService" method="getIssueNavigation" />
 				<service name="article_getCopyNavList" desc="获取可抄送的栏目" title="获取可抄送的栏目" class="space.apps.moudules.website.services.ArticleService" method="getCopyNavigation" />
 				<service name="article_preview" desc="文章正文预览" title="文章正文预览" class="space.apps.moudules.website.services.ArticleService" method="preview" />
+				<service name="article_preview_view" desc="文章正文预览内容" title="文章正文预览内容" class="space.apps.moudules.website.services.ArticleService" method="previewView" />
 			</service>
 			
 			<!-- 流程 -->

+ 105 - 6
WebRoot/apps/space/css/space.editor.css

@@ -5,33 +5,130 @@
 .space-editor-toolstrip {
 	display: flex;
 	align-items: center;
-	gap: 8px;
+	align-content: center;
 	flex-wrap: wrap;
-	padding: 8px 10px;
-	border: 1px solid #c4c4c4;
+	column-gap: 4px;
+	row-gap: 6px;
+	min-height: 40px;
+	padding: 5px 8px;
+	border: 1px solid #dcdfe6;
 	border-bottom: 0;
 	background: #fafafa;
+	box-sizing: border-box;
+}
+
+.space-editor-toolstrip .el-button + .el-button {
+	margin-left: 0;
+}
+
+.space-editor-toolstrip .space-editor-tool-btn.el-button--small {
+	display: inline-flex;
+	align-items: center;
+	justify-content: center;
+	min-width: 78px;
+	height: 30px;
+	margin: 0;
+	padding: 8px 10px;
+	border-color: #dcdfe6;
+	border-radius: 2px;
+	background: #fff;
+	color: #606266;
+	font-size: 12px;
+	font-weight: 400;
+	line-height: 1;
+	white-space: nowrap;
+}
+
+.space-editor-toolstrip .space-editor-tool-btn.el-button--small [class^="el-icon-"],
+.space-editor-toolstrip .space-editor-tool-btn.el-button--small [class*=" el-icon-"] {
+	margin-right: 4px;
+	font-size: 14px;
+}
+
+.space-editor-toolstrip .space-editor-tool-btn.el-button--small:hover,
+.space-editor-toolstrip .space-editor-tool-btn.el-button--small:focus {
+	border-color: #b3d8ff;
+	background: #ecf5ff;
+	color: #409eff;
+}
+
+.space-editor-toolstrip .space-editor-preview-btn.el-button--primary.is-plain {
+	border-color: #b3d8ff;
+	background: #ecf5ff;
+	color: #409eff;
+}
+
+.space-editor-toolstrip .space-editor-preview-btn.el-button--primary.is-plain:hover,
+.space-editor-toolstrip .space-editor-preview-btn.el-button--primary.is-plain:focus {
+	border-color: #409eff;
+	background: #409eff;
+	color: #fff;
+}
+
+.space-editor-toolstrip .space-editor-tool-divider {
+	display: inline-block;
+	width: 1px;
+	height: 18px;
+	margin: 0 2px;
+	background: #dcdfe6;
 }
 
-.space-editor-toolstrip .el-button--small,
 .space-editor-toolstrip .el-input--small .el-input__inner {
 	height: 30px;
 	line-height: 28px;
+	border-color: #dcdfe6;
+	border-radius: 2px;
+	background: #fff;
+	color: #606266;
 }
 
 .space-editor-quality {
-	width: 118px;
+	width: 104px;
+	margin: 0 2px;
 }
 
 .space-editor-upload-status {
+	margin-left: 4px;
 	font-size: 12px;
+	line-height: 30px;
 	color: #909399;
+	white-space: nowrap;
+}
+
+@media screen and (max-width: 768px) {
+	.space-editor-toolstrip {
+		column-gap: 4px;
+		row-gap: 5px;
+		padding: 6px;
+	}
+
+	.space-editor-toolstrip .space-editor-tool-btn.el-button--small {
+		min-width: auto;
+		padding: 7px 8px;
+	}
+
+	.space-editor-toolstrip .space-editor-tool-divider {
+		display: none;
+	}
+
+	.space-editor-quality {
+		width: 100px;
+	}
 }
 
 .space-editor-preview-dialog .el-dialog__body {
 	padding: 12px 18px 18px;
 }
 
+.space-editor-preview-dialog {
+	max-width: calc(100vw - 48px);
+	margin-bottom: 0;
+}
+
+.space-editor-preview-dialog .el-dialog__header {
+	padding: 14px 18px 8px;
+}
+
 .space-editor-preview-toolbar {
 	display: flex;
 	align-items: center;
@@ -40,7 +137,9 @@
 }
 
 .space-editor-preview-stage {
-	height: 700px;
+	height: calc(100vh - 230px);
+	min-height: 360px;
+	max-height: 700px;
 	overflow: auto;
 	text-align: center;
 	background: #f5f7fa;

+ 24 - 9
WebRoot/apps/space/js/space.vue.subassembly.js

@@ -526,6 +526,22 @@ Vue.component('spaceEditor', {
 				return new MyUploadAdapter(loader, _this.getUploadOptions());
 			};
 		},
+		uploadPlainFileByAdapter: function (file, options, onProgress) {
+			if (typeof MyUploadAdapter == "undefined") {
+				return Promise.reject("上传组件未加载完成,请刷新页面后重试");
+			}
+
+			if (typeof MyUploadAdapter.uploadPlainFile == "function") {
+				return MyUploadAdapter.uploadPlainFile(file, options, onProgress);
+			}
+
+			var adapter = new MyUploadAdapter(null, options || {});
+			if (typeof adapter.uploadPlainFile == "function") {
+				return adapter.uploadPlainFile(file, onProgress);
+			}
+
+			return Promise.reject("上传组件未加载完成,请刷新页面后重试");
+		},
 		/**
 		 * 获取高度
 		 */
@@ -763,7 +779,7 @@ Vue.component('spaceEditor', {
 			imageFiles.forEach(function (file, index) {
 				chain = chain.then(function () {
 					_this.uploadStatus = "正在上传图片 " + (index + 1) + "/" + imageFiles.length;
-					return MyUploadAdapter.uploadPlainFile(file, _this.getUploadOptions()).then(function (res) {
+					return _this.uploadPlainFileByAdapter(file, _this.getUploadOptions()).then(function (res) {
 						_this.insertHtml('<p><img src="' + res.default + '"></p>');
 					});
 				});
@@ -787,7 +803,7 @@ Vue.component('spaceEditor', {
 			var _this = this;
 			_this.uploading = true;
 			_this.uploadStatus = "正在上传视频";
-			MyUploadAdapter.uploadPlainFile(file, {
+			_this.uploadPlainFileByAdapter(file, {
 				imageQuality: 'origin'
 			}, function (loaded, total) {
 				if (total > 0) {
@@ -1000,18 +1016,17 @@ Vue.component('spaceEditor', {
 	template: `
 	<div class="space-editor-wrap">
 		<div class="space-editor-toolstrip" v-if="showEditorTools()">
-			<el-button-group>
-				<el-button size="small" icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
-				<el-button size="small" icon="el-icon-picture-outline" @click="openMultiImagePicker" :loading="uploading">多图上传</el-button>
-				<el-button size="small" icon="el-icon-video-camera" @click="openVideoPicker" :loading="uploading">视频上传</el-button>
-			</el-button-group>
+			<el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-magic-stick" @click="formatContent">一键排版</el-button>
+			<el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-picture-outline" @click="openMultiImagePicker" :loading="uploading">多图上传</el-button>
+			<el-button class="space-editor-tool-btn" size="small" plain icon="el-icon-video-camera" @click="openVideoPicker" :loading="uploading">视频上传</el-button>
+			<span class="space-editor-tool-divider"></span>
 			<el-select class="space-editor-quality" v-model="imageQuality" size="small" placeholder="图片质量">
 				<el-option label="原图" value="origin"></el-option>
 				<el-option label="高清 85%" value="high"></el-option>
 				<el-option label="标准 70%" value="standard"></el-option>
 				<el-option label="低流量 50%" value="low"></el-option>
 			</el-select>
-			<el-button size="small" type="primary" plain icon="el-icon-view" @click="openArticlePreview" :loading="previewLoading">三端预览</el-button>
+			<el-button class="space-editor-tool-btn space-editor-preview-btn" size="small" type="primary" plain icon="el-icon-view" @click="openArticlePreview" :loading="previewLoading">三端预览</el-button>
 			<span class="space-editor-upload-status" v-if="uploadStatus">{{uploadStatus}}</span>
 		</div>
 		<input ref="multiImageInput" type="file" accept="image/*" multiple style="display:none;" @change="handleMultiImageSelect">
@@ -1019,7 +1034,7 @@ Vue.component('spaceEditor', {
 		<div :id="id">
 			<script type="text/plain"></script>
 		</div>
-		<el-dialog title="正文预览" :visible.sync="previewVisible" width="90%" append-to-body custom-class="space-editor-preview-dialog">
+		<el-dialog title="正文预览" :visible.sync="previewVisible" width="90%" top="4vh" append-to-body custom-class="space-editor-preview-dialog">
 			<div class="space-editor-preview-toolbar">
 				<el-radio-group v-model="previewMode" size="small">
 					<el-radio-button label="pc">PC端</el-radio-button>

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

@@ -12,13 +12,13 @@
  <link rel="stylesheet" type="text/css" href="/apps/space/css/SpaceIcon/iconfont.css"> 
  <link rel="stylesheet" type="text/css" href="/css/components.css"> 
  <link rel="stylesheet" href="/css/ckeditor.css"> 
- <link rel="stylesheet" href="/apps/space/css/space.editor.css"> 
+ <link rel="stylesheet" href="/apps/space/css/space.editor.css?v=2026062702">
  <script>var space = { vars: {} };</script> 
  <script src="/js/jquery1.11.3.min.js" type="text/javascript" charset="utf-8"></script> 
  <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"></script> 
+ <script src="/js/space.vue.pc.subassembly.js?v=2026062702"></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>

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

@@ -12,13 +12,13 @@
  <link rel="stylesheet" type="text/css" href="/apps/space/css/SpaceIcon/iconfont.css"> 
  <link rel="stylesheet" type="text/css" href="/css/components.css"> 
  <link rel="stylesheet" href="/css/ckeditor.css"> 
- <link rel="stylesheet" href="/apps/space/css/space.editor.css"> 
+ <link rel="stylesheet" href="/apps/space/css/space.editor.css?v=2026062702">
  <script>var space = { vars: {} };</script> 
  <script src="/js/jquery1.11.3.min.js" type="text/javascript" charset="utf-8"></script> 
  <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"></script> 
+ <script src="/js/space.vue.pc.subassembly.js?v=2026062702"></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>

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

@@ -12,13 +12,13 @@
  <link rel="stylesheet" type="text/css" href="/apps/space/css/SpaceIcon/iconfont.css"> 
  <link rel="stylesheet" type="text/css" href="/css/components.css"> 
  <link rel="stylesheet" href="/css/ckeditor.css"> 
- <link rel="stylesheet" href="/apps/space/css/space.editor.css"> 
+ <link rel="stylesheet" href="/apps/space/css/space.editor.css?v=2026062702">
  <script>var space = { vars: {} };</script> 
  <script src="/js/jquery1.11.3.min.js" type="text/javascript" charset="utf-8"></script> 
  <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"></script> 
+ <script src="/js/space.vue.pc.subassembly.js?v=2026062702"></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>

+ 65 - 1
src/space/apps/moudules/website/services/ArticleService.java

@@ -1,6 +1,7 @@
 package space.apps.moudules.website.services;
 
 import java.io.File;
+import java.net.URLEncoder;
 import java.sql.Timestamp;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -59,6 +60,8 @@ public class ArticleService extends BaseTransaction {
 
     private static final long serialVersionUID = 1L;
 
+    private static final String ARTICLE_PREVIEW_SESSION_PREFIX = "articlePreviewPath_";
+
     /**
      * 转换文章内容 html 里的链接
      *
@@ -1194,11 +1197,72 @@ public class ArticleService extends BaseTransaction {
                 space.apps.moudules.website.common.ConstVars.domain);
         String runPath = WebEditorUtil.createHtmlFile(runContent);
 
+        String previewKey = java.util.UUID.randomUUID().toString().replace("-", "");
+        setSessionAttribute(ARTICLE_PREVIEW_SESSION_PREFIX + previewKey, runPath);
+
         Map<String, Object> retMap = new HashMap<String, Object>();
-        retMap.put("url", runPath);
+        retMap.put("url", "/apps?ark=website.article_preview_view&key=" + URLEncoder.encode(previewKey, "UTF-8"));
         write(getResponseSuccessDataPackage(retMap).toJsonWriteNonStringValueAsString());
     }
 
+    /**
+     * 输出文章正文临时预览内容。
+     *
+     * @throws Exception
+     * @author SPACE
+     */
+    public void previewView() throws Exception {
+
+        getResponse().setContentType("text/html;charset=UTF-8");
+
+        String key = getParameter("key");
+        if (StringUtil.isNull(key)) {
+            writePreviewUnavailable();
+            return;
+        }
+
+        Object previewPathObj = getSession().getAttribute(ARTICLE_PREVIEW_SESSION_PREFIX + key);
+        String previewPath = previewPathObj == null ? "" : previewPathObj.toString();
+        File previewFile = getSafePreviewFile(previewPath);
+        if (previewFile == null) {
+            writePreviewUnavailable();
+            return;
+        }
+
+        write(FileUtil.readFile(previewFile.getPath()));
+    }
+
+    private File getSafePreviewFile(String previewPath) throws Exception {
+
+        if (StringUtil.isNull(previewPath)) {
+            return null;
+        }
+
+        String normalizedPath = previewPath.replace("\\", "/");
+        if (!normalizedPath.endsWith(".html")) {
+            return null;
+        }
+
+        File webRoot = new File(getWebRootPath()).getCanonicalFile();
+        File uploadRoot = new File(webRoot, "web/upload").getCanonicalFile();
+        File previewFile = normalizedPath.startsWith("/")
+                ? new File(webRoot, normalizedPath.substring(1)).getCanonicalFile()
+                : new File(webRoot, normalizedPath).getCanonicalFile();
+
+        if (!previewFile.getPath().startsWith(uploadRoot.getPath() + File.separator)) {
+            return null;
+        }
+
+        return previewFile.isFile() ? previewFile : null;
+    }
+
+    private void writePreviewUnavailable() throws Exception {
+        write("<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><style>"
+                + "body{margin:0;font-family:Arial,'Microsoft YaHei',sans-serif;background:#f5f7fa;color:#606266;}"
+                + ".msg{padding:80px 20px;text-align:center;font-size:14px;}"
+                + "</style></head><body><div class=\"msg\">预览内容不存在,请刷新预览后再查看。</div></body></html>");
+    }
+
     // 测试的服务
 
     /**