feat: 支持通关字段上报
This commit is contained in:
@@ -243,6 +243,13 @@ export class PageWriteLevels extends BaseView {
|
||||
|
||||
// 设置默认名称和选中状态(封面由 _loadAndRefreshCover 异步填充)
|
||||
this._initItemState(item, index);
|
||||
|
||||
// 禁用 Button 组件,防止它拦截触摸事件导致 ScrollView 无法滑动
|
||||
const button = item.getComponent(Button);
|
||||
if (button) {
|
||||
button.enabled = false;
|
||||
}
|
||||
|
||||
this._setupItemClick(item, index);
|
||||
|
||||
return item;
|
||||
@@ -323,14 +330,32 @@ export class PageWriteLevels extends BaseView {
|
||||
}
|
||||
|
||||
private _setupItemClick(item: Node, index: number): void {
|
||||
// 只用 Button click 统一处理选中/取消,避免 Toggle 事件与 Button 事件同时触发导致双重调用
|
||||
const button = item.getComponent(Button);
|
||||
if (button) {
|
||||
button.node.on(Button.EventType.CLICK, () => {
|
||||
// 用触摸事件代替 Button,区分点击和滑动:
|
||||
// 短距离松手 = 点击(切换选中),长距离 = 滑动(交给 ScrollView)
|
||||
let touchStartPos: Vec2 | null = null;
|
||||
|
||||
item.on(Node.EventType.TOUCH_START, (event: EventTouch) => {
|
||||
touchStartPos = event.getUILocation();
|
||||
}, this);
|
||||
|
||||
item.on(Node.EventType.TOUCH_END, (event: EventTouch) => {
|
||||
if (!touchStartPos) return;
|
||||
const endPos = event.getUILocation();
|
||||
const dx = endPos.x - touchStartPos.x;
|
||||
const dy = endPos.y - touchStartPos.y;
|
||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||
touchStartPos = null;
|
||||
|
||||
// 滑动距离小于阈值才算点击
|
||||
if (distance < 20) {
|
||||
const isCurrentlySelected = this._selectedIndices.has(index);
|
||||
this._onItemToggle(index, !isCurrentlySelected);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
item.on(Node.EventType.TOUCH_CANCEL, () => {
|
||||
touchStartPos = null;
|
||||
}, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user