为什么先点击treeNodeClicked方法添加节点,在input的值不为空走treeSearch方法,在走treeSearch的else方法,checkedCities会变成ture<el-input placeholder="输入用户姓名/手机号/部门名称" v-model="filterText" @keyup.enter.native="treeSearch" clearable> <i slot="suffix" class="el-input__icon el-icon-search" @click="treeSearch"></i> </el-input> <el-tree v-if="type === 'intersection'" :data="orgaData" icon-class="-" @node-click="treeNodeClicked" :default-expanded-keys="keys" node-key="realId" :props="defaultProps" highlight-current :filter-node-method="filterNode" v-loading="loading"> <span class="custom-tree-node" slot-scope="{ data, node }"> <span v-if="data.nodeType == 2"> <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange"> <el-checkbox :key="data.realId" :label="data" :checked="checkStatusIds.includes(data.realId)" :disabled="!defOrg.includes(data.parentNodeId) || checkStatusIds.includes(data.realId)"> <img v-if="data.sex == 2" src="@/assets/images/girl1.png" alt="" /> <img v-else-if="data.sex == 1" src="@/assets/images/boy1.png" alt="" /> <img v-else src="@/assets/images/peoper.png" alt="" /> {{ data.nodeName }} </el-checkbox> </el-checkbox-group> </span> <span v-else> <i style="margin-left: 5px" :class="node.expanded ? 'el-icon-caret-bottom' : 'el-icon-caret-right'" v-if="data.memberCount || data.childrens.length"></i> <i style="margin-left: 22px" v-else></i> {{ data.nodeName }} </span> </span> </el-tree> async treeSearch() { let res = await getTreeUser({ nickname: this.filterText }) if (this.filterText) { this.orgaData = res.data.data.orgTreeNodeDTOS } else { this.orgaData = this.copyOrgaData } console.log(res) }, async treeNodeClicked(data, node) { if (this.filterText) { console.log(1) return } let res = await getDepartmentUsers(data.realId) if (data.nodeType == 2) return if (!data.memberCount) return if (!this.onceClickIds.includes(data.realId)) { console.log(2) this.onceClickIds.push(data.realId) data.childrens.push(...res.data.data) this.keys = [data.realId] } }
时间: 2023-06-13 18:08:44 浏览: 165
根据你提供的代码,我看到在点击节点时,会调用treeNodeClicked方法添加节点。当输入框的值不为空时,会调用treeSearch方法进行搜索。在treeSearch方法中,如果输入框的值不为空,会将搜索结果赋值给orgaData,否则将copyOrgaData赋值给orgaData。在treeNodeClicked方法中,如果当前节点的节点类型为2(即用户节点),则直接返回,如果当前节点的成员数为0,则也直接返回。如果当前节点已经被点击过,则直接返回,否则将当前节点的成员信息添加到节点的childrens中。
另外,如果checkedCities变成true是因为在el-checkbox上绑定了v-model为checkedCities,当checkbox被选中时,checkedCities的值就会变成true。
阅读全文