feat: 仪表盘分享页面完善

This commit is contained in:
fit2cloud-chenyw 2021-03-18 16:55:31 +08:00
parent 3f5d2bee53
commit 9e9fb73892
14 changed files with 354 additions and 97 deletions

View File

@ -9,7 +9,7 @@ public class PanelShare implements Serializable {
private String panelGroupId; private String panelGroupId;
private Long userId; private Long targetId;
private Long createTime; private Long createTime;

View File

@ -234,63 +234,63 @@ public class PanelShareExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdIsNull() { public Criteria andTargetIdIsNull() {
addCriterion("user_id is null"); addCriterion("target_id is null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdIsNotNull() { public Criteria andTargetIdIsNotNull() {
addCriterion("user_id is not null"); addCriterion("target_id is not null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdEqualTo(Long value) { public Criteria andTargetIdEqualTo(Long value) {
addCriterion("user_id =", value, "userId"); addCriterion("target_id =", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdNotEqualTo(Long value) { public Criteria andTargetIdNotEqualTo(Long value) {
addCriterion("user_id <>", value, "userId"); addCriterion("target_id <>", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdGreaterThan(Long value) { public Criteria andTargetIdGreaterThan(Long value) {
addCriterion("user_id >", value, "userId"); addCriterion("target_id >", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdGreaterThanOrEqualTo(Long value) { public Criteria andTargetIdGreaterThanOrEqualTo(Long value) {
addCriterion("user_id >=", value, "userId"); addCriterion("target_id >=", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdLessThan(Long value) { public Criteria andTargetIdLessThan(Long value) {
addCriterion("user_id <", value, "userId"); addCriterion("target_id <", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdLessThanOrEqualTo(Long value) { public Criteria andTargetIdLessThanOrEqualTo(Long value) {
addCriterion("user_id <=", value, "userId"); addCriterion("target_id <=", value, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdIn(List<Long> values) { public Criteria andTargetIdIn(List<Long> values) {
addCriterion("user_id in", values, "userId"); addCriterion("target_id in", values, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdNotIn(List<Long> values) { public Criteria andTargetIdNotIn(List<Long> values) {
addCriterion("user_id not in", values, "userId"); addCriterion("target_id not in", values, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdBetween(Long value1, Long value2) { public Criteria andTargetIdBetween(Long value1, Long value2) {
addCriterion("user_id between", value1, value2, "userId"); addCriterion("target_id between", value1, value2, "targetId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUserIdNotBetween(Long value1, Long value2) { public Criteria andTargetIdNotBetween(Long value1, Long value2) {
addCriterion("user_id not between", value1, value2, "userId"); addCriterion("target_id not between", value1, value2, "targetId");
return (Criteria) this; return (Criteria) this;
} }

View File

@ -4,7 +4,7 @@
<resultMap id="BaseResultMap" type="io.dataease.base.domain.PanelShare"> <resultMap id="BaseResultMap" type="io.dataease.base.domain.PanelShare">
<id column="share_id" jdbcType="BIGINT" property="shareId" /> <id column="share_id" jdbcType="BIGINT" property="shareId" />
<result column="panel_group_id" jdbcType="VARCHAR" property="panelGroupId" /> <result column="panel_group_id" jdbcType="VARCHAR" property="panelGroupId" />
<result column="user_id" jdbcType="BIGINT" property="userId" /> <result column="target_id" jdbcType="BIGINT" property="targetId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" /> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="type" jdbcType="INTEGER" property="type" /> <result column="type" jdbcType="INTEGER" property="type" />
</resultMap> </resultMap>
@ -67,7 +67,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
share_id, panel_group_id, user_id, create_time, `type` share_id, panel_group_id, target_id, create_time, `type`
</sql> </sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.PanelShareExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.dataease.base.domain.PanelShareExample" resultMap="BaseResultMap">
select select
@ -100,9 +100,9 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.dataease.base.domain.PanelShare"> <insert id="insert" parameterType="io.dataease.base.domain.PanelShare">
insert into panel_share (share_id, panel_group_id, user_id, insert into panel_share (share_id, panel_group_id, target_id,
create_time, `type`) create_time, `type`)
values (#{shareId,jdbcType=BIGINT}, #{panelGroupId,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, values (#{shareId,jdbcType=BIGINT}, #{panelGroupId,jdbcType=VARCHAR}, #{targetId,jdbcType=BIGINT},
#{createTime,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}) #{createTime,jdbcType=BIGINT}, #{type,jdbcType=INTEGER})
</insert> </insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.PanelShare"> <insert id="insertSelective" parameterType="io.dataease.base.domain.PanelShare">
@ -114,8 +114,8 @@
<if test="panelGroupId != null"> <if test="panelGroupId != null">
panel_group_id, panel_group_id,
</if> </if>
<if test="userId != null"> <if test="targetId != null">
user_id, target_id,
</if> </if>
<if test="createTime != null"> <if test="createTime != null">
create_time, create_time,
@ -131,8 +131,8 @@
<if test="panelGroupId != null"> <if test="panelGroupId != null">
#{panelGroupId,jdbcType=VARCHAR}, #{panelGroupId,jdbcType=VARCHAR},
</if> </if>
<if test="userId != null"> <if test="targetId != null">
#{userId,jdbcType=BIGINT}, #{targetId,jdbcType=BIGINT},
</if> </if>
<if test="createTime != null"> <if test="createTime != null">
#{createTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
@ -157,8 +157,8 @@
<if test="record.panelGroupId != null"> <if test="record.panelGroupId != null">
panel_group_id = #{record.panelGroupId,jdbcType=VARCHAR}, panel_group_id = #{record.panelGroupId,jdbcType=VARCHAR},
</if> </if>
<if test="record.userId != null"> <if test="record.targetId != null">
user_id = #{record.userId,jdbcType=BIGINT}, target_id = #{record.targetId,jdbcType=BIGINT},
</if> </if>
<if test="record.createTime != null"> <if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
@ -175,7 +175,7 @@
update panel_share update panel_share
set share_id = #{record.shareId,jdbcType=BIGINT}, set share_id = #{record.shareId,jdbcType=BIGINT},
panel_group_id = #{record.panelGroupId,jdbcType=VARCHAR}, panel_group_id = #{record.panelGroupId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=BIGINT}, target_id = #{record.targetId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
`type` = #{record.type,jdbcType=INTEGER} `type` = #{record.type,jdbcType=INTEGER}
<if test="_parameter != null"> <if test="_parameter != null">
@ -188,8 +188,8 @@
<if test="panelGroupId != null"> <if test="panelGroupId != null">
panel_group_id = #{panelGroupId,jdbcType=VARCHAR}, panel_group_id = #{panelGroupId,jdbcType=VARCHAR},
</if> </if>
<if test="userId != null"> <if test="targetId != null">
user_id = #{userId,jdbcType=BIGINT}, target_id = #{targetId,jdbcType=BIGINT},
</if> </if>
<if test="createTime != null"> <if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
@ -203,7 +203,7 @@
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelShare"> <update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelShare">
update panel_share update panel_share
set panel_group_id = #{panelGroupId,jdbcType=VARCHAR}, set panel_group_id = #{panelGroupId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=BIGINT}, target_id = #{targetId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
`type` = #{type,jdbcType=INTEGER} `type` = #{type,jdbcType=INTEGER}
where share_id = #{shareId,jdbcType=BIGINT} where share_id = #{shareId,jdbcType=BIGINT}

View File

@ -3,12 +3,13 @@ package io.dataease.base.mapper.ext;
import io.dataease.base.domain.PanelShare; import io.dataease.base.domain.PanelShare;
import io.dataease.base.mapper.ext.query.GridExample; import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.dto.panel.PanelShareDto; import io.dataease.dto.panel.PanelShareDto;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface ExtPanelShareMapper { public interface ExtPanelShareMapper {
int batchInsert(List<PanelShare> shares); int batchInsert(@Param("shares") List<PanelShare> shares);
List<PanelShareDto> query(GridExample example); List<PanelShareDto> query(GridExample example);

View File

@ -6,13 +6,14 @@
<id column="id" property="id" /> <id column="id" property="id" />
<result column="name" property="name" /> <result column="name" property="name" />
<result column="pid" property="pid" /> <result column="pid" property="pid" />
<result column="creator" property="create_by" />
</resultMap> </resultMap>
<insert id="batchInsert" parameterType="io.dataease.base.domain.PanelStore"> <insert id="batchInsert" parameterType="io.dataease.base.domain.PanelShare">
INSERT INTO panel_store (panel_group_id,user_id,create_time) INSERT INTO panel_share (panel_group_id,target_id,create_time,type)
VALUES VALUES
<foreach collection="list" item="store" separator=","> <foreach collection="shares" item="share" separator=",">
(#{store.panelGroupId}, #{store.userId}, #{store.createTime}) (#{share.panelGroupId}, #{share.targetId}, #{share.createTime}, #{share.type})
</foreach> </foreach>
</insert> </insert>
@ -33,7 +34,7 @@
</select> </select>
<select id="queryWithResource" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="io.dataease.base.mapper.PanelShareMapper.BaseResultMap"> <select id="queryWithResource" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="io.dataease.base.mapper.PanelShareMapper.BaseResultMap">
select from panel_share select * from panel_share
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" /> <include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
</if> </if>

View File

@ -8,9 +8,10 @@ import java.util.List;
@Data @Data
public class PanelShareRequest implements Serializable { public class PanelShareRequest implements Serializable {
@ApiModelProperty(value = "分享目标类型", allowableValues = "0:user,1:role,2:dept")
@ApiModelProperty("分享目标用户集合") private Integer type;
private List<Long> userIds; @ApiModelProperty("分享目标集合")
private List<Long> targetIds;
@ApiModelProperty("分享仪表板集合") @ApiModelProperty("分享仪表板集合")
private List<String> panelIds; private List<String> panelIds;
} }

View File

@ -2,6 +2,7 @@ package io.dataease.service.panel;
import io.dataease.base.domain.PanelShare; import io.dataease.base.domain.PanelShare;
import io.dataease.base.domain.PanelShareExample; import io.dataease.base.domain.PanelShareExample;
import io.dataease.base.domain.SysUser;
import io.dataease.base.mapper.PanelShareMapper; import io.dataease.base.mapper.PanelShareMapper;
import io.dataease.base.mapper.ext.ExtPanelShareMapper; import io.dataease.base.mapper.ext.ExtPanelShareMapper;
import io.dataease.base.mapper.ext.query.GridExample; import io.dataease.base.mapper.ext.query.GridExample;
@ -36,21 +37,26 @@ public class ShareService {
public void save(PanelShareRequest request){ public void save(PanelShareRequest request){
//1.先根据仪表板删除所有已经分享的 //1.先根据仪表板删除所有已经分享的
Integer type = request.getType();
List<String> panelIds = request.getPanelIds(); List<String> panelIds = request.getPanelIds();
List<Long> userIds = request.getUserIds(); List<Long> targetIds = request.getTargetIds();
// 使用原生对象会导致事物失效 所以这里需要使用spring代理对象 // 使用原生对象会导致事物失效 所以这里需要使用spring代理对象
if (CollectionUtils.isNotEmpty(panelIds)){ if (CollectionUtils.isNotEmpty(panelIds)){
ShareService proxy = CommonBeanFactory.getBean(ShareService.class); ShareService proxy = CommonBeanFactory.getBean(ShareService.class);
panelIds.forEach(proxy::delete); panelIds.forEach(panelId -> {
proxy.delete(panelId, type);
});
} }
if (CollectionUtils.isEmpty(userIds)) return; if (CollectionUtils.isEmpty(targetIds)) return;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
List<PanelShare> shares = panelIds.stream().flatMap(panelId -> List<PanelShare> shares = panelIds.stream().flatMap(panelId ->
userIds.stream().map(userId -> { targetIds.stream().map(targetId -> {
PanelShare share = new PanelShare(); PanelShare share = new PanelShare();
share.setCreateTime(now); share.setCreateTime(now);
share.setPanelGroupId(panelId); share.setPanelGroupId(panelId);
share.setUserId(userId); share.setTargetId(targetId);
share.setType(type);
return share; return share;
}) })
).collect(Collectors.toList()); ).collect(Collectors.toList());
@ -64,20 +70,31 @@ public class ShareService {
* @param panel_group_id * @param panel_group_id
*/ */
@Transactional @Transactional
public void delete(String panel_group_id){ public void delete(String panel_group_id, Integer type){
PanelShareExample example = new PanelShareExample(); PanelShareExample example = new PanelShareExample();
example.createCriteria().andPanelGroupIdEqualTo(panel_group_id); example.createCriteria().andPanelGroupIdEqualTo(panel_group_id).andTypeEqualTo(type);
mapper.deleteByExample(example); mapper.deleteByExample(example);
} }
public List<PanelShareDto> queryTree(BaseGridRequest request){ public List<PanelShareDto> queryTree(BaseGridRequest request){
Long userId = AuthUtils.getUser().getUserId(); SysUser user = AuthUtils.getUser();
Long userId = user.getUserId();
Long deptId = user.getDeptId();
List<Long> roleIds = new ArrayList<>();
List<Long> targetIds = new ArrayList<>();
targetIds.add(userId);
targetIds.add(deptId);
targetIds.addAll(roleIds);
ConditionEntity condition = new ConditionEntity(); ConditionEntity condition = new ConditionEntity();
condition.setField("s.user_id"); condition.setField("s.target_id");
condition.setOperator("eq"); condition.setOperator("in");
condition.setValue(userId); condition.setValue(targetIds);
request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}}); request.setConditions(new ArrayList<ConditionEntity>(){{add(condition);}});
GridExample example = request.convertExample(); GridExample example = request.convertExample();
List<PanelShareDto> datas = extPanelShareMapper.query(example); List<PanelShareDto> datas = extPanelShareMapper.query(example);
return convertTree(datas); return convertTree(datas);
@ -86,7 +103,6 @@ public class ShareService {
//List构建Tree //List构建Tree
private List<PanelShareDto> convertTree(List<PanelShareDto> datas){ private List<PanelShareDto> convertTree(List<PanelShareDto> datas){
Map<String, List<PanelShareDto>> map = datas.stream().collect(Collectors.groupingBy(PanelShareDto::getCreator)); Map<String, List<PanelShareDto>> map = datas.stream().collect(Collectors.groupingBy(PanelShareDto::getCreator));
List<PanelShareDto> roots = new ArrayList<>();
return map.entrySet().stream().map(entry -> PanelShareDto.builder().name(entry.getKey()).children(entry.getValue()).build()).collect(Collectors.toList()); return map.entrySet().stream().map(entry -> PanelShareDto.builder().name(entry.getKey()).children(entry.getValue()).build()).collect(Collectors.toList());
} }

View File

@ -14,6 +14,7 @@ import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest; import io.dataease.controller.sys.request.DeptStatusRequest;
import io.dataease.controller.sys.request.SimpleTreeNode; import io.dataease.controller.sys.request.SimpleTreeNode;
import io.dataease.controller.sys.response.DeptTreeNode; import io.dataease.controller.sys.response.DeptTreeNode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -134,8 +135,10 @@ public class DeptService {
List<SimpleTreeNode> targetNodes = nodeByCondition(request); List<SimpleTreeNode> targetNodes = nodeByCondition(request);
List<Long> ids = upTree(allNodes, targetNodes); List<Long> ids = upTree(allNodes, targetNodes);
SysDeptExample example = new SysDeptExample(); SysDeptExample example = new SysDeptExample();
SysDeptExample.Criteria criteria = example.createCriteria(); if (CollectionUtils.isNotEmpty(ids)){
criteria.andDeptIdIn(ids); SysDeptExample.Criteria criteria = example.createCriteria();
criteria.andDeptIdIn(ids);
}
example.setOrderByClause("dept_sort"); example.setOrderByClause("dept_sort");
List<SysDept> sysDepts = sysDeptMapper.selectByExample(example); List<SysDept> sysDepts = sysDeptMapper.selectByExample(example);
return sysDepts; return sysDepts;

View File

@ -67,7 +67,7 @@ CREATE TABLE `panel_store` (
`user_id` bigint(20) NOT NULL COMMENT '用户ID', `user_id` bigint(20) NOT NULL COMMENT '用户ID',
`create_time` bigint(13) DEFAULT NULL COMMENT '创建日期', `create_time` bigint(13) DEFAULT NULL COMMENT '创建日期',
PRIMARY KEY (`store_id`) USING BTREE, PRIMARY KEY (`store_id`) USING BTREE,
UNIQUE KEY `UK_store_user_id` (`user_id`) USING BTREE KEY `UK_store_user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='仪表板收藏'; ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='仪表板收藏';
@ -86,13 +86,13 @@ DROP TABLE IF EXISTS `panel_share`;
CREATE TABLE `panel_share` ( CREATE TABLE `panel_share` (
`share_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '分享ID', `share_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '分享ID',
`panel_group_id` varchar(50) DEFAULT NULL COMMENT '仪表板ID', `panel_group_id` varchar(50) DEFAULT NULL COMMENT '仪表板ID',
`user_id` bigint(20) DEFAULT NULL COMMENT '用户ID', `target_id` bigint(20) DEFAULT NULL COMMENT '目标ID',
`create_time` bigint(13) DEFAULT NULL COMMENT '创建日期', `create_time` bigint(13) DEFAULT NULL COMMENT '创建日期',
`type` int(8) DEFAULT NULL COMMENT '类型', `type` int(8) DEFAULT NULL COMMENT '类型0:user,1:role,2dept',
PRIMARY KEY (`share_id`) USING BTREE, PRIMARY KEY (`share_id`) USING BTREE,
UNIQUE KEY `UK_share_user_id` (`user_id`) USING BTREE, KEY `UK_share_arget_id` (`target_id`) ,
UNIQUE KEY `UK_share_panel_group_id` (`panel_group_id`) USING BTREE, KEY `UK_share_panel_group_id` (`panel_group_id`) ,
UNIQUE KEY `UK_share_type` (`type`) USING BTREE KEY `UK_share_type` (`type`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='仪表板分享'; ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='仪表板分享';

View File

@ -24,13 +24,17 @@
<script> <script>
import { getDeptTree, loadTable } from '@/api/system/dept' import { getDeptTree, loadTable } from '@/api/system/dept'
import { formatCondition } from '@/utils/index' import { saveShare, loadShares } from '@/api/panel/share'
export default { export default {
name: 'GrantDept', name: 'GrantDept',
props: { props: {
resourceId: { resourceId: {
type: String, type: String,
default: null default: null
},
keyWord: {
type: String,
default: ''
} }
}, },
data() { data() {
@ -40,14 +44,44 @@ export default {
field: 'pid', field: 'pid',
operator: 'eq', operator: 'eq',
value: 0 value: 0
} },
// maps: new Map() type: 2, // 2
shares: [],
changeIndex: 0,
timeMachine: null
}
},
watch: {
keyWord(v, o) {
this.destryTimeMachine()
this.changeIndex++
this.searchWithKey(this.changeIndex)
} }
}, },
created() { created() {
this.search() this.search()
}, },
methods: { methods: {
//
// 1500ms key
searchWithKey(index) {
this.timeMachine = setTimeout(() => {
if (index === this.changeIndex) {
const condition = {
field: 'name',
operator: 'like',
value: this.keyWord
}
this.search(condition)
console.log('start execute search')
}
this.destryTimeMachine()
}, 1500)
},
destryTimeMachine() {
this.timeMachine && clearTimeout(this.timeMachine)
this.timeMachine = null
},
// //
loadExpandDatas(row, treeNode, resolve) { loadExpandDatas(row, treeNode, resolve) {
getDeptTree(row.deptId).then(res => { getDeptTree(row.deptId).then(res => {
@ -60,21 +94,23 @@ export default {
}) })
// this.maps.set(row.deptId, { row, treeNode, resolve }) // this.maps.set(row.deptId, { row, treeNode, resolve })
resolve && resolve(data) resolve && resolve(data)
this.$nextTick(() => {
this.setCheckExpandNodes(data)
})
}) })
}, },
// //
search(condition) { search(condition) {
// this.setTableAttr() // this.setTableAttr()
this.data = [] this.data = []
let param = {} let param = {}
if (condition && condition.quick) { if (condition && condition.value) {
const con = this.quick_condition(condition) param = { conditions: [condition] }
param = formatCondition(con)
} else { } else {
param = { conditions: [this.defaultCondition] } param = { conditions: [this.defaultCondition] }
} }
// param.conditions.push(this.defaultCondition)
loadTable(param).then(res => { loadTable(param).then(res => {
let data = res.data let data = res.data
data = data.map(obj => { data = data.map(obj => {
@ -84,11 +120,22 @@ export default {
return obj return obj
}) })
if (condition && condition.quick) { if (condition && condition.value) {
data = this.buildTree(data) data = data.map(node => {
// this.setTableAttr(true) delete (node.hasChildren)
return node
})
this.data = this.buildTree(data)
this.$nextTick(() => {
data.forEach(node => {
this.$refs.table.toggleRowExpansion(node, true)
})
})
} else {
this.data = data
} }
this.data = data
this.queryShareNodeIds()
}) })
}, },
@ -110,7 +157,62 @@ export default {
parentEl.children = [...(parentEl.children || []), el] parentEl.children = [...(parentEl.children || []), el]
}) })
return roots return roots
},
save() {
const rows = this.$refs.table.store.states.selection
const request = this.buildRequest(rows)
saveShare(request).then(res => {
this.$success('保存成功')
return true
}).catch(err => {
this.$error(err.message)
return false
})
console.log('dept save')
},
cancel() {
console.log('dept cancel')
},
buildRequest(rows) {
const targetIds = rows.map(row => row.deptId)
const panelIds = [this.resourceId]
return {
targetIds: targetIds,
panelIds: panelIds,
type: this.type
}
},
queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => {
const shares = res.data
const nodeIds = shares.map(share => share.targetId)
this.shares = nodeIds
this.$nextTick(() => {
this.setCheckNodes()
})
callBack && callBack()
})
},
setCheckNodes() {
this.data.forEach(node => {
const nodeId = node.deptId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true)
})
},
setCheckExpandNodes(rows) {
rows.forEach(node => {
const nodeId = node.deptId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true)
})
} }
} }
} }
</script> </script>

View File

@ -8,10 +8,16 @@
</div> </div>
<el-tabs v-model="activeName" :class="{'de-search-header': showSearchInput}" @tab-click="handleClick"> <el-tabs v-model="activeName" :class="{'de-search-header': showSearchInput}" @tab-click="handleClick">
<el-tab-pane :lazy="true" class="de-tab" label="部门" name="1"><grant-dept :resource-id="resourceId" /></el-tab-pane> <el-tab-pane :lazy="true" class="de-tab" label="部门" :name="tabNames[0]"><grant-dept :ref="tabNames[0]" :resource-id="resourceId" :key-word="key" /></el-tab-pane>
<el-tab-pane :lazy="true" class="de-tab" label="角色" name="2"><grant-role :resource-id="resourceId" /></el-tab-pane> <el-tab-pane :lazy="true" class="de-tab" label="角色" :name="tabNames[1]"><grant-role :ref="tabNames[1]" :resource-id="resourceId" :key-word="key" /></el-tab-pane>
<el-tab-pane :lazy="true" class="de-tab" label="用户" name="3"><grant-user :resource-id="resourceId" /></el-tab-pane> <el-tab-pane :lazy="true" class="de-tab" label="用户" :name="tabNames[2]"><grant-user :ref="tabNames[2]" :resource-id="resourceId" :key-word="key" /></el-tab-pane>
</el-tabs> </el-tabs>
<div class="auth-root-class">
<span slot="footer">
<el-button @click="cancel"> </el-button>
<el-button type="primary" @click="save"> </el-button>
</span>
</div>
</div> </div>
</template> </template>
@ -31,11 +37,15 @@ export default {
}, },
data() { data() {
return { return {
activeName: '1', tabNames: ['grantDept', 'grantRole', 'grantUser'],
activeName: null,
showSearchInput: false, showSearchInput: false,
key: null key: ''
} }
}, },
created() {
this.activeName = this.tabNames[0]
},
methods: { methods: {
handleClick(tab, event) { handleClick(tab, event) {
@ -45,7 +55,16 @@ export default {
this.showSearchInput = true this.showSearchInput = true
}, },
closeSearchWidget() { closeSearchWidget() {
this.key = ''
this.showSearchInput = false this.showSearchInput = false
},
save() {
this.$refs[this.activeName].save()
this.$emit('close-grant', 0)
},
cancel() {
this.$refs[this.activeName].cancel()
this.$emit('close-grant', 0)
} }
} }
} }
@ -71,6 +90,11 @@ export default {
border-right: none; border-right: none;
} }
.auth-root-class {
margin: 15px 0px 5px;
text-align: right;
}
// ::-webkit-scrollbar { // ::-webkit-scrollbar {
// } // }

View File

@ -2,7 +2,7 @@
<div class="my_table"> <div class="my_table">
<el-table <el-table
ref="table" ref="table"
:data="data" :data="data.filter(node => !keyWord || node[fieldName].toLowerCase().includes(keyWord.toLowerCase()))"
:show-header="true" :show-header="true"
style="width: 100%" style="width: 100%"
:row-style="{height: '35px'}" :row-style="{height: '35px'}"
@ -17,12 +17,17 @@
<script> <script>
import { roleGrid } from '@/api/system/role' import { roleGrid } from '@/api/system/role'
import { formatCondition } from '@/utils/index' import { formatCondition } from '@/utils/index'
import { saveShare, loadShares } from '@/api/panel/share'
export default { export default {
name: 'GrantRole', name: 'GrantRole',
props: { props: {
resourceId: { resourceId: {
type: String, type: String,
default: null default: null
},
keyWord: {
type: String,
default: ''
} }
}, },
data() { data() {
@ -31,7 +36,9 @@ export default {
defaultHeadName: '全部', defaultHeadName: '全部',
columnLabel: null, columnLabel: null,
filter_options: [{ text: '未分享角色', value: 0 }, { text: '已分享角色', value: 1 }], filter_options: [{ text: '未分享角色', value: 0 }, { text: '已分享角色', value: 1 }],
fieldName: 'name' fieldName: 'name',
type: 1, // 1
shares: []
} }
}, },
created() { created() {
@ -50,12 +57,14 @@ export default {
const data = response.data const data = response.data
// this.total = data.itemCount // this.total = data.itemCount
this.data = data.listObject this.data = data.listObject
this.queryShareNodeIds()
}) })
}, },
filterHandler(value, row, column) { filterHandler(value, row, column) {
// const property = column['property'] // const property = column['property']
// return row[property] === value // return row[property] === value
return row['code'] === 'admin' const roleId = row['roleId']
return !(value ^ this.shares.includes(roleId))
}, },
filterChange(obj) { filterChange(obj) {
@ -65,6 +74,52 @@ export default {
return return
} }
this.columnLabel = this.filter_options[arr[0]].text this.columnLabel = this.filter_options[arr[0]].text
},
save() {
const rows = this.$refs.table.store.states.selection
const request = this.buildRequest(rows)
saveShare(request).then(res => {
this.$success('保存成功')
return true
}).catch(err => {
this.$error(err.message)
return false
})
},
cancel() {
console.log('role cancel')
},
buildRequest(rows) {
const targetIds = rows.map(row => row.roleId)
const panelIds = [this.resourceId]
return {
targetIds: targetIds,
panelIds: panelIds,
type: this.type
}
},
queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => {
const shares = res.data
const nodeIds = shares.map(share => share.targetId)
this.shares = nodeIds
this.$nextTick(() => {
this.setCheckNodes()
})
callBack && callBack()
})
},
setCheckNodes() {
this.data.forEach(node => {
const nodeId = node.roleId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true)
})
} }
} }

View File

@ -2,7 +2,7 @@
<div class="my_table"> <div class="my_table">
<el-table <el-table
ref="table" ref="table"
:data="data" :data="data.filter(node => !keyWord || node[fieldName].toLowerCase().includes(keyWord.toLowerCase()))"
:show-header="true" :show-header="true"
style="width: 100%" style="width: 100%"
:row-style="{height: '35px'}" :row-style="{height: '35px'}"
@ -17,12 +17,17 @@
<script> <script>
import { userLists } from '@/api/system/user' import { userLists } from '@/api/system/user'
import { formatCondition } from '@/utils/index' import { formatCondition } from '@/utils/index'
import { saveShare, loadShares } from '@/api/panel/share'
export default { export default {
name: 'GrantUser', name: 'GrantUser',
props: { props: {
resourceId: { resourceId: {
type: String, type: String,
default: null default: null
},
keyWord: {
type: String,
default: ''
} }
}, },
data() { data() {
@ -31,7 +36,9 @@ export default {
defaultHeadName: '全部', defaultHeadName: '全部',
columnLabel: null, columnLabel: null,
filter_options: [{ text: '未分享人员', value: 0 }, { text: '已分享人员', value: 1 }], filter_options: [{ text: '未分享人员', value: 0 }, { text: '已分享人员', value: 1 }],
fieldName: 'nickName' fieldName: 'nickName',
type: 0, // 0
shares: []
} }
}, },
created() { created() {
@ -49,12 +56,14 @@ export default {
const data = response.data const data = response.data
// this.total = data.itemCount // this.total = data.itemCount
this.data = data.listObject this.data = data.listObject
this.queryShareNodeIds()
}) })
}, },
filterHandler(value, row, column) { filterHandler(value, row, column) {
// const property = column['property'] // const property = column['property']
// return row[property] === value // return row[property] === value
return row['code'] === 'admin' const userId = row['userId']
return !(value ^ this.shares.includes(userId))
}, },
filterChange(obj) { filterChange(obj) {
@ -64,6 +73,53 @@ export default {
return return
} }
this.columnLabel = this.filter_options[arr[0]].text this.columnLabel = this.filter_options[arr[0]].text
},
save() {
const rows = this.$refs.table.store.states.selection
const request = this.buildRequest(rows)
saveShare(request).then(res => {
this.$success('保存成功')
return true
}).catch(err => {
this.$error(err.message)
return false
})
},
cancel() {
console.log('user cancel')
},
buildRequest(rows) {
const targetIds = rows.map(row => row.userId)
const panelIds = [this.resourceId]
return {
targetIds: targetIds,
panelIds: panelIds,
type: this.type
}
},
queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => {
const shares = res.data
const nodeIds = shares.map(share => share.targetId)
this.shares = nodeIds
this.$nextTick(() => {
this.setCheckNodes()
})
callBack && callBack()
})
},
setCheckNodes() {
this.data.forEach(node => {
const nodeId = node.userId
this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true)
})
} }
} }

View File

@ -113,15 +113,13 @@
<el-dialog <el-dialog
:title="authTitle" :title="authTitle"
:visible.sync="authVisible" :visible.sync="authVisible"
:show-close="false"
custom-class="de-dialog" custom-class="de-dialog"
:before-close="handleClose"
> >
<grant-auth :resource-id="authResourceId" /> <grant-auth v-if="authVisible" :resource-id="authResourceId" @close-grant="closeGrant" />
<span slot="footer" class="dialog-footer"> <!-- <span slot="footer" class="dialog-footer">
<el-button @click="authVisible = false"> </el-button> <el-button @click="authVisible = false"> </el-button>
<el-button type="primary" @click="authVisible = false"> </el-button> <el-button type="primary" @click="authVisible = false"> </el-button>
</span> </span> -->
</el-dialog> </el-dialog>
</el-col> </el-col>
</el-col> </el-col>
@ -486,9 +484,9 @@ export default {
this.authTitle = '把[' + data.label + ']分享给' this.authTitle = '把[' + data.label + ']分享给'
this.authVisible = true this.authVisible = true
}, },
handleClose(done) { closeGrant() {
this.authResourceId = null this.authResourceId = null
this.handleClose = false this.authVisible = false
} }
} }
} }