|
|
@@ -40,17 +40,20 @@ export default class TableView extends cc.Component {
|
|
|
private count: number = 0;
|
|
|
private itemCanMoveDown: boolean = null;
|
|
|
private itemCanMoveUp: boolean = null;
|
|
|
+
|
|
|
onLoad() {
|
|
|
this.initPro();
|
|
|
- let itemData = [];
|
|
|
- for (let i = 0; i < 20; i++) {
|
|
|
- let test_data = {
|
|
|
- pfbType: 0,
|
|
|
- }
|
|
|
- itemData.push(test_data);
|
|
|
- }
|
|
|
- this.init(itemData);
|
|
|
+ // 测试
|
|
|
+ // let itemData = [];
|
|
|
+ // for (let i = 0; i < 20; i++) {
|
|
|
+ // let test_data = {
|
|
|
+ // pfbType: 0,
|
|
|
+ // }
|
|
|
+ // itemData.push(test_data);
|
|
|
+ // }
|
|
|
+ // this.init(itemData);
|
|
|
}
|
|
|
+
|
|
|
private initPro() {
|
|
|
this.scrollView = this.node.getComponent(cc.ScrollView);
|
|
|
this.content = this.scrollView.content;
|
|
|
@@ -61,12 +64,9 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
this.node.on('srollview-init', this.init, this);
|
|
|
}
|
|
|
- //itemData是item数据,itemPosMap是滚动条滚动时要用到的item位置数据.
|
|
|
+
|
|
|
/**
|
|
|
* @param itemData 列表数据
|
|
|
- * @param scrollView 滑动组件
|
|
|
- * @param item 预制体组
|
|
|
- * @param itemInterval 间隔
|
|
|
* @param isSkipInit 跳过初始化
|
|
|
* @returns
|
|
|
*/
|
|
|
@@ -76,12 +76,6 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
|
|
|
this.itemData = itemData; //item数据
|
|
|
- // this.scrollView = scrollView;
|
|
|
- // this.item = item;
|
|
|
- // this.itemInterval = itemInterval || 0; //间距
|
|
|
- // 初始化各类属性
|
|
|
- // this.content = this.scrollView.content;
|
|
|
- // this.layerHeight = this.scrollView.node.height;
|
|
|
this.firstItemIndex = 0;
|
|
|
this.lastItemIndex = 0;
|
|
|
this.firstItemData = {};
|
|
|
@@ -101,7 +95,9 @@ export default class TableView extends cc.Component {
|
|
|
this.scrollView.node.on('scrolling', this.callback, this);
|
|
|
// cc.log('tableView结束:' + this.testTime());
|
|
|
}
|
|
|
- /** 刷新列表
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新列表
|
|
|
* 仅更新data数据
|
|
|
*/
|
|
|
private updateList() {
|
|
|
@@ -126,6 +122,7 @@ export default class TableView extends cc.Component {
|
|
|
this.updateContentHeigh(this.itemPosMap.get(item_data_count - 1).endPos);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 实例化所有用到的item,控制实例化item的数目,暂定超出两个
|
|
|
*/
|
|
|
@@ -146,6 +143,7 @@ export default class TableView extends cc.Component {
|
|
|
this.updateContentHeigh(this.itemArr[i].height - y);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 添加条目节点
|
|
|
* @param i 编号
|
|
|
@@ -169,6 +167,7 @@ export default class TableView extends cc.Component {
|
|
|
this.itemArr.push(item);
|
|
|
// cc.log('生成itemNode' + i);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 更新centent高
|
|
|
* @param num
|
|
|
@@ -177,6 +176,7 @@ export default class TableView extends cc.Component {
|
|
|
this.content.height = num > this.layerHeight ? num : this.layerHeight;
|
|
|
// cc.log('滚动条高度:', this.content.height);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 触摸滚动条的函数回调
|
|
|
* @param event
|
|
|
@@ -246,6 +246,7 @@ export default class TableView extends cc.Component {
|
|
|
private updateItemIndex() {
|
|
|
//cc.log(this.firstItemIndex, this.lastItemIndex, this.itemArr, this.itemData)
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 得到滚动条此时状态下应有的itemNode元素,包括滚动条上方一个,滚动条下方一个
|
|
|
* @returns
|
|
|
@@ -273,6 +274,7 @@ export default class TableView extends cc.Component {
|
|
|
})
|
|
|
return arr;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 滚动到顶部【滚动条顺序是从上到下开始遍历】
|
|
|
* @param num
|
|
|
@@ -287,8 +289,8 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
num++;
|
|
|
return this.itemMoveUp(num);
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
/** 滚动到底部 */
|
|
|
private itemMoveDown(num: number) {
|
|
|
if (num < 0 || this.firstItemIndex - 1 > num || num + 1 > this.itemData.length) {
|
|
|
@@ -299,8 +301,8 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
num--;
|
|
|
return this.itemMoveDown(num);
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 判断指定index位置是否存在itemNode
|
|
|
* @param index 节点下标
|
|
|
@@ -314,6 +316,7 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 移动条目
|
|
|
* 逻辑判断,第一种情况,修改itemArr数组的某个对象,第二种情况实例化一个新itemNode
|
|
|
@@ -340,6 +343,7 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
this.addItemNode(index, y);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 得到相关位置的排序index
|
|
|
* 方法待验证,可能有问题
|
|
|
@@ -384,6 +388,7 @@ export default class TableView extends cc.Component {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 清理条目
|
|
|
*/
|
|
|
@@ -398,6 +403,7 @@ export default class TableView extends cc.Component {
|
|
|
this.itemArr[i].destroy();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 删除指定条目
|
|
|
* @param i 节点.index
|
|
|
@@ -425,6 +431,7 @@ export default class TableView extends cc.Component {
|
|
|
if (!this.lastItemIndex) this.getItemIndex();// 初始化时没有初始化此值,会导致为0.不能创建新的item,此处校验
|
|
|
this.itemMoveUp(this.firstItemIndex);//
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 重置指定item
|
|
|
* @param index 节点下标
|