Selaa lähdekoodia

完善文章缩略图必填校验

新增文章选择栏目后,根据栏目排版样式动态控制缩略图必填;只有文字列表允许不上传,其他排版样式均在当前录入页提示并阻止保存或提交。

同步调整文章服务端兜底规则,防止绕过页面提交无缩略图数据;保留现有栏目尺寸接口和页面结构。

Validation:
- 两份新增文章 JSP JavaScript 语法检查通过
- ArticleService Java 8 编译通过
- 本地运行副本 JSP/class 校验值一致
- 本地后台 HTTP 200
非繁 4 kuukautta sitten
vanhempi
commit
b2448cbbe4

+ 68 - 38
WebRoot/web/subassembly/app/pc/10021/10104/1002110104_edit.jsp

@@ -91,10 +91,10 @@
 								</el-tooltip>
 								</el-tooltip>
 							</el-form-item>
 							</el-form-item>
 
 
-							<el-form-item label="缩略图" prop="thumbnail" v-show="isColumn">
-								<space-upload-img v-model="obj.thumbnail" type="" :width="photoSize.width" :height="photoSize.height"
-								 :tip="photoSizeMsg"></space-upload-img>
-							</el-form-item>
+							<el-form-item label="缩略图" prop="thumbnail" v-show="isColumn" :class="{ 'is-required': thumbnailRequired }">
+								<space-upload-img v-model="obj.thumbnail" type="" :width="photoSize.width" :height="photoSize.height" @input="thumbnailChange"
+								 :tip="photoSizeMsg"></space-upload-img>
+							</el-form-item>
 						</el-col>
 						</el-col>
 
 
 					</el-row>
 					</el-row>
@@ -173,7 +173,7 @@
 					}
 					}
 					callback();
 					callback();
 				};
 				};
-				var validateUrl = (rule, value, callback) => {
+				var validateUrl = (rule, value, callback) => {
 					if (this.obj.ajtcode == 10020) {
 					if (this.obj.ajtcode == 10020) {
 
 
 						if (!value) {
 						if (!value) {
@@ -187,8 +187,14 @@
 						}
 						}
 
 
 					}
 					}
-					callback();
-				};
+					callback();
+				};
+				var validateThumbnail = (rule, value, callback) => {
+					if (this.thumbnailRequired && space.utils.isNull(value)) {
+						return callback(new Error('请上传缩略图'));
+					}
+					callback();
+				};
 
 
 				return {
 				return {
 					pickerOptions: { //设置选择今天以及今天之后的日期
 					pickerOptions: { //设置选择今天以及今天之后的日期
@@ -258,43 +264,67 @@
 							required: true,
 							required: true,
 							trigger: 'change'
 							trigger: 'change'
 						}],
 						}],
-						url: [{
-							validator: validateUrl,
-							required: true,
-							trigger: 'blur'
-						}]
-					},
-					loading: false,
-					isColumn: false
-				};
-			},
-			methods: {
-				/**
-				 * 栏目变动事件
-				 */
-				navigationChange: function() {
-					this.isColumn = true;
-					if (space.utils.isNull(this.obj.navigationid)) {
-						return;
-					}
-					var that = this;
-					space.utils.ajax({
+						url: [{
+							validator: validateUrl,
+							required: true,
+							trigger: 'blur'
+						}],
+						thumbnail: [{
+							validator: validateThumbnail,
+							trigger: 'change'
+						}]
+					},
+					loading: false,
+					isColumn: false,
+					thumbnailRequired: false
+				};
+			},
+			methods: {
+				thumbnailChange: function() {
+					var that = this;
+					this.$nextTick(function() {
+						if (that.$refs.obj) {
+							that.$refs.obj.clearValidate('thumbnail');
+						}
+					});
+				},
+				/**
+				 * 栏目变动事件
+				 */
+				navigationChange: function() {
+					this.isColumn = !space.utils.isNull(this.obj.navigationid);
+					this.thumbnailRequired = this.isColumn;
+					this.photoSize.width = '';
+					this.photoSize.height = '';
+					this.photoSizeMsg = '';
+					this.thumbnailChange();
+					if (space.utils.isNull(this.obj.navigationid)) {
+						return;
+					}
+					var that = this;
+					var selectedNavigationId = this.obj.navigationid;
+					space.utils.ajax({
 						url: "@service{ name: 'getNavigationThumbnailSize' }@",
 						url: "@service{ name: 'getNavigationThumbnailSize' }@",
 						data: {
 						data: {
 							"navigationid": this.obj.navigationid
 							"navigationid": this.obj.navigationid
 						},
 						},
-						dataType: 'json',
-						callback: function(data) {
-							var d = data.data;
-							that.photoSize.width = d.photoSizeWidth;
-							that.photoSize.height = d.photoSizeHeight;
+						dataType: 'json',
+						callback: function(data) {
+							if (String(that.obj.navigationid) !== String(selectedNavigationId)) {
+								return;
+							}
+							var d = data && data.data ? data.data : {};
+							that.thumbnailRequired = String(d.wnlscode) !== '10000';
+							that.photoSize.width = d.photoSizeWidth;
+							that.photoSize.height = d.photoSizeHeight;
 							if (that.photoSize.height == undefined && that.photoSize.width == undefined) {
 							if (that.photoSize.height == undefined && that.photoSize.width == undefined) {
 								that.photoSizeMsg = "";
 								that.photoSizeMsg = "";
-							} else {
-								that.photoSizeMsg = "(尺寸为 " + d.photoSizeWidth + " x " + d.photoSizeHeight + ")";
-							}
-						}
-					})
+							} else {
+								that.photoSizeMsg = "(尺寸为 " + d.photoSizeWidth + " x " + d.photoSizeHeight + ")";
+							}
+							that.thumbnailChange();
+						}
+					})
 				}
 				}
 			},
 			},
 			created: function() {
 			created: function() {

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

@@ -116,10 +116,10 @@
 								</el-tooltip>
 								</el-tooltip>
 							</el-form-item>
 							</el-form-item>
 
 
-							<el-form-item label="缩略图" prop="thumbnail" v-show="isColumn">
-								<space-upload-img v-model="obj.thumbnail" type="" :width="photoSize.width" :height="photoSize.height"
-								 :tip="photoSizeMsg"></space-upload-img>
-							</el-form-item>
+							<el-form-item label="缩略图" prop="thumbnail" v-show="isColumn" :class="{ 'is-required': thumbnailRequired }">
+								<space-upload-img v-model="obj.thumbnail" type="" :width="photoSize.width" :height="photoSize.height" @input="thumbnailChange"
+								 :tip="photoSizeMsg"></space-upload-img>
+							</el-form-item>
 						</el-col>
 						</el-col>
 
 
 					</el-row>
 					</el-row>
@@ -198,7 +198,7 @@
 					}
 					}
 					callback();
 					callback();
 				};
 				};
-				var validateUrl = (rule, value, callback) => {
+				var validateUrl = (rule, value, callback) => {
 					if (this.obj.ajtcode == 10020) {
 					if (this.obj.ajtcode == 10020) {
 
 
 						if (!value) {
 						if (!value) {
@@ -212,8 +212,14 @@
 						}
 						}
 
 
 					}
 					}
-					callback();
-				};
+					callback();
+				};
+				var validateThumbnail = (rule, value, callback) => {
+					if (this.thumbnailRequired && space.utils.isNull(value)) {
+						return callback(new Error('请上传缩略图'));
+					}
+					callback();
+				};
 
 
 				return {
 				return {
 					pickerOptions: { //设置选择今天以及今天之后的日期
 					pickerOptions: { //设置选择今天以及今天之后的日期
@@ -284,43 +290,67 @@
 							required: true,
 							required: true,
 							trigger: 'change'
 							trigger: 'change'
 						}],
 						}],
-						url: [{
-							validator: validateUrl,
-							required: true,
-							trigger: 'blur'
-						}]
-					},
-					loading: false,
-					isColumn: false
-				};
-			},
-			methods: {
-				/**
-				 * 栏目变动事件
-				 */
-				navigationChange: function() {
-					this.isColumn = true;
-					if (space.utils.isNull(this.obj.navigationid)) {
-						return;
-					}
-					var that = this;
-					space.utils.ajax({
+						url: [{
+							validator: validateUrl,
+							required: true,
+							trigger: 'blur'
+						}],
+						thumbnail: [{
+							validator: validateThumbnail,
+							trigger: 'change'
+						}]
+					},
+					loading: false,
+					isColumn: false,
+					thumbnailRequired: false
+				};
+			},
+			methods: {
+				thumbnailChange: function() {
+					var that = this;
+					this.$nextTick(function() {
+						if (that.$refs.obj) {
+							that.$refs.obj.clearValidate('thumbnail');
+						}
+					});
+				},
+				/**
+				 * 栏目变动事件
+				 */
+				navigationChange: function() {
+					this.isColumn = !space.utils.isNull(this.obj.navigationid);
+					this.thumbnailRequired = this.isColumn;
+					this.photoSize.width = '';
+					this.photoSize.height = '';
+					this.photoSizeMsg = '';
+					this.thumbnailChange();
+					if (space.utils.isNull(this.obj.navigationid)) {
+						return;
+					}
+					var that = this;
+					var selectedNavigationId = this.obj.navigationid;
+					space.utils.ajax({
 						url: "<app:token name='website.getNavigationThumbnailSize' />",
 						url: "<app:token name='website.getNavigationThumbnailSize' />",
 						data: {
 						data: {
 							"navigationid": this.obj.navigationid
 							"navigationid": this.obj.navigationid
 						},
 						},
-						dataType: 'json',
-						callback: function(data) {
-							var d = data.data;
-							that.photoSize.width = d.photoSizeWidth;
-							that.photoSize.height = d.photoSizeHeight;
+						dataType: 'json',
+						callback: function(data) {
+							if (String(that.obj.navigationid) !== String(selectedNavigationId)) {
+								return;
+							}
+							var d = data && data.data ? data.data : {};
+							that.thumbnailRequired = String(d.wnlscode) !== '10000';
+							that.photoSize.width = d.photoSizeWidth;
+							that.photoSize.height = d.photoSizeHeight;
 							if (that.photoSize.height == undefined && that.photoSize.width == undefined) {
 							if (that.photoSize.height == undefined && that.photoSize.width == undefined) {
 								that.photoSizeMsg = "";
 								that.photoSizeMsg = "";
-							} else {
-								that.photoSizeMsg = "(尺寸为 " + d.photoSizeWidth + " x " + d.photoSizeHeight + ")";
-							}
-						}
-					})
+							} else {
+								that.photoSizeMsg = "(尺寸为 " + d.photoSizeWidth + " x " + d.photoSizeHeight + ")";
+							}
+							that.thumbnailChange();
+						}
+					})
 				}
 				}
 			},
 			},
 			created: function() {
 			created: function() {

+ 8 - 7
src/space/apps/moudules/website/services/ArticleService.java

@@ -77,6 +77,7 @@ public class ArticleService extends BaseTransaction {
     private static final String PREVIEW_RELEASE_TIME_KEY = "releaseTime";
     private static final String PREVIEW_RELEASE_TIME_KEY = "releaseTime";
     private static final Pattern LOCAL_UPLOAD_ABSOLUTE_URL_PATTERN = Pattern.compile(
     private static final Pattern LOCAL_UPLOAD_ABSOLUTE_URL_PATTERN = Pattern.compile(
             "(?i)(?:https?:)?//(?:ht\\.gzhxtc\\.edu\\.cn|localhost|127\\.0\\.0\\.1|ffkj-[a-z0-9-]+\\.localhost)(?::\\d+)?(/web/upload/[^\"'<>\\s]*)");
             "(?i)(?:https?:)?//(?:ht\\.gzhxtc\\.edu\\.cn|localhost|127\\.0\\.0\\.1|ffkj-[a-z0-9-]+\\.localhost)(?::\\d+)?(/web/upload/[^\"'<>\\s]*)");
+    private static final Long NAVIGATION_STYLE_TEXT_LIST = 10000L;
     private static final Long NAVIGATION_STYLE_GRAPHIC_LIST = 10010L;
     private static final Long NAVIGATION_STYLE_GRAPHIC_LIST = 10010L;
     private static final String COLLEGE_RED_TEMPLATE_ID_CODE = "ffkjcollegered1";
     private static final String COLLEGE_RED_TEMPLATE_ID_CODE = "ffkjcollegered1";
     private static final String ARTICLE_PUBLISHED_HISTORY_ROOT = "/web/upload/article-history/";
     private static final String ARTICLE_PUBLISHED_HISTORY_ROOT = "/web/upload/article-history/";
@@ -235,7 +236,7 @@ public class ArticleService extends BaseTransaction {
         if (wn == null) {
         if (wn == null) {
             return DEFAULT_FORWARD;
             return DEFAULT_FORWARD;
         }
         }
-        if (!verifyGraphicListThumbnailRequired(gdba, wn, article, "发布栏目")) {
+        if (!verifyNavigationThumbnailRequired(gdba, wn, article, "发布栏目")) {
             return DEFAULT_FORWARD;
             return DEFAULT_FORWARD;
         }
         }
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
@@ -389,7 +390,7 @@ public class ArticleService extends BaseTransaction {
         if (wn == null) {
         if (wn == null) {
             return DEFAULT_FORWARD;
             return DEFAULT_FORWARD;
         }
         }
-        if (!verifyGraphicListThumbnailRequired(gdba, wn, article, "发布栏目")) {
+        if (!verifyNavigationThumbnailRequired(gdba, wn, article, "发布栏目")) {
             return DEFAULT_FORWARD;
             return DEFAULT_FORWARD;
         }
         }
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
@@ -487,16 +488,16 @@ public class ArticleService extends BaseTransaction {
             if (wn == null) {
             if (wn == null) {
                 return false;
                 return false;
             }
             }
-            if (!verifyGraphicListThumbnailRequired(gdba, wn, article, "抄送栏目")) {
+            if (!verifyNavigationThumbnailRequired(gdba, wn, article, "抄送栏目")) {
                 return false;
                 return false;
             }
             }
         }
         }
         return true;
         return true;
     }
     }
 
 
-    private boolean verifyGraphicListThumbnailRequired(GeneralDBAccess gdba, WebsiteNavigation wn, Article article,
+    private boolean verifyNavigationThumbnailRequired(GeneralDBAccess gdba, WebsiteNavigation wn, Article article,
             String targetName) throws Exception {
             String targetName) throws Exception {
-        if (wn == null || !NAVIGATION_STYLE_GRAPHIC_LIST.equals(wn.getWnlscode())) {
+        if (wn == null || NAVIGATION_STYLE_TEXT_LIST.equals(wn.getWnlscode())) {
             return true;
             return true;
         }
         }
 
 
@@ -504,7 +505,7 @@ public class ArticleService extends BaseTransaction {
             return true;
             return true;
         }
         }
 
 
-        setResponsePackage(getResponseWarningMsgPackage(targetName + "为图文列表时必须上传缩略图"));
+        setResponsePackage(getResponseWarningMsgPackage(targetName + "排版样式不是文字列表时必须上传缩略图"));
         return false;
         return false;
     }
     }
 
 
@@ -641,7 +642,7 @@ public class ArticleService extends BaseTransaction {
         if (wn == null) {
         if (wn == null) {
             return TIPS_FORWARD;
             return TIPS_FORWARD;
         }
         }
-        if (!verifyGraphicListThumbnailRequired(gdba, wn, article, "发布栏目")) {
+        if (!verifyNavigationThumbnailRequired(gdba, wn, article, "发布栏目")) {
             return TIPS_FORWARD;
             return TIPS_FORWARD;
         }
         }
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
         if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {