Commit ddd35cac by fengshuonan

整理字典的添加

parent 3496f212
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package cn.stylefeng.guns.core.beetl; package cn.stylefeng.guns.core.beetl;
import cn.stylefeng.guns.core.tag.DictSelectorTag;
import cn.stylefeng.guns.core.util.DefaultImages; import cn.stylefeng.guns.core.util.DefaultImages;
import cn.stylefeng.guns.core.util.KaptchaUtil; import cn.stylefeng.guns.core.util.KaptchaUtil;
import cn.stylefeng.roses.core.util.ToolUtil; import cn.stylefeng.roses.core.util.ToolUtil;
...@@ -39,9 +38,6 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration { ...@@ -39,9 +38,6 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
@Autowired @Autowired
private Environment env; private Environment env;
@Autowired
private DictSelectorTag dictSelectorTag;
@Override @Override
public void initOther() { public void initOther() {
...@@ -49,7 +45,6 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration { ...@@ -49,7 +45,6 @@ public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
groupTemplate.registerFunctionPackage("shiro", new ShiroExt()); groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
groupTemplate.registerFunctionPackage("tool", new ToolUtil()); groupTemplate.registerFunctionPackage("tool", new ToolUtil());
groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil()); groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil());
groupTemplate.registerTagFactory("dictSelector", () -> dictSelectorTag);
groupTemplate.registerFunction("env", new Function() { groupTemplate.registerFunction("env", new Function() {
@Override @Override
......
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.core.tag;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.modular.system.entity.Dict;
import cn.stylefeng.guns.modular.system.service.DictService;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import org.beetl.core.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* 字典标签渲染
*
* @author zhangjiajia
* @Date 2018年6月4日17:33:32
*/
@Component
@Scope("prototype")
public class DictSelectorTag extends Tag {
@Autowired
DictService dictService;
@Override
public void render() {
//String tagName = (String) this.args[0];
Map attrs = (Map) args[1];
if (ToolUtil.isEmpty(attrs.get("code"))) {
throw new ServiceException(BizExceptionEnum.ERROR_CODE_EMPTY);
}
//字典类型编码
String code = attrs.get("code").toString();
//控件显示类型select 选择框,radio 单选按钮,checkbox 多选按钮
String type = ToolUtil.isNotEmpty(attrs.get("type")) ? attrs.get("type").toString() : "select";
//开启多选
String multiple = ToolUtil.isNotEmpty(attrs.get("multiple")) ? attrs.get("multiple").toString() : "";
//字典名称
String label = ToolUtil.isNotEmpty(attrs.get("label")) ? attrs.get("label").toString() : "";
//提示
String placeholder = (ToolUtil.isNotEmpty(attrs.get("placeholder")) ? attrs.get("placeholder").toString() : "");
//宽度
String width = ToolUtil.isNotEmpty(attrs.get("width")) ? attrs.get("width").toString() : "248";
//默认值
String value = ToolUtil.isNotEmpty(attrs.get("value")) ? attrs.get("value").toString() : "";
//id
String id = ToolUtil.isNotEmpty(attrs.get("id")) ? attrs.get("id").toString() : "";
//name
String name = ToolUtil.isNotEmpty(attrs.get("name")) ? attrs.get("name").toString() : "";
//分割线
String underline = ToolUtil.isNotEmpty(attrs.get("underline")) ? attrs.get("underline").toString() : "";
//onchange事件
String onchange = ToolUtil.isNotEmpty(attrs.get("onchange")) ? attrs.get("onchange").toString() : "";
//readonly属性
String readonly = ToolUtil.isNotEmpty(attrs.get("readonly")) ? attrs.get("readonly").toString() : "";
//disabled属性
String disabled = ToolUtil.isNotEmpty(attrs.get("disabled")) ? attrs.get("disabled").toString() : "";
//searchnum 下拉选项数量达到多少启用搜索,默认10
int searchnum = ToolUtil.isNum(attrs.get("searchnum")) ? Integer.parseInt(attrs.get("searchnum").toString()) : 10;
//根据code查询字典数据
List<Dict> list = dictService.selectByParentCode(code);
StringBuffer html = new StringBuffer();
html.append("<div class=\"form-group\">\r\n");
html.append("<label class=\"col-sm-3 control-label\">" + label + "</label>\r\n");
html.append("<div class=\"col-sm-9\">\r\n");
//单选按钮
if ("radio".equals(type)) {
list.forEach(obj -> {
html.append("<label class=\"radio-inline i-checks\">\r\n<input type=\"radio\" ");
//判断控件是否禁用
if ("true".equals(disabled) || "disabled".equals(disabled)) {
html.append("disabled ");
} else {
if (ToolUtil.isNotEmpty(name)) {
html.append("name=\"" + name + "\" ");
}
}
if ("true".equals(readonly) || "disabled".equals(readonly)) {
html.append("disabled ");
}
if (ToolUtil.isNotEmpty(value) && value.equals(obj.getCode())) {
html.append("checked ");
}
html.append("value=\"" + obj.getCode() + "\" >" + obj.getName() + "</label>\r\n");
});
//多选按钮
} else if ("checkbox".equals(type)) {
list.forEach(obj -> {
html.append("<label class=\"checkbox-inline i-checks\">\r\n<input type=\"checkbox\" ");
//判断控件是否禁用
if ("true".equals(disabled) || "disabled".equals(disabled)) {
html.append("disabled ");
} else {
if (ToolUtil.isNotEmpty(name)) {
html.append("name=\"" + name + "\" ");
}
}
if ("true".equals(readonly) || "disabled".equals(readonly)) {
html.append("disabled ");
}
if (ToolUtil.isNotEmpty(value) && value.equals(obj.getCode())) {
html.append("checked ");
}
html.append("value=\"" + obj.getCode() + "\" >" + obj.getName() + "</label>\r\n");
});
//默认select
} else {
//开启多选
if ("true".equals(multiple)) {
if (list.size() >= searchnum) {
html.append("<select multiple ");
} else {
html.append("<select multiple=\"multiple\" size=\"10\" ");
}
} else {
html.append("<select ");
}
//判断控件是否启用提示
if (ToolUtil.isNotEmpty(placeholder)) {
html.append(" data-placeholder=\"" + placeholder + "\" ");
}
//判断控件是否禁用
if ("true".equals(disabled) || "disabled".equals(disabled)) {
html.append("disabled=\"disabled\" ");
} else {
//启用
if (ToolUtil.isNotEmpty(id)) {
html.append("id=\"" + id + "\" ");
}
if (ToolUtil.isNotEmpty(name)) {
html.append("name=\"" + name + "\" ");
}
}
//判断是否启用搜索框
//判断下拉数据,如果查询出来的条数达到启用搜索的数量就启用
if (list.size() >= searchnum) {
html.append("class=\"form-control chosen-select\" style=\"width:" + width + "px\" tabindex=\"1\" \r\n");
} else {
html.append("class=\"form-control\" style=\"width:" + width + "px\" \r\n");
}
//判断控件是否只读
if ("true".equals(readonly) || "readonly".equals(readonly)) {
if (list.size() >= searchnum) {
html.append("disabled=\"disabled\" ");
} else {
html.append("onfocus=\"this.defaultIndex=this.selectedIndex;\" onchange=\"this.selectedIndex=this.defaultIndex;\" ");
}
}
//判断是否绑定onchange事件
if (ToolUtil.isNotEmpty(onchange)) {
html.append("onchange=\"" + onchange + "($(this).children('option:selected').val())\" ");
}
html.append(">");
if (ToolUtil.isNotEmpty(placeholder)) {
html.append("<option value=\"\">" + placeholder + "</option>\r\n");
}
//将查询出来的数据添加到select中
list.forEach(obj -> {
if (ToolUtil.isNotEmpty(value) && value.equals(obj.getCode())) {
html.append("<option selected value=\"" + obj.getCode() + "\">" + obj.getName() + "</option>\r\n");
} else {
html.append("<option value=\"" + obj.getCode() + "\">" + obj.getName() + "</option>\r\n");
}
});
html.append("</select>\r\n");
}
html.append("</div>\r\n</div>\r\n");
//判断是否添加分割线
if (ToolUtil.isNotEmpty(underline) && "true".equals(underline)) {
html.append("<div class=\"hr-line-dashed\" ></div >\r\n");
}
try {
this.ctx.byteWriter.writeString(html.toString());
} catch (IOException e) {
throw new RuntimeException("输出字典标签错误");
}
}
}
...@@ -23,6 +23,7 @@ import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory; ...@@ -23,6 +23,7 @@ import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum; import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.log.LogObjectHolder; import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.modular.system.entity.Dict; import cn.stylefeng.guns.modular.system.entity.Dict;
import cn.stylefeng.guns.modular.system.model.DictDto;
import cn.stylefeng.guns.modular.system.service.DictService; import cn.stylefeng.guns.modular.system.service.DictService;
import cn.stylefeng.guns.modular.system.warpper.DictWarpper; import cn.stylefeng.guns.modular.system.warpper.DictWarpper;
import cn.stylefeng.roses.core.base.controller.BaseController; import cn.stylefeng.roses.core.base.controller.BaseController;
...@@ -64,11 +65,21 @@ public class DictController extends BaseController { ...@@ -64,11 +65,21 @@ public class DictController extends BaseController {
} }
/** /**
* 跳转到添加字典 * 跳转到添加字典类型
*/ */
@RequestMapping("/dict_add") @RequestMapping("/dict_add_type")
public String deptAdd() { public String deptAddType() {
return PREFIX + "dict_add.html"; return PREFIX + "dict_add_type.html";
}
/**
* 跳转到添加字典条目
*/
@RequestMapping("/dict_add_item")
public String deptAddItem(@RequestParam("dictId") Long dictId, Model model) {
model.addAttribute("dictTypeId", dictId);
model.addAttribute("dictTypeName", ConstantFactory.me().getDictName(dictId));
return PREFIX + "dict_add_item.html";
} }
/** /**
...@@ -76,7 +87,7 @@ public class DictController extends BaseController { ...@@ -76,7 +87,7 @@ public class DictController extends BaseController {
*/ */
@Permission(Const.ADMIN_NAME) @Permission(Const.ADMIN_NAME)
@RequestMapping("/dict_edit/{dictId}") @RequestMapping("/dict_edit/{dictId}")
public String deptUpdate(@PathVariable Integer dictId, Model model) { public String deptUpdate(@PathVariable Long dictId, Model model) {
Dict dict = dictService.selectById(dictId); Dict dict = dictService.selectById(dictId);
model.addAttribute("dict", dict); model.addAttribute("dict", dict);
List<Dict> subDicts = dictService.selectList(new EntityWrapper<Dict>().eq("PID", dictId)); List<Dict> subDicts = dictService.selectList(new EntityWrapper<Dict>().eq("PID", dictId));
...@@ -87,18 +98,21 @@ public class DictController extends BaseController { ...@@ -87,18 +98,21 @@ public class DictController extends BaseController {
/** /**
* 新增字典 * 新增字典
*
* @param dictValues 格式例如 "1:启用;2:禁用;3:冻结"
*/ */
@BussinessLog(value = "添加字典记录", key = "dictName,dictValues", dict = DictMap.class)
@RequestMapping(value = "/add") @RequestMapping(value = "/add")
@Permission(Const.ADMIN_NAME) @Permission(Const.ADMIN_NAME)
@ResponseBody @ResponseBody
public Object add(String dictCode, String dictTips, String dictName, String dictValues) { public Object add(DictDto dictDto) {
if (ToolUtil.isOneEmpty(dictCode, dictName, dictValues)) { if (ToolUtil.isOneEmpty(dictDto, dictDto.getCode(), dictDto.getName())) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
} }
this.dictService.addDict(dictCode, dictName, dictTips, dictValues);
if (ToolUtil.isEmpty(dictDto.getDictTypeId())) {
this.dictService.addDictType(dictDto);
} else {
//TODO
}
return SUCCESS_TIP; return SUCCESS_TIP;
} }
......
package cn.stylefeng.guns.modular.system.model;
import lombok.Data;
import java.io.Serializable;
/**
* 字典信息
*
* @author fengshuonan
* @Date 2018/12/8 18:16
*/
@Data
public class DictDto implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 类型id
*/
private Long dictTypeId;
/**
* 名称
*/
private String name;
/**
* 编码
*/
private String code;
/**
* 备注
*/
private String description;
/**
* 序号
*/
private Integer sort;
}
package cn.stylefeng.guns.modular.system.service; package cn.stylefeng.guns.modular.system.service;
import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum; import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.modular.system.entity.Dict; import cn.stylefeng.guns.modular.system.entity.Dict;
import cn.stylefeng.guns.modular.system.mapper.DictMapper; import cn.stylefeng.guns.modular.system.mapper.DictMapper;
import cn.stylefeng.guns.modular.system.model.DictDto;
import cn.stylefeng.roses.kernel.model.exception.ServiceException; import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
...@@ -31,6 +33,19 @@ public class DictService extends ServiceImpl<DictMapper, Dict> { ...@@ -31,6 +33,19 @@ public class DictService extends ServiceImpl<DictMapper, Dict> {
private DictMapper dictMapper; private DictMapper dictMapper;
/** /**
* 添加字典类型
*/
public void addDictType(DictDto dictDto) {
Dict dict = new Dict();
BeanUtil.copyProperties(dictDto, dict);
//类型的父级id都为0
dict.setPid(0L);
this.insert(dict);
}
/**
* 添加字典 * 添加字典
*/ */
@Transactional @Transactional
......
@layout("/common/_container.html"){ @layout("/common/_container.html",{plugins:["table","layer","sweet-alert"],js:["/assets/modular/system/dict/dict.js"]}){
<div class="row"> <div class="row" id="dictPage">
<div class="col-sm-12"> <div class="col-lg-12">
<div class="ibox float-e-margins"> <div class="card card-outline-theme m-b-10">
<div class="ibox-title"> <div class="card-body">
<h5>字典管理</h5> <div class="form-horizontal">
</div> <div class="form-body">
<div class="ibox-content">
<div class="row row-lg">
<div class="col-sm-12">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-md-3">
<#NameCon id="condition" name="名称" /> <div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">字典名称</div>
</div>
<input v-model="condition" type="text" class="form-control" placeholder="字典名称" autocomplete="off">
</div>
</div>
<div class="col-md-3">
<div class="input-group condition-button">
<div class="input-group-btn condition-button">
<button type="button" id="check-minutes"
class="btn btn-info waves-effect waves-light condition-button-width" onclick="Dict.search()">查询
</button>
</div>
</div>
</div>
</div>
</div>
</div> </div>
<div class="col-sm-3">
<#button name="搜索" icon="fa-search" clickFun="Dict.search()"/>
</div> </div>
</div> </div>
<div class="hidden-xs" id="DictTableToolbar" role="group"> </div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card card-outline-theme m-b-0">
<div class="card-body p-t-0 p-b-0">
<div class="form-horizontal">
<div class="form-actions">
<div class="row">
<div class="col-lg-12">
<div class="card m-b-0 p-b-0">
<div class="hidden-xs" id="dictTableToolbar" role="group">
@if(shiro.hasPermission("/dict/add")){ @if(shiro.hasPermission("/dict/add")){
<#button name="添加" icon="fa-plus" clickFun="Dict.openAddDict()"/> <button type="button" class="btn btn-primary waves-effect" onclick="Dict.openAddType()">
<i class="fa fa-plus"></i>&nbsp;添加类型
</button>
@}
@if(shiro.hasPermission("/dict/add")){
<button type="button" class="btn btn-primary waves-effect m-l-5" onclick="Dict.openAddItem()">
<i class="fa fa-plus"></i>&nbsp;添加子条目
</button>
@} @}
@if(shiro.hasPermission("/dict/update")){ @if(shiro.hasPermission("/dict/update")){
<#button name="修改" icon="fa-plus" clickFun="Dict.openDictDetail()" space="true"/> <button type="button" class="btn btn-primary waves-effect m-l-5" onclick="Dict.openDictDetail()">
<i class="fa fa-edit"></i>&nbsp;修改
</button>
@} @}
@if(shiro.hasPermission("/dict/delete")){ @if(shiro.hasPermission("/dict/delete")){
<#button name="删除" icon="fa-plus" clickFun="Dict.delete()" space="true"/> <button type="button" class="btn btn-primary waves-effect m-l-5" onclick="Dict.delete()">
<i class="fa fa-remove"></i>&nbsp;删除
</button>
@} @}
</div> </div>
<#table id="DictTable"/> <#table id="dictTable"/>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script src="${ctxPath}/static/modular/system/dict/dict.js"></script>
@} @}
@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="form-horizontal">
<input type="hidden" id="id" value="">
<div class="row">
<div class="col-sm-12" id="itemsArea">
<div class="form-group">
<label class="col-sm-2 control-label">类型编码</label>
<div class="col-sm-2">
<input class="form-control" id="dictCode" type="text">
</div>
<label class="col-sm-2 control-label">类型名称</label>
<div class="col-sm-2">
<input class="form-control" id="dictName" type="text">
</div>
<div class="col-sm-2">
<#button btnCss="info" name="增加" icon="fa-plus" clickFun="DictInfoDlg.addItem()"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">备注</label>
<div class="col-sm-8">
<input class="form-control" id="dictTips" type="text">
</div>
</div>
<div class="hr-line-dashed"></div>
</div>
</div>
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="DictInfoDlg.addSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="DictInfoDlg.close()"/>
</div>
</div>
</div>
</div>
<script type="text/template" id="itemTemplate">
<div class="form-group" name="dictItem" id="dictItem">
<label class="col-sm-1 control-label"></label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemCode">
</div>
<label class="col-sm-1 control-label" >名称</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemName">
</div>
<label class="col-sm-1 control-label" >序号</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemNum">
</div>
<div class="col-sm-2">
<#button btnCss="danger" name="删除" id="cancel" icon="fa-remove" clickFun="DictInfoDlg.deleteItem(event)"/>
</div>
</div>
</script>
<script src="${ctxPath}/static/modular/system/dict/dict_info.js"></script>
@}
\ No newline at end of file
@layout("/common/_dialog.html",{plugins:["sweet-alert","layer"],js:["/assets/modular/system/dict/dict_add_item.js"]}){
<div class="container-fluid">
<form id="dictForm" \@submit="submitForm">
<input value="${dictTypeId}" type="hidden" class="form-control">
<div class="row">
<div class="col-6">
<div class="form-group">
<h5>父级字典</h5>
<div class="controls">
<input value="${dictTypeName}" disabled="disabled" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>字典名称 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="name" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>字典编码 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="code" type="text" class="form-control">
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<h5>描述</h5>
<div class="controls">
<input v-model="description" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>排序</h5>
<div class="controls">
<input v-model="sort" type="text" class="form-control">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="text-xs-right">
<button class="btn btn-info normal-button-width" \@click="ensure">提交</button>
<button class="btn btn-inverse normal-button-width m-l-10" \@click="close">取消</button>
</div>
</div>
</div>
</form>
</div>
@}
@layout("/common/_dialog.html",{plugins:["sweet-alert","layer"],js:["/assets/modular/system/dict/dict_add_type.js"]}){
<div class="container-fluid">
<form id="dictForm" \@submit="submitForm">
<div class="row">
<div class="col-6">
<div class="form-group">
<h5>父级字典</h5>
<div class="controls">
<input value="顶级" disabled="disabled" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>字典名称 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="name" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>字典编码 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="code" type="text" class="form-control">
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<h5>描述</h5>
<div class="controls">
<input v-model="description" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>排序</h5>
<div class="controls">
<input v-model="sort" type="text" class="form-control">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="text-xs-right">
<button class="btn btn-info normal-button-width" \@click="ensure">提交</button>
<button class="btn btn-inverse normal-button-width m-l-10" \@click="close">取消</button>
</div>
</div>
</div>
</form>
</div>
@}
@layout("/common/_container.html"){ @layout("/common/_dialog.html",{plugins:["sweet-alert","layer"],js:["/assets/modular/system/role/role_edit.js"]}){
<div class="ibox float-e-margins"> <div class="container-fluid">
<div class="ibox-content"> <form id="roleForm" \@submit="submitForm">
<div class="form-horizontal">
<input type="hidden" id="id" value="">
<div class="row"> <div class="row">
<div class="col-sm-12" id="itemsArea"> <div class="col-6">
<input type="hidden" id="itemSize" value="${subDicts.~size!0}" />
<div class="form-group"> <div class="form-group">
<h5>角色名称 <span class="text-danger">*</span></h5>
<label class="col-sm-2 control-label">类型编码</label> <div class="controls">
<div class="col-sm-2"> <input v-model="name" type="text" class="form-control">
<input class="form-control" id="dictCode" type="text" value="${dict.code}">
</div>
<label class="col-sm-2 control-label">类型名称</label>
<div class="col-sm-2">
<input class="form-control" id="dictName" type="text" value="${dict.name}">
<input type="hidden" id="dictId" value="${dict.id}">
</div>
<div class="col-sm-2">
<#button btnCss="info" name="增加" icon="fa-plus" clickFun="DictInfoDlg.addItem()"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">备注</label> <h5>上级名称 <span class="text-danger">*</span></h5>
<div class="col-sm-8"> <div class="controls">
<input class="form-control" id="dictTips" type="text" value="${dict.description}"> <input v-model="pName" id="pName" \@click="showParentSelectTree" type="text" class="form-control" autocomplete="off">
</div> <input v-model="pid" type="hidden" class="form-control">
</div>
<div class="hr-line-dashed"></div>
@for(item in subDicts){
<div class="form-group" name="dictItem" id="dictItem${itemLP.index}">
<label class="col-sm-1 control-label"></label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemCode" value="${item.code}">
</div>
<label class="col-sm-1 control-label" >名称</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemName" value="${item.name}">
</div> </div>
<label class="col-sm-1 control-label" >序号</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemNum" value="${item.num}">
</div> </div>
<div class="col-sm-2"> <div class="form-group">
<#button btnCss="danger" name="删除" id="cancel" icon="fa-remove" clickFun="DictInfoDlg.deleteItem(event)"/> <h5>别名 <span class="text-danger">*</span></h5>
</div> <div class="controls">
</div> <input v-model="description" type="text" class="form-control">
@}
</input>
</div> </div>
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="DictInfoDlg.editSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="DictInfoDlg.close()"/>
</div> </div>
</div> </div>
<div class="col-6">
<div class="form-group">
<h5>排序</h5>
<div class="controls">
<input v-model="sort" type="text" class="form-control">
</div> </div>
</div> </div>
<script type="text/template" id="itemTemplate">
<div class="form-group" name="dictItem" id="dictItem">
<label class="col-sm-1 control-label"></label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemCode">
</div> </div>
<label class="col-sm-1 control-label" >名称</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="itemName">
</div> </div>
<label class="col-sm-1 control-label" >序号</label> <div class="row">
<div class="col-sm-2"> <div class="col-6">
<input class="form-control" type="text" name="itemNum"> <div class="text-xs-right">
<button class="btn btn-info normal-button-width" \@click="ensure">提交</button>
<button class="btn btn-inverse normal-button-width m-l-10" \@click="close">取消</button>
</div> </div>
<div class="col-sm-2">
<#button btnCss="danger" name="删除" id="cancel" icon="fa-remove" clickFun="DictInfoDlg.deleteItem(event)"/>
</div> </div>
</div> </div>
</script> </form>
</div>
<script src="${ctxPath}/static/modular/system/dict/dict_info.js"></script> @}
@}
\ No newline at end of file
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
* 字典管理初始化 * 字典管理初始化
*/ */
var Dict = { var Dict = {
id: "DictTable", //表格id id: "dictTable", //表格id
seItem: null, //选中的条目 seItem: null, //选中的条目
table: null, table: null,
layerIndex: -1 layerIndex: -1,
condition: {
condition: ""
}
}; };
/** /**
...@@ -14,8 +17,9 @@ var Dict = { ...@@ -14,8 +17,9 @@ var Dict = {
Dict.initColumn = function () { Dict.initColumn = function () {
return [ return [
{field: 'selectItem', radio: true}, {field: 'selectItem', radio: true},
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'}, {title: 'id', field: 'dictId', visible: false, align: 'center', valign: 'middle'},
{title: '名称', field: 'name', align: 'center', valign: 'middle', sortable: true}, {title: '名称', field: 'name', align: 'center', valign: 'middle', sortable: true},
{title: '字典编码', field: 'code', align: 'center', valign: 'middle', sortable: true},
{title: '详情', field: 'detail', align: 'center', valign: 'middle', sortable: true}, {title: '详情', field: 'detail', align: 'center', valign: 'middle', sortable: true},
{title: '备注', field: 'description', align: 'center', valign: 'middle', sortable: true}]; {title: '备注', field: 'description', align: 'center', valign: 'middle', sortable: true}];
}; };
...@@ -25,7 +29,7 @@ Dict.initColumn = function () { ...@@ -25,7 +29,7 @@ Dict.initColumn = function () {
*/ */
Dict.check = function () { Dict.check = function () {
var selected = $('#' + this.id).bootstrapTable('getSelections'); var selected = $('#' + this.id).bootstrapTable('getSelections');
if (selected.length == 0) { if (selected.length === 0) {
Feng.info("请先选中表格中的某一记录!"); Feng.info("请先选中表格中的某一记录!");
return false; return false;
} else { } else {
...@@ -35,18 +39,33 @@ Dict.check = function () { ...@@ -35,18 +39,33 @@ Dict.check = function () {
}; };
/** /**
* 点击添加字典 * 点击添加字典类型
*/
Dict.openAddType = function () {
this.layerIndex = layer.open({
type: 2,
title: '添加字典类型',
area: ['800px', '420px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/dict/dict_add_type'
});
};
/**
* 点击添加字典子条目
*/ */
Dict.openAddDict = function () { Dict.openAddItem = function () {
var index = layer.open({ if (this.check()) {
this.layerIndex = layer.open({
type: 2, type: 2,
title: '添加字典', title: '添加字典条目',
area: ['800px', '420px'], //宽高 area: ['800px', '420px'], //宽高
fix: false, //不固定 fix: false, //不固定
maxmin: true, maxmin: true,
content: Feng.ctxPath + '/dict/dict_add' content: Feng.ctxPath + '/dict/dict_add_item?dictId=' + Dict.seItem.dictId
}); });
this.layerIndex = index; }
}; };
/** /**
...@@ -54,15 +73,14 @@ Dict.openAddDict = function () { ...@@ -54,15 +73,14 @@ Dict.openAddDict = function () {
*/ */
Dict.openDictDetail = function () { Dict.openDictDetail = function () {
if (this.check()) { if (this.check()) {
var index = layer.open({ this.layerIndex = layer.open({
type: 2, type: 2,
title: '字典详情', title: '字典详情',
area: ['800px', '420px'], //宽高 area: ['800px', '420px'], //宽高
fix: false, //不固定 fix: false, //不固定
maxmin: true, maxmin: true,
content: Feng.ctxPath + '/dict/dict_edit/' + Dict.seItem.id content: Feng.ctxPath + '/dict/dict_edit/' + Dict.seItem.dictId
}); });
this.layerIndex = index;
} }
}; };
...@@ -72,14 +90,14 @@ Dict.openDictDetail = function () { ...@@ -72,14 +90,14 @@ Dict.openDictDetail = function () {
Dict.delete = function () { Dict.delete = function () {
if (this.check()) { if (this.check()) {
var operation = function(){ var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/dict/delete", function (data) { var ajax = new $ax(Feng.ctxPath + "/dict/delete", function (data) {
Feng.success("删除成功!"); Feng.success("删除成功!");
Dict.table.refresh(); Dict.table.refresh();
}, function (data) { }, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!"); Feng.error("删除失败!" + data.responseJSON.message + "!");
}); });
ajax.set("dictId", Dict.seItem.id); ajax.set("dictId", Dict.seItem.dictId);
ajax.start(); ajax.start();
}; };
......
/**
* 初始化字典详情对话框
*/
var DictInfoDlg = {
count: $("#itemSize").val(),
dictName: '', //字典的名称
dictCode: '', //字典类型编码
dictTips: '', //字典备注
mutiString: '', //拼接字符串内容(拼接字典条目)
itemTemplate: $("#itemTemplate").html()
};
/**
* item获取新的id
*/
DictInfoDlg.newId = function () {
if(this.count == undefined){
this.count = 0;
}
this.count = this.count + 1;
return "dictItem" + this.count;
};
/**
* 关闭此对话框
*/
DictInfoDlg.close = function () {
parent.layer.close(window.parent.Dict.layerIndex);
};
/**
* 添加条目
*/
DictInfoDlg.addItem = function () {
$("#itemsArea").append(this.itemTemplate);
$("#dictItem").attr("id", this.newId());
};
/**
* 删除item
*/
DictInfoDlg.deleteItem = function (event) {
var obj = Feng.eventParseObject(event);
obj = obj.is('button') ? obj : obj.parent();
obj.parent().parent().remove();
};
/**
* 清除为空的item Dom
*/
DictInfoDlg.clearNullDom = function(){
$("[name='dictItem']").each(function(){
var num = $(this).find("[name='itemNum']").val();
var name = $(this).find("[name='itemName']").val();
if(num == '' || name == ''){
$(this).remove();
}
});
};
/**
* 收集添加字典的数据
*/
DictInfoDlg.collectData = function () {
this.clearNullDom();
var mutiString = "";
$("[name='dictItem']").each(function(){
var code = $(this).find("[name='itemCode']").val();
var name = $(this).find("[name='itemName']").val();
var num = $(this).find("[name='itemNum']").val();
mutiString = mutiString + (code + ":" + name + ":"+ num+";");
});
this.dictName = $("#dictName").val();
this.dictCode = $("#dictCode").val();
this.dictTips = $("#dictTips").val();
this.mutiString = mutiString;
};
/**
* 提交添加字典
*/
DictInfoDlg.addSubmit = function () {
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
Feng.success("添加成功!");
window.parent.Dict.table.refresh();
DictInfoDlg.close();
}, function (data) {
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set('dictName',this.dictName);
ajax.set('dictCode',this.dictCode);
ajax.set('dictTips',this.dictTips);
ajax.set('dictValues',this.mutiString);
ajax.start();
};
/**
* 提交修改
*/
DictInfoDlg.editSubmit = function () {
this.collectData();
var ajax = new $ax(Feng.ctxPath + "/dict/update", function (data) {
Feng.success("修改成功!");
window.parent.Dict.table.refresh();
DictInfoDlg.close();
}, function (data) {
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set('dictId',$("#dictId").val());
ajax.set('dictName',this.dictName);
ajax.set('dictCode',this.dictCode);
ajax.set('dictTips',this.dictTips);
ajax.set('dictValues',this.mutiString);
ajax.start();
};
/**
* 角色详情对话框(可用于添加和修改对话框)
*/
var DictInfoDlg = {
data: {
name: "",
code: "",
description: "",
sort: ""
}
};
/**
* 关闭此对话框
*/
DictInfoDlg.close = function () {
parent.layer.close(window.parent.Dict.layerIndex);
};
/**
* 验证表单
*/
DictInfoDlg.validateForm = function () {
var data = DictInfoDlg.data;
if (!data.name) {
return "请输入字典名称";
}
if (!(data.code)) {
return "请输入字典编码";
}
return true;
};
/**
* 提交添加角色
*/
DictInfoDlg.addSubmit = function () {
var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
parent.Feng.success("添加成功!");
window.parent.Dict.table.refresh();
DictInfoDlg.close();
}, function (data) {
parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set(this.data);
ajax.start();
};
$(function () {
DictInfoDlg.app = new Vue({
el: '#dictForm',
data: DictInfoDlg.data,
methods: {
submitForm: function (e) {
e.preventDefault();
},
ensure: function () {
var result = DictInfoDlg.validateForm();
if (result === true) {
DictInfoDlg.addSubmit();
} else {
Feng.alert(result);
}
},
close: function () {
DictInfoDlg.close();
}
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment