update 文档拆分详情修改

This commit is contained in:
赵霄
2023-09-15 18:04:00 +08:00
parent acfc345cd0
commit 838bf6d651
5 changed files with 191 additions and 506 deletions
+164 -489
View File
@@ -3,81 +3,102 @@
<div class="page-left-right-layout">
<!--树部分-->
<div class="page-left-box">
<a-spin :spinning="loading">
<a-input-search style="margin-bottom: 8px" :placeholder="$t('nodeQuickLookup')" @change="onLeftChange"
@search="onSearch" />
<a-tree
v-if="gData.length>0"
:selected-keys="selectedKeys"
:expanded-keys.sync="expandedKeys"
:auto-expand-parent="autoExpandParent"
:defaultExpandAll="true"
:tree-data="gData"
@expand="onExpand"
@rightClick="rightClick"
@select="onSelect"
>
<template #title="{ key: treeKey, title, record }">
<a-dropdown :trigger="['contextmenu']">
<span v-if="title.indexOf(searchValue) >= -1 && title.length <= 18" :title="title"
class="expand-title">
{{ title.substr(0, title.indexOf(searchValue)) }}<span style="color: #f50">{{ searchValue }}</span>
{{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
</span>
<span
v-else-if="title.indexOf(searchValue) >= -1 && title.length > 18 && title.indexOf(searchValue)>18"
:title="title">
{{ title && title.length > 18 ? title.slice(0, 17) + '...' : title }}
</span>
<span
v-else-if="title.indexOf(searchValue) >= -1 && title.length > 18 && title.indexOf(searchValue)<=18"
:title="title">
{{ title.substr(0, title.indexOf(searchValue)) }}
<span style="color: #f50">
{{ title.indexOf(searchValue) + searchValue.length > 18 ? searchValue.substr(0, 18 - title.indexOf(searchValue)) : searchValue
}}
</span>
{{ title.indexOf(searchValue) + searchValue.length > 18 ? '...' : title.substr(title.indexOf(searchValue) + searchValue.length, 18 - title.indexOf(searchValue) - searchValue.length) + '...'
}}
</span>
<span v-else :title="title">
{{ title && title.length > 18 ? title.slice(0, 17) + '...' : title }}
</span>
<template #overlay>
<a-menu v-if="$route.query.createBy === userData.username || administrators"
@click="({ key: menuKey }) => onContextMenuClick(treeKey, menuKey, record)">
<a-menu-item key="1" @click="orgAdd" v-has="'split:sarFileSplitMenu:add'">
{{ $t('newNode') }}
</a-menu-item>
<a-menu-item key="2" @click="orgEdit" v-has="'split:sarFileSplitMenu:update'">
{{ $t('modifyNode') }}
</a-menu-item>
<a-menu-item key="3" @click="orgDelete" v-if="deleteNode"
v-has="'split:sarFileSplitMenu:delete'">{{ $t('deleteNode') }}
</a-menu-item>
<a-menu-item key="4" @click="orgMoveUp" v-if="deleteNode && moveUpFlag"
v-has="'split:sarFileSplitMenu:moveUp'">{{ $t('moveUp') }}
</a-menu-item>
<a-menu-item key="5" @click="orgmoveDown" v-if="deleteNode && moveDownFlag"
v-has="'split:sarFileSplitMenu:moveDown'">{{ $t('moveDown') }}
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
</a-tree>
</a-spin>
<a-input-search class="tree-search" v-model="searchValue" :placeholder="$t('nodeQuickLookup')" @search="onSearch" />
<div class="page-tree-box page-tree-box-has-search">
<a-spin :spinning="loading">
<a-tree :show-line="true" :show-icon="true" :tree-data="treeData" :selected-keys="selectedKeys">
<a-icon type="folder" slot="folder" class="tree-icon" />
<a-icon type="file" slot="file" class="tree-icon" />
<template #custom="record">
<div class="tree-operate-node"
@mouseenter="handleTreeMouseover(record.key)"
@mouseleave="handleTreeMouseout(record.key)"
@click="handleSelectTreeNode(record)">
<a-tooltip>
<template #title>
{{ record.title }}
</template>
<span class="tree-node-custom-title">{{ record.title }}</span>
</a-tooltip>
<div class="tree-operate-node-btn-box" :class="{'tree-operate-node-btn-box-hide': record.key !== mouseInNodeKey}">
<!--新增-->
<a-button icon="plus"
class="tree-operate-node-btn"
@click.stop="orgAdd(record)"
v-has="'split:sarFileSplitMenu:add'">
</a-button>
<!--编辑-->
<a-button class="tree-operate-node-btn"
@click.stop="orgEdit(record)"
v-has="'split:sarFileSplitMenu:update'">
<i class="iconfont icon-bianji" />
</a-button>
<!--删除根节点不能删除-->
<a-button class="tree-operate-node-btn"
v-has="'split:sarFileSplitMenu:delete'"
@click.stop="orgDelete(record)">
<i class="iconfont icon-shanchu_" />
</a-button>
<!--节点上移是否可以上移在树形数据中应该有字段标识-->
<a-button icon="up"
class="tree-operate-node-btn"
@click.stop="orgMoveUp(record)"
v-has="'split:sarFileSplitMenu:moveUp'">
</a-button>
<!--节点下移是否可以下移在树形数据中应该有字段标识-->
<a-button icon="up"
class="tree-operate-node-btn"
@click.stop="orgmoveDown(record)"
v-has="'split:sarFileSplitMenu:moveDown'">
</a-button>
</div>
<!--<template #overlay>-->
<!-- <a-menu v-if="$route.query.createBy === userInfo.username || administrators"-->
<!-- @click="({ key: menuKey }) => onContextMenuClick(treeKey, menuKey, record)">-->
<!-- <a-menu-item key="1" @click="orgAdd" v-has="'split:sarFileSplitMenu:add'">-->
<!-- {{ $t('newNode') }}-->
<!-- </a-menu-item>-->
<!-- <a-menu-item key="2" @click="orgEdit" v-has="'split:sarFileSplitMenu:update'">-->
<!-- {{ $t('modifyNode') }}-->
<!-- </a-menu-item>-->
<!-- <a-menu-item key="3" @click="orgDelete" v-if="deleteNode"-->
<!-- v-has="'split:sarFileSplitMenu:delete'">{{ $t('deleteNode') }}-->
<!-- </a-menu-item>-->
<!-- <a-menu-item key="4" @click="orgMoveUp" v-if="deleteNode && moveUpFlag"-->
<!-- v-has="'split:sarFileSplitMenu:moveUp'">{{ $t('moveUp') }}-->
<!-- </a-menu-item>-->
<!-- <a-menu-item key="5" @click="orgmoveDown" v-if="deleteNode && moveDownFlag"-->
<!-- v-has="'split:sarFileSplitMenu:moveDown'">{{ $t('moveDown') }}-->
<!-- </a-menu-item>-->
<!-- </a-menu>-->
<!--</template>-->
</div>
</template>
</a-tree>
</a-spin>
</div>
</div>
<!--表格部分-->
<div class="page-right-box">
<div class="table-page-search-wrapper">
<search ref="searchRef"
:url="url"
:get-query-condition-func="getQueryConditionFunc"
search-has="domesticStandard:search"
@search="searchQuery"
@reset="searchReset" />
</div>
<!--操作按钮-->
<div class="table-operator">
<!--新增-->
<a-button icon="plus" type="primary" @click="handleAdd" v-has="'domesticStandard:add'">{{ $t('newlyAdded') }}</a-button>
<!--导入-->
<a-upload name="file"
:showUploadList="false"
:multiple="false"
:headers="tokenHeader"
:action="importExcelUrl"
v-has="'domesticStandard:import'"
@change="handleImportExcel">
<a-button type="primary" icon="download" ghost>{{ $t('import') }}</a-button>
</a-upload>
@@ -85,7 +106,6 @@
<a-button icon="upload"
type="primary"
ghost
v-has="'domesticStandard:export'"
@click="handleExportXls($t('standardRegulationLibrary.domesticStandard.exportFileName'))">
{{ $t('export') }}
</a-button>
@@ -95,12 +115,11 @@
<a-button type="primary"
icon="download"
ghost
v-has="'domesticStandard:downTemplate'"
@click="downTemplate($t('standardRegulationLibrary.domesticStandard.templateName'))">
{{ $t('templateDownload') }}
</a-button>
<!--批量复制-->
<a-button type="primary" ghost @click="handleCopyManage" v-has="'domesticStandard:batchDel'">{{ $t('docTool.split.batchCopy') }}</a-button>
<a-button type="primary" ghost @click="handleCopyManage">{{ $t('docTool.split.batchCopy') }}</a-button>
<!--批量编辑-->
<a-button type="primary" ghost @click="handleManage">{{ $t('docTool.split.batchEdit') }}</a-button>
<!--合并条款-->
@@ -153,8 +172,9 @@
<split-detail-node-add ref="splitDetailNodeAdd" @ok="nodeAddOk" @update="nodeUpdateOk"></split-detail-node-add>
<!-- 批量设置弹框 -->
<split-detail-batch-setting ref="splitDetailBatchSetting" @ok="batchSettingOk"></split-detail-batch-setting>
<split-add-form ref="splitForm" :flag="'4'"
:url="url" :infoId="infoId" :menuId="menuId" :itemId="itemId" @closeVisible="closeVisible"
<!--条款添加-->
<split-add-form ref="modalForm" :flag="'4'"
:url="url" :infoId="infoId" :menuId="menuId" :itemId="itemId"
@sumber="sumber"></split-add-form>
</internal-detail-page>
</template>
@@ -170,13 +190,11 @@ import SplitClauseDetail from './modules/SplitClauseDetail.vue'
import SplitDetailNodeAdd from './modules/SplitDetailNodeAdd.vue'
// 批量设置弹框
import SplitDetailBatchSetting from './modules/SplitDetailBatchSetting.vue'
import Vue from 'vue'
import { ACCESS_TOKEN } from '../../store/mutation-types.js'
import { mapGetters } from 'vuex'
import { postAction, getAction, downloadFile } from '../../api/manage.js'
import moment from 'moment'
import { ConfigurableTableMixin } from '../../mixins/ConfigurableTableMixin.js'
import {getDocSplitTableHeader} from '../../api/documentToolApi.js'
import { getDocSplitTableHeader, getDocSplitSearch } from '../../api/documentToolApi.js'
import Search from '../../components/customField/Search.vue'
export default {
name: 'DocumentSplitDetail',
@@ -186,23 +204,12 @@ export default {
SplitAddForm,
SplitClauseDetail,
SplitDetailNodeAdd,
SplitDetailBatchSetting
SplitDetailBatchSetting,
Search
},
mixins: [ConfigurableTableMixin],
data () {
return {
userData: {},
contentVisible: false, // 条款内容弹框显示
selectedRowKeys: [],
selectedRows: [],
selectedKeys: [],
expandedKeys: [],
searchValue: '',
autoExpandParent: true,
dataList: [],
contentValue: '',
gData: [],
attId: '',
data: [],
loading: false, // 提交的加载
confirmLoading: false,
@@ -212,26 +219,6 @@ export default {
menuId: '',
itemId: '',
itemVal: {},
// 操作栏
operationList: [
{
text: this.$t('edit'),
ClickEvent: 'editClick'
},
{
text: this.$t('delete'),
ClickEvent: 'deleteClick'
}
],
url: {
tableHeader: 'split/sarFileSplitItems/getHeader', // 表格头部字段
getSearchList: 'split/sarFileSplitItems/queryCondition', // 搜索字段
list: 'split/sarFileSplitItems/getSplitItemsByPage', // 表格数据
getAddForm: 'split/sarFileSplitItems/getForm', // 表单的字段
getDocumentInfo: 'split/sarFileSplitItems/getSplitItemsById',
importZipUrl: '/split/sarFileSplitItems/importSplitItems' // 导入
},
token: Vue.ls.get(ACCESS_TOKEN),
uploadMenuId: '',
deleteNode: false,
moveDownFlag: false,
@@ -240,29 +227,55 @@ export default {
parameter: {},
administrators: false,
showAction: this.isCanOperate,
flag: '4' // 查询要用到
flag: '4', // 查询要用到
getQueryConditionFunc: getDocSplitSearch,
getTableHeaderFunc: getDocSplitTableHeader,
treeData: [],
searchValue: '',
selectedKeys: [],
mouseInNodeKey: null, // 鼠标悬浮的节点key值
// 操作栏
operationList: [
{
text: this.$t('edit'),
ClickEvent: 'handleEdit'
},
{
text: this.$t('delete'),
ClickEvent: 'handleDelete'
}
],
url: {
list: '',
importUrl: '', // 导入
exportXlsUrl: '', // 导出
delete: '', // 删除
deleteBatch: '', // 批量删除
downTemplateUrl: '' // 模板下载
}
}
},
computed: {
isCanOperate () {
return !!(this.$route.query.createBy === this.userData.username || this.administrators)
},
filters () {
return {
menu_id: this.menuId,
info_id: this.infoId
}
return !!(this.$route.query.createBy === this.userInfo.username || this.administrators)
},
// 页面标题是标准名称
pageTitle () {
return this.$route.query.standardName
},
...mapGetters(['userInfo'])
},
created () {
this.filters = {
menu_id: this.menuId,
info_id: this.infoId
}
},
mounted () {
this.userData = this.userInfo()
this.administrators = false
if (this.userInfo().userRoleList && this.userInfo().userRoleList.length > 0) {
this.userInfo().userRoleList.forEach(res => {
if (this.userInfo.userRoleList && this.userInfo.userRoleList.length > 0) {
this.userInfo.userRoleList.forEach(res => {
if (res.roleCode === 'admin') {
this.administrators = true
}
@@ -270,59 +283,38 @@ export default {
}
this.infoId = this.$route.query.infoId
this.loadMenuData()
this.generateList(this.gData)
},
methods: {
...mapGetters(['userInfo']),
/**
* 树节点鼠标移入
* @param key
*/
handleTreeMouseover (key) {
this.mouseInNodeKey = key
},
/**
* 树节点鼠标移出
* @param key
*/
handleTreeMouseout (key) {
if (this.mouseInNodeKey === key) {
this.mouseInNodeKey = null
}
},
/**
* 选中树节点
* @param dataRef
*/
handleSelectTreeNode ({ dataRef }) {
this.selectedKeys = [dataRef.key]
this.filters.nodeCode = dataRef.nodeCode
this.loadData(1)
},
// 显示条款内容弹框
showContent (val) {
this.$refs.splitClauseDetail.open(val)
},
generateList (data) {
for (let i = 0; i < data.length; i++) {
const node = data[i]
const key = node.key
this.dataList.push({ key, title: key })
if (node.children) {
this.generateList(node.children)
}
}
},
getParentKey (key, tree) {
let parentKey
for (let i = 0; i < tree.length; i++) {
const node = tree[i]
if (node.children) {
if (node.children.some(item => item.key === key)) {
parentKey = node.key
} else if (this.getParentKey(key, node.children)) {
parentKey = this.getParentKey(key, node.children)
}
}
}
return parentKey
},
onExpand (expandedKeys) {
this.expandedKeys = expandedKeys
this.autoExpandParent = false
},
onLeftChange (e) {
const value = e.target.value
const expandedKeys = this.dataList
.map(item => {
if (item.title.indexOf(value) > -1) {
return this.getParentKey(item.key, this.gData)
}
return null
})
.filter((item, i, self) => item && self.indexOf(item) === i)
Object.assign(this, {
expandedKeys,
searchValue: value,
autoExpandParent: true
})
this.onSearch()
},
// 获取左侧目录数据
loadMenuData () {
const params = {
@@ -332,11 +324,7 @@ export default {
getAction(`split/sarFileSplitMenu/getSplitMenusByInfoId`, params).then(res => {
if (res.success) {
this.data = this.toTree(res.result)
this.gData = [...this.data]
Object.assign(this, {
expandedKeys: this.expandedKeys,
autoExpandParent: true
})
this.treeData = [...this.data]
}
}).finally(() => {
this.loading = false
@@ -373,34 +361,6 @@ export default {
})
return val
},
// 鼠标右键
rightClick ({ event, node }) {
this.deleteNode = !!node._props.dataRef.pid
this.moveDownFlag = node._props.dataRef.moveDownFlag === true
this.moveUpFlag = node._props.dataRef.moveUpFlag === true
const x = event.currentTarget.offsetLeft + event.currentTarget.clientWidth
const y = event.currentTarget.offsetTop
this.nodeTreeItem = {
pageX: x,
pageY: y,
id: node._props.dataRef.id,
name: node._props.dataRef.name,
itemName: node._props.dataRef.itemName,
displaySeq: node._props.dataRef.displaySeq,
title: node._props.dataRef.title,
pid: node._props.dataRef.pid || null
}
this.nodeItem = JSON.parse(JSON.stringify(this.nodeTreeItem))
this.tmpStyle = {
position: 'absolute',
maxHeight: 40,
textAlign: 'center',
left: `${x + 10 - 0}px`,
top: `${y + 6 - 0}px`,
background: `#FFFFFF`,
zIndex: `2`
}
},
// 用于点击空白处隐藏增删改菜单
clearMenu () {
this.nodeTreeItem = null
@@ -410,8 +370,8 @@ export default {
this.menuId = selectedKeys[0]
this.uploadMenuId = selectedKeys[0]
this.selectedKeys = selectedKeys
this.parameter.info_id = this.infoId
this.parameter.menu_id = this.menuId
this.filters.info_id = this.infoId
this.filters.menu_id = this.menuId
this.loadData()
},
// 树形新增
@@ -424,7 +384,6 @@ export default {
},
// 添加节点完成后的回调
nodeAddOk () {
this.expandedKeys.push(this.nodeItem.id)
this.loadMenuData()
this.loadData()
},
@@ -496,62 +455,6 @@ export default {
onContextMenuClick (treeKey, menuKey) {
// console.log(`treeKey: ${treeKey}, menuKey: ${menuKey}`);
},
// 表格操作列按钮的点击
operationClick (operation, record) {
if (this[operation.clickEvent]) {
this[operation.clickEvent](record)
}
},
/**
* 处理表头数据
* @param columns
* @returns {*[]}
*/
dealColumns (columns) {
const tempColumns = []
columns.forEach(item => {
// 可点击项加入插槽
if (item.click === 'true') {
item.scopedSlots = {
customRender: 'detailClick'
}
} else if (item.urlClick === 'true') {
item.scopedSlots = {
customRender: 'urlClick'
}
} else if (item.db_field_name === 'iterms_conditions') {
// 拆分文档详情页的条款内容点击可预览
item.scopedSlots = {
customRender: 'showContent'
}
}
// 是否可排序
item.sorter = item.sort === 'true'
item.width = 215
item.title = item.db_field_txt
item.dataIndex = item.db_field_name
item.align = 'left'
tempColumns.push(item)
})
if (this.showAction && this.operateColumn) {
let width = 0
if (this.operationList.length > 0) {
for (let i = 0; i < this.operationList.length; i++) {
width += this.getTextWith(this.operationList[i].text)
}
}
const operateColumn = JSON.parse(JSON.stringify(this.operateColumn))
operateColumn.width = width
tempColumns.push(operateColumn)
}
return tempColumns
},
// 清空按钮
resetSearch () {
this.menuId = ''
this.uploadMenuId = ''
this.selectedKeys = []
},
// 复制按钮
handleCopyManage (record) {
const ids = []
@@ -575,7 +478,7 @@ export default {
getAction('/split/sarFileSplitItems/batchCopyItems', params).then((res) => {
if (res.data.success) {
this.$message.success(this.$t('operationSuccessful'))
this.selectClear()
this.onClearSelected()
this.loadMenuData()
this.loadData()
} else {
@@ -595,76 +498,6 @@ export default {
this.$refs.splitForm.add()
this.$refs.splitForm.formTitle = this.$t('add')
})
// if (this.menuId) {
// this.formTitle = this.$t('add')
// this.itemId = ''
// this.addVisible = true
// this.$nextTick(() => {
// this.$refs.splitForm.add()
// this.$refs.splitForm.formTitle = this.$t('add')
// })
// } else {
// this.$message.warning(this.$t('docTool.split.selectDirectoryTerms'))
// }
},
// 关闭新增弹框
closeVisible (val) {
this.addVisible = val
},
// 导入
handleImportManage () {
if (!this.menuId) {
this.$message.warning(this.$t('docTool.split.selectDirectoryTerms'))
}
},
// 上传成功
uploadSuccess (data, status) {
if (status === 'success') {
this.loadMenuData()
this.loadData()
}
const attIdList = []
if (data && data.length > 0) {
data.forEach(item => {
attIdList.push(item.id || data.name)
})
this.attId = attIdList.join(',')
}
},
queryParamsValues (search) {
Object.keys(search).forEach(res => {
if (search[res] instanceof Array) {
search[res] = search[res].join(',')
}
})
this.parameter = search
this.parameter.info_id = this.infoId
this.parameter.menu_id = this.menuId
},
// 导出
handleExportManage () {
if (JSON.stringify(this.parameter) === '{}') {
this.parameter.info_id = this.infoId
this.parameter.menu_id = this.menuId
}
// console.log('menuId',this.menuId)
const dateName = moment(new Date()).format('YYYY-MM-DD HH-mm-ss')
const name = this.$route.query.infoNumber + ' ' + dateName + '.zip'
const query = {
exportName: this.$route.query.infoNumber + ' ' + dateName,
idList: this.selectedRowKeys.join(','),
parameter: this.parameter
}
downloadFile('split/sarFileSplitItems/exportSplitInfoZip', name, query, this.selectClear)
},
selectClear () {
this.selectedRowKeys = []
this.selectedRows = []
},
// 模板下载
handleDownManage () {
const name = this.$t('docTool.split.documentSplitTemplate') + '.xlsx'
downloadFile('split/sarFileSplitItems/exportTemplate', name, {})
},
// 合并条款
handleMergeManage () {
@@ -679,7 +512,7 @@ export default {
getAction('/split/sarFileSplitItems/batchMergeItems', { ids: ids }).then(res => {
if (res.data.success) {
this.$message.success(this.$t('operationSuccessful'))
this.selectClear()
this.onClearSelected()
this.loadMenuData()
this.loadData()
this.selectedRowKeys = []
@@ -702,174 +535,16 @@ export default {
},
// 批量设置完成的回调
batchSettingOk () {
this.selectClear()
this.onClearSelected()
this.loadData()
},
// 批量删除
handleBatCancel () {
const params = {
ids: this.selectedRowKeys.join(',')
}
if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
this.$confirm({
title: this.$t('confirmBatchDeletion'),
content: '',
onOk: () => {
postAction('/split/sarFileSplitItems/batchDeleteItems', params).then((res) => {
if (res.data.success) {
this.$message.success(this.$t('operationSuccessful'))
this.loadMenuData()
this.filter = {
menu_id: this.menuId,
info_id: this.infoId
}
this.loadData()
this.selectClear()
} else {
this.$message.warning(res.data.message)
}
})
}
})
} else {
this.$message.warning(this.$t('selectLeastOne'))
}
},
// 编辑
editClick (val) {
this.formTitle = this.$t('edit')
this.itemVal = val
this.itemId = val.id
this.addVisible = true
this.$nextTick(() => {
this.$refs.splitForm.edit(val)
this.$refs.splitForm.formTitle = this.$t('edit')
})
},
// 保存成功
sumber () {
this.loadData()
this.loadMenuData()
},
// 删除
deleteClick (val) {
const params = {
ids: val.id
}
this.$confirm({
title: this.$t('areYouSure'),
content: '',
onOk: () => {
postAction('/split/sarFileSplitItems/batchDeleteItems', params).then((res) => {
if (res.data.success) {
this.$message.success(this.$t('operationSuccessful'))
this.loadMenuData()
this.loadData()
} else {
this.$message.warning(this.$t('operationFailed'))
}
})
}
})
},
// 选择框
onSelectChange (selectedRowKeys, rows) {
this.selectedRowKeys = selectedRowKeys
this.selectedRows = rows
},
onSearch () {
const self = this
const tree = JSON.parse(JSON.stringify(this.data))
this.expandedKeys = []
if (this.searchValue.trim() === '') {
this.gData = JSON.parse(JSON.stringify(this.data))
return
}
if (tree && tree.length > 0) {
tree.forEach((n, i, a) => {
self.searchEach(n, this.searchValue)
})
// 没有叶子节点的根节点也要清理掉
const length = tree.length
for (let i = length - 1; i >= 0; i--) {
const e2 = tree[i]
if (!this.isHasChildren(e2) && e2.title.indexOf(this.searchValue) <= -1) {
tree.splice(i, 1)
this.expandedKeys.push(e2.key)
}
}
this.gData = [...tree]
}
},
searchEach (node, value) {
const depth = this.getTreeDepth(node)
const self = this
for (let i = 0; i < depth - 1; i++) {
let spliceCounter = 0
this.traverseTree(node, n => {
if (self.isHasChildren(n)) {
const children = n.children
const length = children.length
for (let j = length - 1; j >= 0; j--) {
const e3 = children[j]
if (!self.isHasChildren(e3) && e3.title.indexOf(value) <= -1) {
children.splice(j, 1)
spliceCounter++
} else {
this.expandedKeys.push(e3.key)
}
}
}
})
if (spliceCounter === 0) {
break
}
}
},
// 判断树形结构中的一个节点是否具有孩子节点
isHasChildren (node) {
let flag = false
if (node.children && node.children.length > 0) {
flag = true
}
return flag
},
// 通过传入根节点获得树的深度
getTreeDepth (node) {
if (undefined === node || node === null) {
return 0
}
let r = 0
let currentLevelNodes = [node]
while (currentLevelNodes.length > 0) {
r++
let nextLevelNodes = []
for (let i = 0; i < currentLevelNodes.length; i++) {
const e = currentLevelNodes[i]
if (this.isHasChildren(e)) {
nextLevelNodes = nextLevelNodes.concat(e.children)
}
}
currentLevelNodes = nextLevelNodes
}
return r
},
traverseTree (node, callback) {
if (!node) {
return
}
const stack = []
stack.push(node)
let tmpNode
while (stack.length > 0) {
tmpNode = stack.pop()
callback(tmpNode)
if (tmpNode.children && tmpNode.children.length > 0) {
for (let i = tmpNode.children.length - 1; i >= 0; i--) {
stack.push(tmpNode.children[i])
}
}
}
}
},
beforeDestroy () {