import { Injectable } from '@angular/core'; import { Store } from './store'; @Injectable() export class AppOpen { constructor( public store:Store ) { } // 获取app打开次数 getTimes = () => { return this.store.get('openTimes').then((openTimes)=>{ openTimes = openTimes || 0; return openTimes; }); } // 设置app打开次数 setTimes = (openTimes) => { return this.store.set('openTimes',openTimes); } // 增加启动次数 addOnce = () => { return this.getTimes().then((openTimes:number)=>{ openTimes += 1; // 打开次数加1 return this.setTimes(openTimes); }); } // 是否是第一次打开,必须先执行openCountOnce isFirst = () => { return this.getTimes().then((openTimes:number)=>{ return openTimes == 1; }); } }