新增:数据资源表编辑表单支持字段配置

master
Guo XIn 1 year ago
parent 5f912be209
commit 7005a36be6
  1. 8
      shandan-bianmu/src/main/java/com/keyware/shandan/bianmu/controller/MetadataController.java
  2. 3
      shandan-bianmu/src/main/resources/static/js/business/metadata/edit.js
  3. 31
      shandan-bianmu/src/main/resources/view/business/metadata/metadataEdit.html
  4. 7
      shandan-common/src/main/resources/static/js/common/layui/extend/dict.js
  5. 4
      shandan-common/src/main/resources/view/common/head.html
  6. 15
      shandan-system/src/main/java/com/keyware/shandan/frame/aspect/SafetyAspect.java
  7. 10
      shandan-system/src/main/java/com/keyware/shandan/system/entity/SysFormConfig.java
  8. 13
      shandan-system/src/main/resources/static/js/sys/form/formConfig.js

@ -14,7 +14,9 @@ import com.keyware.shandan.common.enums.SecretLevel;
import com.keyware.shandan.common.util.StreamUtil; import com.keyware.shandan.common.util.StreamUtil;
import com.keyware.shandan.common.util.StringUtils; import com.keyware.shandan.common.util.StringUtils;
import com.keyware.shandan.system.entity.SysFile; import com.keyware.shandan.system.entity.SysFile;
import com.keyware.shandan.system.entity.SysFormConfig;
import com.keyware.shandan.system.service.SysFileService; import com.keyware.shandan.system.service.SysFileService;
import com.keyware.shandan.system.service.SysFormConfigService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -46,6 +48,9 @@ public class MetadataController extends BaseController<MetadataService, Metadata
@Autowired @Autowired
private DataLabelsService labelsService; private DataLabelsService labelsService;
@Autowired
private SysFormConfigService formConfigService;
@GetMapping("/") @GetMapping("/")
public ModelAndView index(ModelAndView mov) { public ModelAndView index(ModelAndView mov) {
mov.setViewName("business/metadata/metadata"); mov.setViewName("business/metadata/metadata");
@ -93,6 +98,9 @@ public class MetadataController extends BaseController<MetadataService, Metadata
public ModelAndView edit(ModelAndView mav) { public ModelAndView edit(ModelAndView mav) {
mav.setViewName("business/metadata/metadataEdit"); mav.setViewName("business/metadata/metadataEdit");
mav.addObject("LabelConfigSet", labelsService.formConfigList()); mav.addObject("LabelConfigSet", labelsService.formConfigList());
QueryWrapper<SysFormConfig> query = new QueryWrapper<>();
query.eq("FORM_TYPE", 1);
mav.addObject("metadataFormConfig", formConfigService.list(query));
return mav; return mav;
} }

@ -276,9 +276,10 @@ layui.use(['form', 'layer', 'editPage', 'laytpl', 'laydate', 'element', 'table',
layui.dict.setData('dict-secret-level', data); layui.dict.setData('dict-secret-level', data);
} }
console.info(new Date().getTime())
//日期选择器 //日期选择器
laydate.render({ laydate.render({
elem: '#collectionTime', elem: 'input[name="collectionTime"]',
type: 'datetime', type: 'datetime',
value: new Date(), value: new Date(),
format: "yyyy-MM-dd HH:mm:ss" format: "yyyy-MM-dd HH:mm:ss"

@ -34,7 +34,27 @@
<div class="layui-form-item"> <div class="layui-form-item">
<div id="metadataTablesTab"><label style="color: red">* 请先选择数据表</label></div> <div id="metadataTablesTab"><label style="color: red">* 请先选择数据表</label></div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item" th:each="field,iterStat : ${metadataFormConfig}" th:if="${field.isShow}">
<label class="layui-form-label" th:text="${field.showTitle}">字段名称</label>
<div class="layui-input-block">
<input type="hidden" name="metadataComment" th:if="${field.fieldName == 'metadataName'}">
<!-- 文本框输入框类型 -->
<input class="layui-input" type="text" autocomplete="off"
th:if="${field.fieldType == 'input'}"
th:name="${field.fieldName}"
th:disabled="${field.isDisabled}"
th:placeholder="${field.showTitle}"
th:lay-verify="${field.isRequired ? 'required' : ''}">
<!-- 数据字典类型 -->
<div dict-component="select"
th:if="${field.fieldType == 'dict'}"
th:disabled="${field.isDisabled}"
th:dict-type="${field.dictType}"
th:dict-name="${field.fieldName}"
th:id="${'dict-'+field.fieldName}"></div>
</div>
</div>
<!--<div class="layui-form-item">
<label class="layui-form-label">数据名称</label> <label class="layui-form-label">数据名称</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="hidden" name="metadataComment"> <input type="hidden" name="metadataComment">
@ -76,7 +96,7 @@
<input type="text" name="themeTask" autocomplete="off" placeholder="主题任务" <input type="text" name="themeTask" autocomplete="off" placeholder="主题任务"
class="layui-input"> class="layui-input">
</div> </div>
</div> </div>-->
<div class="layui-form-item" th:each="labelSet, iterState:${LabelConfigSet}"> <div class="layui-form-item" th:each="labelSet, iterState:${LabelConfigSet}">
<label class="layui-form-label" th:text="${labelSet.fieldTitle}">标签类型</label> <label class="layui-form-label" th:text="${labelSet.fieldTitle}">标签类型</label>
<div class="layui-input-block label-set-component" <div class="layui-input-block label-set-component"
@ -88,8 +108,10 @@
th:data-label-title-path="${labelSet.labelTitlePath}"></div> th:data-label-title-path="${labelSet.labelTitlePath}"></div>
</div> </div>
<div class="layui-form-item other-label-item"> <div class="layui-form-item other-label-item">
<label class="layui-form-label"><a class="label-type choose-data add-other" id="addOtherLabelBtn">添加</a>其他标签</label> <label class="layui-form-label"><a class="label-type choose-data add-other"
<div class="layui-input-block label-set-component other-label" th:data-field-title="其他标签"></div> id="addOtherLabelBtn">添加</a>其他标签</label>
<div class="layui-input-block label-set-component other-label"
th:data-field-title="其他标签"></div>
</div> </div>
<!-- 隐藏域 --> <!-- 隐藏域 -->
<input type="text" name="id" hidden="hidden"/> <input type="text" name="id" hidden="hidden"/>
@ -147,6 +169,5 @@
{{# } }} {{# } }}
</script> </script>
<!-- js --> <!-- js -->
<script th:src="@{/js/business/mark/markTag.js}"></script>
<script th:src="@{/js/business/metadata/edit.js}"></script> <script th:src="@{/js/business/metadata/edit.js}"></script>
</html> </html>

@ -52,6 +52,7 @@ layui.define(['form'], function (exports) {
data = '';// 选中的数据 data = '';// 选中的数据
change;// 数据改变后的回调函数 change;// 数据改变后的回调函数
readonly;// 是否只读 readonly;// 是否只读
disabled; // 是否禁用
width;// 宽度 width;// 宽度
constructor(type, options) { constructor(type, options) {
@ -82,6 +83,7 @@ layui.define(['form'], function (exports) {
this.change = options.onchange || function () { this.change = options.onchange || function () {
}; };
this.readonly = options.readonly; this.readonly = options.readonly;
this.disabled = options.disabled;
this.width = options.width || 'fit-content'; this.width = options.width || 'fit-content';
// 开始渲染 // 开始渲染
@ -249,7 +251,7 @@ layui.define(['form'], function (exports) {
} }
let nodes_html = nodes.join(''); let nodes_html = nodes.join('');
return `<select id="${_this.id}" name="${_this.name}" lay-filter="${_this.id}">${nodes_html}</select>`; return `<select id="${_this.id}" name="${_this.name}" lay-filter="${_this.id}" ${_this.readonly ? 'readonly="readonly"' : ''} ${_this.disabled ? 'disabled="disabled"' : ''}>${nodes_html}</select>`;
} }
/** /**
@ -304,11 +306,12 @@ layui.define(['form'], function (exports) {
type = _elem.attr('dict-type'), type = _elem.attr('dict-type'),
dictType = _elem.attr('dict-component'), dictType = _elem.attr('dict-component'),
readonly = _elem.attr('readonly'), readonly = _elem.attr('readonly'),
disabled = _elem.attr('disabled'),
data = _elem.attr('data'), data = _elem.attr('data'),
width = _elem.attr('dict-width'), width = _elem.attr('dict-width'),
formFilter = getFormElementFilter(_elem); formFilter = getFormElementFilter(_elem);
let option = {elem, id, name, type, formFilter, readonly, data, width}; let option = {elem, id, name, type, formFilter, readonly, disabled, data, width};
new DictComponent(dictType, option) new DictComponent(dictType, option)
}); });
} }

@ -34,6 +34,10 @@
USER_ROLES.push(role.roleName); USER_ROLES.push(role.roleName);
} }
} }
// 表单配置
const METADATA_FORM_CONFIG = /*[[${metadataFormConfig}]]*/ [];
const FILEUPLOAD_FORM_CONFIG = /*[[${uploadFormConfig}]]*/ [];
</script> </script>
<!-- 引入公用库 --> <!-- 引入公用库 -->

@ -6,8 +6,10 @@ import com.keyware.shandan.common.entity.Result;
import com.keyware.shandan.common.util.*; import com.keyware.shandan.common.util.*;
import com.keyware.shandan.frame.config.security.SecurityUtil; import com.keyware.shandan.frame.config.security.SecurityUtil;
import com.keyware.shandan.frame.properties.CustomProperties; import com.keyware.shandan.frame.properties.CustomProperties;
import com.keyware.shandan.system.entity.SysFormConfig;
import com.keyware.shandan.system.entity.SysRole; import com.keyware.shandan.system.entity.SysRole;
import com.keyware.shandan.system.entity.SysUser; import com.keyware.shandan.system.entity.SysUser;
import com.keyware.shandan.system.service.SysFormConfigService;
import com.keyware.shandan.system.service.SysRoleService; import com.keyware.shandan.system.service.SysRoleService;
import com.keyware.shandan.system.utils.SysSettingUtil; import com.keyware.shandan.system.utils.SysSettingUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -25,7 +27,9 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* AES + RSA 加解密AOP处理 * AES + RSA 加解密AOP处理
@ -44,6 +48,9 @@ public class SafetyAspect {
@Autowired @Autowired
private SysRoleService sysRoleService; private SysRoleService sysRoleService;
@Autowired
private SysFormConfigService formConfigService;
/** /**
* Pointcut 切入点 * Pointcut 切入点
*/ */
@ -98,7 +105,7 @@ public class SafetyAspect {
ModelAndView modelAndView = (ModelAndView) result; ModelAndView modelAndView = (ModelAndView) result;
modelAndView.addObject("publicKey", RsaUtil.getPublicKey()); modelAndView.addObject("publicKey", RsaUtil.getPublicKey());
modelAndView.addObject("sys", SysSettingUtil.getCurrentSysSetting()); modelAndView.addObject("sys", SysSettingUtil.getCurrentSysSetting());
SysUser loginUser = SecurityUtil.getLoginSysUser(); SysUser loginUser = SecurityUtil.getLoginSysUser();
loginUser.setPassword(null); loginUser.setPassword(null);
modelAndView.addObject("loginUser", loginUser); modelAndView.addObject("loginUser", loginUser);
//登录用户角色信息 //登录用户角色信息
@ -121,6 +128,10 @@ public class SafetyAspect {
} }
//展示用户角色 //展示用户角色
modelAndView.addObject("userRole", userRoles.get(index)); modelAndView.addObject("userRole", userRoles.get(index));
List<SysFormConfig> formConfigList = formConfigService.list();
modelAndView.addObject("metadataFormConfig", formConfigList.stream().filter(conf -> conf.getFormType() == 1).collect(Collectors.toList()));
modelAndView.addObject("uploadFormConfig", formConfigList.stream().filter(conf -> conf.getFormType() == 2).collect(Collectors.toList()));
setStaticResourceAddress(request, modelAndView); setStaticResourceAddress(request, modelAndView);
} }
return result; return result;

@ -26,17 +26,21 @@ public class SysFormConfig extends BaseEntity {
*/ */
private Integer formType; private Integer formType;
/** /**
* 字段标题 * 字段
*/ */
private String fieldTitle; private String fieldName;
/** /**
* 字段标题 * 字段显示标题
*/ */
private String showTitle; private String showTitle;
/** /**
* 字段类型 * 字段类型
*/ */
private String fieldType; private String fieldType;
/**
* 数据字典类型只有当fieldType为"dict"时才有效
*/
private String dictType;
/** /**
* 默认值 * 默认值
*/ */

@ -18,9 +18,10 @@ class FormConfigComponent {
page: false, page: false,
cols: [[ cols: [[
{field: 'id', hide: true}, {field: 'id', hide: true},
{field: 'fieldTitle', title: '字段'}, {field: 'fieldName', title: '字段'},
{field: 'showTitle', title: '显示的标题', edit: 'text'}, {field: 'showTitle', title: '显示的标题', edit: 'text'},
{field: 'fieldType', title: '字段类型', hide: true}, {field: 'fieldType', title: '字段类型', hide: true},
{field: 'dictType', title: '数据字典', hide: true},
{field: 'defaultValue', title: '默认值', edit: 'text', hide: true}, {field: 'defaultValue', title: '默认值', edit: 'text', hide: true},
{ {
field: 'isRequired', field: 'isRequired',
@ -68,14 +69,10 @@ class FormConfigComponent {
} }
} }
switchChangeListen({elem, value}) { switchChangeListen({elem}) {
const id = $(elem).attr('id'), name = $(elem).attr('name'); const id = $(elem).attr('id'), name = $(elem).attr('name');
this.dataMap.get(id)[name] = Boolean(value); const value = this.dataMap.get(id)[name];
this.consoleDataMap(); this.dataMap.get(id)[name] = !value;
}
consoleDataMap() {
console.info(this.dataMap);
} }
} }