2021-07-22 03:34:17 +08:00
|
|
|
import { isArray, arrayLength } from 'Common/Utils';
|
2021-03-16 23:49:14 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export class AbstractScreen {
|
|
|
|
constructor(screenName, viewModels = []) {
|
2021-09-23 02:17:44 +08:00
|
|
|
this.__cross = null;
|
|
|
|
this.screenName = screenName;
|
|
|
|
this.viewModels = isArray(viewModels) ? viewModels : [];
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {?Array)}
|
|
|
|
*/
|
|
|
|
routes() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-23 02:17:44 +08:00
|
|
|
/*
|
|
|
|
onBuild(viewModelDom) {}
|
|
|
|
onShow() {}
|
|
|
|
onHide() {}
|
|
|
|
__started
|
|
|
|
__builded
|
|
|
|
*/
|
2016-07-07 07:11:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-01-27 07:26:31 +08:00
|
|
|
onStart() {
|
2022-03-08 07:51:32 +08:00
|
|
|
const routes = this.routes();
|
|
|
|
if (arrayLength(routes)) {
|
|
|
|
let route = new Crossroads(),
|
|
|
|
fMatcher = (this.onRoute || (()=>0)).bind(this);
|
2021-01-27 07:26:31 +08:00
|
|
|
|
2022-09-08 16:07:27 +08:00
|
|
|
routes.forEach(item => item && (route.addRoute(item[0], fMatcher).rules = item[1]));
|
2021-01-27 07:26:31 +08:00
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
this.__cross = route;
|
2016-07-07 07:11:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|