mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 17:58:17 +08:00
新增节点CRUD
This commit is contained in:
parent
a6bde3c5da
commit
28e97ce97a
@ -0,0 +1,111 @@
|
|||||||
|
package com.ruoyi.web.controller.qianlan;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.system.domain.vo.TestNodeVo;
|
||||||
|
import com.ruoyi.system.domain.bo.TestNodeBo;
|
||||||
|
import com.ruoyi.system.service.ITestNodeService;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护Controller
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@Api(value = "节点维护控制器", tags = {"节点维护管理"})
|
||||||
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/node")
|
||||||
|
public class TestNodeController extends BaseController {
|
||||||
|
|
||||||
|
private final ITestNodeService iTestNodeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询节点维护列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("查询节点维护列表")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:list')")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public AjaxResult<List<TestNodeVo>> list(@Validated TestNodeBo bo) {
|
||||||
|
List<TestNodeVo> list = iTestNodeService.queryList(bo);
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出节点维护列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("导出节点维护列表")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:export')")
|
||||||
|
@Log(title = "节点维护", businessType = BusinessType.EXPORT)
|
||||||
|
@GetMapping("/export")
|
||||||
|
public AjaxResult<TestNodeVo> export(@Validated TestNodeBo bo) {
|
||||||
|
List<TestNodeVo> list = iTestNodeService.queryList(bo);
|
||||||
|
ExcelUtil<TestNodeVo> util = new ExcelUtil<TestNodeVo>(TestNodeVo.class);
|
||||||
|
return util.exportExcel(list, "节点维护");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点维护详细信息
|
||||||
|
*/
|
||||||
|
@ApiOperation("获取节点维护详细信息")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:query')")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public AjaxResult<TestNodeVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable("id") Long id) {
|
||||||
|
return AjaxResult.success(iTestNodeService.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增节点维护
|
||||||
|
*/
|
||||||
|
@ApiOperation("新增节点维护")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:add')")
|
||||||
|
@Log(title = "节点维护", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit
|
||||||
|
@PostMapping()
|
||||||
|
public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody TestNodeBo bo) {
|
||||||
|
return toAjax(iTestNodeService.insertByBo(bo) ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改节点维护
|
||||||
|
*/
|
||||||
|
@ApiOperation("修改节点维护")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:edit')")
|
||||||
|
@Log(title = "节点维护", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit
|
||||||
|
@PutMapping()
|
||||||
|
public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody TestNodeBo bo) {
|
||||||
|
return toAjax(iTestNodeService.updateByBo(bo) ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点维护
|
||||||
|
*/
|
||||||
|
@ApiOperation("删除节点维护")
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:node:remove')")
|
||||||
|
@Log(title = "节点维护" , businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(iTestNodeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -78,7 +78,7 @@ spring:
|
|||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码
|
# 密码
|
||||||
password:
|
password: root
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
# 是否开启ssl
|
# 是否开启ssl
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
package com.ruoyi.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护对象 test_node
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("test_node")
|
||||||
|
public class TestNode implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类
|
||||||
|
*/
|
||||||
|
private String categary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父id
|
||||||
|
*/
|
||||||
|
private Long pid;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package com.ruoyi.system.domain.bo;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.TreeEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护业务对象 test_node
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ApiModel("节点维护业务对象")
|
||||||
|
public class TestNodeBo extends TreeEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("主键")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("节点名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("分类")
|
||||||
|
private String categary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("父id")
|
||||||
|
private Long pid;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页大小
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("分页大小")
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页数
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("当前页数")
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序列
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("排序列")
|
||||||
|
private String orderByColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序的方向desc或者asc
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "排序的方向", example = "asc,desc")
|
||||||
|
private String isAsc;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package com.ruoyi.system.domain.vo;
|
||||||
|
|
||||||
|
import com.ruoyi.common.annotation.Excel;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护视图对象 test_node
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ApiModel("节点维护视图对象")
|
||||||
|
public class TestNodeVo {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("主键")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名
|
||||||
|
*/
|
||||||
|
@Excel(name = "节点名")
|
||||||
|
@ApiModelProperty("节点名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类
|
||||||
|
*/
|
||||||
|
@Excel(name = "分类")
|
||||||
|
@ApiModelProperty("分类")
|
||||||
|
private String categary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父id
|
||||||
|
*/
|
||||||
|
@Excel(name = "父id")
|
||||||
|
@ApiModelProperty("父id")
|
||||||
|
private Long pid;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.system.mapper;
|
||||||
|
|
||||||
|
import com.ruoyi.system.domain.TestNode;
|
||||||
|
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
|
||||||
|
import com.ruoyi.common.core.mybatisplus.cache.MybatisPlusRedisCache;
|
||||||
|
import org.apache.ibatis.annotations.CacheNamespace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护Mapper接口
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
public interface TestNodeMapper extends BaseMapperPlus<TestNode> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
|
import com.ruoyi.system.domain.TestNode;
|
||||||
|
import com.ruoyi.system.domain.vo.TestNodeVo;
|
||||||
|
import com.ruoyi.system.domain.bo.TestNodeBo;
|
||||||
|
import com.ruoyi.common.core.mybatisplus.core.IServicePlus;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护Service接口
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
public interface ITestNodeService extends IServicePlus<TestNode, TestNodeVo> {
|
||||||
|
/**
|
||||||
|
* 查询单个
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
TestNodeVo queryById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询列表
|
||||||
|
*/
|
||||||
|
List<TestNodeVo> queryList(TestNodeBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据新增业务对象插入节点维护
|
||||||
|
* @param bo 节点维护新增业务对象
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(TestNodeBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据编辑业务对象修改节点维护
|
||||||
|
* @param bo 节点维护编辑业务对象
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(TestNodeBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并删除数据
|
||||||
|
* @param ids 主键集合
|
||||||
|
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.system.domain.bo.TestNodeBo;
|
||||||
|
import com.ruoyi.system.domain.vo.TestNodeVo;
|
||||||
|
import com.ruoyi.system.domain.TestNode;
|
||||||
|
import com.ruoyi.system.mapper.TestNodeMapper;
|
||||||
|
import com.ruoyi.system.service.ITestNodeService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点维护Service业务层处理
|
||||||
|
*
|
||||||
|
* @author qianlan
|
||||||
|
* @date 2021-08-08
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TestNodeServiceImpl extends ServicePlusImpl<TestNodeMapper, TestNode, TestNodeVo> implements ITestNodeService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestNodeVo queryById(Long id){
|
||||||
|
return getVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TestNodeVo> queryList(TestNodeBo bo) {
|
||||||
|
return listVo(buildQueryWrapper(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<TestNode> buildQueryWrapper(TestNodeBo bo) {
|
||||||
|
Map<String, Object> params = bo.getParams();
|
||||||
|
LambdaQueryWrapper<TestNode> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.like(StrUtil.isNotBlank(bo.getName()), TestNode::getName, bo.getName());
|
||||||
|
lqw.eq(StrUtil.isNotBlank(bo.getCategary()), TestNode::getCategary, bo.getCategary());
|
||||||
|
lqw.eq(bo.getPid() != null, TestNode::getPid, bo.getPid());
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(TestNodeBo bo) {
|
||||||
|
TestNode add = BeanUtil.toBean(bo, TestNode.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
return save(add);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(TestNodeBo bo) {
|
||||||
|
TestNode update = BeanUtil.toBean(bo, TestNode.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return updateById(update);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*
|
||||||
|
* @param entity 实体类数据
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(TestNode entity){
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if(isValid){
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return removeByIds(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.system.mapper.TestNodeMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.ruoyi.system.domain.TestNode" id="TestNodeResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="name" column="name"/>
|
||||||
|
<result property="categary" column="categary"/>
|
||||||
|
<result property="pid" column="pid"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
53
ruoyi-ui/src/api/system/node.js
Normal file
53
ruoyi-ui/src/api/system/node.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 查询节点维护列表
|
||||||
|
export function listNode(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询节点维护详细
|
||||||
|
export function getNode(id) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node/' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增节点维护
|
||||||
|
export function addNode(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改节点维护
|
||||||
|
export function updateNode(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除节点维护
|
||||||
|
export function delNode(id) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node/' + id,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出节点维护
|
||||||
|
export function exportNode(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/node/export',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
274
ruoyi-ui/src/views/system/node/index.vue
Normal file
274
ruoyi-ui/src/views/system/node/index.vue
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
||||||
|
<el-form-item label="节点名" prop="name">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入节点名"
|
||||||
|
clearable
|
||||||
|
size="small"
|
||||||
|
@keyup.enter.native="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="分类" prop="categary">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.categary"
|
||||||
|
placeholder="请输入分类"
|
||||||
|
clearable
|
||||||
|
size="small"
|
||||||
|
@keyup.enter.native="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="父id" prop="pid">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.pid"
|
||||||
|
placeholder="请输入父id"
|
||||||
|
clearable
|
||||||
|
size="small"
|
||||||
|
@keyup.enter.native="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
icon="el-icon-plus"
|
||||||
|
size="mini"
|
||||||
|
@click="handleAdd"
|
||||||
|
v-hasPermi="['system:node:add']"
|
||||||
|
>新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="nodeList"
|
||||||
|
row-key="id"
|
||||||
|
default-expand-all
|
||||||
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
|
>
|
||||||
|
<el-table-column label="节点名" prop="name" />
|
||||||
|
<el-table-column label="id" prop="id" />
|
||||||
|
<el-table-column label="分类" align="center" prop="categary" />
|
||||||
|
<el-table-column label="父id" align="center" prop="pid" />
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="text"
|
||||||
|
icon="el-icon-edit"
|
||||||
|
@click="handleUpdate(scope.row)"
|
||||||
|
v-hasPermi="['system:node:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="text"
|
||||||
|
icon="el-icon-plus"
|
||||||
|
@click="handleAdd(scope.row)"
|
||||||
|
v-hasPermi="['system:node:add']"
|
||||||
|
>新增</el-button>
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="text"
|
||||||
|
icon="el-icon-delete"
|
||||||
|
@click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['system:node:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<!-- 添加或修改节点维护对话框 -->
|
||||||
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||||
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
|
<el-form-item label="节点名" prop="name">
|
||||||
|
<el-input v-model="form.name" placeholder="请输入节点名" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="分类" prop="categary">
|
||||||
|
<el-input v-model="form.categary" placeholder="请输入分类" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="父id" prop="pid">
|
||||||
|
<treeselect v-model="form.pid" :options="nodeOptions" :normalizer="normalizer" placeholder="请选择父id" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { listNode, getNode, delNode, addNode, updateNode, exportNode } from "@/api/system/node";
|
||||||
|
import Treeselect from "@riophae/vue-treeselect";
|
||||||
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "Node",
|
||||||
|
components: {
|
||||||
|
Treeselect
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 按钮loading
|
||||||
|
buttonLoading: false,
|
||||||
|
// 遮罩层
|
||||||
|
loading: true,
|
||||||
|
// 显示搜索条件
|
||||||
|
showSearch: true,
|
||||||
|
// 节点维护表格数据
|
||||||
|
nodeList: [],
|
||||||
|
// 节点维护树选项
|
||||||
|
nodeOptions: [],
|
||||||
|
// 弹出层标题
|
||||||
|
title: "",
|
||||||
|
// 是否显示弹出层
|
||||||
|
open: false,
|
||||||
|
// 查询参数
|
||||||
|
queryParams: {
|
||||||
|
name: null,
|
||||||
|
categary: null,
|
||||||
|
pid: null
|
||||||
|
},
|
||||||
|
// 表单参数
|
||||||
|
form: {},
|
||||||
|
// 表单校验
|
||||||
|
rules: {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 查询节点维护列表 */
|
||||||
|
getList() {
|
||||||
|
this.loading = true;
|
||||||
|
listNode(this.queryParams).then(response => {
|
||||||
|
this.nodeList = this.handleTree(response.data, "id", "pid");
|
||||||
|
this.loading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 转换节点维护数据结构 */
|
||||||
|
normalizer(node) {
|
||||||
|
if (node.children && !node.children.length) {
|
||||||
|
delete node.children;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: node.id,
|
||||||
|
label: node.name,
|
||||||
|
children: node.children
|
||||||
|
};
|
||||||
|
},
|
||||||
|
/** 查询节点维护下拉树结构 */
|
||||||
|
getTreeselect() {
|
||||||
|
listNode().then(response => {
|
||||||
|
this.nodeOptions = [];
|
||||||
|
const data = { id: 0, name: '顶级节点', children: [] };
|
||||||
|
data.children = this.handleTree(response.data, "id", "pid");
|
||||||
|
this.nodeOptions.push(data);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消按钮
|
||||||
|
cancel() {
|
||||||
|
this.open = false;
|
||||||
|
this.reset();
|
||||||
|
},
|
||||||
|
// 表单重置
|
||||||
|
reset() {
|
||||||
|
this.form = {
|
||||||
|
id: null,
|
||||||
|
name: null,
|
||||||
|
categary: null,
|
||||||
|
pid: null
|
||||||
|
};
|
||||||
|
this.resetForm("form");
|
||||||
|
},
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
handleQuery() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
resetQuery() {
|
||||||
|
this.resetForm("queryForm");
|
||||||
|
this.handleQuery();
|
||||||
|
},
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
handleAdd(row) {
|
||||||
|
this.reset();
|
||||||
|
this.getTreeselect();
|
||||||
|
if (row != null && row.id) {
|
||||||
|
this.form.pid = row.id;
|
||||||
|
} else {
|
||||||
|
this.form.pid = 0;
|
||||||
|
}
|
||||||
|
this.open = true;
|
||||||
|
this.title = "添加节点维护";
|
||||||
|
},
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
handleUpdate(row) {
|
||||||
|
this.loading = true;
|
||||||
|
this.reset();
|
||||||
|
this.getTreeselect();
|
||||||
|
if (row != null) {
|
||||||
|
this.form.pid = row.id;
|
||||||
|
}
|
||||||
|
getNode(row.id).then(response => {
|
||||||
|
this.loading = false;
|
||||||
|
this.form = response.data;
|
||||||
|
this.open = true;
|
||||||
|
this.title = "修改节点维护";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 提交按钮 */
|
||||||
|
submitForm() {
|
||||||
|
this.$refs["form"].validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
this.buttonLoading = true;
|
||||||
|
if (this.form.id != null) {
|
||||||
|
updateNode(this.form).then(response => {
|
||||||
|
this.msgSuccess("修改成功");
|
||||||
|
this.open = false;
|
||||||
|
this.getList();
|
||||||
|
}).finally(() => {
|
||||||
|
this.buttonLoading = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
addNode(this.form).then(response => {
|
||||||
|
this.msgSuccess("新增成功");
|
||||||
|
this.open = false;
|
||||||
|
this.getList();
|
||||||
|
}).finally(() => {
|
||||||
|
this.buttonLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
handleDelete(row) {
|
||||||
|
this.$confirm('是否确认删除节点维护编号为"' + row.id + '"的数据项?', "警告", {
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
type: "warning"
|
||||||
|
}).then(() => {
|
||||||
|
this.loading = true;
|
||||||
|
return delNode(row.id);
|
||||||
|
}).then(() => {
|
||||||
|
this.loading = false;
|
||||||
|
this.getList();
|
||||||
|
this.msgSuccess("删除成功");
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user