Explorar o código

知识库积分部分功能提交,样式调整

徐滕 hai 6 días
pai
achega
e4d33e090b

+ 19 - 12
src/main/webapp/webpage/modules/WorkKnowledgeBase/workKnowledgeBasePointRuleForm.jsp

@@ -63,7 +63,8 @@
             setTimeout(function() {
                 var categoryId = $("#categoryId").val();
                 var categoryName = $("#categoryName").val();
-                updateRuleTypeOptions(categoryId, categoryName);
+                var currentRuleType = "${workKnowledgeBasePointRule.ruleType}" || "1";
+                updateRuleTypeOptions(categoryId, categoryName, currentRuleType);
             }, 100);
         });
 
@@ -91,8 +92,8 @@
         }
         
         // 根据归属分类切换规则类型选项
-        function updateRuleTypeOptions(categoryId, categoryName) {
-            console.log("更新规则类型 - categoryId:", categoryId, "categoryName:", categoryName);
+        function updateRuleTypeOptions(categoryId, categoryName, savedRuleType) {
+            console.log("更新规则类型 - categoryId:", categoryId, "categoryName:", categoryName, "savedRuleType:", savedRuleType);
             
             // 判断是否是基础积分(支持ID或名称匹配)
             var isBasicPoints = (categoryName && categoryName.indexOf("基础积分") !== -1);
@@ -104,10 +105,12 @@
                 $("#ruleTypeOption1").html('<input type="radio" name="ruleType" value="10" lay-filter="ruleTypeFilter" style="margin-right:5px;"/> 阅读');
                 $("#ruleTypeOption2").html('<input type="radio" name="ruleType" value="20" lay-filter="ruleTypeFilter" style="margin-right:5px;"/> 点赞');
                 
-                // 如果当前选中的是创建/审核积分,重置为阅读
-                var currentRuleType = $("input[name='ruleType']:checked").val();
-                console.log("当前选中的ruleType:", currentRuleType);
-                if (currentRuleType != "10" && currentRuleType != "20") {
+                // 如果传入了保存的值,使用它;否则默认选中阅读
+                var ruleTypeToCheck = savedRuleType || "10";
+                if (ruleTypeToCheck == "10" || ruleTypeToCheck == "20") {
+                    $("input[name='ruleType'][value='" + ruleTypeToCheck + "']").prop("checked", true);
+                    console.log("选中保存的ruleType:", ruleTypeToCheck);
+                } else {
                     $("input[name='ruleType'][value='10']").prop("checked", true);
                     console.log("重置为阅读");
                 }
@@ -117,10 +120,12 @@
                 $("#ruleTypeOption1").html('<input type="radio" name="ruleType" value="1" lay-filter="ruleTypeFilter" style="margin-right:5px;"/> 创建积分');
                 $("#ruleTypeOption2").html('<input type="radio" name="ruleType" value="2" lay-filter="ruleTypeFilter" style="margin-right:5px;"/> 审核积分');
                 
-                // 如果当前选中的是阅读/点赞,重置为创建积分
-                var currentRuleType = $("input[name='ruleType']:checked").val();
-                console.log("当前选中的ruleType:", currentRuleType);
-                if (currentRuleType != "1" && currentRuleType != "2") {
+                // 如果传入了保存的值,使用它;否则默认选中创建积分
+                var ruleTypeToCheck = savedRuleType || "1";
+                if (ruleTypeToCheck == "1" || ruleTypeToCheck == "2") {
+                    $("input[name='ruleType'][value='" + ruleTypeToCheck + "']").prop("checked", true);
+                    console.log("选中保存的ruleType:", ruleTypeToCheck);
+                } else {
                     $("input[name='ruleType'][value='1']").prop("checked", true);
                     console.log("重置为创建积分");
                 }
@@ -146,7 +151,9 @@
                 if (currentCategoryId != lastCategoryId || currentCategoryName != lastCategoryName) {
                     lastCategoryId = currentCategoryId;
                     lastCategoryName = currentCategoryName;
-                    updateRuleTypeOptions(currentCategoryId, currentCategoryName);
+                    // 分类变化时,获取当前选中的ruleType并传递
+                    var currentRuleType = $("input[name='ruleType']:checked").val();
+                    updateRuleTypeOptions(currentCategoryId, currentCategoryName, currentRuleType);
                 }
             }, 500); // 每500ms检查一次
         }

+ 1 - 1
src/main/webapp/webpage/modules/WorkKnowledgeBase/workKnowledgeBasePointRuleList.jsp

@@ -238,7 +238,7 @@
                 , {align: 'center', title: "操作", width: 240, templet: function (d) {
                     var xml = "<div class=\"layui-btn-group\">";
                     <shiro:hasPermission name="workKnowledgeBase:pointRule:edit">
-                    xml += "<a href=\"javascript:void(0)\" onclick=\"openDialog('修改积分规则', '${ctx}/workKnowledgeBase/pointRule/form?id=" + d.id + "','800px', '450px')\" class=\"layui-btn layui-btn-xs  layui-bg-green\"> 修改</a>";
+                    xml += "<a href=\"javascript:void(0)\" onclick=\"openDialog('修改积分规则', '${ctx}/workKnowledgeBase/pointRule/form?id=" + d.id + "','1000px', '600px')\" class=\"layui-btn layui-btn-xs  layui-bg-green\"> 修改</a>";
                     var st = d.status;
                     if (st == "1") {
                         xml += "<a href=\"javascript:void(0)\" onclick=\"toggleStatus('禁用规则', '" + d.id + "', '0')\" class=\"layui-btn layui-btn-xs  layui-bg-orange\"> 禁用</a>";

+ 27 - 5
src/main/webapp/webpage/modules/WorkKnowledgeBase/workKnowledgeBaseShareForm.jsp

@@ -23,7 +23,17 @@
         }
 
         $(document).ready(function() {
+            // 添加内容属性必填验证
+            $.validator.addMethod("requiredRadio", function(value, element, params) {
+                return $("input[name='contentAttribute']:checked").length > 0;
+            }, "请选择内容属性");
+            
             validateForm = $('#inputForm').validate({
+                rules: {
+                    contentAttribute: {
+                        requiredRadio: true
+                    }
+                },
                 submitHandler: function(form) {
                     loading('正在提交,请稍等...');
                     form.submit();
@@ -31,16 +41,28 @@
                 errorContainer: '#messageBox',
                 errorPlacement: function(error, element) {
                     $('#messageBox').text('输入有误,请先更正。');
-                    error.insertAfter(element);
+                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
+                        error.appendTo(element.parent().parent());
+                    } else {
+                        error.insertAfter(element);
+                    }
                 }
             });
 
 
             var contentAttribute = '${workKnowledgeBaseShareInfo.contentAttribute}';
-            // 选中对应单选
+            // 选中对应单选,如果为空则默认选中“原创”(0)
             var radioList = document.querySelectorAll("input[name='contentAttribute']");
+            var hasValue = false;
             for(let item of radioList){
-                item.checked = (item.value === contentAttribute);
+                if (item.value === contentAttribute && contentAttribute !== '') {
+                    item.checked = true;
+                    hasValue = true;
+                }
+            }
+            // 如果没有值(新建时),默认选中“原创”
+            if (!hasValue) {
+                $("input[name='contentAttribute'][value='0']").prop('checked', true);
             }
 
             // 初始化动态字段中 Date 类型的 laydate 日期选择器
@@ -112,8 +134,8 @@
                 <div class="layui-item layui-col-sm6 lw6">
                     <label class="layui-form-label"><span class="require-item">*</span>内容属性:</label>
                     <div class="layui-input-block">
-                        <input type="radio" name="contentAttribute" lay-filter="contentAttributeRadio" title="原创" value="0">
-                        <input type="radio" name="contentAttribute" lay-filter="contentAttributeRadio" title="转载" value="1">
+                        <input type="radio" name="contentAttribute" lay-filter="contentAttributeRadio" title="原创" value="0" class="required">
+                        <input type="radio" name="contentAttribute" lay-filter="contentAttributeRadio" title="转载" value="1" class="required">
                     </div>
                 </div>
             </div>