Files
mp-xieyingeng/assets/prefabs/PageHome.ts
2026-04-06 11:04:09 +08:00

95 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { _decorator, Node, Button } from 'cc';
import { BaseView } from 'db://assets/scripts/core/BaseView';
import { ViewManager } from 'db://assets/scripts/core/ViewManager';
import { WxSDK } from 'db://assets/scripts/utils/WxSDK';
const { ccclass, property } = _decorator;
/**
* 首页组件
* 继承 BaseView实现页面生命周期
*/
@ccclass('PageHome')
export class PageHome extends BaseView {
@property({ type: Node, tooltip: '开始游戏按钮' })
startGameBtn: Node | null = null;
@property({ type: Node, tooltip: 'PK按钮' })
pkBtn: Node | null = null;
/**
* 页面首次加载时调用
*/
onViewLoad(): void {
console.log('[PageHome] onViewLoad');
this._initButtons();
this._initWxShare();
}
/**
* 初始化微信分享功能
*/
private _initWxShare(): void {
WxSDK.initShare({
title: '写英语',
imageUrl: '',
query: ''
});
}
/**
* 初始化按钮事件
*/
private _initButtons(): void {
if (this.startGameBtn) {
this.startGameBtn.on(Button.EventType.CLICK, this._onStartGameClick, this);
}
if (this.pkBtn) {
this.pkBtn.on(Button.EventType.CLICK, this._onPkClick, this);
}
}
/**
* 开始游戏按钮点击回调
*/
private _onStartGameClick(): void {
console.log('[PageHome] 开始游戏按钮点击');
ViewManager.instance.open('PageLevel');
}
/**
* PK按钮点击回调
*/
private _onPkClick(): void {
console.log('[PageHome] PK按钮点击');
ViewManager.instance.open('PageWriteLevels');
}
/**
* 页面每次显示时调用
*/
onViewShow(): void {
console.log('[PageHome] onViewShow');
}
/**
* 页面隐藏时调用
*/
onViewHide(): void {
console.log('[PageHome] onViewHide');
}
/**
* 页面销毁时调用
*/
onViewDestroy(): void {
console.log('[PageHome] onViewDestroy');
// 移除按钮事件监听
if (this.startGameBtn) {
this.startGameBtn.off(Button.EventType.CLICK, this._onStartGameClick, this);
}
if (this.pkBtn) {
this.pkBtn.off(Button.EventType.CLICK, this._onPkClick, this);
}
}
}