dataease/frontend/src/views/panel/GrantAuth/shareTree.vue

261 lines
6.4 KiB
Vue
Raw Normal View History

2021-03-18 18:30:10 +08:00
<template>
2021-11-09 18:23:45 +08:00
<el-col style="padding: 0 5px 0 5px;">
<el-row>
2021-11-10 18:04:20 +08:00
<span class="header-title">{{ $t('panel.share_in') }}</span>
2021-11-09 18:23:45 +08:00
<div class="block" style="margin-top:8px;">
2022-05-23 16:36:27 +08:00
<el-tree
ref="topTree"
:data="datas"
:props="defaultProps"
:highlight-current="true"
node-key="name"
:default-expanded-keys="expandNodes"
@node-click="handleNodeClick"
>
2021-11-10 18:04:20 +08:00
<span slot-scope="{ data }" class="custom-tree-node father">
<span style="display: flex; flex: 1 1 0%; width: 0px;" :class="!!data.msgNode ? 'msg-node-class': ''">
<span v-if="!!data.id">
<svg-icon :icon-class="'panel-'+data.status" class="ds-icon-scene" />
2021-11-10 18:04:20 +08:00
</span>
2022-05-23 16:36:27 +08:00
<span
:class="data.status"
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
>{{ data.name }}</span>
2021-11-10 18:04:20 +08:00
</span>
2021-11-29 13:52:35 +08:00
2021-11-09 18:23:45 +08:00
</span>
</el-tree>
</div>
</el-row>
2021-03-18 18:30:10 +08:00
2021-11-09 18:23:45 +08:00
<el-row>
2021-11-10 18:04:20 +08:00
<span class="header-title">{{ $t('panel.share_out') }}</span>
2021-11-09 18:23:45 +08:00
<div class="block" style="margin-top:8px;">
2022-05-23 16:36:27 +08:00
<el-tree
ref="botTree"
:data="outDatas"
:props="defaultProps"
:highlight-current="true"
node-key="name"
:default-expand-all="true"
>
2021-11-10 18:04:20 +08:00
<span slot-scope="{ data }" class="custom-tree-node father">
2021-11-29 13:52:35 +08:00
<span style="display: flex; flex: 1 1 0%; width: 0px;" @click="viewMyShare(data)">
2021-11-09 18:23:45 +08:00
<span v-if="!!data.id">
<svg-icon :icon-class="'panel-'+data.status" class="ds-icon-scene" />
2021-11-10 18:04:20 +08:00
</span>
2022-05-23 16:36:27 +08:00
<span
:class="data.status"
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
>{{ data.name }}</span>
2021-11-10 18:04:20 +08:00
</span>
<span class="child">
<span class="el-dropdown-link">
2021-11-09 18:23:45 +08:00
<el-button
2021-11-10 18:04:20 +08:00
icon="el-icon-delete"
2021-11-09 18:23:45 +08:00
type="text"
2021-11-10 18:04:20 +08:00
size="small"
@click="removeCurrent(data)"
2021-11-09 18:23:45 +08:00
/>
</span>
</span>
</span>
2021-11-10 18:04:20 +08:00
2021-11-09 18:23:45 +08:00
</el-tree>
</div>
</el-row>
</el-col>
2021-03-18 18:30:10 +08:00
</template>
<script>
2021-11-10 18:04:20 +08:00
import { loadTree, loadShareOutTree, removeShares } from '@/api/panel/share'
2021-04-20 14:19:10 +08:00
import { uuid } from 'vue-uuid'
import { initPanelData } from '@/api/panel/panel'
import { proxyInitPanelData } from '@/api/panel/shareProxy'
import bus from '@/utils/bus'
2022-05-23 16:36:27 +08:00
2021-03-18 18:30:10 +08:00
export default {
name: 'ShareTree',
props: {
msgPanelIds: {
type: Array,
default: null
}
},
2021-03-18 18:30:10 +08:00
data() {
return {
datas: [],
2021-03-18 18:30:10 +08:00
defaultProps: {
children: 'children',
label: 'name'
},
2021-11-09 18:23:45 +08:00
expandNodes: [],
outDatas: []
2021-03-18 18:30:10 +08:00
}
},
2021-11-29 13:52:35 +08:00
computed: {
panelInfo() {
return this.$store.state.panel.panelInfo
}
},
2021-03-18 18:30:10 +08:00
created() {
bus.$on('refresh-my-share-out', this.refreshMyShareOut)
this.initData().then(res => {
this.datas = res.data
if (this.msgPanelIds && this.msgPanelIds.length > 0) {
this.expandMsgNode(this.msgPanelIds)
}
})
2021-11-09 18:23:45 +08:00
this.initOutData().then(res => {
this.outDatas = res.data
})
2021-03-18 18:30:10 +08:00
},
beforeDestroy() {
bus.$off('refresh-my-share-out', this.refreshMyShareOut)
},
2021-03-18 18:30:10 +08:00
methods: {
refreshMyShareOut() {
this.initOutData().then(res => {
this.outDatas = res.data
this.setMainNull()
})
},
2021-03-18 18:30:10 +08:00
initData() {
const param = {}
return loadTree(param)
2021-03-18 18:30:10 +08:00
},
2021-11-09 18:23:45 +08:00
initOutData() {
return loadShareOutTree()
},
2021-03-18 18:30:10 +08:00
handleNodeClick(data) {
if (!data || !data.userId || !data.id) {
return
}
const param = { userId: data.userId }
proxyInitPanelData(data.id, param, function() {
2021-11-10 18:04:20 +08:00
bus.$emit('set-panel-show-type', 1)
bus.$emit('set-panel-share-user', data.userId)
2021-11-10 18:04:20 +08:00
})
2021-12-30 19:31:28 +08:00
this.$refs['botTree'].setCurrentKey(null)
2021-11-10 18:04:20 +08:00
},
viewMyShare(data) {
initPanelData(data.id, function() {
2021-11-10 18:04:20 +08:00
bus.$emit('set-panel-show-type', 2)
2021-04-20 14:19:10 +08:00
})
2021-12-30 19:31:28 +08:00
this.$refs['topTree'].setCurrentKey(null)
2021-04-20 14:19:10 +08:00
},
resetID(data) {
2021-05-20 16:45:27 +08:00
if (data) {
2021-05-05 22:14:23 +08:00
data.forEach(item => {
2021-05-20 16:45:27 +08:00
item.type !== 'custom' && (item.id = uuid.v1())
2021-05-05 22:14:23 +08:00
})
}
2021-04-20 14:19:10 +08:00
return data
},
expandMsgNode(panelIds) {
this.$nextTick(() => {
this.getMsgNodes(panelIds)
})
},
getMsgNodes(panelIds) {
this.datas.forEach(item => {
if (item.children && item.children.length > 0) {
item.children.forEach(node => {
if (panelIds.includes(node.id)) {
node.msgNode = true
this.expandNodes.push(item.name)
}
})
}
})
2021-11-10 18:04:20 +08:00
},
removeCurrent(node) {
const param = {
panelId: node.id
}
this.$confirm(this.$t('panel.remove_share_confirm'), '', {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
removeShares(param).then(res => {
2021-11-29 13:52:35 +08:00
this.panelInfo && this.panelInfo.id && node.id === this.panelInfo.id && this.setMainNull()
2021-11-10 18:04:20 +08:00
this.initOutData().then(res => {
this.outDatas = res.data
})
this.$success(this.$t('commons.delete_success'))
})
}).catch(() => {
this.$message({
type: 'info',
message: this.$t('commons.delete_cancelled')
})
})
2021-11-29 13:52:35 +08:00
},
setMainNull() {
this.$store.dispatch('panel/setPanelInfo', { id: null, name: '', preStyle: null })
2021-03-18 18:30:10 +08:00
}
2021-03-18 18:30:10 +08:00
}
}
</script>
<style lang="scss" scoped>
2022-05-23 16:36:27 +08:00
.header-title {
2021-11-09 18:23:45 +08:00
font-size: 14px;
flex: 1;
color: var(--TextPrimary, #606266);
font-weight: bold;
display: block;
height: 100%;
/*line-height: 36px;*/
}
2022-05-23 16:36:27 +08:00
.msg-node-class {
color: red;
2022-05-23 16:36:27 +08:00
> > > i {
color: red;
}
}
2022-05-23 16:36:27 +08:00
.custom-tree-node {
2021-11-10 18:04:20 +08:00
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
2022-05-23 16:36:27 +08:00
padding-right: 8px;
2021-11-10 18:04:20 +08:00
}
.custom-tree-node-list {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
2022-05-23 16:36:27 +08:00
padding: 0 8px;
2021-11-10 18:04:20 +08:00
}
2022-05-23 16:36:27 +08:00
2021-11-10 18:04:20 +08:00
.father .child {
/*display: none;*/
visibility: hidden;
}
2022-05-23 16:36:27 +08:00
2021-11-10 18:04:20 +08:00
.father:hover .child {
/*display: inline;*/
visibility: visible;
}
2022-05-23 16:36:27 +08:00
.unpublished {
color: #b2b2b2
}
.publish {
}
</style>