当前位置:网站首页>Set lazy loading and default tick for El tree
Set lazy loading and default tick for El tree
2022-07-22 14:01:00 【Ride my beloved little motorcycle】
- load tree Tree time , It is required to be able to lazy load by clicking to view more , And you can check the check box to get data , Because there are many interfaces Tree Trees , So name multiple ref Values are passed into the subcomponent Tree Inside the tree
<DsmasTreeLoadMore
ref="dataStructure"
:show-checkbox="true"
:bind-ref="{label: ' Structured data ',id: 'dataStructure'}"
/>
<script>
import DsmasTreeLoadMore from '@/views/components/dsmas-tree-loadmore';
export default {
components: {
DsmasTreeLoadMore
}
data(){
return{
defaultProps: {
label: 'label',
children: 'children',
isLeaf: 'leaf'
},
pageNumber: 1,
pageSize: 10,
complete: false,
defaultCheckedKeys: [],
treeData: {
dataStructure: [
{
label: ' Structured data ',
id: 'dataStructure',
children: [],
disabled: true
}
],
dataUnstructure: [
{
label: ' Unstructured data ',
id: 'dataUnstructure',
children: [],
disabled: true
}
],
collapse:false
}
},
created() {
this.getTreeLoadmore();
},
methods: {
// See more buttons
loadmore() {
++this.pageNumber;
this.getTreeLoadmore();
},
async getTreeLoadmore() {
let ref = this.bindRef.id; let resultData = ''; let treeData = [];
if (ref === 'dataStructure') {
resultData = await getDistributeDatasource({
pageNumber: this.pageNumber, pageSize: this.pageSize, structured: true});
treeData = resultData.data.items.map(({
id, name: label}) => {
return {
id, label};
});
} else if (ref === 'dataUnstructure') {
resultData = await getDistributeDatasource({
pageNumber: this.pageNumber, pageSize: this.pageSize, structured: false});
treeData = resultData.data.items.map(({
id, name: label}) => {
return {
id, label};
});
}
this.treeData[ref][0].children = this.treeData[ref][0].children.concat(treeData);
// First load the selected top ten storage and query data
let storage = this.getStorageMethod(this.bindRef.id); let setChecked = [];
if (storage) {
setChecked = storage;
} else {
setChecked = treeData.map(({
id}) => {
return id;
});
}
this.$nextTick(() => {
this.$refs[ref].setCheckedKeys(setChecked);
});
this.defaultCheckedKeys = setChecked;
// Data loaded
if (this.treeData[ref][0].children.length >= resultData.data.total) {
this.complete = true;
}
},
// Take out the current ref Corresponding cache
getStorageMethod(ref) {
let paramObj = getStorage('distribute');
if (paramObj) {
if (ref === 'dataStructure' && paramObj.dataStructure) {
return paramObj.dataStructure;
} else if (ref === 'dataUnstructure' && paramObj.dataUnstructure) {
return paramObj.dataUnstructure;
}
}
},
// Check interface aggregation
handleCheck(data, checked) {
let checkedNode = this.$refs[this.bindRef.id].getNode(data.id).checked;
let storage = this.getStorageMethod(this.bindRef.id);
if (storage) {
if (checkedNode) {
storage.push(data.id);
} else {
storage.splice(storage.findIndex(item => item === data.id), 1);
}
} else {
storage = checked.checkedKeys;
}
this.defaultCheckedKeys = storage;
this.$refs[this.bindRef.id].setCheckedKeys(storage);
this.$forceUpdate();
let storageFormal = getStorage('distribute');
storageFormal[this.bindRef.id] = storage;
setStorage('distribute', storageFormal);
},
// Node expansion
handleNodeExpand() {
this.collapse = true;
},
// Node shutdown
handleNodeCollapse() {
this.collapse = false;
// Eliminate all child nodes of the current node The filter node closes the current node and is its child , Then no assignment will be made
// this.defaultExpandKeys = this.defaultExpandKeys.filter((x) => (![data.id].some((item) => x === item) && !(x.indexOf(data.id) > -1)));
},
handleNodeClick(node) {
this.$emit('handleNodeClick', {
id: node.id, label: node.label});
}
}
</script>
- At present Tree Trees , The default is a two-tier structure , So there's no need to use loadmore A native method , Here, the data is directly spliced , The query interface data is transferred into the second layer data , At present , When turning to the second page , By default, the second page is not checked , When the user checks, the page turning effect will not be affected
<div class="tree-load">
<el-tree
:ref="bindRef.id"
class="treeDom"
:data="treeData[bindRef.id]"
default-expand-all
show-checkbox
node-key="id"
:expand-on-click-node="false"
:default-checked-keys="defaultCheckedKeys"
:props="defaultProps"
@node-expand="handleNodeExpand"
@node-collapse="handleNodeCollapse"
@check="handleCheck"
>
<div slot-scope="{ node,data }" class="custom-tree-node">
<el-tooltip
class="item"
effect="light"
placement="right-start"
>
<div slot="content" style="max-width: 300px;">
{
{
node.label }}
</div>
<span v-if="data.id !=='loadmore'" class="span-tree-node">{
{
node.label }}</span>
</el-tooltip>
</div>
</el-tree>
<el-link
v-if="!complete && collapse"
:underline="false"
class="tree-more"
@click="loadmore"
>
To view more
</el-link>
</div>
边栏推荐
- Error: your local changes to the following files would be overwritten by merge:xxxx
- 生信常用分析图形绘制 -- 各种类型的热图!你学会了吗?
- Usage scenarios of stale read function
- OpenCV 常用的API总结(迅速查询)
- 透过Redis源码探究Hash表的实现
- PyTorch(四)——PyTorch模型定义
- c语言进阶篇:数据的存储(浮点型)
- Research on autojs wechat: many tests have found that occasionally click() returned true, but it did not click successfully, such as "address book" (solved)
- [ManageEngine] seven ways to strengthen the security of enterprise privileged access
- 灰色关联分析
猜你喜欢
易基因 | 简化基因组DNA甲基化测序(RRBS)实验怎么做?
[interpretation of kitex source code] kitex extensibility design idea
Idea décompile toute la source du paquet jar
寻找斐波那契数
torch.jit.trace与torch.jit.script的区别
Live review | wonderful playback of Apache pulsar meetup (including PPT download)
Interview project preparation | how to show the project to the interviewer?
FAST-LIO2: 快速且直接的激光雷达与惯导里程计
基于SSM+JSP+MYSQL+H-UI 实现的火锅店点餐系统
最终一致性性分布式事务 TCC
随机推荐
正则 删除特定字符后面所有的元素(不区分大小写)
JUC synchronization
Which pits of BigDecimal precision
Advanced architects, 16 common principles of microservice design and Governance
Seektiger's okaleido has a big move. Will the STI of ecological pass break out?
谈谈程序员如何提高自己的写作能力
How to choose sentinel vs. hystrix current limiting?
Android 面试题:说一下 PendingIntent 和 Intent 的区别
Do you have to follow flush privileges after MySQL grant?
JUC concurrent contracting
Load and display the label information of raincityspaces
cookie和seesion的区别和联系
微服务高可用的两个关键技巧,你一定用得上
Best practices for three node hybrid deployment
Interview project preparation | how to show the project to the interviewer?
【带你上手云原生体系】第四部分:Kubernetes从入门到精通
Mass region cluster tuning best practices
Win10 registry of the nth reinstallation of the system
Interview reply 4
[interpretation of kitex source code] kitex extensibility design idea