import { Injectable } from '@angular/core'; import { Store } from './store'; import { Log } from '../utils/log' const log = new Log('AppBase'); @Injectable() export class AppBase { constructor( public store:Store ) { } getOpenTimes = () => { return this.store.get('openTimes').then((openTimes)=>{ openTimes = openTimes || 0; return openTimes; }); } setOpenTimes = (openTimes) => { return this.store.set('openTimes',openTimes); } // 应用启动计数(只执行一次) openCountOnce = () => { return this.getOpenTimes().then((openTimes:number)=>{ openTimes += 1; // 打开次数加1 log.info('openTimes',openTimes,true); return this.setOpenTimes(openTimes); }) } // 是否是第一次打开,必须先执行openCountOnce isFirstOpen = () => { return this.getOpenTimes().then((openTimes:number)=>{ return openTimes <= 1; }) } }