UNPKG

@fengxi/ui-framework

Version:

Cocos Creator UI框架库 类似鸿蒙的UI框架

46 lines (45 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RouterManager = void 0; const SingletonMixin_1 = require("../base/SingletonMixin"); const Index_1 = require("../Index"); const MAX_LENGTH = 24; class RouterManager extends SingletonMixin_1.SingletonMixin { constructor() { super(...arguments); this.pageStack = []; } static get Instance() { return super.getInstance(); } /** * 添加页面, 如果页面栈长度大于最大长度,则移除最前面的页面, TODO 待实现动画 */ push(param, animation) { if (this.pageStack.length >= MAX_LENGTH) { // 将第二个页面移出,保留首页 this.pageStack.splice(1, 1); } this.pageStack.push([param.uri, param]); Index_1.UIManager.Instance.changeCurrentPage(param.uri, false); } /** * 替换页面, TODO 待实现动画 */ replace(param, animation) { } /** * 返回上一个页面 */ back() { } /** * 获取页面路由参数 * @template T - 参数类型(必须为对象类型) * @returns 路由参数对象,当不存在时返回空对象 */ getRouterParam() { var _a, _b; const lastPage = (_b = (_a = this.pageStack) === null || _a === void 0 ? void 0 : _a[this.pageStack.length - 1]) === null || _b === void 0 ? void 0 : _b[1]; return (lastPage === null || lastPage === void 0 ? void 0 : lastPage.params) ? { ...lastPage.params } : {}; } } exports.RouterManager = RouterManager;