将字典树移到底层;

pull/65/head
huangyao 4 years ago
parent c366cc45ad
commit d1d8c9c9f4

@ -1,4 +1,4 @@
package cn.stylefeng.guns.modular.dict.controller;
package cn.stylefeng.guns.modular.dict;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
@ -14,7 +14,7 @@ import org.springframework.stereotype.Controller;
**/
@Controller
@Slf4j
@ApiResource(name = "字典类型管理相关的界面渲染", path = "dictType")
@ApiResource(name = "字典类型管理相关的界面渲染")
public class DictTypeViewController {
private String PREFIX = "/modular/system/dictType";
@ -27,7 +27,7 @@ public class DictTypeViewController {
* @author huangyao
* @date 2021/1/6 21:08
*/
@GetResource(name = "字典类型管理-列表-视图", path = "")
@GetResource(name = "字典类型管理-列表-视图", path = "/view/dictType")
public String indexView() {
return PREFIX + "/dictType.html";
}
@ -40,7 +40,7 @@ public class DictTypeViewController {
* @author huangyao
* @date 2021/1/6 21:25
*/
@GetResource(name = "字典类型管理-添加-视图", path = "/addView")
@GetResource(name = "字典类型管理-添加-视图", path = "/view/dictType/addView")
public String addView() {
return PREFIX + "/dictType_add.html";
}
@ -53,7 +53,7 @@ public class DictTypeViewController {
* @author huangyao
* @date 2021/1/6 21:26
*/
@GetResource(name = "字典类型管理-编辑-视图", path = "/editView")
@GetResource(name = "字典类型管理-编辑-视图", path = "/view/dictType/editView")
public String editView() {
return PREFIX + "/dictType_edit.html";
}

@ -1,24 +1,18 @@
package cn.stylefeng.guns.modular.dict.controller;
package cn.stylefeng.guns.modular.dict;
import cn.stylefeng.guns.modular.dict.service.ExtendDictService;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
*
*
@ -27,13 +21,11 @@ import java.util.List;
**/
@Controller
@Slf4j
@ApiResource(name = "字典管理相关的界面渲染", path = "dict")
@ApiResource(name = "字典管理相关的界面渲染")
public class DictViewController {
private String PREFIX = "/modular/system/dict";
@Autowired
private ExtendDictService extendDictService;
@Autowired
private DictService dictService;
@Autowired
@ -47,7 +39,7 @@ public class DictViewController {
* @author huangyao
* @date 2021/1/9 22:37
*/
@GetResource(name = "字典管理-列表-视图", path = "")
@GetResource(name = "字典管理-列表-视图", path = "/view/dict")
public ModelAndView indexView(ModelAndView view, @RequestParam Long dictTypeId) {
SysDictType dictType = dictTypeService.getById(dictTypeId);
view.addObject("dictTypeId", dictType.getDictTypeId());
@ -65,7 +57,7 @@ public class DictViewController {
* @author huangyao
* @date 2021/1/9 22:37
*/
@GetResource(name = "字典管理-添加-视图", path = "/addView")
@GetResource(name = "字典管理-添加-视图", path = "/view/dict/addView")
public ModelAndView addView(ModelAndView view, @RequestParam Long dictTypeId) {
SysDictType dictType = dictTypeService.getById(dictTypeId);
view.addObject("dictTypeName", dictType.getDictTypeName());
@ -83,29 +75,18 @@ public class DictViewController {
* @author huangyao
* @date 2021/1/9 22:38
*/
@GetResource(name = "字典管理-编辑-视图", path = "/editView")
@GetResource(name = "字典管理-编辑-视图", path = "/view/dict/editView")
public ModelAndView editView(ModelAndView view, @RequestParam Long dictId) {
SysDictType dictType = extendDictService.getDictTypeByDictId(dictId);
SysDict dict = dictService.getById(dictId);
// 根据字典获取字典类型
SysDictType dictType = dictTypeService.getOne(new QueryWrapper<SysDictType>().lambda().eq(SysDictType::getDelFlag, "N")
.eq(SysDictType::getDictTypeCode, dict.getDictTypeCode()));
view.addObject("dictTypeName", dictType.getDictTypeName());
view.addObject("dictTypeId", dictType.getDictTypeId());
view.addObject("dictId", dictId);
view.addObject("dictTypeCode", dictType.getDictTypeCode());
view.setViewName(PREFIX + "/dict_edit.html");
return view;
}
/**
*
*
* @param
* @return
* @author huangyao
* @date 2021/1/10 17:31
*/
@GetResource(name = "获取zTree形式的字典树layui版本", path = "/zTree")
@ResponseBody
public List<ZTreeNode> layuiSelectParentMenuTreeList(DictRequest dictRequest) {
return this.extendDictService.dictZTree(dictRequest);
}
}

@ -1,38 +0,0 @@
package cn.stylefeng.guns.modular.dict.service;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import java.util.List;
/**
*
*
* @param
* @author huangyao
* @return
* @date 2021/1/10 16:23
*/
public interface ExtendDictService {
/**
* ztree
*
* @param
* @return
* @author huangyao
* @date 2021/1/10 16:26
*/
List<ZTreeNode> dictZTree(DictRequest dictRequest);
/**
* id
*
* @param
* @return
* @author huangyao
* @date 2021/1/11 21:39
*/
SysDictType getDictTypeByDictId(Long dictId);
}

@ -1,125 +0,0 @@
package cn.stylefeng.guns.modular.dict.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.modular.dict.service.ExtendDictService;
import cn.stylefeng.roses.kernel.dict.api.exception.DictException;
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @param
* @author huangyao
* @return
* @date 2021/1/10 16:24
*/
@Service
public class ExtendDictServiceImpl implements ExtendDictService {
@Autowired
private DictService dictService;
@Autowired
private DictTypeService dictTypeService;
@Override
public List<ZTreeNode> dictZTree(DictRequest dictRequest) {
// 查询条件
LambdaQueryWrapper<SysDict> queryWrapper = createWrapper(dictRequest);
List<SysDict> dictList = dictService.list(queryWrapper);
// 构建ztree
ArrayList<ZTreeNode> zTreeNodes = new ArrayList<>();
for (SysDict dict : dictList) {
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setId(dict.getDictId());
zTreeNode.setpId(dict.getDictParentId());
zTreeNode.setName(dict.getDictName());
zTreeNode.setOpen(true);
zTreeNodes.add(zTreeNode);
}
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setId(-1L);
zTreeNode.setpId(0L);
zTreeNode.setName("顶级");
zTreeNode.setOpen(true);
zTreeNodes.add(zTreeNode);
// 构建已选中的状态
return zTreeNodes;
}
@Override
public SysDictType getDictTypeByDictId(Long dictId) {
SysDict dict = dictService.getById(dictId);
// 根据字典类型编码获取字典类型
SysDictType dictType = dictTypeService.getOne(new QueryWrapper<SysDictType>().lambda()
.eq(SysDictType::getDelFlag, 'N')
.eq(SysDictType::getDictTypeCode, dict.getDictTypeCode()));
if (ObjectUtil.isEmpty(dictType)) {
throw new DictException(DictExceptionEnum.DICT_TYPE_NOT_EXISTED, dictType.getDictTypeCode());
}
return dictType;
}
/**
* wrapper
*
* @param
* @return
* @author huangyao
* @date 2021/1/10 16:33
*/
private LambdaQueryWrapper<SysDict> createWrapper(DictRequest dictRequest) {
LambdaQueryWrapper<SysDict> queryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotNull(dictRequest)) {
// 拼接字典名称查询条件
if (ObjectUtil.isNotEmpty(dictRequest.getDictName())) {
queryWrapper.like(SysDict::getDictName, dictRequest.getDictName());
}
// 拼接字典拼音查询条件
if (ObjectUtil.isNotEmpty(dictRequest.getDictNamePinYin())) {
queryWrapper.eq(SysDict::getDictNamePinyin, dictRequest.getDictNamePinYin());
}
// 根据字典类型查询条件
if (ObjectUtil.isNotEmpty(dictRequest.getDictTypeCode())) {
queryWrapper.eq(SysDict::getDictTypeCode, dictRequest.getDictTypeCode());
}
// 拼接字典父级id查询条件
if (ObjectUtil.isNotEmpty(dictRequest.getDictParentId())) {
queryWrapper
.eq(SysDict::getDictParentId, dictRequest.getDictParentId())
.or()
.like(SysDict::getDictPids, dictRequest.getDictPids());
}
}
// 查询未删除状态的
queryWrapper.eq(SysDict::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(SysDict::getDictSort);
return queryWrapper;
}
}

@ -1,6 +1,7 @@
layui.use(['treeTable', 'func', 'HttpRequest'], function () {
layui.use(['table', 'treeTable', 'func', 'HttpRequest'], function () {
var $ = layui.$;
var treeTable = layui.treeTable;
var table = layui.table;
var func = layui.func;
var HttpRequest = layui.HttpRequest;
@ -23,15 +24,6 @@ layui.use(['treeTable', 'func', 'HttpRequest'], function () {
{field: 'dictName', align: "center", title: '字典名称'},
{field: 'dictCode', align: "center", title: '字典编码'},
{field: 'dictNamePinYin', align: "center", title: '字典拼音'},
{
field: 'status', align: "center", title: '状态', templet: function (d) {
if (d.status === 1) {
return "启用";
} else {
return "禁用";
}
}
},
{align: 'center', toolbar: '#tableBar', title: '操作'}
];
};
@ -51,9 +43,9 @@ layui.use(['treeTable', 'func', 'HttpRequest'], function () {
*/
Dict.openAddDlg = function () {
func.open({
height: 650,
height: 550,
title: '添加字典',
content: Feng.ctxPath + '/dict/addView?dictTypeId=' + $("#dictTypeId").val(),
content: Feng.ctxPath + '/view/dict/addView?dictTypeId=' + $("#dictTypeId").val(),
tableId: Dict.tableId,
endCallback: function () {
Dict.initTable(Dict.tableId);
@ -68,9 +60,9 @@ layui.use(['treeTable', 'func', 'HttpRequest'], function () {
*/
Dict.openEditDlg = function (data) {
func.open({
height: 650,
height: 550,
title: '修改字典',
content: Feng.ctxPath + '/dict/editView?dictId=' + data.dictId,
content: Feng.ctxPath + '/view/dict/editView?dictId=' + data.dictId,
tableId: Dict.tableId,
endCallback: function () {
Dict.initTable(Dict.tableId);
@ -115,7 +107,7 @@ layui.use(['treeTable', 'func', 'HttpRequest'], function () {
height: "full-98",
cols: Dict.initColumn(),
reqData: function (d, callback) {
var httpRequest = new HttpRequest(Feng.ctxPath + 'dict/getDictTreeList?dictTypeCode=' + $("#dictTypeCode").val(), 'get', function (result) {
var httpRequest = new HttpRequest(Feng.ctxPath + '/dict/getDictTreeList?dictTypeCode=' + $("#dictTypeCode").val(), 'get', function (result) {
callback(result.data);
}, function (result) {
Feng.error("加载失败!" + result.message + "!");
@ -145,7 +137,7 @@ layui.use(['treeTable', 'func', 'HttpRequest'], function () {
// 关闭页面
$('#btnBack').click(function () {
window.location.href = Feng.ctxPath + "/dictType";
window.location.href = Feng.ctxPath + "/view/dictType";
});
// 工具条点击事件

@ -3,17 +3,8 @@
*/
var DictInfoDlg = {
data: {
dictTypeId: "",
code: "",
name: "",
parentId: "",
parentName: "",
status: "",
description: "",
createTime: "",
updateTime: "",
createUser: "",
updateUser: ""
dictParentId: "-1",
parentName: "顶级"
}
};
@ -41,8 +32,8 @@ layui.use(['form', 'admin', 'HttpRequest'], function () {
//父级字典时
$('#parentName').click(function () {
var formName = encodeURIComponent("parent.DictInfoDlg.data.parentName");
var formId = encodeURIComponent("parent.DictInfoDlg.data.parentId");
var treeUrl = encodeURIComponent("/dict/zTree?dictTypeId=" + $("#dictTypeId").val());
var formId = encodeURIComponent("parent.DictInfoDlg.data.dictParentId");
var treeUrl = encodeURIComponent("/dict/zTree?dictTypeCode=" + $("#dictTypeCode").val());
layer.open({
type: 2,
@ -50,7 +41,7 @@ layui.use(['form', 'admin', 'HttpRequest'], function () {
area: ['300px', '400px'],
content: Feng.ctxPath + '/view/common/tree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
end: function () {
$("#dictParentId").val(DictInfoDlg.data.parentId);
$("#dictParentId").val(DictInfoDlg.data.dictParentId);
$("#parentName").val(DictInfoDlg.data.parentName);
}
});

@ -3,61 +3,53 @@
*/
var DictInfoDlg = {
data: {
dictTypeId: "",
code: "",
name: "",
parentId: "",
status: "",
description: "",
createTime: "",
updateTime: "",
createUser: "",
updateUser: ""
dictParentId: "-1",
parentName: "顶级"
}
};
layui.use(['form', 'admin'], function () {
layui.use(['form', 'admin', 'HttpRequest'], function () {
var $ = layui.jquery;
var form = layui.form;
var admin = layui.admin;
var HttpRequest = layui.HttpRequest;
//获取详情信息,填充表单
// var ajax = new $ax(Feng.ctxPath + "/dict/detail?dictId=" + Feng.getUrlParam("dictId"));
// var result = ajax.start();
// form.val('dictForm', result.data);
var request = new HttpRequest(Feng.ctxPath + "/dict/getDictDetail?dictId=" + Feng.getUrlParam("dictId"), 'get', function (result) {
form.val('dictForm', result.data);
}, function (data) {
Feng.error("加载失败!" + data.message);
});
request.start();
//表单提交事件
form.on('submit(btnSubmit)', function (data) {
// var ajax = new $ax(Feng.ctxPath + "/dict/editItem", function (data) {
// Feng.success("更新成功!");
// //传给上个页面刷新table用
// admin.putTempData('formOk', true);
// //关掉对话框
// admin.closeThisDialog();
var request = new HttpRequest(Feng.ctxPath + "/dict/updateDict", 'post', function (data) {
admin.closeThisDialog();
Feng.success("更新成功!");
admin.putTempData('formOk', true);
}, function (data) {
admin.closeThisDialog();
Feng.error("更新失败!" + data.message);
});
// }, function (data) {
// Feng.error("更新失败!" + data.responseJSON.message)
// });
// ajax.set(data.field);
// ajax.start();
// return false;
request.set(data.field);
request.start(true);
});
//父级字典时
$('#parentName').click(function () {
var formName = encodeURIComponent("parent.DictInfoDlg.data.parentName");
var formId = encodeURIComponent("parent.DictInfoDlg.data.parentId");
var treeUrl = encodeURIComponent("/dict/ztree?dictTypeId=" + $("#dictTypeId").val() + "&dictId=" + $("#dictId").val());
var formId = encodeURIComponent("parent.DictInfoDlg.data.dictParentId");
var treeUrl = encodeURIComponent("/dict/zTree?dictTypeCode=" + $("#dictTypeCode").val() + "&dictId=" + $("#dictId").val());
layer.open({
type: 2,
title: '父级字典',
area: ['300px', '400px'],
content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
content: Feng.ctxPath + '/view/common/tree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
end: function () {
$("#parentId").val(DictInfoDlg.data.parentId);
$("#dictParentId").val(DictInfoDlg.data.dictParentId);
$("#parentName").val(DictInfoDlg.data.parentName);
}
});

@ -21,7 +21,7 @@ layui.use(['table', 'func', 'HttpRequest', 'form'], function () {
{field: 'dictTypeId', hide: true, title: '字典类型id'},
{
field: 'dictTypeName', align: "center", sort: true, title: '类型名称', templet: function (d) {
var url = Feng.ctxPath + '/dict?dictTypeId=' + d.dictTypeId;
var url = Feng.ctxPath + '/view/dict?dictTypeId=' + d.dictTypeId;
return '<a style="color: #01AAED;" href="' + url + '">' + d.dictTypeName + '</a>';
}
},
@ -63,7 +63,7 @@ layui.use(['table', 'func', 'HttpRequest', 'form'], function () {
func.open({
height: 700,
title: '添加字典类型',
content: Feng.ctxPath + '/dictType/addView',
content: Feng.ctxPath + '/view/dictType/addView',
tableId: DictType.tableId
});
};
@ -77,7 +77,7 @@ layui.use(['table', 'func', 'HttpRequest', 'form'], function () {
func.open({
height: 700,
title: '修改字典类型',
content: Feng.ctxPath + '/dictType/editView?dictTypeId=' + data.dictTypeId,
content: Feng.ctxPath + '/view/dictType/editView?dictTypeId=' + data.dictTypeId,
tableId: DictType.tableId
});
};
@ -115,7 +115,7 @@ layui.use(['table', 'func', 'HttpRequest', 'form'], function () {
Feng.success("修改成功!");
}, function (data) {
table.reload(DictType.tableId);
Feng.error("修改失败!" + data.responseJSON.message);
Feng.error("修改失败!" + data.message);
});
httpRequest.set({"dictTypeId": dictTypeId, "statusFlag": checked});
httpRequest.start(true);

@ -11,7 +11,7 @@ layui.use(['form', 'admin', 'HttpRequest'], function () {
}
form.val('dictTypeForm', result.data);
}, function (data) {
Feng.error("加失败!" + data.message);
Feng.error("失败!" + data.message);
});
request.start();

@ -34,4 +34,5 @@
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
@}

@ -36,13 +36,7 @@
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
<input id="dictSort" name="dictSort" placeholder="请输入字典排序" type="text" class="layui-input">
</div>
</div>
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">字典描述</label>
<div class="layui-input-block">
<textarea id="description" name="description" placeholder="请输入字典描述" class="layui-textarea"></textarea>
<input id="dictSort" name="dictSort" placeholder="请输入字典排序" type="text" class="layui-input" lay-verify="required" required>
</div>
</div>
</div>

@ -10,7 +10,7 @@
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">字典类型</label>
<div class="layui-input-block">
<input id="dictTypeId" name="dictTypeId" type="hidden" value="${dictTypeId}"/>
<input id="dictId" name="dictId" type="hidden" value="${dictId}"/>
<input id="dictTypeCode" name="dictTypeCode" type="hidden" value="${dictTypeCode}"/>
<input type="text" class="layui-input white-border layui-disabled" value="${dictTypeName}" disabled="disabled"/>
</div>
@ -18,32 +18,26 @@
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">字典名称<span style="color: red;">*</span></label>
<div class="layui-input-block">
<input id="name" name="name" placeholder="请输入字典名称" type="text" class="layui-input" lay-verify="required" required/>
<input id="dictName" name="dictName" placeholder="请输入字典名称" type="text" class="layui-input" lay-verify="required" required/>
</div>
</div>
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">字典编码<span style="color: red;">*</span></label>
<div class="layui-input-block">
<input id="code" name="code" placeholder="请输入字典编码" type="text" class="layui-input layui-disabled" lay-verify="required" disabled required/>
<input id="dictCode" name="dictCode" placeholder="请输入字典编码" type="text" class="layui-input layui-disabled" lay-verify="required" disabled required/>
</div>
</div>
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">上级字典<span style="color: red;">*</span></label>
<div class="layui-input-block">
<input id="parentId" name="parentId" type="hidden" class="layui-input" lay-verify="required" required/>
<input id="dictParentId" name="dictParentId" type="hidden" class="layui-input" lay-verify="required" required/>
<input id="parentName" name="parentName" placeholder="请选择上级字典,如没有请选择顶级" type="text" class="layui-input" lay-verify="required" required readonly="readonly"/>
</div>
</div>
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
<input id="sort" name="sort" placeholder="请输入字典排序" type="text" class="layui-input">
</div>
</div>
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">字典描述</label>
<div class="layui-input-block">
<textarea id="description" name="description" placeholder="请输入字典描述" class="layui-textarea"></textarea>
<input id="dictSort" name="dictSort" placeholder="请输入字典排序" type="text" class="layui-input" lay-verify="required" required>
</div>
</div>
</div>

Loading…
Cancel
Save