Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.30 KB | None | 0 0
  1. app
  2.  
  3. app.component.ts
  4.  
  5. import { Component, ViewChild } from '@angular/core';
  6. import { Nav, Platform } from 'ionic-angular';
  7. import { StatusBar } from '@ionic-native/status-bar';
  8. import { SplashScreen } from '@ionic-native/splash-screen';
  9.  
  10. import { HomePage } from '../pages/home/home';
  11. import { ListPage } from '../pages/list/list';
  12. import { AboutPage } from '../pages/about/about';
  13. import { LoginPage } from '../pages/login/login';
  14. import { PhotoPage } from '../pages/photo/photo';
  15.  
  16. @Component({
  17.   templateUrl: 'app.html'
  18. })
  19. export class MyApp {
  20.   @ViewChild(Nav) nav: Nav;
  21.  
  22.   rootPage: any = LoginPage;
  23.  
  24.   pages: Array<{title: string, component: any}>;
  25.  
  26.   constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
  27.     this.initializeApp();
  28.  
  29.     // used for an example of ngFor and navigation
  30.     this.pages = [
  31.       { title: 'หน้าแรก', component: HomePage },
  32.       { title: 'ผลการเรียน', component: ListPage },
  33.       {title: 'ถ่ายรูป', component: PhotoPage },
  34.       {title: 'เกียวกับ', component: AboutPage}
  35.     ];
  36.  
  37.   }
  38.  
  39.   initializeApp() {
  40.     this.platform.ready().then(() => {
  41.       // Okay, so the platform is ready and our plugins are available.
  42.       // Here you can do any higher level native things you might need.
  43.       this.statusBar.styleDefault();
  44.       this.splashScreen.hide();
  45.     });
  46.   }
  47.  
  48.   openPage(page) {
  49.     // Reset the content nav to have just this page
  50.     // we wouldn't want the back button to show in this scenario
  51.     this.nav.setRoot(page.component);
  52.   }
  53. }
  54. ------------------------------------------
  55.  
  56. app.html
  57.  
  58. <ion-menu [content]="content">
  59.   <ion-header>
  60.     <ion-toolbar>
  61.       <ion-title>เลือกเมนู</ion-title>
  62.     </ion-toolbar>
  63.   </ion-header>
  64.  
  65.   <ion-content>
  66.     <ion-list>
  67.       <button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
  68.         {{p.title}}
  69.       </button>
  70.     </ion-list>
  71.   </ion-content>
  72.  
  73. </ion-menu>
  74.  
  75. <!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
  76. <ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
  77. ---------------------------------------------------
  78. app.module.ts
  79.  
  80. import { BrowserModule } from '@angular/platform-browser';
  81. import { ErrorHandler, NgModule } from '@angular/core';
  82. import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
  83.  
  84. import { MyApp } from './app.component';
  85. import { HomePage } from '../pages/home/home';
  86. import { ListPage } from '../pages/list/list';
  87. import { Camera } from '@ionic-native/camera';
  88.  
  89. import { StatusBar } from '@ionic-native/status-bar';
  90. import { SplashScreen } from '@ionic-native/splash-screen';
  91. import { AboutPage } from '../pages/about/about';
  92. import { LoginPage } from '../pages/login/login';
  93. import { RegisterPage } from '../pages/register/register';
  94. import { PhotoPage } from '../pages/photo/photo';
  95.  
  96. @NgModule({
  97.  declarations: [
  98.    MyApp,
  99.    HomePage,
  100.    ListPage,
  101.    AboutPage,
  102.    LoginPage,
  103.    RegisterPage,
  104.    PhotoPage
  105.  ],
  106.  imports: [
  107.    BrowserModule,
  108.    IonicModule.forRoot(MyApp),
  109.  ],
  110.  bootstrap: [IonicApp],
  111.  entryComponents: [
  112.    MyApp,
  113.    HomePage,
  114.    ListPage,
  115.    AboutPage,
  116.    LoginPage,
  117.    RegisterPage,
  118.    PhotoPage
  119.  ],
  120.  providers: [
  121.    Camera,
  122.    StatusBar,
  123.    SplashScreen,
  124.    {provide: ErrorHandler, useClass: IonicErrorHandler}
  125.  ]
  126. })
  127. export class AppModule {}
  128. ---------------------------------------
  129. model
  130. user.ts
  131. export interface User {
  132.    email: string;
  133.    password: string;
  134. }
  135. ---------------------------------------
  136. pages
  137. about
  138. about.module
  139. import { NgModule } from '@angular/core';
  140. import { IonicPageModule } from 'ionic-angular';
  141. import { AboutPage } from './about';
  142.  
  143. @NgModule({
  144.  declarations: [
  145.    AboutPage,
  146.  ],
  147.  imports: [
  148.    IonicPageModule.forChild(AboutPage),
  149.  ],
  150. })
  151. export class AboutPageModule {}
  152. --------------------------------------
  153. home.html
  154. <ion-header>
  155.  <ion-navbar color="champ1">
  156.    <button ion-button menuToggle>
  157.      <ion-icon name="menu"></ion-icon>
  158.    </button>
  159.    <ion-title>หน้าแรก</ion-title>
  160.  </ion-navbar>
  161. </ion-header>
  162.  
  163. <ion-content padding>
  164.  <h3>Profile: </h3>
  165. </ion-content>
  166. --------------------------------
  167. login.html
  168. <ion-header>
  169.  
  170.  <ion-navbar color="champ2">
  171.    <ion-title>เข้าสูระบบ</ion-title>
  172.  </ion-navbar>
  173.  
  174. </ion-header>
  175.  
  176.  
  177. <ion-content padding>
  178.  
  179.  <ion-item>
  180.    <ion-label floating>อีเมล์</ion-label>
  181.    <ion-input type="email" [(ngModel)]="user.email"></ion-input>
  182.  </ion-item>
  183.  <ion-item>
  184.      <ion-label floating>รหัสผ่าน</ion-label>
  185.      <ion-input type="password" [(ngModel)]="user.password"></ion-input>
  186.    </ion-item>
  187.    <ion-grid>
  188.      <ion-row>
  189.        <ion-col ></ion-col>
  190.          <ion-col >
  191.          <button color="champ2"ion-button full (click)="login(user)">เข้าสู่ระบบ</button>
  192.          </ion-col>
  193.        <ion-col>
  194.          <button color="light"ion-button full (click)="register()">ลงทะเบียน</button>
  195.        </ion-col>
  196.      </ion-row>
  197.    </ion-grid>
  198.  
  199.    <ion-footer>
  200.      <ion-navbar color="champ2">
  201.        <ion-title>
  202.            6139010013 นาย สุขเกษม สังสัมพันธ์
  203.        </ion-title>
  204.      </ion-navbar>
  205.    </ion-footer>
  206.    
  207.  
  208.  
  209.    
  210.    
  211. </ion-content>
  212. -----------------------------------------------
  213. login.module.ts
  214. import { NgModule } from '@angular/core';
  215. import { IonicPageModule } from 'ionic-angular';
  216. import { LoginPage } from './login';
  217.  
  218. @NgModule({
  219.  declarations: [
  220.    LoginPage,
  221.  ],
  222.  imports: [
  223.    IonicPageModule.forChild(LoginPage),
  224.  ],
  225. })
  226. export class LoginPageModule {}
  227. --------------------------------------------
  228. login.ts
  229. import { Component } from '@angular/core';
  230. import { IonicPage, NavController, NavParams,AlertController } from 'ionic-angular';
  231. import { User } from '../../model/user';
  232. import { HomePage } from '../home/home';
  233. import { RegisterPage } from '../register/register';
  234.  
  235.  
  236. @IonicPage()
  237. @Component({
  238.  selector: 'page-login',
  239.  templateUrl: 'login.html',
  240. })
  241. export class LoginPage {
  242.  
  243.  user = {
  244.   email:'',
  245.   password:''
  246.   } as User;
  247.  
  248.  constructor(public alertCtrl:AlertController,
  249.              public navCtrl: NavController,
  250.              public navParams: NavParams) {
  251.  }
  252.  
  253.  login(user: User){
  254.    if(user.email == 'test@test.com' && user.password =='123456'){
  255.      this.navCtrl.setRoot(HomePage);
  256.    }else{
  257.      const alert = this.alertCtrl.create({
  258.      title: 'เตื่อนความปลอดภัย',
  259.      subTitle:'อีเมล์ หรือ รหัสผ่าน ไม่ถูกต้อง',
  260.      buttons:['ตกลง']
  261.      });
  262.      alert.present();
  263.    }
  264.  }
  265.  
  266.  register(){
  267.    this.navCtrl.push(RegisterPage);
  268.  }
  269.  
  270. }
  271. ---------------------------------------
  272. photo.html
  273. <ion-header>
  274.  
  275.  <ion-navbar>
  276.      <button ion-button menuToggle>
  277.          <ion-icon name="menu"></ion-icon>
  278.        </button>
  279.    <ion-title>ถ่ายรูป</ion-title>
  280.  </ion-navbar>
  281.  </ion-header>
  282.  
  283.  
  284. <ion-content padding>
  285.  
  286.  <button ion-button large (click)="takePhoto()">
  287.    <ion-icon name="camera"></ion-icon>
  288.  </button>
  289.  
  290. </ion-content>
  291. --------------------------------
  292. photo.module.ts
  293. import { NgModule } from '@angular/core';
  294. import { IonicPageModule } from 'ionic-angular';
  295. import { PhotoPage } from './photo';
  296.  
  297. @NgModule({
  298.  declarations: [
  299.    PhotoPage,
  300.  ],
  301.  imports: [
  302.    IonicPageModule.forChild(PhotoPage),
  303.  ],
  304. })
  305. export class PhotoPageModule {}
  306.  
  307. -----------------------------------------
  308. photo.ts
  309. import { Component } from '@angular/core';
  310. import { IonicPage, NavController, NavParams } from 'ionic-angular';
  311. import { Camera, CameraOptions } from '@ionic-native/camera';
  312. @IonicPage()
  313. @Component({
  314.  selector: 'page-photo',
  315.  templateUrl: 'photo.html',
  316. })
  317. export class PhotoPage {
  318.  
  319.  constructor(private Camera: Camera,
  320.              public navCtrl: NavController,
  321.              public navParams: NavParams) {
  322.    
  323.              
  324.  }
  325.    takePhoto(){
  326.        const options:CameraOptions ={
  327.          quality: 100,
  328.          destinationType: this.Camera.DestinationType.FILE_URI,
  329.          encodingType: this.Camera.EncodingType.JPEG,
  330.          mediaType: this.Camera.MediaType.PICTURE
  331.        }
  332.        this.Camera.getPicture(options).then((imageData) => {
  333.          let base64image = 'data:image/jpeg;base64,' + imageData;
  334.        },(err) => {          
  335.        console.log(err);
  336.          
  337.        });
  338.    }
  339.  
  340. }
  341. -------------------------------------
  342. register.html
  343. <ion-header>
  344.  
  345.  <ion-navbar color="dark">
  346.    <ion-title>ลงทะเบียนผู้ใช้</ion-title>
  347.  </ion-navbar>
  348.  
  349. </ion-header>
  350.  
  351.  
  352. <ion-content padding>
  353.    <ion-item>
  354.        <ion-label floating>อีเมล์</ion-label>
  355.        <ion-input type="email"></ion-input>
  356.      </ion-item>
  357.      <ion-item>
  358.          <ion-label floating>รหัสผ่าน</ion-label>
  359.          <ion-input type="password"></ion-input>
  360.        </ion-item>
  361.        <ion-item>
  362.        <ion-label floating>ชื่อ-สกุล</ion-label>
  363.          <ion-input type="text"></ion-input>
  364.        </ion-item>
  365.        
  366.              <button color="light"ion-button full (click)="register()">ลงทะเบียน</button>
  367. </ion-content>
  368. -------------------------------
  369. register.module.ts
  370. import { NgModule } from '@angular/core';
  371. import { IonicPageModule } from 'ionic-angular';
  372. import { RegisterPage } from './register';
  373.  
  374. @NgModule({
  375.  declarations: [
  376.    RegisterPage,
  377.  ],
  378.  imports: [
  379.    IonicPageModule.forChild(RegisterPage),
  380.  ],
  381. })
  382. export class RegisterPageModule {}
  383. ---------------------------------
  384. register.ts
  385. import { Component } from '@angular/core';
  386. import { IonicPage, NavController, NavParams } from 'ionic-angular';
  387. import { LoginPage } from '../login/login';
  388.  
  389. @IonicPage()
  390. @Component({
  391.  selector: 'page-register',
  392.  templateUrl: 'register.html',
  393. })
  394. export class RegisterPage {
  395.  
  396.  constructor(public navCtrl: NavController, public navParams: NavParams) {
  397.  }
  398.  
  399.  register() {
  400.    this.navCtrl.setRoot(LoginPage);
  401.  }
  402.  
  403. }
  404. ---------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement