调整freemarker模板问题,增加模板页面展示功能
This commit is contained in:
parent
a00eab5a26
commit
55a7cf8cf9
@ -1,6 +1,7 @@
|
||||
package ink.wgink.common.service.api.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
@ -26,10 +27,12 @@ import springfox.documentation.service.Documentation;
|
||||
import springfox.documentation.spring.web.DocumentationCache;
|
||||
import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
@ -53,14 +56,9 @@ public class ApiInfoServiceImpl extends DefaultBaseService implements IApiInfoSe
|
||||
@Autowired
|
||||
private ServiceModelToSwagger2Mapper serviceModelToSwagger2Mapper;
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
freeMarkerConfigurer.getConfiguration().setClassForTemplateLoading(ApiInfoServiceImpl.class, "/templates");
|
||||
}
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
@Override
|
||||
public SystemApiDTO getSystemApi(String group, String apiType, HttpServletRequest request) {
|
||||
@ -148,7 +146,7 @@ public class ApiInfoServiceImpl extends DefaultBaseService implements IApiInfoSe
|
||||
@Override
|
||||
public void get(HttpServletRequest request, HttpServletResponse response) throws IOException, TemplateException {
|
||||
String apiTypes = request.getParameter("apiTypes");
|
||||
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("ftl/api-template.ftl");
|
||||
Template template = getTemplate("ftl/api-template.ftl");
|
||||
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("接口文档.doc", "UTF-8"));
|
||||
Map<String, Object> apiDocMap = getApi(StringUtils.isBlank(apiTypes) ? null : Arrays.asList(apiTypes.split(",")));
|
||||
Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), ISystemConstant.CHARSET_UTF8));
|
||||
@ -477,4 +475,15 @@ public class ApiInfoServiceImpl extends DefaultBaseService implements IApiInfoSe
|
||||
}
|
||||
return subRefProperty;
|
||||
}
|
||||
|
||||
private Configuration getConfiguration() {
|
||||
Configuration configuration = freeMarkerConfigurer.getConfiguration();
|
||||
configuration.setClassForTemplateLoading(ApiInfoServiceImpl.class, "/templates");
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Template getTemplate(String fileName) throws IOException {
|
||||
return getConfiguration().getTemplate(fileName, ISystemConstant.CHARSET_UTF8);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package ink.wgink.module.form.consts;
|
||||
|
||||
/**
|
||||
* @ClassName: IFormDesignConst
|
||||
* @Description: 表单设计常量
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/8 9:31 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IFormDesignConst {
|
||||
|
||||
String ID = "id";
|
||||
String INDEX = "index";
|
||||
String LABEL = "label";
|
||||
String TAG = "tag";
|
||||
String COLUMNS = "columns";
|
||||
String LIST = "list";
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package ink.wgink.module.form.controller.api.design;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.form.pojo.dtos.design.FormDTO;
|
||||
import ink.wgink.module.form.service.design.IFormService;
|
||||
import ink.wgink.pojo.ListPage;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import ink.wgink.pojo.result.SuccessResultList;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FormController
|
||||
* @Description: 表单
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/10 7:38 AM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "表单")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.API_PREFIX + "/form")
|
||||
public class FormController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFormService formService;
|
||||
|
||||
@ApiOperation(value = "表单删除", notes = "通过id列表批量删除表单接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "表单ID列表,用下划线分隔", paramType = "path", example = "1_2_3")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@DeleteMapping("remove/{ids}")
|
||||
public SuccessResult remove(@PathVariable("ids") String ids) {
|
||||
formService.remove(Arrays.asList(ids.split("\\_")));
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "表单列表", notes = "表单列表接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("list")
|
||||
public List<FormDTO> list() {
|
||||
Map<String, Object> params = requestParams();
|
||||
return formService.list(params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "表单分页列表", notes = "表单分页列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
|
||||
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
|
||||
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listpage")
|
||||
public SuccessResultList<List<FormDTO>> listPage(ListPage page) {
|
||||
Map<String, Object> params = requestParams();
|
||||
page.setParams(params);
|
||||
return formService.listPage(page);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package ink.wgink.module.form.controller.api.design;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.form.controller.pojo.vos.design.FormDesignVO;
|
||||
import ink.wgink.module.form.pojo.vos.design.FormDesignVO;
|
||||
import ink.wgink.module.form.service.design.IFormDesignService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
|
@ -0,0 +1,11 @@
|
||||
package ink.wgink.module.form.controller.api.report;
|
||||
|
||||
/**
|
||||
* @ClassName: FormReportController
|
||||
* @Description: 表单上报
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/10 7:29 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class FormReportController {
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package ink.wgink.module.form.controller.pojo;
|
||||
|
||||
/**
|
||||
* @Description: 基础字段
|
||||
* @Author: WenG
|
||||
* @Date: 2022/3/8 20:24
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FormField {
|
||||
|
||||
private String id;
|
||||
private String tag;
|
||||
private String label;
|
||||
private Integer index;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package ink.wgink.module.form.controller.pojo.vos.design;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
/**
|
||||
* @Description: 表单设计
|
||||
* @Author: WenG
|
||||
* @Date: 2022/3/8 20:21
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FormDesignVO {
|
||||
|
||||
private JSONArray data;
|
||||
private String code;
|
||||
|
||||
public JSONArray getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(JSONArray data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package ink.wgink.module.form.controller.route.design;
|
||||
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @Description: 表单设计
|
||||
* @Author: WenG
|
||||
* @Date: 2022/3/7 11:17
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "表单")
|
||||
@Controller
|
||||
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/form")
|
||||
public class FormRouteController {
|
||||
|
||||
@GetMapping("list")
|
||||
public ModelAndView save() {
|
||||
ModelAndView mv = new ModelAndView("/form/list");
|
||||
return mv;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ink.wgink.module.form.controller.route.report;
|
||||
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.form.service.report.IFormReportService;
|
||||
import io.swagger.annotations.Api;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* @ClassName: FormReportRouteController
|
||||
* @Description: 表单上报
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/10 7:29 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "表单")
|
||||
@Controller
|
||||
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/form-report")
|
||||
public class FormReportRouteController {
|
||||
|
||||
@Autowired
|
||||
private IFormReportService formReportService;
|
||||
|
||||
@GetMapping("save/{formCode}")
|
||||
public void get(@PathVariable("formCode") String formCode, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
formReportService.get(formCode, httpSession, httpServletRequest, httpServletResponse);
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,7 @@ import java.util.Map;
|
||||
@Repository
|
||||
public interface IFormDao extends IInitBaseTable {
|
||||
|
||||
void createDynamicForm(String createTableSQL) throws SaveException;
|
||||
|
||||
void save(Map<String, Object> params) throws SaveException;
|
||||
|
||||
@ -31,4 +32,5 @@ public interface IFormDao extends IInitBaseTable {
|
||||
List<FormDTO> list(Map<String, Object> params) throws SearchException;
|
||||
|
||||
List<FormDTO> listPO(Map<String, Object> params) throws SearchException;
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,11 @@ public enum FormFieldTypeEnum {
|
||||
INPUT("input", "单行文本"),
|
||||
PASSWORD("password", "密码框"),
|
||||
SELECT("select", "下拉框"),
|
||||
SELECT_DICTIONARY("selectDictionary", "下拉框字典"),
|
||||
RADIO("radio", "单选组"),
|
||||
RADIO_DICTIONARY("radioDictionary", "单选字典"),
|
||||
CHECKBOX("checkbox", "复选组"),
|
||||
CHECKBOX_DICTIONARY("checkboxDictionary", "复选字典"),
|
||||
SWITCH("switch", "开关"),
|
||||
SLIDER("slider", "滑块"),
|
||||
NUMBER_INPUT("numberInput", "数字输入框"),
|
||||
@ -22,10 +25,8 @@ public enum FormFieldTypeEnum {
|
||||
ICON_PICKER("iconPicker", "图标选择器"),
|
||||
CRON("cron", "Cron表达式"),
|
||||
DATE("date", "日期"),
|
||||
DATE_RANGE("dateRange", "日期范围"),
|
||||
RATE("rate", "评分"),
|
||||
CAROUSEL("carousel", "轮播图"),
|
||||
COLOR_PICKER("colorpicker", "颜色选择器"),
|
||||
IMAGE("image", "上传图片"),
|
||||
FILE("file", "上传文件"),
|
||||
TEXTAREA("textarea", "多行文本"),
|
||||
|
@ -11,6 +11,7 @@ public class FormFieldPO implements Serializable {
|
||||
private String fieldName;
|
||||
private String fieldExplain;
|
||||
private String fieldType;
|
||||
private String fieldTag;
|
||||
private String fieldDefault;
|
||||
|
||||
public Long getId() {
|
||||
@ -61,6 +62,14 @@ public class FormFieldPO implements Serializable {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getFieldTag() {
|
||||
return fieldTag == null ? "" : fieldTag.trim();
|
||||
}
|
||||
|
||||
public void setFieldTag(String fieldTag) {
|
||||
this.fieldTag = fieldTag;
|
||||
}
|
||||
|
||||
public String getFieldDefault() {
|
||||
return fieldDefault;
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package ink.wgink.module.form.pojo.vos.design;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
/**
|
||||
* @Description: 表单设计
|
||||
* @Author: WenG
|
||||
* @Date: 2022/3/8 20:21
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FormDesignVO {
|
||||
|
||||
private String formName;
|
||||
private String formSummary;
|
||||
private JSONArray data;
|
||||
private String code;
|
||||
|
||||
public String getFormName() {
|
||||
return formName == null ? "" : formName.trim();
|
||||
}
|
||||
|
||||
public void setFormName(String formName) {
|
||||
this.formName = formName;
|
||||
}
|
||||
|
||||
public String getFormSummary() {
|
||||
return formSummary == null ? "" : formSummary.trim();
|
||||
}
|
||||
|
||||
public void setFormSummary(String formSummary) {
|
||||
this.formSummary = formSummary;
|
||||
}
|
||||
|
||||
public JSONArray getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(JSONArray data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ public class FormFieldVO {
|
||||
private String fieldExplain;
|
||||
@ApiModelProperty(name = "fieldType", value = "字段类型")
|
||||
private String fieldType;
|
||||
@ApiModelProperty(name = "fieldTag", value = "字段标签")
|
||||
private String fieldTag;
|
||||
@ApiModelProperty(name = "fieldDefault", value = "字段默认值")
|
||||
private String fieldDefault;
|
||||
|
||||
@ -49,6 +51,14 @@ public class FormFieldVO {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getFieldTag() {
|
||||
return fieldTag == null ? "" : fieldTag.trim();
|
||||
}
|
||||
|
||||
public void setFieldTag(String fieldTag) {
|
||||
this.fieldTag = fieldTag;
|
||||
}
|
||||
|
||||
public String getFieldDefault() {
|
||||
return fieldDefault;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package ink.wgink.module.form.service.design;
|
||||
|
||||
import ink.wgink.module.form.controller.pojo.vos.design.FormDesignVO;
|
||||
import ink.wgink.module.form.pojo.vos.design.FormDesignVO;
|
||||
|
||||
/**
|
||||
* @Description: 表单设计
|
||||
|
@ -11,6 +11,13 @@ import java.util.Map;
|
||||
|
||||
public interface IFormService {
|
||||
|
||||
/**
|
||||
* 创建动态表单
|
||||
*
|
||||
* @param createTableSQL
|
||||
*/
|
||||
void createDynamicForm(String createTableSQL);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
@ -82,6 +89,14 @@ public interface IFormService {
|
||||
*/
|
||||
FormPO getPO(String formId);
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param formCode 表单编码
|
||||
* @return
|
||||
*/
|
||||
FormPO getPOByCode(String formCode);
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
|
@ -1,12 +1,28 @@
|
||||
package ink.wgink.module.form.service.design.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.module.form.controller.pojo.FormField;
|
||||
import ink.wgink.module.form.controller.pojo.vos.design.FormDesignVO;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.PropertiesException;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.form.consts.IFormDesignConst;
|
||||
import ink.wgink.module.form.enums.design.FormFieldTypeEnum;
|
||||
import ink.wgink.module.form.pojo.vos.design.FormDesignVO;
|
||||
import ink.wgink.module.form.pojo.vos.design.FormFieldVO;
|
||||
import ink.wgink.module.form.pojo.vos.design.FormVO;
|
||||
import ink.wgink.module.form.service.design.IFormDesignService;
|
||||
import ink.wgink.module.form.service.design.IFormFieldService;
|
||||
import ink.wgink.module.form.service.design.IFormService;
|
||||
import ink.wgink.properties.form.FormProperties;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -19,16 +35,172 @@ import java.util.List;
|
||||
@Service
|
||||
public class FormDesignServiceImpl extends DefaultBaseService implements IFormDesignService {
|
||||
|
||||
@Autowired
|
||||
private FormProperties formProperties;
|
||||
@Autowired
|
||||
private IFormService formService;
|
||||
@Autowired
|
||||
private IFormFieldService formFieldService;
|
||||
|
||||
@Override
|
||||
public void save(FormDesignVO formDesignVO) {
|
||||
if (StringUtils.isBlank(formProperties.getTemplatePath())) {
|
||||
throw new PropertiesException("未配置模板路径");
|
||||
}
|
||||
List<FormFieldVO> formFields = new ArrayList<>();
|
||||
setFormFieldList(formFields, formDesignVO.getData());
|
||||
if (formFields.isEmpty()) {
|
||||
throw new ParamsException("表单字段不能为空");
|
||||
}
|
||||
// 时间戳表单编码
|
||||
String formCode = DateUtil.getSdfTimes();
|
||||
// df:dynamicForm 动态表单
|
||||
String tableName = "df_" + formCode;
|
||||
|
||||
LOG.debug("保存表单");
|
||||
FormVO formVO = new FormVO();
|
||||
formVO.setFormName(formDesignVO.getFormName());
|
||||
formVO.setFormCode(formCode);
|
||||
formVO.setFormSummary(formDesignVO.getFormSummary());
|
||||
formVO.setFormTableName(tableName);
|
||||
formVO.setFormVersion(1);
|
||||
formVO.setFormSourceData(JSON.toJSONString(formDesignVO.getData()));
|
||||
formVO.setFormPageCode(formDesignVO.getCode());
|
||||
String formId = formService.saveReturnId(formVO);
|
||||
|
||||
LOG.debug("保存表单字段");
|
||||
formFields.forEach(formFieldVO -> {
|
||||
formFieldVO.setFormId(formId);
|
||||
formFieldService.save(formFieldVO);
|
||||
});
|
||||
|
||||
LOG.debug("建表");
|
||||
String createTableSQL = getCreateTableSQL(tableName, formFields);
|
||||
formService.createDynamicForm(createTableSQL);
|
||||
|
||||
LOG.debug("创建静态页面");
|
||||
File formFolder = new File(formProperties.getTemplatePath());
|
||||
if (!formFolder.exists()) {
|
||||
formFolder.mkdirs();
|
||||
}
|
||||
try (
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(formProperties.getTemplatePath() + formCode + ".ftl");
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, ISystemConstant.CHARSET_UTF8);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)
|
||||
) {
|
||||
bufferedWriter.write(formDesignVO.getCode());
|
||||
bufferedWriter.flush();
|
||||
} catch (IOException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new SystemException("创建模板文件异常");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setFormField(List<FormField> formFields, JSONArray dataJsonArray) {
|
||||
/**
|
||||
* 建表SQL
|
||||
*
|
||||
* @param tableName
|
||||
* @param formFieldVOs
|
||||
* @return
|
||||
*/
|
||||
private String getCreateTableSQL(String tableName, List<FormFieldVO> formFieldVOs) {
|
||||
StringBuffer createTableSB = new StringBuffer("CREATE TABLE `").append(tableName).append("`(");
|
||||
createTableSB.append("`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,");
|
||||
createTableSB.append("`uid` char(36) NOT NULL,");
|
||||
for (FormFieldVO formFieldVO : formFieldVOs) {
|
||||
createTableSB.append("`").append(formFieldVO.getFieldName()).append("` ").append(formFieldVO.getFieldType()).append(" NOT NULL COMMENT '").append(formFieldVO.getFieldExplain()).append("',");
|
||||
}
|
||||
createTableSB.append("`creator` char(36) DEFAULT NULL,");
|
||||
createTableSB.append("`gmt_create` datetime DEFAULT NULL,");
|
||||
createTableSB.append("`modifier` char(36) DEFAULT NULL,");
|
||||
createTableSB.append("`gmt_modified` datetime DEFAULT NULL,");
|
||||
createTableSB.append("`is_delete` int(2) DEFAULT '0',");
|
||||
createTableSB.append("PRIMARY KEY (`id`)");
|
||||
createTableSB.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
return createTableSB.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表单字段列表
|
||||
*
|
||||
* @param formFields
|
||||
* @param dataJsonArray
|
||||
*/
|
||||
private void setFormFieldList(List<FormFieldVO> formFields, JSONArray dataJsonArray) {
|
||||
formFields = formFields == null ? new ArrayList<>() : formFields;
|
||||
for (int i = 0; i < dataJsonArray.size(); i++) {
|
||||
JSONObject dataJsonObject = dataJsonArray.getJSONObject(i);
|
||||
String id = dataJsonObject.getString(IFormDesignConst.ID);
|
||||
String index = dataJsonObject.getString(IFormDesignConst.INDEX);
|
||||
String label = dataJsonObject.getString(IFormDesignConst.LABEL);
|
||||
String tag = dataJsonObject.getString(IFormDesignConst.TAG);
|
||||
// grid特殊,需要递归处理
|
||||
if (StringUtils.equals(FormFieldTypeEnum.GRID.getType(), tag)) {
|
||||
JSONArray columnJsonArray = dataJsonObject.getJSONArray(IFormDesignConst.COLUMNS);
|
||||
for (int j = 0; j < columnJsonArray.size(); j++) {
|
||||
JSONObject columnJsonObject = columnJsonArray.getJSONObject(j);
|
||||
JSONArray listJsonArray = columnJsonObject.getJSONArray(IFormDesignConst.LIST);
|
||||
if (!listJsonArray.isEmpty()) {
|
||||
setFormFieldList(formFields, listJsonArray);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FormFieldVO formField = new FormFieldVO();
|
||||
formField.setFieldName(id);
|
||||
formField.setFieldTag(tag);
|
||||
formField.setFieldExplain(label);
|
||||
formField.setFieldType(getSingleFieldType(tag));
|
||||
formFields.add(formField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getSingleFieldType(String fieldTag) {
|
||||
if (StringUtils.equals(FormFieldTypeEnum.INPUT.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.NUMBER_INPUT.getType(), fieldTag)) {
|
||||
return "DOUBLE(11,4)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.PASSWORD.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.RADIO.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.RADIO_DICTIONARY.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.SELECT.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.SELECT_DICTIONARY.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.CHECKBOX.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.CHECKBOX_DICTIONARY.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.TEXTAREA.getType(), fieldTag)) {
|
||||
return "TEXT";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.CAROUSEL.getType(), fieldTag)) {
|
||||
return "VARCHAR(300)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.FILE.getType(), fieldTag)) {
|
||||
return "VARCHAR(300)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.IMAGE.getType(), fieldTag)) {
|
||||
return "VARCHAR(300)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.RATE.getType(), fieldTag)) {
|
||||
return "DOUBLE(11,2)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.DATE.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.SLIDER.getType(), fieldTag)) {
|
||||
return "DOUBLE(11,2)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.SWITCH.getType(), fieldTag)) {
|
||||
return "INT(1)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.LABEL_GENERATION.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.EDITOR.getType(), fieldTag)) {
|
||||
return "LONGTEXT";
|
||||
} else if (StringUtils.equals(FormFieldTypeEnum.SIGN.getType(), fieldTag)) {
|
||||
return "VARCHAR(255)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ink.wgink.module.form.service.design.impl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.module.form.dao.design.IFormDao;
|
||||
import ink.wgink.module.form.pojo.dtos.design.FormDTO;
|
||||
import ink.wgink.module.form.pojo.pos.design.FormPO;
|
||||
@ -24,6 +25,11 @@ public class FormServiceImpl extends DefaultBaseService implements IFormService
|
||||
@Autowired
|
||||
private IFormDao formDao;
|
||||
|
||||
@Override
|
||||
public void createDynamicForm(String createTableSQL) {
|
||||
formDao.createDynamicForm(createTableSQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(FormVO formVO) {
|
||||
saveReturnId(formVO);
|
||||
@ -31,6 +37,10 @@ public class FormServiceImpl extends DefaultBaseService implements IFormService
|
||||
|
||||
@Override
|
||||
public String saveReturnId(FormVO formVO) {
|
||||
FormPO formPO = getPOByCode(formVO.getFormCode());
|
||||
if (formPO != null) {
|
||||
throw new ParamsException("编码存在,请稍后重试");
|
||||
}
|
||||
String formId = UUIDUtil.getUUID();
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(formVO);
|
||||
params.put("formId", formId);
|
||||
@ -87,6 +97,13 @@ public class FormServiceImpl extends DefaultBaseService implements IFormService
|
||||
return getPO(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormPO getPOByCode(String formCode) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("formCode", formCode);
|
||||
return getPO(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FormDTO> list(Map<String, Object> params) {
|
||||
params = params == null ? getHashMap(2) : params;
|
||||
|
@ -0,0 +1,25 @@
|
||||
package ink.wgink.module.form.service.report;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* @ClassName: IFormReportService
|
||||
* @Description: 表单上报
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/10 7:33 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IFormReportService {
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param formCode
|
||||
* @param httpSession
|
||||
* @param httpServletRequest
|
||||
* @param httpServletResponse
|
||||
*/
|
||||
void get(String formCode, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package ink.wgink.module.form.service.report.impl;
|
||||
|
||||
import freemarker.cache.FileTemplateLoader;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.form.service.report.IFormReportService;
|
||||
import ink.wgink.properties.form.FormProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FormReportServiceImpl
|
||||
* @Description: 表单上报
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/3/10 7:33 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class FormReportServiceImpl extends DefaultBaseService implements IFormReportService {
|
||||
|
||||
@Autowired
|
||||
private FormProperties formProperties;
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
@Override
|
||||
public void get(String formCode, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
httpServletResponse.setContentType("text/html; charset=" + ISystemConstant.CHARSET_UTF8);
|
||||
try {
|
||||
Template template = getTemplate(formCode + ".ftl");
|
||||
PrintWriter out = httpServletResponse.getWriter();
|
||||
Map<String, Object> modal = getHashMap(2);
|
||||
template.process(modal, out);
|
||||
} catch (IOException e) {
|
||||
httpServletResponse.setStatus(HttpStatus.NOT_FOUND.value());
|
||||
} catch (TemplateException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new SystemException("模板错误");
|
||||
}
|
||||
}
|
||||
|
||||
private Configuration getConfiguration() throws IOException {
|
||||
freeMarkerConfigurer.setDefaultEncoding(ISystemConstant.CHARSET_UTF8);
|
||||
FileTemplateLoader fileTemplateLoader = new FileTemplateLoader(new File(formProperties.getTemplatePath()));
|
||||
Configuration configuration = freeMarkerConfigurer.getConfiguration();
|
||||
configuration.setTemplateLoader(fileTemplateLoader);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Template getTemplate(String fileName) throws IOException {
|
||||
return getConfiguration().getTemplate(fileName, ISystemConstant.CHARSET_UTF8);
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
<result column="field_name" property="fieldName"/>
|
||||
<result column="field_explain" property="fieldExplain"/>
|
||||
<result column="field_type" property="fieldType"/>
|
||||
<result column="field_tag" property="fieldTag"/>
|
||||
<result column="field_default" property="fieldDefault"/>
|
||||
</resultMap>
|
||||
|
||||
@ -18,18 +19,20 @@
|
||||
<result column="field_name" property="fieldName"/>
|
||||
<result column="field_explain" property="fieldExplain"/>
|
||||
<result column="field_type" property="fieldType"/>
|
||||
<result column="field_tag" property="fieldTag"/>
|
||||
<result column="field_default" property="fieldDefault"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 建表 -->
|
||||
<update id="createTable">
|
||||
CREATE TABLE IF NOT EXISTS `form_form_field` (
|
||||
CREATE TABLE IF NOT EXISTS `form_field` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`field_id` char(36) DEFAULT NULL COMMENT '主键',
|
||||
`form_id` char(36) DEFAULT NULL COMMENT '字段ID',
|
||||
`field_name` varchar(255) DEFAULT NULL COMMENT '字段名',
|
||||
`field_explain` varchar(255) DEFAULT NULL COMMENT '字段说明',
|
||||
`field_type` varchar(255) DEFAULT NULL COMMENT '字段类型',
|
||||
`field_tag` varchar(255) DEFAULT NULL COMMENT '标签类型',
|
||||
`field_default` varchar(255) DEFAULT NULL COMMENT '字段默认',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字段字段';
|
||||
@ -43,6 +46,7 @@
|
||||
field_name,
|
||||
field_explain,
|
||||
field_type,
|
||||
field_tag,
|
||||
field_default
|
||||
) VALUES(
|
||||
#{fieldId},
|
||||
@ -50,6 +54,7 @@
|
||||
#{fieldName},
|
||||
#{fieldExplain},
|
||||
#{fieldType},
|
||||
#{fieldTag},
|
||||
#{fieldDefault}
|
||||
)
|
||||
</insert>
|
||||
@ -84,6 +89,7 @@
|
||||
field_name = #{fieldName},
|
||||
field_explain = #{fieldExplain},
|
||||
field_type = #{fieldType},
|
||||
field_tag = #{fieldTag},
|
||||
field_default = #{fieldDefault}
|
||||
WHERE
|
||||
field_id = #{fieldId}
|
||||
@ -97,6 +103,7 @@
|
||||
field_name,
|
||||
field_explain,
|
||||
field_type,
|
||||
field_tag,
|
||||
field_default
|
||||
FROM
|
||||
form_field
|
||||
@ -112,6 +119,7 @@
|
||||
field_name,
|
||||
field_explain,
|
||||
field_type,
|
||||
field_tag,
|
||||
field_default
|
||||
FROM
|
||||
form_field
|
||||
@ -127,6 +135,7 @@
|
||||
field_name,
|
||||
field_explain,
|
||||
field_type,
|
||||
field_tag,
|
||||
field_default
|
||||
FROM
|
||||
form_field
|
||||
@ -140,6 +149,7 @@
|
||||
field_name,
|
||||
field_explain,
|
||||
field_type,
|
||||
field_tag,
|
||||
field_default
|
||||
FROM
|
||||
form_field
|
||||
|
@ -58,6 +58,11 @@
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='表单';
|
||||
</update>
|
||||
|
||||
<!-- 建表 -->
|
||||
<update id="createDynamicForm" parameterType="java.lang.String">
|
||||
${_parameter}
|
||||
</update>
|
||||
|
||||
<!-- 新增表单 -->
|
||||
<insert id="save" parameterType="map" flushCache="true">
|
||||
INSERT INTO form_form(
|
||||
@ -159,4 +164,78 @@
|
||||
form_id = #{formId}
|
||||
</update>
|
||||
|
||||
<!-- 详情 -->
|
||||
<select id="get" parameterType="map" resultMap="formDTO">
|
||||
SELECT
|
||||
form_id,
|
||||
form_code,
|
||||
form_name,
|
||||
form_summary,
|
||||
form_type,
|
||||
form_status,
|
||||
form_table_name,
|
||||
form_version
|
||||
FROM
|
||||
form_form
|
||||
WHERE
|
||||
<if test="formId != null and formId != ''">
|
||||
form_id = #{formId}
|
||||
</if>
|
||||
<if test="formCode != null and formCode != ''">
|
||||
form_code = #{formCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 详情 -->
|
||||
<select id="getPO" parameterType="map" resultMap="formPO">
|
||||
SELECT
|
||||
form_id,
|
||||
form_code,
|
||||
form_name,
|
||||
form_summary,
|
||||
form_type,
|
||||
form_status,
|
||||
form_table_name,
|
||||
form_version
|
||||
FROM
|
||||
form_form
|
||||
WHERE
|
||||
<if test="formId != null and formId != ''">
|
||||
form_id = #{formId}
|
||||
</if>
|
||||
<if test="formCode != null and formCode != ''">
|
||||
form_code = #{formCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 列表 -->
|
||||
<select id="list" parameterType="map" resultMap="formDTO">
|
||||
SELECT
|
||||
form_id,
|
||||
form_code,
|
||||
form_name,
|
||||
form_summary,
|
||||
form_type,
|
||||
form_status,
|
||||
form_table_name,
|
||||
form_version
|
||||
FROM
|
||||
form_form
|
||||
</select>
|
||||
|
||||
<!-- 列表 -->
|
||||
<select id="listPO" parameterType="map" resultMap="formPO">
|
||||
SELECT
|
||||
form_id,
|
||||
form_code,
|
||||
form_name,
|
||||
form_summary,
|
||||
form_type,
|
||||
form_status,
|
||||
form_table_name,
|
||||
form_version
|
||||
FROM
|
||||
form_form
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -14,13 +14,11 @@
|
||||
}
|
||||
|
||||
.layui-layout-admin .layui-side {
|
||||
top : 60px;
|
||||
width : 260px;
|
||||
overflow-x: hidden
|
||||
}
|
||||
|
||||
.layui-layout-admin .layui-side-right {
|
||||
top : 60px;
|
||||
width : 350px;
|
||||
overflow-x: hidden
|
||||
}
|
||||
@ -41,6 +39,7 @@
|
||||
}
|
||||
|
||||
.layui-layout-admin .layui-body {
|
||||
top: 0px !important;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
|
@ -641,35 +641,10 @@ layui.config({
|
||||
//模块名称常量
|
||||
, MOD_NAME = 'formDesigner',
|
||||
ELEM = '.layui-form-designer',
|
||||
|
||||
|
||||
TP_MAIN = [
|
||||
'<div class="layui-layout layui-layout-admin">',
|
||||
' <div class="layui-header">',
|
||||
' <div class="layui-logo">表单设计器</div>',
|
||||
' <!-- 头部区域(可配合layui已有的水平导航) -->',
|
||||
' <ul class="layui-nav layui-layout-left">',
|
||||
' <li class="layui-nav-item"><a href=""></a></li>',
|
||||
' </ul>',
|
||||
' <ul class="layui-nav layui-layout-right">',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a id="saveJson" href="javascript:void(0);" class="saveJson">保存</a>',
|
||||
' </li>',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a id="btnImportJson" href="javascript:void(0);" class="importJson">导入数据</a>',
|
||||
' </li>',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a id="btnExportJson" href="javascript:void(0);" class="exportJson">导出数据</a>',
|
||||
' </li>',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a id="btnTemplateList" href="javascript:void(0);" class="templateList">模板</a>',
|
||||
' </li>',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a href="javascript:void(0);" class="previewForm">预览</a>',
|
||||
' </li>',
|
||||
' <li class="layui-nav-item">',
|
||||
' <a href="javascript:void(0);" class="generateCode">生成代码</a>',
|
||||
' </li>',
|
||||
' </ul>',
|
||||
' </div>',
|
||||
' <div class="layui-side">',
|
||||
' <div class="layui-side-scroll" style="width: 260px;">',
|
||||
' <!-- 左侧导航区域(可配合layui已有的垂直导航) -->',
|
||||
@ -711,21 +686,23 @@ layui.config({
|
||||
' <div class="layui-tab-item layui-show" id="columnProperty">',
|
||||
' </div>',
|
||||
' <div class="layui-tab-item" id="formProperty">',
|
||||
' <!--表单ID-->',
|
||||
' <div class="layui-form-item">',
|
||||
' <label class="layui-form-label">表单ID</label>',
|
||||
' <div class="layui-input-block">',
|
||||
' <input type="text" name="formId" required="" lay-verify="required"', 'placeholder="请输入表单ID" autocomplete="off" class="layui-input">',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' <!--//表单ID-->',
|
||||
' <!--表单名称-->',
|
||||
' <div class="layui-form-item">',
|
||||
' <label class="layui-form-label">表单名称</label>',
|
||||
' <label class="layui-form-label">表单名称 *</label>',
|
||||
' <div class="layui-input-block">',
|
||||
' <input type="text" name="formName" required="" lay-verify="required"', 'placeholder="请输入表单名称" autocomplete="off" class="layui-input">',
|
||||
' <input type="text" id="formName" name="formName" lay-verify="required" placeholder="请输入表单名称" class="layui-input">',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' <div class="layui-form-item">',
|
||||
' <label class="layui-form-label">表单描述 *</label>',
|
||||
' <div class="layui-input-block">',
|
||||
' <input type="text" id="formSummary" name="formSummary" lay-verify="required" placeholder="请输入表单描述" class="layui-input">',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' <div class="layui-btn-group">',
|
||||
' <button id="save" type="button" class="layui-btn">保存</button>',
|
||||
' <button id="preview" type="button" class="layui-btn layui-btn-primary">预览</button>',
|
||||
' </div>',
|
||||
' <!--//end-->',
|
||||
' </div>',
|
||||
' </div>',
|
||||
@ -3570,11 +3547,13 @@ layui.config({
|
||||
layer.closeAll();
|
||||
layer.msg('导入成功');
|
||||
});
|
||||
$('.generateCode').on('click', function () {
|
||||
options.htmlCode.script = '';
|
||||
|
||||
// 生成HTML代码
|
||||
function getHtmlCode() {
|
||||
var _htmlelem = $('<div style="height:100%;width:100%;"></div>');
|
||||
that.generateHtml(options.data, _htmlelem);
|
||||
//构件 html
|
||||
options.htmlCode.script = '';
|
||||
//构件 html
|
||||
var TP_HTML_CODE = [
|
||||
'<!DOCTYPE html>',
|
||||
'<html>',
|
||||
@ -3639,27 +3618,15 @@ layui.config({
|
||||
if (tabsize == 1) {
|
||||
tabchar = '\t';
|
||||
}
|
||||
document.getElementById('generate-code-view').value = style_html(TP_HTML_CODE, tabsize, tabchar, 400);
|
||||
return style_html(TP_HTML_CODE, tabsize, tabchar, 400);
|
||||
}
|
||||
$('.generateCode').on('click', function () {
|
||||
//构件 html
|
||||
var TP_HTML_CODE = getHtmlCode();
|
||||
document.getElementById('generate-code-view').value = TP_HTML_CODE;
|
||||
console.log($('#generate-code-view').val());
|
||||
// layer.open({
|
||||
// type: 1,
|
||||
// title: 'HTML代码',
|
||||
// id: 'Lay_layer_htmlcodeview',
|
||||
// content: $('.htmlcodeview'),
|
||||
// area: ['800px', '640px'],
|
||||
// shade: false,
|
||||
// resize: false,
|
||||
// success: function (layero, index) {
|
||||
// layer.style(index, {
|
||||
// marginLeft: -220
|
||||
// });
|
||||
// },
|
||||
// end: function () {
|
||||
// $('.htmlcodeview').css("display", "none")
|
||||
// }
|
||||
// });
|
||||
});
|
||||
$('.previewForm').on('click', function () {
|
||||
$('#preview').on('click', function () {
|
||||
window.localStorage.setItem('layui_form_json', JSON.stringify(options.data));
|
||||
layer.confirm('请选择你要预览页面的方式?', {
|
||||
btn: ['弹窗', '新页面'] //按钮
|
||||
@ -3686,29 +3653,53 @@ layui.config({
|
||||
window.open("./preview.html");
|
||||
});
|
||||
});
|
||||
$('.saveJson').on('click', function () {
|
||||
//window.localStorage.setItem('layui_form_json', JSON.stringify(options.data));
|
||||
CoreUtil.sendPut("/activiti-form/setActivitiForm", {
|
||||
"id": $("#fromId").val(),
|
||||
"formData": JSON.stringify(options.data)
|
||||
}, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, {
|
||||
icon: 1
|
||||
$('#save').on('click', function () {
|
||||
var formName = $('#formName').val();
|
||||
if(!formName) {
|
||||
top.dialog.msg('请输入表单名称');
|
||||
return;
|
||||
}
|
||||
var formSummary = $('#formSummary').val();
|
||||
if(!formSummary) {
|
||||
top.dialog.msg('请输入表单描述');
|
||||
return;
|
||||
}
|
||||
var data = options.data;
|
||||
if(data.length == 0) {
|
||||
top.dialog.msg('请添加组件');
|
||||
return;
|
||||
}
|
||||
var pageCode = getHtmlCode();
|
||||
|
||||
top.dialog.confirm(top.dataMessage.commit, function(index) {
|
||||
top.dialog.close(index);
|
||||
var loadLayerIndex;
|
||||
top.restAjax.post(top.restAjax.path('api/form-design/save', []), {
|
||||
formName: formName,
|
||||
formSummary: formSummary,
|
||||
data: data,
|
||||
code: pageCode
|
||||
}, null, function(code, data) {
|
||||
var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
|
||||
time: 0,
|
||||
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
|
||||
shade: 0.3,
|
||||
yes: function(index) {
|
||||
top.dialog.close(index);
|
||||
window.location.reload();
|
||||
},
|
||||
btn2: function() {
|
||||
closeBox();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
icon: 2
|
||||
});
|
||||
}
|
||||
setTimeout(function () {
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(index); //关闭弹出层
|
||||
parent.location.reload();
|
||||
}, 1000);
|
||||
})
|
||||
//var index = parent.layer.getFrameIndex(window.name);
|
||||
//parent.layer.close(index);
|
||||
}, function(code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function() {
|
||||
loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function() {
|
||||
top.dialog.close(loadLayerIndex);
|
||||
});
|
||||
});
|
||||
});
|
||||
that.renderForm();
|
||||
};
|
||||
|
195
module-form/src/main/resources/templates/form/list.html
Normal file
195
module-form/src/main/resources/templates/form/list.html
Normal file
@ -0,0 +1,195 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<div class="test-table-reload-btn" style="margin-bottom: 10px;">
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="keywords" class="layui-input search-item" placeholder="输入关键字">
|
||||
</div>
|
||||
<button type="button" id="search" class="layui-btn layui-btn-sm">
|
||||
<i class="fa fa-lg fa-search"></i> 搜索
|
||||
</button>
|
||||
</div>
|
||||
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
|
||||
<!-- 表头按钮字典 -->
|
||||
<script type="text/html" id="headerToolBar">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-sm" lay-event="save">
|
||||
<i class="fa fa-lg fa-plus"></i> 新增
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">
|
||||
<i class="fa fa-lg fa-edit"></i> 编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="remove">
|
||||
<i class="fa fa-lg fa-trash"></i> 删除
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="parentId" th:value="${parentId}">
|
||||
<script src="assets/layuiadmin/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.config({
|
||||
base: 'assets/layuiadmin/'
|
||||
}).extend({
|
||||
index: 'lib/index'
|
||||
}).use(['index', 'table', 'laydate', 'ztree'], function() {
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
var table = layui.table;
|
||||
var admin = layui.admin;
|
||||
var laydate = layui.laydate;
|
||||
|
||||
// 初始化表格
|
||||
function initTable() {
|
||||
table.render({
|
||||
elem: '#dataTable',
|
||||
id: 'dataTable',
|
||||
url: top.restAjax.path('api/form/listpage', []),
|
||||
width: admin.screen() > 1 ? '100%' : '',
|
||||
height: $win.height() - 60,
|
||||
limit: 20,
|
||||
limits: [20, 40, 60, 80, 100, 200],
|
||||
toolbar: '#headerToolBar',
|
||||
request: {
|
||||
pageName: 'page',
|
||||
limitName: 'rows'
|
||||
},
|
||||
cols: [
|
||||
[
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||
{field:'dataId', width:200, title: '字典ID', align:'center',},
|
||||
{field:'dataName', width:160, title: '字典名称', align:'center',},
|
||||
{field:'dataSummary', width:160, title: '字典说明', align:'center',},
|
||||
{field:'dataCode', width:160, title: '字典编码', align:'center',},
|
||||
{field:'dataSort', width:100, title: '字典排序', align:'center',},
|
||||
]
|
||||
],
|
||||
page: true,
|
||||
parseData: function(data) {
|
||||
return {
|
||||
'code': 0,
|
||||
'msg': '',
|
||||
'count': data.total,
|
||||
'data': data.rows
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
// 重载表格
|
||||
function reloadTable() {
|
||||
table.reload('dataTable', {
|
||||
where: {
|
||||
keywords: $('#keywords').val(),
|
||||
},
|
||||
height: $win.height() - 60,
|
||||
});
|
||||
}
|
||||
// 初始化日期
|
||||
function initDate() {}
|
||||
// 删除
|
||||
function removeData(ids) {
|
||||
top.dialog.msg(top.dataMessage.delete, {
|
||||
time: 0,
|
||||
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
|
||||
shade: 0.3,
|
||||
yes: function (index) {
|
||||
top.dialog.close(index);
|
||||
var layIndex;
|
||||
top.restAjax.delete(top.restAjax.path('api/form/remove/{ids}', [ids]), {}, null, function (code, data) {
|
||||
top.dialog.msg(top.dataMessage.deleteSuccess, {time: 1000}, function () {
|
||||
reloadTable();
|
||||
});
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function () {
|
||||
layIndex = top.dialog.msg(top.dataMessage.deleting, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function () {
|
||||
top.dialog.close(layIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
initTable();
|
||||
initDate();
|
||||
|
||||
// 事件 - 页面变化
|
||||
$win.on('resize', function() {
|
||||
reloadTable();
|
||||
});
|
||||
// 事件 - 搜索
|
||||
$(document).on('click', '#search', function() {
|
||||
reloadTable();
|
||||
});
|
||||
// 事件 - 增删改
|
||||
table.on('toolbar(dataTable)', function(obj) {
|
||||
var layEvent = obj.event;
|
||||
var checkStatus = table.checkStatus('dataTable');
|
||||
var checkDatas = checkStatus.data;
|
||||
if(layEvent === 'save') {
|
||||
top.dialog.open({
|
||||
title: '表单设计器',
|
||||
url: top.restAjax.path('route/form-design/save', []),
|
||||
width: '99%',
|
||||
height: '99%',
|
||||
onClose: function () {
|
||||
reloadTable();
|
||||
}
|
||||
})
|
||||
} else if(layEvent === 'update') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.dialog.msg(top.dataMessage.table.selectEdit);
|
||||
} else if(checkDatas.length > 1) {
|
||||
top.dialog.msg(top.dataMessage.table.selectOneEdit);
|
||||
} else {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: false,
|
||||
closeBtn: 0,
|
||||
area: ['100%', '100%'],
|
||||
shadeClose: true,
|
||||
anim: 2,
|
||||
content: top.restAjax.path('route/form-design/update?formId={formId}', [checkDatas[0].formId]),
|
||||
end: function() {
|
||||
reloadTable();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if(layEvent === 'remove') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.dialog.msg(top.dataMessage.table.selectDelete);
|
||||
} else {
|
||||
var ids = '';
|
||||
for(var i = 0, item; item = checkDatas[i++];) {
|
||||
if(i > 1) {
|
||||
ids += '_';
|
||||
}
|
||||
ids += item.formId;
|
||||
}
|
||||
removeData(ids);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user