完善动态表单动态新增

This commit is contained in:
wenc000 2019-12-11 23:32:25 +08:00
parent bc6cbc0d55
commit b8216124ac
16 changed files with 578 additions and 92 deletions

View File

@ -33,8 +33,6 @@ public class DynamicDataController extends AbstractController {
@Autowired
private IDynamicDataService dynamicDataService;
@Autowired
private IDynamicFormService dynamicFormService;
@ApiOperation(value = "保存动态数据", notes = "保存动态数据接口")
@ApiImplicitParams({

View File

@ -1,17 +1,17 @@
package com.cm.common.plugin.controller.apis.dynamic;
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormFormShowFieldDTO;
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormListShowFieldDTO;
import com.cm.common.plugin.pojo.vos.dynamic.DynamicFormVO;
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

View File

@ -104,5 +104,16 @@ public class FileController extends AbstractController {
return fileService.uEditor(file, request, params);
}
@ApiOperation(value = "上传图片", notes = "上传图片接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "image", value = "文件name", paramType = "form")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("wangeditorimage")
public JSONObject wangEditorImage(MultipartFile image, HttpServletRequest request) {
Map<String, Object> params = requestParams();
return fileService.wangEditorImage(image, UploadTypeEnum.IMAGE, params);
}
}

View File

@ -32,4 +32,10 @@ public class TreeRouteController extends AbstractController {
return mv;
}
@GetMapping("treeuser")
public ModelAndView treeUser() {
ModelAndView mv = new ModelAndView("tree/tree-user");
return mv;
}
}

View File

@ -59,7 +59,11 @@ public enum FieldTypeEnum {
/**
* 选择部门
*/
SELECT_DEPARTMENT("selectDepartment");
SELECT_DEPARTMENT("selectDepartment"),
/**
* 文件
*/
FILE("file");
private String value;

View File

@ -28,7 +28,7 @@ public class DynamicConfigFormVO {
@CheckEmptyAnnotation(name = "字段说明")
private String fieldExplain;
@ApiModelProperty(name = "fieldType", value = "字段类型")
@CheckEmptyAnnotation(name = "字段类型", types = {"string", "datetime", "date", "number", "double", "textarea", "richText", "select", "checkbox", "radio", "selectUser", "selectDepartment"})
@CheckEmptyAnnotation(name = "字段类型", types = {"string", "datetime", "date", "number", "double", "textarea", "richText", "select", "checkbox", "radio", "selectUser", "selectDepartment", "file"})
private String fieldType;
@ApiModelProperty(name = "fieldDefault", value = "字段默认值")
private String fieldDefault;

View File

@ -81,7 +81,7 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
List<String> listShowField = new ArrayList<>();
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
if (dynamicFormDTO.getFormShow() == 1) {
listShowField.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
listShowField.add(dynamicFormDTO.getFieldName());
}
}
return listShowField;
@ -94,7 +94,7 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
if (dynamicFormDTO.getListShow() == 1) {
DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = new DynamicFormListShowFieldDTO();
dynamicFormListShowFieldDTO.setFieldName(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
dynamicFormListShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName());
dynamicFormListShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain());
dynamicFormListShowFieldDTOList.add(dynamicFormListShowFieldDTO);
}
@ -109,7 +109,7 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
if (dynamicFormDTO.getFormShow() == 1) {
DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = new DynamicFormFormShowFieldDTO();
dynamicFormFormShowFieldDTO.setFieldName(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
dynamicFormFormShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName());
dynamicFormFormShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain());
dynamicFormFormShowFieldDTO.setFieldDefault(dynamicFormDTO.getFieldDefault());
dynamicFormFormShowFieldDTO.setDictionaryId(dynamicFormDTO.getDictionaryId());
@ -260,6 +260,8 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
return true;
} else if (StringUtils.equals(FieldTypeEnum.SELECT_DEPARTMENT.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
return true;
} else if (StringUtils.equals(FieldTypeEnum.FILE.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
return true;
}
return false;
}
@ -305,6 +307,8 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
} else if (StringUtils.equals(FieldTypeEnum.SELECT_DEPARTMENT.getValue(), dynamicFormFieldVO.getFieldType())) {
tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
} else if (StringUtils.equals(FieldTypeEnum.FILE.getValue(), dynamicFormFieldVO.getFieldType())) {
tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
}
return tableColumnVO;
}

View File

@ -100,6 +100,7 @@ public interface IFileService {
/**
* 文件上传
*
* @param token
* @param uploadFile
* @param uploadTypeEnum
@ -130,6 +131,16 @@ public interface IFileService {
*/
JSONObject uEditor(MultipartFile file, HttpServletRequest request, Map<String, Object> params) throws SystemException, IOException;
/**
* wangEditor上传文件
*
* @param image
* @param image1
* @param params
* @return
*/
JSONObject wangEditorImage(MultipartFile image, UploadTypeEnum image1, Map<String, Object> params);
/**
* 获取文件详情
*

View File

@ -1,8 +1,11 @@
package com.cm.common.plugin.service.file.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cm.common.base.AbstractService;
import com.cm.common.config.properties.FileProperties;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.enums.ErrorResultCodeEnum;
import com.cm.common.enums.UploadTypeEnum;
import com.cm.common.exception.FileException;
import com.cm.common.exception.ParamsException;
@ -191,6 +194,22 @@ public class FileServiceImpl extends AbstractService implements IFileService {
return result;
}
@Override
public JSONObject wangEditorImage(MultipartFile image, UploadTypeEnum image1, Map<String, Object> params) {
JSONObject result = new JSONObject();
try {
FileDTO fileDTO = uploadSingleForFileDTO(null, image, UploadTypeEnum.IMAGE, params);
result.put("errno", 0);
JSONArray fileArray = new JSONArray();
fileArray.add(String.format("route/file/downloadfile/false/%s", fileDTO.getFileId()));
result.put("data", fileArray);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.put("errno", ErrorResultCodeEnum.FILE_ERROR.getValue());
}
return result;
}
@Override
public FilePO getFile(Map<String, Object> params) throws SearchException {
return fileDao.getFile(params);
@ -522,7 +541,7 @@ public class FileServiceImpl extends AbstractService implements IFileService {
* @param fileFullPath
*/
private void compressImage(String fileFullPath) {
if(fileFullPath.endsWith(".blob")) {
if (fileFullPath.endsWith(".blob")) {
return;
}
try {

View File

@ -61,8 +61,8 @@
<!-- 动态数据列表 -->
<select id="listDynamicData" parameterType="map" resultType="map">
SELECT
${uuidField},
<foreach collection="listShowFieldList" item="item" separator=",">
${uuidField}
<foreach collection="listShowFieldList" item="item" open="," separator="," close="">
${item}
</foreach>
FROM
@ -74,8 +74,8 @@
<!-- 动态数据详情 -->
<select id="getDynamicData" parameterType="map" resultType="map">
SELECT
${uuidField},
<foreach collection="formShowFieldList" item="item" separator=",">
${uuidField}
<foreach collection="formShowFieldList" item="item" open="," separator="," close="">
${item}
</foreach>
FROM

View File

@ -19,7 +19,7 @@
<!-- 保存动态表单 -->
<insert id="saveDynamicForm" parameterType="map">
INSERT INTO dynamic_form(
INSERT INTO dynamic_config_form(
id,
table_name,
field_name,
@ -51,7 +51,7 @@
<!-- 更新动态表单 -->
<update id="updateDynamicForm" parameterType="map">
UPDATE
dynamic_form
dynamic_config_form
SET
field_name = #{fieldName},
field_explain = #{fieldExplain},
@ -74,8 +74,10 @@
SELECT
*
FROM
dynamic_form
dynamic_config_form
WHERE
is_delete = 0
AND
table_name = #{_parameter}
ORDER BY
field_sort

View File

@ -55,6 +55,7 @@
<option value="radio">单选</option>
<option value="selectUser">选择人员</option>
<option value="selectDepartment">选择部门</option>
<option value="file">文件</option>
</select>
</div>
</div>

View File

@ -55,6 +55,7 @@
<option value="radio">单选</option>
<option value="selectUser">选择人员</option>
<option value="selectDepartment">选择部门</option>
<option value="file">文件</option>
</select>
</div>
</div>

View File

@ -238,28 +238,34 @@
height: '500px'
});
} else if(layEvent === 'saveDynamicTable') {
var layIndex;
top.restAjax.post(top.restAjax.path('api/dynamicconfigtable/savedynamictable/{id}', [data.id]), {}, null, function(code, data) {
top.dialog.msg('建表成功');
reloadTable();
}, function (code, data) {
top.dialog.msg(data.msg);
}, function () {
layIndex = top.dialog.msg('正在建表,请稍后...', {icon: 16, time: 0, shade: 0.3});
}, function () {
top.dialog.close(layIndex);
top.dialog.confirm('确定建表吗?', function(index) {
top.dialog.close(index);
var layIndex;
top.restAjax.post(top.restAjax.path('api/dynamicconfigtable/savedynamictable/{id}', [data.id]), {}, null, function(code, data) {
top.dialog.msg('建表成功');
reloadTable();
}, function (code, data) {
top.dialog.msg(data.msg);
}, function () {
layIndex = top.dialog.msg('正在建表,请稍后...', {icon: 16, time: 0, shade: 0.3});
}, function () {
top.dialog.close(layIndex);
});
});
} else if(layEvent === 'updateDynamicTable') {
var layIndex;
top.restAjax.put(top.restAjax.path('api/dynamicconfigtable/updatedynamictable/{id}', [data.id]), {}, null, function(code, data) {
top.dialog.msg('更新成功');
reloadTable();
}, function (code, data) {
top.dialog.msg(data.msg);
}, function () {
layIndex = top.dialog.msg('正在更新,请稍后...', {icon: 16, time: 0, shade: 0.3});
}, function () {
top.dialog.close(layIndex);
top.dialog.confirm('确定更新表吗?字段新增或者删除都会直接修改表结构,有数据的列也会直接删除!', function(index) {
top.dialog.close(index);
var layIndex;
top.restAjax.put(top.restAjax.path('api/dynamicconfigtable/updatedynamictable/{id}', [data.id]), {}, null, function(code, data) {
top.dialog.msg('更新成功');
reloadTable();
}, function (code, data) {
top.dialog.msg(data.msg);
}, function () {
layIndex = top.dialog.msg('正在更新,请稍后...', {icon: 16, time: 0, shade: 0.3});
}, function () {
top.dialog.close(layIndex);
});
});
}
});

View File

@ -20,60 +20,122 @@
</span>
</div>
<div class="layui-card-body" style="padding: 15px;">
<form class="layui-form" lay-filter="dataForm">
<div class="layui-form-item" th:each="dynamicFormFormShowFieldDTO, state: ${dynamicFormFormShowFieldDTOList}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'string'}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=required">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'phone'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=phone">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'email'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=email">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'url'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=url">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'date'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=date">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'identity'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=identity">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'datetime' or dynamicFormFormShowFieldDTO.fieldType eq 'date'}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'date'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=date">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'number'}">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'double'}">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'textarea'}">
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'richText'}">
<script th:id="${dynamicFormFormShowFieldDTO.fieldName}" type="text/plain" style="width:100%;height:400px;"></script>
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'select'}">
<select th:each="selectMap: ${selectMapList}" th:if="${selectMap.name eq dynamicFormFormShowFieldDTO.fieldName}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" lay-verify="required">
<option value="">请选择</option>
<option th:each="select: ${selectMap.list}" th:value="${select.dictionaryId}" th:text="${select.dictionaryName}"></option>
</select>
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'checkbox'}">
<div th:each="checkboxMap: ${checkboxMapList}" th:if="${checkboxMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
<input type="checkbox" th:each="checkbox: ${checkboxMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName +'['+ checkbox.dictionaryId +']'}" th:title="${checkbox.dictionaryName}">
<form class="layui-form layui-form-pane" lay-filter="dataForm">
<div th:each="dynamicFormFormShowFieldDTO, state: ${dynamicFormFormShowFieldDTOList}">
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'string'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=required">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'phone'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=phone">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'email'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=email">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'url'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=url">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'date'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=date">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'identity'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=identity">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
</div>
<div class="layui-input-block" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'radio'}">
<div th:each="radioMap: ${radioMapList}" th:if="${radioMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
<input type="radio" th:each="radio: ${radioMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${radio.dictionaryId}" th:title="${radio.dictionaryName}">
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'datetime' or dynamicFormFormShowFieldDTO.fieldType eq 'date'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'date'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=date">
<input type="text" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'number'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="number" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'double'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'number'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=number">
<input type="number" step="0.01" th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="lay-verify=custom">
</div>
</div>
<div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'textarea'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'none'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'required'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
<textarea th:if="${dynamicFormFormShowFieldDTO.verifyType eq 'custom'}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
</div>
</div>
<div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'richText'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<div th:id="${dynamicFormFormShowFieldDTO.fieldName}"></div>
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'select'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<select th:each="selectMap: ${selectMapList}" th:if="${selectMap.name eq dynamicFormFormShowFieldDTO.fieldName}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" lay-verify="required">
<option value="">请选择</option>
<option th:each="select: ${selectMap.list}" th:value="${select.dictionaryId}" th:text="${select.dictionaryName}"></option>
</select>
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'checkbox'}" pane>
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<div th:each="checkboxMap: ${checkboxMapList}" th:if="${checkboxMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
<input type="checkbox" th:each="checkbox: ${checkboxMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName +'['+ checkbox.dictionaryId +']'}" th:title="${checkbox.dictionaryName}">
</div>
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'radio'}" pane>
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<div th:each="radioMap: ${radioMapList}" th:if="${radioMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
<input type="radio" th:each="radio: ${radioMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${radio.dictionaryId}" th:title="${radio.dictionaryName}">
</div>
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'file'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
<button type="button" class="layui-btn" lay-form-button th:attr="data-explain=${dynamicFormFormShowFieldDTO.fieldExplain},data-name=${dynamicFormFormShowFieldDTO.fieldName},lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'UploadFile'}">
<i class="fa fa-cloud-upload"></i> <span th:text="${'上传'+ dynamicFormFormShowFieldDTO.fieldExplain}"></span>
</button>
<div class="layui-btn-container" th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileBox'}"></div>
<script th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileDownload'}" type="text/html" th:inline="javascript">
{{# var fieldName = [[${dynamicFormFormShowFieldDTO.fieldName}]]; }}
{{# if(d[fieldName] != '') { }}
{{# var files = d[fieldName].split(',');}}
{{# for(var i = 0, item = files[i]; item = files[i++];) {}}
<span class="layui-btn-group">
<a class="layui-btn layui-btn-normal" href="route/file/downloadfile/false/{{item}}">点击下载此文件</a>
<a class="layui-btn layui-btn-danger text-danger" href="javascript:void(0);" lay-form-button data-id="{{item}}" th:attr="data-name=${dynamicFormFormShowFieldDTO.fieldName},lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'RemoveFile'}">删除</a>
</span>
{{# } }}
{{# } }}
</script>
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'selectUser'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}">
<input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName +'SelectUser'}" class="layui-input" th:placeholder="${'请选择'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="data-name=${dynamicFormFormShowFieldDTO.fieldName}" readonly style="cursor:pointer;">
</div>
</div>
<div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'selectDepartment'}">
<label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
<div class="layui-input-block">
<input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}">
<input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName +'SelectDepartment'}" class="layui-input" th:placeholder="${'请选择'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="data-name=${dynamicFormFormShowFieldDTO.fieldName}" readonly style="cursor:pointer;">
</div>
</div>
</div>
@ -91,21 +153,197 @@
</div>
</div>
<input type="hidden" id="tableName" th:value="${tableName}"/>
<script src="assets/js/vendor/wangEditor/wangEditor.min.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script th:inline="javascript">
layui.config({
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate'], function(){
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var wangEditor = window.wangEditor;
var wangEditorArray = [];
var formFieldList = [[${dynamicFormFormShowFieldDTOList}]];
function closeBox() {
parent.layer.close(parent.layer.getFrameIndex(window.name));
}
function refreshDownloadTemplet(fileName, file) {
var dataForm = {};
dataForm[fileName] = file;
form.val('dataForm', dataForm);
var dataRander = {};
dataRander[fileName] = $('#'+ fileName).val();
laytpl(document.getElementById(fileName +'FileDownload').innerHTML).render(dataRander, function(html) {
document.getElementById(fileName +'FileBox').innerHTML = html;
});
}
// 初始化
function initData() {
for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) {
if(item.fieldType === 'richText') {
var editor = new wangEditor('#'+ item.fieldName);
editor.customConfig.zIndex = 1000;
editor.customConfig.uploadImgMaxSize = 5 * 1024 * 1024;
editor.customConfig.uploadImgMaxLength = 1;
editor.customConfig.uploadFileName = 'image';
editor.customConfig.uploadImgServer = 'api/file/wangeditorimage';
editor.customConfig.uploadImgHooks = {
fail: function (xhr, editor, result) {
top.dialog.msg('系统错误,图片上传失败');
},
error: function (xhr, editor) {
top.dialog.msg('网络异常');
},
timeout: function (xhr, editor) {
top.dialog.msg('网络请求超时');
}
};
editor.create();
wangEditorArray.push(editor);
} else if(item.fieldType === 'file') {
form.on('button('+ item.fieldName +'UploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'file',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
refreshDownloadTemplet(name, files);
}
}
});
});
form.on('button('+ item.fieldName +'RemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 2);
}
console.log(files);
refreshDownloadTemplet(name, files);
});
} else if(item.fieldType === 'selectUser') {
$(document.body).on('click', '#'+ item.fieldName +'SelectUser', function() {
var name = this.dataset.name;
var selectedUsers = [];
var selectDepartmentUser = $('#'+ name).val().split(',');
for(var i = 0, item = selectDepartmentUser[i]; item = selectDepartmentUser[i++];) {
var userInfo = item.split('|');
selectedUsers.push({
userId: userInfo[0],
departmentId: userInfo[1]
});
}
top.dialog.dialogData.selectedUsers = selectedUsers;
top.dialog.open({
url: top.restAjax.path('route/tree/treeuser', []),
title: '选择组织部门人员',
width: '500px',
height: '500px',
onClose: function() {
var selectedUsers = top.dialog.dialogData.selectedDepartmentUsers;
if(selectedUsers != null && selectedUsers.length > 0) {
var selectedUsersVal = '';
var showSelectedUsersVal = '';
for(var j = 0, selectUser = selectedUsers[j]; selectUser = selectedUsers[j++];) {
if(selectedUsersVal.length > 0) {
selectedUsersVal += ',';
}
if(showSelectedUsersVal.length > 0) {
showSelectedUsersVal += ',';
}
selectedUsersVal += (selectUser.userId +'|'+ selectUser.departmentId +'|'+ selectUser.userName +'|'+ selectUser.userTitle);
showSelectedUsersVal += selectUser.userName;
}
$('#'+ name).val(selectedUsersVal);
$('#'+ name +'SelectUser').val(showSelectedUsersVal);
} else {
$('#'+ name).val('');
$('#'+ name +'SelectUser').val('');
}
}
});
});
} else if(item.fieldType === 'selectDepartment') {
$(document.body).on('click', '#'+ item.fieldName +'SelectDepartment', function() {
var name = this.dataset.name;
var selectedNodes = [];
var selectDepartment = $('#'+ name).val().split(',');
for(var i = 0, item = selectDepartment[i]; item = selectDepartment[i++];) {
var departmentInfo = item.split('|');
selectedNodes.push({
id: departmentInfo[0],
name: departmentInfo[1],
title: departmentInfo[1]
});
}
top.dialog.tree({
title: '选择部门',
apiUri: top.restAjax.path('api/department/listztreedepartment', []),
width: '250px',
height: '400px',
dataFilter: function(treeId, parentNode, childNodes) {
return childNodes;
},
check: {
enable: true,
selectType: 'checkbox',
checkboxType: {Y: 'ps', N: 'ps'},
radioType: 'level',
},
selectedNodes: selectedNodes,
onClose: function() {
var selectNodes = top.dialog.dialogTreeData.selectedNodes;
if(typeof(selectNodes) != 'undefined' && selectNodes != null) {
if(selectNodes.length > 0) {
var selectedDepartmentVal = '';
var showSelectedDepartmentsVal = '';
for(var j = 0, selectNode = selectNodes[j]; selectNode = selectNodes[j++];) {
if(selectedDepartmentVal.length > 0) {
selectedDepartmentVal += ',';
}
if(showSelectedDepartmentsVal.length > 0) {
showSelectedDepartmentsVal += ',';
}
selectedDepartmentVal += (selectNode.id +'|'+ selectNode.name);
showSelectedDepartmentsVal += selectNode.name;
}
$('#'+ name).val(selectedDepartmentVal);
$('#'+ name +'SelectDepartment').val(showSelectedDepartmentsVal);
}
}
}
});
});
}
}
}
initData();
// 提交表单
form.on('submit(submitForm)', function(formData) {
top.dialog.confirm(top.dataMessage.commit, function(index) {

View File

@ -0,0 +1,185 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<base th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort() + #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" type="text/css" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.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-card">
<div class="layui-card-body" style="padding: 0px;">
<div class="layui-row">
<div class="layui-col-xs5">
<div class="selector-tree-wrapper">
<ul id="leftTree" class="ztree"></ul>
</div>
</div>
<div class="layui-col-xs7">
<div class="selector-body-wrapper">
<div id="selectUsers" class="selector-body-content-user layui-btn-container"></div>
</div>
</div>
</div>
<div class="layui-form-item layui-layout-admin">
<div class="layui-input-block">
<div class="layui-footer" style="left: 0;">
<button type="button" class="layui-btn confirm">确认</button>
<button type="button" class="layui-btn layui-btn-primary close">关闭</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
layui.config({
base: 'assets/layuiadmin/'
}).extend({
index: 'lib/index'
}).use(['index', 'ztree', 'common'], function() {
var $ = layui.$;
var $win = $(window);
var common = layui.common;
var selectedUsers = top.dialog.dialogData.selectedUsers;
var selectDepartmentUserArray = [];
function closeBox() {
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;
top.dialog.dialogData.selectedUsers = null;
top.dialog.closeBox();
}
// 初始化框架
function initFrame() {
var height = $win.height() - 80;
$('.selector-tree-wrapper').css({
marginTop: '5px',
height: height +'px',
border: '1px dotted silver'
});
$('.selector-body-wrapper').css({
marginTop: '5px',
height: height +'px',
border: '1px dotted silver'
});
}
// 初始化数据
var initTimeout = null;
var isInited = false;
function initCheckData(zTree) {
top.dialog.dialogData.selectedDepartmentUsers = [];
if(isInited) {
return;
}
if(selectedUsers) {
if(selectedUsers.length == 0) {
return;
}
var loadLayerIndex;
top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), {
selectedUsers: selectedUsers
}, null, function(code, data) {
var nodes = zTree.transformToArray(zTree.getNodes());
for(var i = 0, node = nodes[i]; node = nodes[i++];) {
for(var j = 0, item = data[j]; item = data[j++]; ) {
if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) {
zTree.checkNode(node, true, true);
break;
}
}
}
selectUser(zTree.getCheckedNodes(true));
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
}
isInited = true;
}
// 初始化树
function initThree() {
var setting = {
check: {
enable: true
},
async: {
enable: true,
autoLoad: false,
type: 'get',
url: top.restAjax.path('api/department/listztreedepartmentwithuser', []),
autoParam:['id'],
otherParam:{},
dataFilter: function(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
},
callback: {
onCheck: function(event, treeId, treeNode) {
selectUser(zTree.getCheckedNodes(true));
return false;
},
onAsyncSuccess: function(event, treeId, treeNode) {
if(initTimeout != null) {
clearTimeout(initTimeout)
}
var subNodes = zTree.getNodesByParam('pId', treeNode.id, null);
for(var i = 0, item = subNodes[i]; item = subNodes[i++];) {
if(item.id.indexOf('u_') < 0) {
zTree.expandNode(item, true, false, false);
}
}
initTimeout = setTimeout(function() {
initCheckData(zTree);
}, 500);
}
},
view: {
fontCss: {'color': 'black'}
}
};
var zTree = $.fn.zTree.init($('#leftTree'), setting);
zTree.addNodes(null, {id: '0', pId: '-1', name: '根节点', url: 'javascript:void(0);', icon: 'assets/images/tree/tree-department.png', isParent: 'true'});
common.refreshTree('leftTree');
}
initFrame();
initThree();
// 选择人员
function selectUser(checkedNodes) {
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length);
$('#selectUsers').empty();
for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) {
if(item.title && item.title != '') {
selectDepartmentUserArray.push({
userId: item.id.substring(2, item.id.length),
userName: item.name,
userTitle: item.title,
departmentId: item.pId,
});
$('#selectUsers').append('<span id="selected_user_'+ item.id +'" class="layui-btn layui-btn-xs">'+ item.title +' </span>');
}
}
}
$('.confirm').on('click', function() {
closeBox();
});
$('.close').on('click', function() {
closeBox();
})
});
</script>
</body>
</html>