提交 dbde0b42 编写于 作者: tony001's avatar tony001

优化列表逻辑

上级 c7c6559f
......@@ -405,6 +405,7 @@ import CodeListService from "@/codelist/codelist-service";
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public afterMounted () {
const loadMoreCallBack:any = this.throttle(this.loadMore,3000);
this.$el.addEventListener('scroll', ()=> {
if(this.$el.scrollHeight > this.$el.clientHeight) {
this.isScrollBar = true;
......@@ -412,7 +413,7 @@ import CodeListService from "@/codelist/codelist-service";
this.isScrollBar = false;
}
if( this.$el.scrollTop + this.$el.clientHeight >= this.$el.scrollHeight) {
this.loadMore();
loadMoreCallBack();
}
})
}
......@@ -437,8 +438,13 @@ import CodeListService from "@/codelist/codelist-service";
if (!Object.is(this.name, tag)) {
return;
}
if (Object.is(action,'load') || Object.is(action,'refresh')) {
this.refresh(data)
if (Object.is(action,'load'))) {
this.curPage = 1;
this.items = [];
this.load(data);
}
if (Object.is(action,'refresh')) {
this.refresh(data);
}
});
}
......@@ -486,8 +492,7 @@ import CodeListService from "@/codelist/codelist-service";
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public loadMore(){
if(this.totalRecord>this.items.length)
{
if(this.totalRecord>this.items.length){
this.curPage = ++this.curPage;
this.isAddBehind = true;
this.load({});
......@@ -501,7 +506,7 @@ import CodeListService from "@/codelist/codelist-service";
* @memberof Main
*/
public refresh(args?: any) {
this.curPage = 1;
this.isAddBehind = true;
this.load(args);
}
......@@ -548,13 +553,14 @@ import CodeListService from "@/codelist/codelist-service";
if(!this.isAddBehind){
this.items = [];
}
if (Object.keys(data).length > 0) {
if (data && data.length > 0) {
let datas = JSON.parse(JSON.stringify(data));
datas.map((item: any) => {
Object.assign(item, { isselected: false });
});
this.totalRecord = response.total;
this.items.push(...datas);
this.items = this.arrayNonRepeatfy(this.items);
}
this.isAddBehind = false;
this.$emit('load', this.items);
......@@ -582,6 +588,44 @@ import CodeListService from "@/codelist/codelist-service";
});
}
/**
* 列表数据去重
*
* @param {Array<any>} [arr]
* @returns {void}
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public arrayNonRepeatfy(arr:Array<any>) {
let map = new Map();
let array = new Array();
for (let i = 0; i < arr.length; i++) {
map .set(arr[i].srfkey, arr[i]);
}
map.forEach((value:any, key:string, map:any) => {
array.push(value);
});
return array ;
}
/**
* 节流
*
* @param {Array<any>} [arr]
* @returns {void}
* @memberof ${srfclassname('${ctrl.codeName}')}Base
*/
public throttle(fn:any, wait:number){
let time = 0;
return () =>{
let now = Date.now()
let args = arguments;
if(now - time > wait){
fn.apply(this, args)
time = now;
}
}
}
/**
* 删除
*
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册