提交 daf441a0 authored 作者: taojinlong's avatar taojinlong

Merge branch 'main' of github.com:dataease/dataease into main

...@@ -14,8 +14,6 @@ public class SysDept implements Serializable { ...@@ -14,8 +14,6 @@ public class SysDept implements Serializable {
private String name; private String name;
private Integer level;
private Integer deptSort; private Integer deptSort;
private Boolean enabled; private Boolean enabled;
......
...@@ -355,66 +355,6 @@ public class SysDeptExample { ...@@ -355,66 +355,6 @@ public class SysDeptExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andLevelIsNull() {
addCriterion("`level` is null");
return (Criteria) this;
}
public Criteria andLevelIsNotNull() {
addCriterion("`level` is not null");
return (Criteria) this;
}
public Criteria andLevelEqualTo(Integer value) {
addCriterion("`level` =", value, "level");
return (Criteria) this;
}
public Criteria andLevelNotEqualTo(Integer value) {
addCriterion("`level` <>", value, "level");
return (Criteria) this;
}
public Criteria andLevelGreaterThan(Integer value) {
addCriterion("`level` >", value, "level");
return (Criteria) this;
}
public Criteria andLevelGreaterThanOrEqualTo(Integer value) {
addCriterion("`level` >=", value, "level");
return (Criteria) this;
}
public Criteria andLevelLessThan(Integer value) {
addCriterion("`level` <", value, "level");
return (Criteria) this;
}
public Criteria andLevelLessThanOrEqualTo(Integer value) {
addCriterion("`level` <=", value, "level");
return (Criteria) this;
}
public Criteria andLevelIn(List<Integer> values) {
addCriterion("`level` in", values, "level");
return (Criteria) this;
}
public Criteria andLevelNotIn(List<Integer> values) {
addCriterion("`level` not in", values, "level");
return (Criteria) this;
}
public Criteria andLevelBetween(Integer value1, Integer value2) {
addCriterion("`level` between", value1, value2, "level");
return (Criteria) this;
}
public Criteria andLevelNotBetween(Integer value1, Integer value2) {
addCriterion("`level` not between", value1, value2, "level");
return (Criteria) this;
}
public Criteria andDeptSortIsNull() { public Criteria andDeptSortIsNull() {
addCriterion("dept_sort is null"); addCriterion("dept_sort is null");
return (Criteria) this; return (Criteria) this;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<result column="pid" jdbcType="BIGINT" property="pid" /> <result column="pid" jdbcType="BIGINT" property="pid" />
<result column="sub_count" jdbcType="INTEGER" property="subCount" /> <result column="sub_count" jdbcType="INTEGER" property="subCount" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="level" jdbcType="INTEGER" property="level" />
<result column="dept_sort" jdbcType="INTEGER" property="deptSort" /> <result column="dept_sort" jdbcType="INTEGER" property="deptSort" />
<result column="enabled" jdbcType="BIT" property="enabled" /> <result column="enabled" jdbcType="BIT" property="enabled" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" /> <result column="create_by" jdbcType="VARCHAR" property="createBy" />
...@@ -73,8 +72,8 @@ ...@@ -73,8 +72,8 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
dept_id, pid, sub_count, `name`, `level`, dept_sort, enabled, create_by, update_by, dept_id, pid, sub_count, `name`, dept_sort, enabled, create_by, update_by, create_time,
create_time, update_time update_time
</sql> </sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.SysDeptExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.dataease.base.domain.SysDeptExample" resultMap="BaseResultMap">
select select
...@@ -108,13 +107,13 @@ ...@@ -108,13 +107,13 @@
</delete> </delete>
<insert id="insert" parameterType="io.dataease.base.domain.SysDept"> <insert id="insert" parameterType="io.dataease.base.domain.SysDept">
insert into sys_dept (dept_id, pid, sub_count, insert into sys_dept (dept_id, pid, sub_count,
`name`, `level`, dept_sort, `name`, dept_sort, enabled,
enabled, create_by, update_by, create_by, update_by, create_time,
create_time, update_time) update_time)
values (#{deptId,jdbcType=BIGINT}, #{pid,jdbcType=BIGINT}, #{subCount,jdbcType=INTEGER}, values (#{deptId,jdbcType=BIGINT}, #{pid,jdbcType=BIGINT}, #{subCount,jdbcType=INTEGER},
#{name,jdbcType=VARCHAR}, #{level,jdbcType=INTEGER}, #{deptSort,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{deptSort,jdbcType=INTEGER}, #{enabled,jdbcType=BIT},
#{enabled,jdbcType=BIT}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) #{updateTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.SysDept"> <insert id="insertSelective" parameterType="io.dataease.base.domain.SysDept">
insert into sys_dept insert into sys_dept
...@@ -131,9 +130,6 @@ ...@@ -131,9 +130,6 @@
<if test="name != null"> <if test="name != null">
`name`, `name`,
</if> </if>
<if test="level != null">
`level`,
</if>
<if test="deptSort != null"> <if test="deptSort != null">
dept_sort, dept_sort,
</if> </if>
...@@ -166,9 +162,6 @@ ...@@ -166,9 +162,6 @@
<if test="name != null"> <if test="name != null">
#{name,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
</if> </if>
<if test="level != null">
#{level,jdbcType=INTEGER},
</if>
<if test="deptSort != null"> <if test="deptSort != null">
#{deptSort,jdbcType=INTEGER}, #{deptSort,jdbcType=INTEGER},
</if> </if>
...@@ -210,9 +203,6 @@ ...@@ -210,9 +203,6 @@
<if test="record.name != null"> <if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
</if> </if>
<if test="record.level != null">
`level` = #{record.level,jdbcType=INTEGER},
</if>
<if test="record.deptSort != null"> <if test="record.deptSort != null">
dept_sort = #{record.deptSort,jdbcType=INTEGER}, dept_sort = #{record.deptSort,jdbcType=INTEGER},
</if> </if>
...@@ -242,7 +232,6 @@ ...@@ -242,7 +232,6 @@
pid = #{record.pid,jdbcType=BIGINT}, pid = #{record.pid,jdbcType=BIGINT},
sub_count = #{record.subCount,jdbcType=INTEGER}, sub_count = #{record.subCount,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
`level` = #{record.level,jdbcType=INTEGER},
dept_sort = #{record.deptSort,jdbcType=INTEGER}, dept_sort = #{record.deptSort,jdbcType=INTEGER},
enabled = #{record.enabled,jdbcType=BIT}, enabled = #{record.enabled,jdbcType=BIT},
create_by = #{record.createBy,jdbcType=VARCHAR}, create_by = #{record.createBy,jdbcType=VARCHAR},
...@@ -265,9 +254,6 @@ ...@@ -265,9 +254,6 @@
<if test="name != null"> <if test="name != null">
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
</if> </if>
<if test="level != null">
`level` = #{level,jdbcType=INTEGER},
</if>
<if test="deptSort != null"> <if test="deptSort != null">
dept_sort = #{deptSort,jdbcType=INTEGER}, dept_sort = #{deptSort,jdbcType=INTEGER},
</if> </if>
...@@ -294,7 +280,6 @@ ...@@ -294,7 +280,6 @@
set pid = #{pid,jdbcType=BIGINT}, set pid = #{pid,jdbcType=BIGINT},
sub_count = #{subCount,jdbcType=INTEGER}, sub_count = #{subCount,jdbcType=INTEGER},
`name` = #{name,jdbcType=VARCHAR}, `name` = #{name,jdbcType=VARCHAR},
`level` = #{level,jdbcType=INTEGER},
dept_sort = #{deptSort,jdbcType=INTEGER}, dept_sort = #{deptSort,jdbcType=INTEGER},
enabled = #{enabled,jdbcType=BIT}, enabled = #{enabled,jdbcType=BIT},
create_by = #{createBy,jdbcType=VARCHAR}, create_by = #{createBy,jdbcType=VARCHAR},
......
package io.dataease.base.mapper.ext;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface ExtDeptMapper {
@Update(" update sys_dept set sub_count = sub_count+1 where dept_id = #{deptId} ")
int incrementalSubcount(@Param("deptId") Long deptId);
@Update(" update sys_dept set sub_count = sub_count-1 where dept_id = #{deptId} and sub_count > 0")
int decreasingSubcount(@Param("deptId") Long deptId);
@Delete("<script> " +
" delete from sys_dept where dept_id in " +
" <foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach> " +
"</script>")
int batchDelete(@Param("ids") List<Long> ids);
}
package io.dataease.controller.sys; package io.dataease.controller.sys;
import io.dataease.base.domain.SysDept; import io.dataease.base.domain.SysDept;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.ResultHolder; import io.dataease.controller.ResultHolder;
import io.dataease.controller.sys.request.DeptCreateRequest;
import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest;
import io.dataease.controller.sys.response.DeptNodeResponse;
import io.dataease.service.sys.DeptService; import io.dataease.service.sys.DeptService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
...@@ -23,17 +27,45 @@ public class SysDeptController extends ResultHolder { ...@@ -23,17 +27,45 @@ public class SysDeptController extends ResultHolder {
@Resource @Resource
private DeptService deptService; private DeptService deptService;
@PostMapping("/childNodes/{pid}")
public List<DeptNodeResponse> childNodes(@PathVariable("pid") Long pid){
List<SysDept> nodes = deptService.nodesByPid(pid);
List<DeptNodeResponse> nodeResponses = nodes.stream().map(node -> {
DeptNodeResponse deptNodeResponse = BeanUtils.copyBean(new DeptNodeResponse(), node);
deptNodeResponse.setHasChildren(node.getSubCount() > 0);
deptNodeResponse.setTop(node.getPid() == deptService.DEPT_ROOT_PID);
return deptNodeResponse;
}).collect(Collectors.toList());
return nodeResponses;
}
@ApiOperation("查询部门") @ApiOperation("查询部门")
@PostMapping("/root") @PostMapping("/root")
public ResultHolder rootData(){ public ResultHolder rootData(){
List<SysDept> root = deptService.root(); List<SysDept> root = deptService.nodesByPid(null);
return success(root); return success(root);
} }
@ApiOperation("新增部门") @ApiOperation("新增部门")
@PostMapping("/create") @PostMapping("/create")
public void create(@RequestBody SysDept dept){ public void create(@RequestBody DeptCreateRequest dept){
deptService.add(dept); deptService.add(dept);
} }
@ApiOperation("删除部门")
@PostMapping("/delete")
public void delete(@RequestBody List<DeptDeleteRequest> requests){
deptService.batchDelete(requests);
}
@ApiOperation("更新部门")
@PostMapping("/update")
public void update(@RequestBody DeptCreateRequest dept){
deptService.update(dept);
}
@ApiOperation("更新状态")
@PostMapping("/updateStatus")
public void updateStatus(@RequestBody DeptStatusRequest request){
deptService.updateStatus(request);
}
} }
package io.dataease.controller.sys.request; package io.dataease.controller.sys.request;
public class DeptCreateRequest { import io.dataease.base.domain.SysDept;
import lombok.Data;
@Data
public class DeptCreateRequest extends SysDept {
private boolean top;
} }
package io.dataease.controller.sys.request;
import lombok.Data;
@Data
public class DeptDeleteRequest {
private Long deptId;
private Long pid;
}
package io.dataease.controller.sys.request;
import lombok.Data;
@Data
public class DeptStatusRequest {
private Long deptId;
private boolean status;
}
package io.dataease.controller.sys.response;
import io.dataease.base.domain.SysDept;
import lombok.Data;
@Data
public class DeptNodeResponse extends SysDept {
private boolean hasChildren;
private boolean top;
}
...@@ -3,46 +3,121 @@ package io.dataease.service.sys; ...@@ -3,46 +3,121 @@ package io.dataease.service.sys;
import io.dataease.base.domain.SysDept; import io.dataease.base.domain.SysDept;
import io.dataease.base.domain.SysDeptExample; import io.dataease.base.domain.SysDeptExample;
import io.dataease.base.mapper.SysDeptMapper; import io.dataease.base.mapper.SysDeptMapper;
import io.dataease.base.mapper.ext.ExtDeptMapper;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.sys.request.DeptCreateRequest;
import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class DeptService { public class DeptService {
private final static Integer DEPT_ROOT_LEVEL = 0; private final static Integer DEPT_ROOT_LEVEL = 0;
private final static Integer DEFAULT_SUBCOUNT = 0;
public final static Long DEPT_ROOT_PID = 0L;
@Resource @Resource
private SysDeptMapper sysDeptMapper; private SysDeptMapper sysDeptMapper;
public List<SysDept> root(){
@Resource
private ExtDeptMapper extDeptMapper;
public List<SysDept> nodesByPid(Long pid){
SysDeptExample example = new SysDeptExample(); SysDeptExample example = new SysDeptExample();
example.createCriteria().andLevelEqualTo(DEPT_ROOT_LEVEL); SysDeptExample.Criteria criteria = example.createCriteria();
if (ObjectUtils.isEmpty(pid)){
criteria.andPidEqualTo(0L);
}else {
criteria.andPidEqualTo(pid);
}
example.setOrderByClause("dept_sort"); example.setOrderByClause("dept_sort");
List<SysDept> sysDepts = sysDeptMapper.selectByExample(example); List<SysDept> sysDepts = sysDeptMapper.selectByExample(example);
return sysDepts; return sysDepts;
} }
public boolean add(SysDept sysDept){ @Transactional
if (ObjectUtils.isEmpty(sysDept.getLevel())){ public boolean add(DeptCreateRequest deptCreateRequest){
sysDept.setLevel(DEPT_ROOT_LEVEL); SysDept sysDept = BeanUtils.copyBean(new SysDept(), deptCreateRequest);
if (deptCreateRequest.isTop()){
sysDept.setPid(DEPT_ROOT_PID);
} }
Date now = new Date(); Date now = new Date();
sysDept.setCreateTime(now); sysDept.setCreateTime(now);
sysDept.setUpdateTime(now); sysDept.setUpdateTime(now);
sysDept.setCreateBy(null); sysDept.setCreateBy(null);
sysDept.setUpdateBy(null); sysDept.setUpdateBy(null);
sysDept.setSubCount(DEFAULT_SUBCOUNT);
try { try {
int insert = sysDeptMapper.insert(sysDept); int insert = sysDeptMapper.insert(sysDept);
Long pid = null;
if ((pid = sysDept.getPid()) != DEPT_ROOT_PID ){
//这里需要更新上级节点SubCount
extDeptMapper.incrementalSubcount(pid);
}
if (insert == 1){ if (insert == 1){
return true; return true;
} }
}catch (Exception e){ }catch (Exception e){
return false; e.printStackTrace();
} }
return false; return false;
} }
@Transactional
public int batchDelete(List<DeptDeleteRequest> requests){
/* Integer index = ids.stream().map(sysDeptMapper::deleteByPrimaryKey).reduce(Integer::sum).orElse(-1);
return index;*/
List<Long> ids = requests.stream().map(request -> {
Long pid = request.getPid();
if (pid != DEPT_ROOT_PID){
extDeptMapper.decreasingSubcount(pid);
}
return request.getDeptId();
}).collect(Collectors.toList());
return extDeptMapper.batchDelete(ids);
}
@Transactional
public int update(DeptCreateRequest deptCreateRequest){
SysDept sysDept = BeanUtils.copyBean(new SysDept(), deptCreateRequest);
if (deptCreateRequest.isTop()){
sysDept.setPid(DEPT_ROOT_PID);
}
sysDept.setUpdateTime(new Date());
sysDept.setUpdateBy(null);
Long deptId = sysDept.getDeptId();
SysDept dept_old = sysDeptMapper.selectByPrimaryKey(deptId);
//如果PID发生了改变
//判断oldPid是否是跟节点PID ? nothing : parent.subcount-1
//判断newPid是否是跟节点PID ? nothing : parent.subcount+1
if (sysDept.getPid() != dept_old.getPid()){
Long oldPid = dept_old.getPid();
if (oldPid != DEPT_ROOT_PID){
extDeptMapper.decreasingSubcount(oldPid);
}
if (sysDept.getPid() != DEPT_ROOT_PID){
extDeptMapper.incrementalSubcount(sysDept.getPid());
}
}
return sysDeptMapper.updateByPrimaryKeySelective(sysDept);
}
public int updateStatus(DeptStatusRequest request){
Long deptId = request.getDeptId();
boolean status = request.isStatus();
SysDept sysDept = new SysDept();
sysDept.setDeptId(deptId);
sysDept.setEnabled(status);
return sysDeptMapper.updateByPrimaryKeySelective(sysDept);
}
} }
CREATE TABLE IF NOT EXISTS `sys_dept` (
`dept_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`pid` bigint(20) DEFAULT NULL COMMENT '上级部门',
`sub_count` int(5) DEFAULT 0 COMMENT '子部门数目',
`name` varchar(255) NOT NULL COMMENT '名称',
`dept_sort` int(5) DEFAULT 999 COMMENT '排序',
`enabled` bit(1) NOT NULL COMMENT '状态',
`create_by` varchar(255) DEFAULT NULL COMMENT '创建者',
`update_by` varchar(255) DEFAULT NULL COMMENT '更新者',
`create_time` datetime DEFAULT NULL COMMENT '创建日期',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`dept_id`) USING BTREE,
KEY `inx_pid` (`pid`),
KEY `inx_enabled` (`enabled`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='部门';
\ No newline at end of file
...@@ -7,10 +7,18 @@ ...@@ -7,10 +7,18 @@
:create-tip="$t('organization.create')" :title="$t('commons.organization')"/> :create-tip="$t('organization.create')" :title="$t('commons.organization')"/>
</template> </template>
<!-- system menu organization table--> <!-- system menu organization table-->
<el-table border class="adjust-table" :data="tableData" style="width: 100%"> <el-table border
<el-table-column :selectable="checkboxT" type="selection" width="55" /> class="adjust-table"
:data="tableData"
lazy
:load="initTableData"
style="width: 100%"
ref="table"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
row-key="deptId">
<!-- <el-table-column :selectable="checkboxT" type="selection" width="55" /> -->
<el-table-column label="名称" prop="name" /> <el-table-column label="名称" prop="name" />
<el-table-column label="排序" prop="deptSort" /> <el-table-column label="下属部门数" prop="subCount" />
<el-table-column label="状态" align="center" prop="enabled"> <el-table-column label="状态" align="center" prop="enabled">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
...@@ -27,78 +35,23 @@ ...@@ -27,78 +35,23 @@
<span>{{ scope.row.createTime }}</span> <span>{{ scope.row.createTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="$t('commons.operating')"> <el-table-column :label="$t('commons.operating')">
<template v-slot:default="scope"> <template v-slot:default="scope">
<ms-table-operator @editClick="edit(scope.row)" @deleteClick="handleDelete(scope.row)"/> <ms-table-operator @editClick="edit(scope.row)" @deleteClick="handleDelete(scope.row)"/>
</template> </template>
</el-table-column> --> </el-table-column> -->
<!-- <el-table-column prop="name" :label="$t('commons.name')"/>
<el-table-column prop="description" :label="$t('commons.description')"/>
<el-table-column :label="$t('commons.member')">
<template v-slot:default="scope">
<el-link type="primary" class="member-size" @click="cellClick(scope.row)">
{{ scope.row.memberSize }}
</el-link>
</template>
</el-table-column>
<el-table-column :label="$t('commons.operating')">
<template v-slot:default="scope">
<ms-table-operator @editClick="edit(scope.row)" @deleteClick="handleDelete(scope.row)"/>
</template>
</el-table-column> -->
</el-table> </el-table>
</el-card> </el-card>
<!-- dialog of organization member -->
<el-dialog :close-on-click-modal="false" :visible.sync="dialogOrgMemberVisible" width="70%" :destroy-on-close="true" @close="closeFunc"
class="dialog-css">
<ms-table-header :condition.sync="dialogCondition" @create="addMember" @search="dialogSearch"
:create-tip="$t('member.create')" :title="$t('commons.member')"/>
<!-- organization member table -->
<el-table
:border="true"
class="adjust-table"
:data="memberLineData"
style="width: 100%;margin-top:5px;"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
row-key="deptId"
>
<el-table-column prop="id" label="ID"/>
<el-table-column prop="name" :label="$t('commons.username')"/>
<el-table-column prop="email" :label="$t('commons.email')"/>
<el-table-column prop="phone" :label="$t('commons.phone')"/>
<el-table-column :label="$t('commons.role')" width="140">
<template v-slot:default="scope">
<ms-roles-tag :roles="scope.row.roles"/>
</template>
</el-table-column>
<el-table-column :label="$t('commons.operating')">
<template v-slot:default="scope">
<ms-table-operator :tip2="$t('commons.remove')" @editClick="editMember(scope.row)"
@deleteClick="delMember(scope.row)"/>
</template>
</el-table-column>
</el-table>
<ms-table-pagination :change="dialogSearch" :current-page.sync="dialogCurrentPage"
:page-size.sync="dialogPageSize"
:total="dialogTotal"/>
</el-dialog>
<!-- add organization form --> <!-- add organization form -->
<el-dialog :close-on-click-modal="false" :title="$t('organization.create')" :visible.sync="dialogOrgAddVisible" width="30%" @closed="closeFunc" <el-dialog :close-on-click-modal="false" :title="formType=='add' ? $t('organization.create') : $t('organization.modify')" :visible.sync="dialogOrgAddVisible" width="30%" @closed="closeFunc"
:destroy-on-close="true"> :destroy-on-close="true">
<!-- <el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule" <el-form ref="createOrganization" inline :model="form" :rules="rule" size="small" label-width="80px">
ref="createOrganization">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input v-model="form.name" autocomplete="off"/>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description">
<el-input v-model="form.description" autocomplete="off" type="textarea"/>
</el-form-item>
</el-form> -->
<el-form ref="form" inline :model="form" :rules="rule" size="small" label-width="80px">
<el-form-item label="部门名称" prop="name"> <el-form-item label="部门名称" prop="name">
<el-input v-model="form.name" style="width: 370px;" /> <el-input v-model="form.name" style="width: 370px;" />
</el-form-item> </el-form-item>
...@@ -111,20 +64,26 @@ ...@@ -111,20 +64,26 @@
style="width: 370px;" style="width: 370px;"
/> />
</el-form-item> </el-form-item>
<el-form-item label="顶级部门">
<el-radio-group v-model="form.isTop" style="width: 140px"> <el-form-item label="顶级部门" prop="top">
<el-radio label="1"></el-radio> <el-radio-group v-model="form.top" style="width: 140px">
<el-radio label="0"></el-radio> <el-radio :label='true'></el-radio>
<el-radio :label='false'></el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="enabled">
<el-radio label="1">启用</el-radio> <el-form-item label="状态" prop="enabled" >
<el-radio label="0">停用</el-radio> <el-radio-group v-model="form.enabled" style="width: 140px">
<el-radio :label='true'>启用</el-radio>
<el-radio :label='false'>停用</el-radio>
</el-radio-group>
<!-- <el-radio v-for="item in dict.dept_status" :key="item.id" v-model="form.enabled" :label="item.value">{{ item.label }}</el-radio> --> <!-- <el-radio v-for="item in dict.dept_status" :key="item.id" v-model="form.enabled" :label="item.value">{{ item.label }}</el-radio> -->
</el-form-item> </el-form-item>
<el-form-item v-if="form.isTop === '0'" style="margin-bottom: 0;" label="上级部门" prop="pid"> <el-form-item v-if="!form.top" style="margin-bottom: 0;" label="上级部门" prop="pid">
<treeselect <treeselect
v-model="form.pid" v-model="form.pid"
:auto-load-root-options="false"
:load-options="loadDepts" :load-options="loadDepts"
:options="depts" :options="depts"
style="width: 370px;" style="width: 370px;"
...@@ -139,102 +98,7 @@ ...@@ -139,102 +98,7 @@
<template v-slot:footer> <template v-slot:footer>
<ms-dialog-footer <ms-dialog-footer
@cancel="dialogOrgAddVisible = false" @cancel="dialogOrgAddVisible = false"
@confirm="createOrganization('createOrganization')"/> @confirm="createDept('createOrganization')"/>
</template>
</el-dialog>
<!-- update organization form -->
<el-dialog :close-on-click-modal="false" :title="$t('organization.modify')" :visible.sync="dialogOrgUpdateVisible" width="30%"
:destroy-on-close="true"
@close="closeFunc">
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule"
ref="updateOrganizationForm">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input v-model="form.name" autocomplete="off"/>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description">
<el-input v-model="form.description" autocomplete="off"/>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="dialogOrgUpdateVisible = false"
@confirm="updateOrganization('updateOrganizationForm')"/>
</template>
</el-dialog>
<!-- add organization member form -->
<el-dialog :close-on-click-modal="false" :title="$t('member.create')" :visible.sync="dialogOrgMemberAddVisible" width="30%"
:destroy-on-close="true"
@close="closeFunc">
<el-form :model="memberForm" ref="form" :rules="orgMemberRule" label-position="right" label-width="100px"
size="small">
<el-form-item :label="$t('commons.member')" prop="userIds">
<el-select filterable v-model="memberForm.userIds" multiple :placeholder="$t('member.please_choose_member')"
class="select-width" :filter-method="dataFilter">
<el-option
v-for="item in memberForm.userList"
:key="item.id"
:label="item.name"
:value="item.id">
<span class="org-member-id">{{ item.id }}</span>
<span class="org-member-email">{{ item.email }}</span>
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('commons.role')" prop="roleIds">
<el-select filterable v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
class="select-width">
<el-option
v-for="item in memberForm.roles"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="dialogOrgMemberAddVisible = false"
@confirm="submitForm('form')"/>
</template>
</el-dialog>
<!-- update organization member form -->
<el-dialog :close-on-click-modal="false" :title="$t('member.modify')" :visible.sync="dialogOrgMemberUpdateVisible" width="30%"
:destroy-on-close="true"
@close="closeFunc">
<el-form :model="memberForm" label-position="right" label-width="100px" size="small" ref="updateUserForm">
<el-form-item label="ID" prop="id">
<el-input v-model="memberForm.id" autocomplete="off" :disabled="true"/>
</el-form-item>
<el-form-item :label="$t('commons.username')" prop="name">
<el-input v-model="memberForm.name" autocomplete="off" :disabled="true"/>
</el-form-item>
<el-form-item :label="$t('commons.email')" prop="email">
<el-input v-model="memberForm.email" autocomplete="off" :disabled="true"/>
</el-form-item>
<el-form-item :label="$t('commons.phone')" prop="phone">
<el-input v-model="memberForm.phone" autocomplete="off" :disabled="true"/>
</el-form-item>
<el-form-item :label="$t('commons.role')" prop="roleIds"
:rules="{required: true, message: $t('role.please_choose_role'), trigger: 'change'}">
<el-select filterable v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
class="select-width">
<el-option
v-for="item in memberForm.allroles"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="dialogOrgMemberUpdateVisible = false"
@confirm="updateOrgMember('updateUserForm')"/>
</template> </template>
</el-dialog> </el-dialog>
...@@ -246,7 +110,7 @@ ...@@ -246,7 +110,7 @@
<script> <script>
import Treeselect from '@riophae/vue-treeselect' import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css' import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' import { LOAD_CHILDREN_OPTIONS, LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect'
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
import MsTableHeader from "../../common/components/MsTableHeader"; import MsTableHeader from "../../common/components/MsTableHeader";
import MsRolesTag from "../../common/components/MsRolesTag"; import MsRolesTag from "../../common/components/MsRolesTag";
...@@ -254,10 +118,7 @@ import MsTableOperator from "../../common/components/MsTableOperator"; ...@@ -254,10 +118,7 @@ import MsTableOperator from "../../common/components/MsTableOperator";
import MsTableOperatorButton from "../../common/components/MsTableOperatorButton"; import MsTableOperatorButton from "../../common/components/MsTableOperatorButton";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import { import {
getCurrentOrganizationId,
getCurrentUser,
listenGoBack, listenGoBack,
refreshSessionAndCookies,
removeGoBackListener removeGoBackListener
} from "@/common/js/utils"; } from "@/common/js/utils";
import {DEFAULT, ORGANIZATION} from "@/common/js/constants"; import {DEFAULT, ORGANIZATION} from "@/common/js/constants";
...@@ -277,45 +138,22 @@ export default { ...@@ -277,45 +138,22 @@ export default {
}, },
data() { data() {
return { return {
depts:[], rootNodeLoaded: false,
components: [ depts:null,
{field: "name", label: "姓名", component: "FuInputComponent", defaultOperator: "eq"}, formType:"add",
{field: "email", label: "Email", component: "FuInputComponent"},
{ queryPath: '/api/dept/childNodes',
field: "status", deletePath: '/api/dept/delete',
label: "状态", createPath: '/api/dept/create',
component: "FuSelectComponent", updatePath: '/api/dept/update',
options: [ changeStatusPath: '/api/dept/updateStatus',
{label: "运行中", value: "Running"},
{label: "成功", value: "Success"},
{label: "失败", value: "Fail"}
],
multiple: true
},
{field: "create_time", label: "创建时间", component: "FuDateTimeComponent"},
],
queryPath: '/api/dept/root',
deletePath: '/organization/delete/',
createPath: '/organization/add',
updatePath: '/organization/update',
result: {}, result: {},
dialogOrgAddVisible: false, dialogOrgAddVisible: false,
dialogOrgUpdateVisible: false,
dialogOrgMemberVisible: false,
dialogOrgMemberAddVisible: false,
dialogOrgMemberUpdateVisible: false,
multipleSelection: [],
dialogCurrentPage: 1,
dialogPageSize: 10,
dialogTotal: 0,
currentRow: {},
condition: {}, condition: {},
dialogCondition: {},
tableData: [], tableData: [],
memberLineData: [], maps: new Map(),
oldPid: null,
form: {}, form: {},
memberForm: {},
rule: { rule: {
name: [ name: [
{required: true, message: this.$t('organization.input_name'), trigger: 'blur'}, {required: true, message: this.$t('organization.input_name'), trigger: 'blur'},
...@@ -324,16 +162,8 @@ export default { ...@@ -324,16 +162,8 @@ export default {
description: [ description: [
{max: 50, message: this.$t('commons.input_limit', [0, 50]), trigger: 'blur'} {max: 50, message: this.$t('commons.input_limit', [0, 50]), trigger: 'blur'}
] ]
},
orgMemberRule: {
userIds: [
{required: true, message: this.$t('member.please_choose_member'), trigger: ['blur']}
],
roleIds: [
{required: true, message: this.$t('role.please_choose_role'), trigger: ['blur']}
]
} }
} }
}, },
activated() { activated() {
...@@ -342,264 +172,158 @@ export default { ...@@ -342,264 +172,158 @@ export default {
methods: { methods: {
create() { create() {
this.dialogOrgAddVisible = true; this.dialogOrgAddVisible = true;
this.formType = "add";
listenGoBack(this.closeFunc); listenGoBack(this.closeFunc);
}, },
search(condition) { search(condition) {
console.log(condition) console.log(condition)
}, },
addMember() {
this.dialogOrgMemberAddVisible = true;
this.memberForm = {};
this.result = this.$get('/user/list/', response => {
this.$set(this.memberForm, "userList", response.data);
this.$set(this.memberForm, "copyUserList", response.data);
});
this.result = this.$get('/role/list/org', response => {
this.$set(this.memberForm, "roles", response.data);
})
},
dataFilter(val) {
if (val) {
this.memberForm.userList = this.memberForm.copyUserList.filter((item) => {
if (!!~item.id.indexOf(val) || !!~item.id.toUpperCase().indexOf(val.toUpperCase())) {
return true
}
})
} else {
this.memberForm.userList = this.memberForm.copyUserList;
}
},
edit(row) { edit(row) {
this.dialogOrgUpdateVisible = true; this.dialogOrgAddVisible = true;
this.formType = "modify";
this.oldPid = row.pid;
this.form = Object.assign({}, row); this.form = Object.assign({}, row);
// this.treeByRow(row);
listenGoBack(this.closeFunc); listenGoBack(this.closeFunc);
}, },
editMember(row) {
this.dialogOrgMemberUpdateVisible = true; treeByRow(row){
this.memberForm = Object.assign({}, row); !this.depts && (this.depts = [])
let roleIds = this.memberForm.roles.map(r => r.id); if (!this.depts.some(node => node.id==row.deptId)) {
this.result = this.$get('/role/list/org', response => { this.depts.push(this.normalizer(row));
this.$set(this.memberForm, "allroles", response.data); }
})
// 编辑时填充角色信息
this.$set(this.memberForm, 'roleIds', roleIds);
listenGoBack(this.closeFunc);
}, },
cellClick(row) {
// 保存当前点击的组织信息到currentRow
this.currentRow = row; initTableData(row, treeNode, resolve) {
this.dialogOrgMemberVisible = true; let _self = this;
let param = { let url = row ? (this.queryPath+"/"+row.deptId) : (this.queryPath+"/0");
name: '', this.result = this.$post(url , this.condition, (response) => {
organizationId: row.id let data = response.data;
}; data = data.map(obj => {
let path = "/user/special/org/member/list"; if(obj.subCount > 0){
this.result = this.$post(path + "/" + this.dialogCurrentPage + "/" + this.dialogPageSize, param, res => { obj.hasChildren = true;
let data = res.data; }
this.memberLineData = data.listObject; return obj;
let url = "/userrole/list/org/" + row.id; })
for (let i = 0; i < this.memberLineData.length; i++) { if(!row){
this.$get(url + "/" + encodeURIComponent(this.memberLineData[i].id), response => { data.some(node => node.children = null);
let roles = response.data; _self.tableData = data;
this.$set(this.memberLineData[i], "roles", roles); _self.depts = null;
})
}else{
this.maps.set(row.deptId, {row, treeNode, resolve})
resolve && resolve(data);
} }
this.dialogTotal = data.itemCount; })
});
listenGoBack(this.closeFunc);
}, },
dialogSearch() { closeFunc() {
let row = this.currentRow; this.initTableData();
this.dialogOrgMemberVisible = true; this.form = {};
let param = this.dialogCondition; this.oldPid = null;
this.$set(param, 'organizationId', row.id); removeGoBackListener(this.closeFunc);
let path = "/user/special/org/member/list"; this.dialogOrgAddVisible = false;
this.result = this.$post(path + "/" + this.dialogCurrentPage + "/" + this.dialogPageSize, param, res => {
let data = res.data;
this.memberLineData = data.listObject;
let url = "/userrole/list/org/" + row.id;
for (let i = 0; i < this.memberLineData.length; i++) {
this.$get(url + "/" + encodeURIComponent(this.memberLineData[i].id), response => {
let roles = response.data;
this.$set(this.memberLineData[i], "roles", roles);
})
}
this.dialogTotal = data.itemCount;
});
}, },
handleDelete(organization) {
this.$refs.deleteConfirm.open(organization); // 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_ROOT_OPTIONS) {
let _self = this;
!this.depts && this.$post("api/dept/childNodes/0", null, (res) => {
_self.depts = res.data.map(node => _self.normalizer(node))
callback()
})
}
if (action === LOAD_CHILDREN_OPTIONS) {
let _self = this;
this.$post("api/dept/childNodes/"+parentNode.id, null, (res) => {
parentNode.children = res.data.map(function(obj) {
return _self.normalizer(obj)
})
callback()
})
}
}, },
_handleDelete(organization) { normalizer(node) {
this.$confirm(this.$t('organization.delete_confirm'), '', { if(node.hasChildren){
confirmButtonText: this.$t('commons.confirm'), node.children = null
cancelButtonText: this.$t('commons.cancel'), }
type: 'warning' return {
}).then(() => { id: node.deptId,
this.result = this.$get(this.deletePath + organization.id, () => { label:node.name,
let lastOrganizationId = getCurrentOrganizationId(); children:node.children
let sourceId = organization.id; }
if (lastOrganizationId === sourceId) {
refreshSessionAndCookies(DEFAULT, sourceId);
}
this.$success(this.$t('commons.delete_success'));
this.initTableData();
});
}).catch(() => {
this.$message({
type: 'info',
message: this.$t('commons.delete_cancelled')
});
});
}, },
delMember(row) { // 改变状态
this.$confirm(this.$t('member.remove_member'), '', { changeEnabled(data, val) {
confirmButtonText: this.$t('commons.confirm'), this.$confirm('此操作将 "停用" ' + data.name + '部门, 是否继续?', '提示', {
cancelButtonText: this.$t('commons.cancel'), confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.result = this.$get('/user/special/org/member/delete/' + this.currentRow.id + '/' + encodeURIComponent(row.id), () => { const param = {deptId: data.deptId, status: data.enabled}
let sourceId = this.currentRow.id; this.$post(this.changeStatusPath, param, () => {
let currentUser = getCurrentUser(); this.$success(this.$t('commons.modify_success'));
let userId = row.id;
if (currentUser.id === userId) {
refreshSessionAndCookies(ORGANIZATION, sourceId);
}
this.$success(this.$t('commons.remove_success'))
this.cellClick(this.currentRow);
}); });
}).catch(() => { }).catch(() => {
this.$info(this.$t('commons.remove_cancel')); data.enabled = !data.enabled
}); })
}, },
createOrganization(createOrganizationForm) { // checkboxT(row, rowIndex) {
// return row.depId !== 1
// },
createDept(createOrganizationForm) {
this.$refs[createOrganizationForm].validate(valid => { this.$refs[createOrganizationForm].validate(valid => {
if (valid) { if (valid) {
this.result = this.$post(this.createPath, this.form, () => { let url = this.createPath;
this.formType == "modify" && this.form['deptId'] && (url = this.updatePath)
this.result = this.$post(url, this.form, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.initTableData(); this.initTableData();
this.oldPid && this.reloadByPid(this.oldPid)
this.reloadByPid(this.form['pid'])
this.dialogOrgAddVisible = false; this.dialogOrgAddVisible = false;
}); });
} else { } else {
return false; return false;
} }
}) })
}, },
updateOrganization(updateOrganizationForm) { handleDelete(organization) {
this.$refs[updateOrganizationForm].validate(valid => { this.$refs.deleteConfirm.open(organization);
if (valid) {
this.result = this.$post(this.updatePath, this.form, () => {
this.$success(this.$t('commons.modify_success'));
this.dialogOrgUpdateVisible = false;
this.initTableData();
});
} else {
return false;
}
})
},
initTableData() {
this.result = this.$post(this.queryPath , this.condition, (response) => {
let data = response.data;
data = data.map(obj => {
if(obj.subCount > 0){
obj.hasChildren = true;
obj.children = null;
}
return obj;
})
this.tableData = data;
this.depts = data;
// for (let i = 0; i < this.tableData.length; i++) {
// let param = {
// name: '',
// organizationId: this.tableData[i].id
// }
// let path = "user/special/org/member/list/all";
// this.$post(path, param, res => {
// let member = res.data;
// this.$set(this.tableData[i], "memberSize", member.length);
// })
// }
// this.total = data.itemCount;
})
},
closeFunc() {
this.memberLineData = [];
this.initTableData();
this.form = {};
removeGoBackListener(this.closeFunc);
this.dialogOrgAddVisible = false;
this.dialogOrgUpdateVisible = false;
this.dialogOrgMemberVisible = false;
this.dialogOrgMemberAddVisible = false;
this.dialogOrgMemberUpdateVisible = false;
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
let param = {
userIds: this.memberForm.userIds,
roleIds: this.memberForm.roleIds,
organizationId: this.currentRow.id
};
this.result = this.$post("user/special/org/member/add", param, () => {
let sign = "other";
let sourceId = this.currentRow.id;
refreshSessionAndCookies(sign, sourceId);
this.cellClick(this.currentRow);
this.dialogOrgMemberAddVisible = false;
})
} else {
return false;
}
});
}, },
updateOrgMember(formName) { _handleDelete(organization) {
let param = { this.$confirm(this.$t('organization.delete_confirm'), '', {
id: this.memberForm.id, confirmButtonText: this.$t('commons.confirm'),
name: this.memberForm.name, cancelButtonText: this.$t('commons.cancel'),
email: this.memberForm.email, type: 'warning'
phone: this.memberForm.phone, }).then(() => {
roleIds: this.memberForm.roleIds, let requests = [{deptId: organization.deptId, pid: organization.pid}]
organizationId: this.currentRow.id this.$post(this.deletePath, requests, () => {
} // this.result = this.$get(this.deletePath + organization.id, () => {
this.$refs[formName].validate((valid) => { this.$success(this.$t('commons.delete_success'));
if (valid) { this.initTableData();
this.result = this.$post("/organization/member/update", param, () => { this.reloadByPid(organization.pid)
this.$success(this.$t('commons.modify_success')); });
this.dialogOrgMemberUpdateVisible = false; }).catch(() => {
this.cellClick(this.currentRow); this.$message({
}); type: 'info',
} message: this.$t('commons.delete_cancelled')
});
}); });
}, },
// 获取弹窗内部门数据 reloadByPid(pid) {
loadDepts({ action, parentNode, callback }) { if (pid !== 0 && this.maps.get(pid)) {
console.log("111"); const { row, treeNode, resolve } = this.maps.get(pid);
if (action === LOAD_CHILDREN_OPTIONS) { this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, []);
this.$post("api/dept/root", { enabled: true, pid: parentNode.id }, (res) => { this.initTableData(row, treeNode, resolve);
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
setTimeout(() => {
callback()
}, 100)
})
} }
},
changeEnabled(data, val) {
},
checkboxT(row, rowIndex) {
return row.id !== 1
} }
} }
...@@ -629,5 +353,8 @@ export default { ...@@ -629,5 +353,8 @@ export default {
.dialog-css >>> .el-dialog__header { .dialog-css >>> .el-dialog__header {
padding: 0; padding: 0;
} }
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论