完善表单

This commit is contained in:
459816669@qq.com 2021-11-18 22:31:02 +08:00
parent 7f6e0c0126
commit c52bf46748
4 changed files with 98 additions and 6 deletions

View File

@ -1,15 +1,30 @@
package com.snow.from.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.snow.common.core.domain.AjaxResult;
import com.snow.common.utils.StringUtils;
import com.snow.framework.util.ShiroUtils;
import com.snow.from.domain.FieldContentDTO;
import com.snow.from.domain.FromInfoDTO;
import com.snow.from.domain.SysFormField;
import com.snow.from.domain.SysFormInstance;
import com.snow.from.domain.request.FormFieldRequest;
import com.snow.from.domain.request.FormRequest;
import com.snow.from.service.impl.SysFormFieldServiceImpl;
import com.snow.from.service.impl.SysFormInstanceServiceImpl;
import com.snow.system.domain.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;
/**
* @author qimingjin
* @Title:
@ -21,6 +36,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
public class FormController {
@Autowired
private SysFormInstanceServiceImpl sysFormInstanceService;
@Autowired
private SysFormFieldServiceImpl sysFormFieldService;
/**
* 跳转form表单首页
* @return 首页url路径
@ -50,6 +70,39 @@ public class FormController {
public AjaxResult saveForm(FormRequest formRequest){
log.info("=====>{}", JSON.toJSONString(formRequest));
String formData = formRequest.getFormData();
if(StrUtil.isBlank(formData)){
return AjaxResult.error("还没有创建组件呢!");
}
SysFormInstance sysFormInstanceCode = sysFormInstanceService.selectSysFormInstanceByFormCode(formRequest.getFormId());
if(StringUtils.isNotNull(sysFormInstanceCode)){
return AjaxResult.error(String.format("表单编号:%已存在",formRequest.getFormId()));
}
SysFormInstance sysFormInstanceName = sysFormInstanceService.selectSysFormInstanceByFormName(formRequest.getFormName());
if(StringUtils.isNotNull(sysFormInstanceName)){
return AjaxResult.error(String.format("表单名称:%已存在",formRequest.getFormName()));
}
SysFormInstance sysFormInstance=new SysFormInstance();
sysFormInstance.setFormCode(formRequest.getFormId());
sysFormInstance.setFormName(formRequest.getFormName());
sysFormInstance.setRev(1L);
sysFormInstance.setFromContentHtml(formData);
sysFormInstance.setCreateBy(String.valueOf(ShiroUtils.getUserId()));
sysFormInstance.setUpdateTime(new Date());
sysFormInstanceService.insertSysFormInstance(sysFormInstance);
List<FormFieldRequest> fieldContentDTOS = JSON.parseArray(formData, FormFieldRequest.class);
for (int i=0;i<fieldContentDTOS.size();i++){
SysFormField sysFormField=new SysFormField();
sysFormField.setFromId(sysFormInstance.getId());
sysFormField.setFieldKey(fieldContentDTOS.get(i).getId());
sysFormField.setFieldName(fieldContentDTOS.get(i).getLabel());
sysFormField.setFieldType(fieldContentDTOS.get(i).getTag());
sysFormField.setFieldHtml(JSON.parseArray(formData).getString(i));
sysFormField.setRev(sysFormInstance.getRev());
sysFormFieldService.insertSysFormField(sysFormField);
}
return AjaxResult.success();
}
}

View File

@ -0,0 +1,39 @@
package com.snow.from.domain.request;
import lombok.Data;
import java.io.Serializable;
/**
* @program: snow
* @description
* @author: 没用的阿吉
* @create: 2021-11-18 22:08
**/
@Data
public class FormFieldRequest implements Serializable {
private String id;
private String label;
private String tag;
private String tagIcon;
private boolean readonly;
private String placeholder;
private Boolean disabled;
private Boolean required;
private String defaultValue;
private String expression;
private String document;
}

View File

@ -3682,14 +3682,14 @@ layui.config({base: './ayq/modules/'}).define(["layer", "laytpl", "element", "fo
success: function(result) {
if (result.code === 0) {
layer.msg(result.msg, {icon: 1});
setTimeout(function(){
var index = parent.layer.getFrameIndex(window.name);
layer.close(index);//关闭弹出层
location.reload();
}, 1000);
} else {
layer.msg(result.msg, {icon: 2});
}
setTimeout(function(){
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);//关闭弹出层
parent.location.reload();
}, 1000);
}
};
$.ajax(config);

View File

@ -93,7 +93,7 @@
}
function designFrom() {
var detailUrl="/from/interface";
var detailUrl="/formIndex";
$.modal.openTab("设计表单", detailUrl);
}