前提
- ionic 5.4.13
- @ionic/storageはインストール済み
- welcome pageのパスはfirstとします
- ホームのパスはhomeとします
実装
app.component.ts
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { Router } from '@angular/router';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Storage } from '@ionic/storage';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent {
params: any;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private storage: Storage,
private _router: Router,
) {
this.initializeApp();
}
async initializeApp() {
await this.platform.ready().then(() => {
try {
this.storage.get('Welcomeslides').then((val) => {
if (!val) {
this._router.navigate(['/first']);
}
});
} catch {
this._router.navigate(['/first']);
}
this.statusBar.styleDefault();
this.splashScreen.hide();
};
}
(ストレージにWelcomeslidesの血がセットされていない場合に/firstに移動します..)
first.page.ts(作成した任意のpage)
import { Component, OnInit } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Router } from '@angular/router';
@Component({
selector: 'app-first',
templateUrl: './first.page.html',
styleUrls: ['./first.page.scss'],
})
export class FirstPage implements OnInit {
isenabled: any;
constructor(public _router:Router,public storage:Storage) { }
async ngOnInit() {
try {
this.storage.get('Welcomeslides').then((val) => {
if (val) {
this._router.navigate(['/home']);
}
});
} catch {
console.log("err");
}
}
/*ここから下は任意で...*/
policy(ev) {
console.log("policy");
if (ev["detail"]["checked"]) {
console.log("checked");
this.isenabled = true;
} else {
console.log("unchecked");
this.isenabled = false;
}
}
async btnclick() {
console.log("BTN CLICK");
await this.storage.set('tutorialComplete', 'true');
this._router.navigate(['/tabs']);
}
}
first.page.html
(サンプル)
<style>
:root {
--ion-safe-area-top: 20px;
--ion-safe-area-bottom: 22px;
}
.btnR {
position: absolute;
left: 10px;
bottom: 10px;
right: 10px;
--color-activated: #fff;
}
.btd{
position:absolute;
width: 100%;
height:35%;
left: 0px;
right: 0px;
border-radius: 20px 20px 0px 0px;
bottom: 0px;
background: #5797ff;
}
ion-slides{
position: absolute;
height: 55%;
width: 100%;
left: 0px;
right: 0px;
}
.swiper-slide{
width: 80%;
}
.swiper-pagination{
position: absolute;
left: 10px;
bottom: 100px;
right: 10px;
}
.btn2 {
position: absolute;
left: 10px;
bottom: 70px;
right: 10px;
}
.swiper-slide {
display: block;
}
ion-slide > h2 {
margin-top: 2.8rem;
}
ion-slide > img {
max-height: 50%;
max-width: 60%;
margin: 36px 0;
}
</style>
<ion-header>
<ion-toolbar>
<ion-title>ようこそ!</ion-title>
</ion-toolbar>
</ion-header>
<ion-content fullscreen padding scroll-y="false">
<ion-slides pager>
<ion-slide>
<img src="./slide-1.png"/>
<h2>hogeをインストールしていただきありがとうございます。</h2>
<p>ホゲホゲフガフガ〜〜〜</p>
</ion-slide>
<ion-slide>
<img src="./slide-2.png"/>
<h2>ほげ〜</h2>
<p>ホゲホゲフガフガ〜</p>
</ion-slide>
</ion-slides>
<div class="btd">
<ion-item class="btn2">
<ion-label style="color: #ffffff;"><a style="color: #fff;" href="http://sz.gov.cn">利用規約</a>に同意する</ion-label>
<ion-checkbox color="light" (ionChange)="policy($event)"></ion-checkbox>
</ion-item>
<ion-button (click)="btnclick()" color="light" style="border: #fff; color: #fff;" class="btnR" [disabled]="!isenabled" fill="outline">始める<ion-icon slot="end" name="arrow-forward"></ion-icon></ion-button>
</div>
</ion-content>