管控系统-系统管理-表单配置,文件上传表单可按照数据类型进行配置表单属性

master
xiong_cl 7 months ago
parent e6cf65add8
commit fbe3e9d958
  1. 4
      shandan-system/src/main/java/com/keyware/shandan/frame/aspect/SafetyAspect.java
  2. 28
      shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFormConfigController.java
  3. 5
      shandan-system/src/main/java/com/keyware/shandan/system/entity/SysFormConfig.java
  4. 18
      shandan-system/src/main/resources/static/js/sys/form/formConfig.js
  5. 21
      shandan-system/src/main/resources/view/sys/form/formConfig.html

@ -130,8 +130,8 @@ public class SafetyAspect {
modelAndView.addObject("userRole", userRoles.get(index)); modelAndView.addObject("userRole", userRoles.get(index));
List<SysFormConfig> formConfigList = formConfigService.list(); List<SysFormConfig> formConfigList = formConfigService.list();
modelAndView.addObject("metadataFormConfig", formConfigList.stream().filter(conf -> conf.getFormType() == 1).collect(Collectors.toList())); modelAndView.addObject("metadataFormConfig", formConfigList.stream().filter(conf -> "1".equals(conf.getFormType())).collect(Collectors.toList()));
modelAndView.addObject("uploadFormConfig", formConfigList.stream().filter(conf -> conf.getFormType() == 2).collect(Collectors.toList())); modelAndView.addObject("uploadFormConfig", formConfigList.stream().filter(conf -> "2".equals(conf.getFormType())).collect(Collectors.toList()));
setStaticResourceAddress(request, modelAndView); setStaticResourceAddress(request, modelAndView);
} }
return result; return result;

@ -45,13 +45,33 @@ public class SysFormConfigController {
public Result<List<SysFormConfig>> list(@PathVariable String formType) { public Result<List<SysFormConfig>> list(@PathVariable String formType) {
QueryWrapper<SysFormConfig> query = new QueryWrapper<>(); QueryWrapper<SysFormConfig> query = new QueryWrapper<>();
query.eq("FORM_TYPE", formType); query.eq("FORM_TYPE", formType);
return Result.of(formConfigService.list(query)); List<SysFormConfig> list = formConfigService.list(query);
if(list.size() < 1){
//新增类型,使用默认的模版
list = formConfigService.list(new QueryWrapper<SysFormConfig>().eq("FORM_TYPE","2"));
}
return Result.of(list);
} }
@PostMapping(value = "/api/save") @PostMapping(value = "/api/save")
public Result<Object> save(String params) { public Result<Object> save(String params,String formType) {
JSONArray jsonArray = JSONUtil.parseArray(params); JSONArray jsonArray = JSONUtil.parseArray(params);
List<SysFormConfig> list = jsonArray.toList(SysFormConfig.class); //判断是否新增数据类型
return Result.of(formConfigService.saveOrUpdateBatch(list)); System.out.println(formType);
List<SysFormConfig> resultList = jsonArray.toList(SysFormConfig.class);
//查询是否存在该FORM_TYPE,不存在则视为新增
QueryWrapper<SysFormConfig> query = new QueryWrapper<>();
query.eq("FORM_TYPE", formType);
List<SysFormConfig> list = formConfigService.list(query);
if(list.size() < 1){
resultList.forEach(sys -> {
sys.setId(null);
sys.setFormType(formType);
formConfigService.save(sys);
} );
return Result.of(true);
}else {
return Result.of(formConfigService.saveOrUpdateBatch(resultList));
}
} }
} }

@ -1,6 +1,8 @@
package com.keyware.shandan.system.entity; package com.keyware.shandan.system.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.OrderBy; import com.baomidou.mybatisplus.annotation.OrderBy;
import com.baomidou.mybatisplus.annotation.TableId;
import com.keyware.shandan.common.entity.BaseEntity; import com.keyware.shandan.common.entity.BaseEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -20,11 +22,12 @@ public class SysFormConfig extends BaseEntity {
/** /**
* 主键 * 主键
*/ */
@TableId(type = IdType.AUTO )
private Integer id; private Integer id;
/** /**
* 表单类型1-资源注册表单2-文件上传表单 * 表单类型1-资源注册表单2-文件上传表单
*/ */
private Integer formType; private String formType;
/** /**
* 字段名 * 字段名
*/ */

@ -5,6 +5,14 @@ class FormConfigComponent {
this.lay = lay; this.lay = lay;
this.dataMap = new Map(); this.dataMap = new Map();
this.renderTable(); this.renderTable();
// 文件上传表单按数据类型配置不同的字段属性。
if(elemId == 'fileUploadFormTable') {
lay.dict.render();
lay.dict.onchange('dict-dataType', (data) => {
new FormConfigComponent(data.value, 'fileUploadFormTable', layui);
lay.dict.setData('dict-dataType',data.value);
})
}
} }
renderTable() { renderTable() {
@ -40,11 +48,13 @@ class FormConfigComponent {
}, },
{field: 'sort', title: '显示顺序', edit: 'text'} {field: 'sort', title: '显示顺序', edit: 'text'}
]], ]],
done: (res) => this.tableLoadDoneListen(res), done: (res) => {
this.tableLoadDoneListen(res)
},
onToolBarTable: ({event, config})=> { onToolBarTable: ({event, config})=> {
if(event === 'save'){ if(event === 'save'){
const datas = [...this.dataMap.values()]; const datas = [...this.dataMap.values()];
Util.post(`/sys/form/config/api/save`, {params: JSON.stringify(datas)}).then(res=>{ Util.post(`/sys/form/config/api/save`, {params: JSON.stringify(datas),formType: formType}).then(res=>{
if(res.flag){ if(res.flag){
showOkMsg('保存成功') showOkMsg('保存成功')
}else{ }else{
@ -66,12 +76,14 @@ class FormConfigComponent {
const id = data.id, value = data[fieldName]; const id = data.id, value = data[fieldName];
return `<input type="checkbox" id="${id}" name="${fieldName}" value="${value}" title="是|否" lay-skin="switch" lay-filter="${elemId}-switch" ${value ? 'checked' : ''} />` return `<input type="checkbox" id="${id}" name="${fieldName}" value="${value}" title="是|否" lay-skin="switch" lay-filter="${elemId}-switch" ${value ? 'checked' : ''} />`
} }
} }
tableLoadDoneListen(res) { tableLoadDoneListen(res) {
if (res.flag) { if (res.flag) {
res.records.map(record => this.dataMap.set(record.id + '', record)); res.records.map(record => this.dataMap.set(record.id + '', record));
} }
} }
switchChangeListen({elem}) { switchChangeListen({elem}) {
@ -81,7 +93,7 @@ class FormConfigComponent {
} }
} }
layui.use(['form', 'gtable', 'dropdown', 'element'], function () { layui.use(['form', 'gtable', 'dropdown', 'element','dict'], function () {
const metadataForm = new FormConfigComponent(1, 'metadataFormTable', layui); const metadataForm = new FormConfigComponent(1, 'metadataFormTable', layui);
const fileUploadForm = new FormConfigComponent(2, 'fileUploadFormTable', layui); const fileUploadForm = new FormConfigComponent(2, 'fileUploadFormTable', layui);
}); });

@ -33,7 +33,26 @@
lay-filter="fileUploadFormTable"></table> lay-filter="fileUploadFormTable"></table>
</div> </div>
<script type="text/html" id="tableTool"> <script type="text/html" id="tableTool">
<div class="layui-btn-container"> {{# if(d.id == 'fileUploadFormTable'){ }}
<div class="layui-form-item"
th:each="field,iterStat : ${uploadFormConfig}"
th:if="${field.isShow && field.fieldName=='dataType'}"
>
<label th:if="${field.isRequired}" class="layui-form-label">
<label th:text="${field.showTitle}">*</label>
</label>
<label th:if="${!field.isRequired}" class="layui-form-label" th:text="${field.showTitle}"></label>
<div class="layui-input-block" style="width: 200px;">
<!-- 数据字典类型 -->
<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>
{{# } }}
<button class="layui-btn layui-btn-sm" lay-event="save">保存修改</button> <button class="layui-btn layui-btn-sm" lay-event="save">保存修改</button>
</div> </div>
</script> </script>