fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
2.8 KiB

import { Listasynctree } from "./listasynctree";
import { shortcut, extend, Events, delay } from "@/core";
import { TreeView } from "../treeview";
import $ from "jquery";
/**
* guy
* 局部树,两个请求树, 第一个请求构造树,第二个请求获取节点
* @class ListPartTree
* @extends AsyncTree
*/
@shortcut()
export class ListPartTree extends Listasynctree {
static xtype = "bi.list_part_tree";
_loadMore() {
const self = this,
o = this.options;
const op = extend({}, o.paras, {
type: TreeView.REQ_TYPE_INIT_DATA,
times: ++this.times,
});
this.tip.setLoading();
o.itemsCreator(op, d => {
const hasNext = !!d.hasNext,
nodes = d.items || [];
o.paras.lastSearchValue = d.lastSearchValue;
if (self._stop === true) {
return;
}
if (!hasNext) {
self.tip.setEnd();
} else {
self.tip.setLoaded();
}
if (nodes.length > 0) {
self.nodes.addNodes(null, self._dealWidthNodes(nodes));
}
});
}
_initTree(setting, keyword) {
const self = this,
o = this.options;
this.times = 1;
const tree = this.tree;
tree.empty();
self.tip.setVisible(false);
this.loading();
const op = extend({}, o.paras, {
type: TreeView.REQ_TYPE_INIT_DATA,
times: this.times,
});
function complete(d) {
if (self._stop === true || keyword !== o.paras.keyword) {
return;
}
const hasNext = !!d.hasNext,
nodes = d.items || [];
o.paras.lastSearchValue = d.lastSearchValue;
// 没有请求到数据也要初始化空树, 如果不初始化, 树就是上一次构造的树, 节点信息都是过期的
callback(nodes.length > 0 ? self._dealWidthNodes(nodes) : []);
self.setTipVisible(nodes.length <= 0);
self.loaded();
if (!hasNext) {
self.tip.invisible();
} else {
self.tip.setLoaded();
}
self.fireEvent(Events.AFTERINIT);
}
function callback(nodes) {
if (self._stop === true) {
return;
}
self.nodes = $.fn.zTree.init(tree.element, setting, nodes);
}
delay(() => {
o.itemsCreator(op, complete);
}, 100);
}
// 生成树方法
stroke(config) {
const o = this.options;
delete o.paras.keyword;
extend(o.paras, config);
delete o.paras.lastSearchValue;
const setting = this._configSetting();
this._initTree(setting, o.paras.keyword);
}
}