引入并注册Empty,组织结构树选择组件新增起始节点

This commit is contained in:
qinjie 2021-08-28 10:42:15 +08:00
parent 8ed75d939c
commit 64631ef5d0
2 changed files with 49 additions and 30 deletions

View File

@ -1,9 +1,12 @@
<template> <template>
<div class="organization-popover"> <div class="organization-popover">
<!-- :overlayStyle="{paddingTop: '0px', marginTop: '0px', border: '1px solid #1890ff'}" --> <!-- 气泡框位置 placement="bottomLeft" -->
<a-popover placement="bottomLeft" trigger="click" overlayClassName="popover-tree"> <!-- 触发行为 trigger="click" -->
<!-- 卡片类名 overlayClassName="popover-tree" 注意这里的css类要放到index.html才会生效-->
<!-- 隐藏后是否销毁 :destroyTooltipOnHide="true" -->
<a-popover placement="bottomLeft" trigger="click" overlayClassName="popover-tree" :destroyTooltipOnHide="true">
<template slot="content" id="popover-tree"> <template slot="content" id="popover-tree">
<a-input placeholder="输入关键字进行过滤" @change="onChange" allow-clear></a-input> <a-input placeholder="输入关键字进行过滤" @change="onChange" allow-clear v-show="treeData.length != 0"></a-input>
<!-- 树数据源 :tree-data="treeData" --> <!-- 树数据源 :tree-data="treeData" -->
<!-- 是否自动展开父节点 :auto-expand-parent="false" --> <!-- 是否自动展开父节点 :auto-expand-parent="false" -->
<!-- 是否节点占据一行 :blockNode="true" --> <!-- 是否节点占据一行 :blockNode="true" -->
@ -14,6 +17,7 @@
<!-- 点击树节点触发 :select="selectTree" --> <!-- 点击树节点触发 :select="selectTree" -->
<!-- 展开/收起节点时触发 @expand="onExpand" --> <!-- 展开/收起节点时触发 @expand="onExpand" -->
<a-tree :tree-data="treeData" :auto-expand-parent="autoExpandParent" :blockNode="true" :defaultSelectedKeys="defaultSelectedKeys" :expanded-keys="expandedKeys" @select="selectTree" @expand="onExpand"></a-tree> <a-tree :tree-data="treeData" :auto-expand-parent="autoExpandParent" :blockNode="true" :defaultSelectedKeys="defaultSelectedKeys" :expanded-keys="expandedKeys" @select="selectTree" @expand="onExpand"></a-tree>
<a-empty v-show="treeData.length == 0" description="没有找到组织机构树数据" :image-style="{height: '60px', marginTop: '10px'}" />
</template> </template>
<a-button class="organization-tree-button" type="primary">组织机构树 <a-button class="organization-tree-button" type="primary">组织机构树
<a-icon type="down" /> <a-icon type="down" />
@ -42,11 +46,23 @@
export default { export default {
props: { props: {
defaultOrganizationId: String, // defaultOrganizationId: String, //
startOrganizationId: String, //
}, },
data() { data() {
return { return {
// localStorage // localStorage
treeData: [ treeData: [],
filterText: null, //
selectTitle: "", //
selectKey: "", // Key
autoExpandParent: true, //
defaultSelectedKeys: [], //
expandedKeys: [], //
};
},
created: function () {
//
const listData = [
{ {
title: '三峡大学', title: '三峡大学',
key: '0001', key: '0001',
@ -64,22 +80,21 @@ export default {
}, },
] ]
} }
], ];
filterText: null, // if (!this.startOrganizationId) {
selectTitle: "", // this.treeData = listData;
selectKey: "", // Key } else {
autoExpandParent: true, // let currentNode = this.getCurrentNode(this.startOrganizationId, listData);
defaultSelectedKeys: [], // if (currentNode) this.treeData.push(currentNode);
expandedKeys: [], // }
};
},
created: function () {
// //
if (this.defaultOrganizationId) { if (this.defaultOrganizationId) {
let selectTitle = this.getCurrentTtile(this.defaultOrganizationId, this.treeData); let currentNode = this.getCurrentNode(this.defaultOrganizationId, this.treeData);
if (selectTitle) { if (currentNode) {
this.defaultSelectedKeys.push(this.defaultOrganizationId); this.defaultSelectedKeys.push(this.defaultOrganizationId);
this.selectTitle = selectTitle; this.selectTitle = currentNode.title;
this.selectKey = this.defaultOrganizationId; this.selectKey = this.defaultOrganizationId;
this.$emit('getSelectTreeKey', this.selectKey); this.$emit('getSelectTreeKey', this.selectKey);
} }
@ -115,18 +130,20 @@ export default {
} }
}, },
// KeyTitle // KeyTitle
getCurrentTtile(key, tree) { getCurrentNode(key, tree) {
if (!key) return; if (!key) return null;
for (let i = 0; i < tree.length; i++) { for (let i = 0; i < tree.length; i++) {
const node = tree[i]; const node = tree[i];
if (node.key === key) return node.title; if (node.key === key) return node;
if (node.children) { if (node.children) {
return this.getCurrentTtile(key, node.children); return this.getCurrentNode(key, node.children);
} }
} }
return null;
}, },
// //
onChange(e) { onChange(e) {

View File

@ -47,7 +47,8 @@ import {
notification, notification,
space, space,
Transfer, Transfer,
Tree Tree,
Empty
} from 'ant-design-vue' } from 'ant-design-vue'
import Viser from 'viser-vue' import Viser from 'viser-vue'
@ -103,6 +104,7 @@ Vue.use(Descriptions)
Vue.use(space) Vue.use(space)
Vue.use(Tree) Vue.use(Tree)
Vue.use(Transfer) Vue.use(Transfer)
Vue.use(Empty)
Vue.prototype.$confirm = Modal.confirm Vue.prototype.$confirm = Modal.confirm
Vue.prototype.$message = message Vue.prototype.$message = message