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

升级文章富文本发布能力

在现有 spaceEditor/CKEditor 组件内增加文章发布专用工具条,提供一键排版、多图上传、视频上传/粘贴上传、图片质量选择和三端预览入口,样式继续使用 Element UI 与后台现有控件风格。

为文章新增、修改、变动表单接入预览参数和专用样式;新增文章正文临时预览服务,并注册 article_preview 接口。保留此前已调整的摘要逻辑:未填写摘要时不再自动截取正文内容。

Validation:

- 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

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

- curl 校验 /apps/space/css/space.editor.css 返回 200,/js/space.vue.pc.subassembly.js 包含新工具条与三端预览代码
非繁 пре 5 месеци
родитељ
комит
d22fb67557

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

@@ -59,6 +59,7 @@
 			<service name="article_api" desc="文章接口" title="api" >
 				<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>
 			
 			<!-- 流程 -->

+ 56 - 0
WebRoot/apps/space/css/space.editor.css

@@ -0,0 +1,56 @@
+.space-editor-wrap {
+	width: 100%;
+}
+
+.space-editor-toolstrip {
+	display: flex;
+	align-items: center;
+	gap: 8px;
+	flex-wrap: wrap;
+	padding: 8px 10px;
+	border: 1px solid #c4c4c4;
+	border-bottom: 0;
+	background: #fafafa;
+}
+
+.space-editor-toolstrip .el-button--small,
+.space-editor-toolstrip .el-input--small .el-input__inner {
+	height: 30px;
+	line-height: 28px;
+}
+
+.space-editor-quality {
+	width: 118px;
+}
+
+.space-editor-upload-status {
+	font-size: 12px;
+	color: #909399;
+}
+
+.space-editor-preview-dialog .el-dialog__body {
+	padding: 12px 18px 18px;
+}
+
+.space-editor-preview-toolbar {
+	display: flex;
+	align-items: center;
+	justify-content: space-between;
+	margin-bottom: 12px;
+}
+
+.space-editor-preview-stage {
+	height: 700px;
+	overflow: auto;
+	text-align: center;
+	background: #f5f7fa;
+	border: 1px solid #e4e7ed;
+	padding: 16px;
+}
+
+.space-editor-preview-stage iframe {
+	display: inline-block;
+	max-width: 100%;
+	background: #fff;
+	box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
+}

+ 349 - 5
WebRoot/apps/space/js/space.vue.subassembly.js

@@ -384,6 +384,13 @@ Vue.component('spaceEditor', {
 			// 标识,全部为 true 则代表全部加载完成
 			jsUrlFlag: [],
 			notLoadEditor: true, // 未加载完 editor 编辑器,true:未加载完,false:已加载完
+			imageQuality: 'standard',
+			uploading: false,
+			uploadStatus: '',
+			previewVisible: false,
+			previewMode: 'pc',
+			previewUrl: '',
+			previewLoading: false,
 		}
 	},
 	name: "spaceEditor",
@@ -400,7 +407,20 @@ Vue.component('spaceEditor', {
 	 * type:编辑器工具栏类型
 	 * isfullscreen:是否有全屏,
 	 */
-	props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen'],
+	props: ['htmlContent', 'size', 'width', 'height', 'placeholder', 'type', 'isfullscreen', 'articlepreview', 'previewdata', 'previewurl'],
+	computed: {
+		previewFrameStyle: function () {
+			var widthMap = {
+				pc: '1200px',
+				pad: '768px',
+				mobile: '390px'
+			};
+			return {
+				width: widthMap[this.previewMode] || widthMap.pc,
+				height: '680px'
+			};
+		}
+	},
 	watch: {
 		height: function (newVal, oldVal) {
 
@@ -484,10 +504,26 @@ Vue.component('spaceEditor', {
 			document.getElementsByTagName('head')[0].appendChild(script);
 
 		},
+		isArticlePreview: function () {
+			return this.articlepreview === true || this.articlepreview === 'true';
+		},
+		showEditorTools: function () {
+			return this.type != 'flow' && this.isArticlePreview();
+		},
+		getUploadOptions: function () {
+			return {
+				imageQuality: this.imageQuality,
+				imageMaxWidth: 1920
+			};
+		},
 		myCustomUploadAdapterPlugin: function (editor) {
+			this.installUploadAdapter(editor);
+		},
+		installUploadAdapter: function (editor) {
+			var _this = this;
 			editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
 				// 第二个参数设置上传图片的地址
-				return new MyUploadAdapter(loader);
+				return new MyUploadAdapter(loader, _this.getUploadOptions());
 			};
 		},
 		/**
@@ -597,6 +633,267 @@ Vue.component('spaceEditor', {
 				}
 			}
 		},
+		formatContent: function () {
+			if (!this.editor) {
+				return;
+			}
+
+			var html = this.editor.getData();
+			if (space.utils.isNull(html)) {
+				space.message.warning("正文内容为空");
+				return;
+			}
+
+			var wrapper = document.createElement("div");
+			wrapper.innerHTML = html;
+
+			var all = wrapper.querySelectorAll("*");
+			for (var i = 0; i < all.length; i++) {
+				var node = all[i];
+				node.removeAttribute("lang");
+				node.removeAttribute("width");
+				node.removeAttribute("height");
+				node.removeAttribute("onload");
+				node.removeAttribute("border");
+				node.removeAttribute("vspace");
+				node.removeAttribute("hspace");
+
+				var style = node.getAttribute("style") || "";
+				if (/mso-|font-family|text-indent:\s*0|background:\s*transparent/i.test(style)) {
+					node.removeAttribute("style");
+				}
+			}
+
+			var inlineNodes = wrapper.querySelectorAll("span, font");
+			for (var s = inlineNodes.length - 1; s >= 0; s--) {
+				var inlineNode = inlineNodes[s];
+				if (inlineNode.attributes.length == 0 && inlineNode.parentNode) {
+					while (inlineNode.firstChild) {
+						inlineNode.parentNode.insertBefore(inlineNode.firstChild, inlineNode);
+					}
+					inlineNode.parentNode.removeChild(inlineNode);
+				}
+			}
+
+			var emptyBlocks = wrapper.querySelectorAll("p, div");
+			for (var e = emptyBlocks.length - 1; e >= 0; e--) {
+				var block = emptyBlocks[e];
+				var hasMedia = block.querySelector("img, video, iframe, table");
+				var text = (block.textContent || "").replace(/\u00a0/g, "").trim();
+				if (!hasMedia && text == "" && block.parentNode) {
+					block.parentNode.removeChild(block);
+				}
+			}
+
+			var images = wrapper.querySelectorAll("img");
+			for (var imgIndex = 0; imgIndex < images.length; imgIndex++) {
+				images[imgIndex].style.maxWidth = "100%";
+				images[imgIndex].style.height = "auto";
+				images[imgIndex].style.display = "block";
+				images[imgIndex].style.margin = "12px auto";
+			}
+
+			var videos = wrapper.querySelectorAll("video, iframe");
+			for (var v = 0; v < videos.length; v++) {
+				videos[v].style.maxWidth = "100%";
+				if (videos[v].tagName.toLowerCase() == "video") {
+					videos[v].setAttribute("controls", "controls");
+					videos[v].setAttribute("playsinline", "playsinline");
+					videos[v].style.display = "block";
+					videos[v].style.margin = "12px auto";
+				}
+			}
+
+			var tables = wrapper.querySelectorAll("table");
+			for (var t = 0; t < tables.length; t++) {
+				tables[t].style.width = "100%";
+				tables[t].style.borderCollapse = "collapse";
+			}
+
+			this.editor.setData(wrapper.innerHTML);
+			this.$emit("input", this.editor.getData());
+			space.message.success("正文已完成排版整理");
+		},
+		insertHtml: function (html) {
+			if (!this.editor || space.utils.isNull(html)) {
+				return;
+			}
+
+			var viewFragment = this.editor.data.processor.toView(html);
+			var modelFragment = this.editor.data.toModel(viewFragment);
+			this.editor.model.insertContent(modelFragment);
+			this.$emit("input", this.editor.getData());
+		},
+		openMultiImagePicker: function () {
+			if (this.$refs.multiImageInput) {
+				this.$refs.multiImageInput.click();
+			}
+		},
+		openVideoPicker: function () {
+			if (this.$refs.videoInput) {
+				this.$refs.videoInput.click();
+			}
+		},
+		handleMultiImageSelect: function (event) {
+			var files = Array.prototype.slice.call(event.target.files || []);
+			event.target.value = "";
+			this.uploadImageFiles(files);
+		},
+		handleVideoSelect: function (event) {
+			var files = Array.prototype.slice.call(event.target.files || []);
+			event.target.value = "";
+			if (files.length > 0) {
+				this.uploadVideoFile(files[0]);
+			}
+		},
+		uploadImageFiles: function (files) {
+			var imageFiles = files.filter(function (file) {
+				return file && file.type && file.type.indexOf("image/") === 0;
+			});
+			if (imageFiles.length == 0) {
+				space.message.warning("请选择图片文件");
+				return;
+			}
+
+			var _this = this;
+			_this.uploading = true;
+			_this.uploadStatus = "正在上传图片 0/" + imageFiles.length;
+
+			var chain = Promise.resolve();
+			imageFiles.forEach(function (file, index) {
+				chain = chain.then(function () {
+					_this.uploadStatus = "正在上传图片 " + (index + 1) + "/" + imageFiles.length;
+					return MyUploadAdapter.uploadPlainFile(file, _this.getUploadOptions()).then(function (res) {
+						_this.insertHtml('<p><img src="' + res.default + '"></p>');
+					});
+				});
+			});
+
+			chain.then(function () {
+				space.message.success("图片已上传");
+			}).catch(function (msg) {
+				space.message.error(msg || "图片上传失败");
+			}).finally(function () {
+				_this.uploading = false;
+				_this.uploadStatus = "";
+			});
+		},
+		uploadVideoFile: function (file) {
+			if (!file || !file.type || file.type.indexOf("video/") !== 0) {
+				space.message.warning("请选择视频文件");
+				return;
+			}
+
+			var _this = this;
+			_this.uploading = true;
+			_this.uploadStatus = "正在上传视频";
+			MyUploadAdapter.uploadPlainFile(file, {
+				imageQuality: 'origin'
+			}, function (loaded, total) {
+				if (total > 0) {
+					_this.uploadStatus = "正在上传视频 " + Math.round(loaded * 100 / total) + "%";
+				}
+			}).then(function (res) {
+				if (_this.editor && _this.editor.commands.get('mediaEmbed')) {
+					_this.editor.execute('mediaEmbed', res.default);
+				} else {
+					_this.insertHtml('<p><video controls playsinline preload="metadata" src="' + res.default + '"></video></p>');
+				}
+				_this.$emit("input", _this.editor.getData());
+				space.message.success("视频已插入正文");
+			}).catch(function (msg) {
+				space.message.error(msg || "视频上传失败");
+			}).finally(function () {
+				_this.uploading = false;
+				_this.uploadStatus = "";
+			});
+		},
+		bindVideoPasteUpload: function () {
+			if (!this.editor || !this.editor.ui || !this.editor.ui.getEditableElement) {
+				return;
+			}
+
+			var editable = this.editor.ui.getEditableElement();
+			if (!editable || editable.getAttribute("data-space-video-upload") == "true") {
+				return;
+			}
+
+			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) {
+					return;
+				}
+
+				var files = Array.prototype.slice.call(dataTransfer.files);
+				var videoFile = files.find(function (file) {
+					return file && file.type && file.type.indexOf("video/") === 0;
+				});
+
+				if (videoFile) {
+					event.preventDefault();
+					_this.uploadVideoFile(videoFile);
+				}
+			};
+
+			editable.addEventListener("paste", handler);
+			editable.addEventListener("drop", handler);
+		},
+		getPreviewPostData: function () {
+			var data = this.previewdata || {};
+			return {
+				title: data.title || '',
+				source: data.source || '',
+				navigationid: data.navigationid || '',
+				desc: data.desc || '',
+				body: this.editor ? this.editor.getData() : (this.htmlContent || '')
+			};
+		},
+		openArticlePreview: function () {
+			if (!this.editor) {
+				return;
+			}
+
+			var postData = this.getPreviewPostData();
+			if (space.utils.isNull(postData.navigationid)) {
+				space.message.warning("请先选择发布栏目");
+				return;
+			}
+			if (space.utils.isNull(postData.body)) {
+				space.message.warning("正文内容为空");
+				return;
+			}
+
+			var _this = this;
+			_this.previewLoading = true;
+			$.ajax({
+				url: _this.previewurl || "/apps?ark=website.article_preview",
+				type: "POST",
+				data: postData,
+				dataType: "json",
+				success: function (res) {
+					if (res.code != "success") {
+						space.message.error(res.msg || "生成预览失败");
+						return;
+					}
+					var data = res.data || {};
+					var baseUrl = data.url || data.previewUrl || "";
+					if (space.utils.isNull(baseUrl)) {
+						space.message.error("生成预览失败");
+						return;
+					}
+					_this.previewUrl = baseUrl + (baseUrl.indexOf("?") == -1 ? "?" : "&") + "_t=" + new Date().getTime();
+					_this.previewVisible = true;
+				},
+				error: function () {
+					space.message.error("生成预览失败");
+				},
+				complete: function () {
+					_this.previewLoading = false;
+				}
+			});
+		},
 		/**
 		 * 初始化编辑器
 		 */
@@ -605,12 +902,26 @@ Vue.component('spaceEditor', {
 
 			var _this = this;
 			ClassicEditor.create(document.querySelector("#" + _this.id), {
-				extraPlugins: [_this.myCustomUploadAdapterPlugin], // 添加上传适配器
+				extraPlugins: [function (editor) {
+					_this.installUploadAdapter(editor);
+				}], // 添加上传适配器
 				toolbar: toolbar || {},
 				language: 'zh-cn',
 				placeholder: _this.placeholder || '',
 				mediaEmbed: {
+					previewsInData: true,
 					providers: [{
+						name: 'spaceVideo',
+						url: [
+							/\.(mp4|webm|ogg)(\?.*)?$/i
+						],
+						html: match => {
+							const input = match['input'];
+							return (
+								`<video controls playsinline preload="metadata" src="${input}" style="max-width:100%;"></video>`
+							);
+						}
+					}, {
 						name: 'myprovider',
 						url: [
 							/^lizzy.*\.com.*\/media\/(\w+)/,
@@ -632,6 +943,7 @@ Vue.component('spaceEditor', {
 
 				_this.editor = editor;
 				_this.alignFullScreenToolbarButton();
+				_this.bindVideoPasteUpload();
 
 				if (_this.htmlContent != undefined) {
 					_this.editor.setData(_this.htmlContent);
@@ -686,8 +998,40 @@ Vue.component('spaceEditor', {
 
 	},
 	template: `
-	<div :id="id">
-		<script type="text/plain"></script>
+	<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-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>
+			<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">
+		<input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
+		<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">
+			<div class="space-editor-preview-toolbar">
+				<el-radio-group v-model="previewMode" size="small">
+					<el-radio-button label="pc">PC端</el-radio-button>
+					<el-radio-button label="pad">平板端</el-radio-button>
+					<el-radio-button label="mobile">手机端</el-radio-button>
+				</el-radio-group>
+				<el-button size="small" icon="el-icon-refresh" @click="openArticlePreview" :loading="previewLoading">刷新预览</el-button>
+			</div>
+			<div class="space-editor-preview-stage">
+				<iframe v-if="previewUrl" :src="previewUrl" :style="previewFrameStyle" frameborder="0"></iframe>
+			</div>
+		</el-dialog>
 	</div>
 	`
 })

+ 122 - 8
WebRoot/apps/space/plug-in/ckeditor5/src/plugins/upload/src/myUploadAdapter.js

@@ -1,19 +1,30 @@
 class MyUploadAdapter {
 
-	constructor(loader) {
+	constructor(loader, options) {
 		// The file loader instance to use during the upload.
 		this.loader = loader;
+		this.options = options || {};
 	}
 
 	// Starts the upload process.
 	upload() {
-		return this.loader.file.then(file => new Promise((resolve, reject) => {
+		return this.loader.file
+			.then(file => this._prepareFile(file))
+			.then(file => new Promise((resolve, reject) => {
 				this._initRequest();
 				this._initListeners(resolve, reject, file);
 				this._sendRequest(file);
 			}));
 	}
 
+	uploadPlainFile(file, onProgress) {
+		return this._prepareFile(file).then(uploadFile => new Promise((resolve, reject) => {
+			this._initRequest();
+			this._initListeners(resolve, reject, uploadFile, onProgress);
+			this._sendRequest(uploadFile);
+		}));
+	}
+
 	// Aborts the upload process.
 	abort() {
 		if(this.xhr) {
@@ -34,7 +45,7 @@ class MyUploadAdapter {
 	}
 
 	// Initializes XMLHttpRequest listeners.
-	_initListeners(resolve, reject, file) {
+	_initListeners(resolve, reject, file, onProgress) {
 		const xhr = this.xhr;
 		const loader = this.loader;
 		const genericErrorText = `Couldn't upload file: ${ file.name }.`;
@@ -50,8 +61,12 @@ class MyUploadAdapter {
 			//
 			// Your integration may handle upload errors in a different way so make sure
 			// it is done properly. The reject() function must be called when the upload fails.
-			if(response.code != 'success') {
-				return reject(response.msg);
+			if(!response || response.code != 'success') {
+				return reject(response && response.msg ? response.msg : genericErrorText);
+			}
+
+			if(!response.data || !response.data[0] || !response.data[0].msg) {
+				return reject(genericErrorText);
 			}
 
 			// If the upload is successful, resolve the upload promise with an object containing
@@ -69,13 +84,107 @@ class MyUploadAdapter {
 		if(xhr.upload) {
 			xhr.upload.addEventListener('progress', evt => {
 				if(evt.lengthComputable) {
-					loader.uploadTotal = evt.total;
-					loader.uploaded = evt.loaded;
+					if (loader) {
+						loader.uploadTotal = evt.total;
+						loader.uploaded = evt.loaded;
+					}
+					if (onProgress) {
+						onProgress(evt.loaded, evt.total);
+					}
 				}
 			});
 		}
 	}
 
+	_prepareFile(file) {
+		if (!file || !this._shouldCompress(file)) {
+			return Promise.resolve(file);
+		}
+
+		return this._compressImage(file).catch(() => file);
+	}
+
+	_shouldCompress(file) {
+		var quality = this.options.imageQuality || 'standard';
+		if (quality == 'origin') {
+			return false;
+		}
+
+		if (!file.type || file.type.indexOf('image/') !== 0) {
+			return false;
+		}
+
+		var type = file.type.toLowerCase();
+		if (type.indexOf('gif') !== -1 || type.indexOf('svg') !== -1 || type.indexOf('png') !== -1) {
+			return false;
+		}
+
+		return typeof FileReader != 'undefined' && typeof document != 'undefined';
+	}
+
+	_getQualityValue() {
+		var quality = this.options.imageQuality || 'standard';
+		if (quality == 'high') {
+			return 0.85;
+		}
+		if (quality == 'low') {
+			return 0.5;
+		}
+		return 0.7;
+	}
+
+	_compressImage(file) {
+		var maxWidth = parseInt(this.options.imageMaxWidth || 1920);
+		var qualityValue = this._getQualityValue();
+
+		return new Promise((resolve, reject) => {
+			var reader = new FileReader();
+			reader.onload = function (event) {
+				var img = new Image();
+				img.onload = function () {
+					var width = img.width;
+					var height = img.height;
+					if (!width || !height) {
+						reject();
+						return;
+					}
+
+					if (maxWidth > 0 && width > maxWidth) {
+						height = Math.round(height * maxWidth / width);
+						width = maxWidth;
+					}
+
+					var canvas = document.createElement('canvas');
+					canvas.width = width;
+					canvas.height = height;
+					var context = canvas.getContext('2d');
+					context.drawImage(img, 0, 0, width, height);
+					if (!canvas.toBlob || typeof File == 'undefined') {
+						resolve(file);
+						return;
+					}
+
+					canvas.toBlob(function (blob) {
+						if (!blob || blob.size >= file.size) {
+							resolve(file);
+							return;
+						}
+
+						var name = file.name.replace(/\.(jpe?g|webp)$/i, '') + '.jpg';
+						resolve(new File([blob], name, {
+							type: 'image/jpeg',
+							lastModified: Date.now()
+						}));
+					}, 'image/jpeg', qualityValue);
+				};
+				img.onerror = reject;
+				img.src = event.target.result;
+			};
+			reader.onerror = reject;
+			reader.readAsDataURL(file);
+		});
+	}
+
 	// Prepares the data and sends the request.
 	_sendRequest(file) {
 		// Prepare the form data.
@@ -92,4 +201,9 @@ class MyUploadAdapter {
 		this.xhr.send(data);
 	}
 
-}
+}
+
+MyUploadAdapter.uploadPlainFile = function (file, options, onProgress) {
+	var adapter = new MyUploadAdapter(null, options || {});
+	return adapter.uploadPlainFile(file, onProgress);
+};

+ 5 - 4
WebRoot/web/subassembly/app/pc/10021/10104/1002110104_edit.jsp

@@ -1,8 +1,8 @@
 <html>
 
-	<head>
-		
-	</head>
+	<head>
+		<link rel="stylesheet" href="/apps/space/css/space.editor.css">
+	</head>
 
 	<body>
 		<div id="space-content">
@@ -36,7 +36,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="@service{ name: 'article_preview' }@"></space-editor>
 							</el-form-item>
 						</el-col>
 

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

@@ -12,6 +12,7 @@
  <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"> 
  <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> 
@@ -56,7 +57,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
 							</el-form-item>
 						</el-col>
 

+ 5 - 4
WebRoot/web/subassembly/app/pc/10021/10105/1002110105_edit.jsp

@@ -1,8 +1,8 @@
 <html>
 
-	<head>
-		
-	</head>
+	<head>
+		<link rel="stylesheet" href="/apps/space/css/space.editor.css">
+	</head>
 
 	<body>
 		<div id="space-content">
@@ -37,7 +37,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="@service{ name: 'article_preview' }@"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

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

@@ -12,6 +12,7 @@
  <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"> 
  <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> 
@@ -57,7 +58,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

+ 5 - 4
WebRoot/web/subassembly/app/pc/10021/10211/1002110211_edit.jsp

@@ -1,8 +1,8 @@
 <html>
 
-	<head>
-		
-	</head>
+	<head>
+		<link rel="stylesheet" href="/apps/space/css/space.editor.css">
+	</head>
 
 	<body>
 		<div id="space-content">
@@ -38,7 +38,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor" ></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="@service{ name: 'article_preview' }@"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

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

@@ -12,6 +12,7 @@
  <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"> 
  <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> 
@@ -58,7 +59,8 @@
 							</el-form-item>
 
 							<el-form-item label="正文" prop="body" class="ueditor" style="margin-bottom: 0;">
-								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor" ></space-editor>
+								<space-editor v-model="obj.body" :height="editorHeight" placeholder="请输入正文内容" ref="editor"
+								 articlepreview="true" :previewdata="obj" previewurl="<app:token name='website.article_preview' />"></space-editor>
 								<pre id="body_content" style="display: none;">${editBody}</pre>
 							</el-form-item>
 						</el-col>

+ 44 - 26
src/space/apps/moudules/website/services/ArticleService.java

@@ -173,7 +173,7 @@ public class ArticleService extends BaseTransaction {
     }
 
     /**
-     * 根据 html 正文内容填写摘要,没有填写摘要时,才从正文中获取前 100 个字,保存摘要
+     * 保留手填摘要;未填写摘要时允许为空,不再从正文自动提取。
      *
      * @param article     文章
      * @param htmlContent html 正文内容
@@ -181,31 +181,6 @@ public class ArticleService extends BaseTransaction {
      * @log 2020年10月19日
      */
     private void saveArticleDesc(Article article, String htmlContent) {
-
-        if (StringUtil.isNull(article.getDesc())) {// 没有填写摘要时,默认获取正文中的前 100 个字
-
-        	// 去掉 html
-			String contentStr = StringUtil.delHTMLTag(htmlContent);
-			// 去掉换行符
-			contentStr = StringUtil.clearJavaLine(contentStr);
-			
-            String desc = contentStr;
-
-            if (StringUtil.notNull(contentStr)) {
-                contentStr = contentStr.replace("&nbsp;", " ");
-
-                if (contentStr.length() > 100) {
-                    desc = contentStr.substring(0, 100);
-                } else {
-                    // 少于 100 字
-                    desc = contentStr.substring(0, contentStr.length());
-                }
-
-            }
-
-            article.setDesc(desc);
-        }
-
     }
 
     /**
@@ -1181,6 +1156,49 @@ public class ArticleService extends BaseTransaction {
         return DEFAULT_FORWARD;
     }
 
+    /**
+     * 生成文章正文临时预览。
+     *
+     * @throws Exception
+     * @author SPACE
+     */
+    public void preview() throws Exception {
+
+        String content = getParameterNotXSS("body");
+        Long navigationid = getParameterToLong("navigationid");
+
+        if (StringUtil.isNull(content)) {
+            write(getResponseWarningMsgPackage("正文内容为空").toJson());
+            return;
+        }
+
+        if (navigationid == null || navigationid <= 0) {
+            write(getResponseWarningMsgPackage("请先选择发布栏目").toJson());
+            return;
+        }
+
+        GeneralDBAccess gdba = getGdbaInstance();
+        WebsiteNavigation wn = getWebsiteNavigationById(gdba, navigationid);
+        if (!isArticleTargetNavigation(wn)) {
+            write(getResponseWarningMsgPackage("发布栏目必须选择可发布文章的栏目").toJson());
+            return;
+        }
+
+        if (hasEnabledChildNavigation(gdba, navigationid)) {
+            write(getResponseWarningMsgPackage("发布栏目必须选择最下级栏目,请继续向右选择最后一级栏目").toJson());
+            return;
+        }
+
+        String editPath = WebEditorUtil.createHtmlFile(content);
+        String runContent = converArticleContentHtmlLink(getWebRootPath() + editPath,
+                space.apps.moudules.website.common.ConstVars.domain);
+        String runPath = WebEditorUtil.createHtmlFile(runContent);
+
+        Map<String, Object> retMap = new HashMap<String, Object>();
+        retMap.put("url", runPath);
+        write(getResponseSuccessDataPackage(retMap).toJsonWriteNonStringValueAsString());
+    }
+
     // 测试的服务
 
     /**