【ionic4】自定义弹框

定义方法

import { ToastController, AlertController } from '@ionic/angular';
constructor(
    // 构造方法
    public router: Router,
    public http: InterceptorService,
    public tipMessageService: TipMessageService,
    public toastController: ToastController,
    public alertController: AlertController,
  ) {
    super();
  }

/**
   * 没有数据时显示弹框
   * @author: ght
   * @param {string} 提示消息
   * @Date: 2019-06-15 22:18:43
   */
async presentAlertNoData(
    alertController: AlertController,
    message: string,
    router?: Router,
    cancelUrl?: string,
    // confirmUrl?: string
  ) {
    const alert = await alertController.create({
      header: '^_^温馨提示',
      message: message,
      backdropDismiss: false,
      mode: 'ios',
      buttons: [
        {
          text: '取消',
          role: 'cancel',
          cssClass: 'secondary',
          handler: () => {
            if (cancelUrl !== null && cancelUrl !== undefined) {
              router.navigateByUrl(cancelUrl);
            } else {
              console.log('Cancel Okay');
            }
          }
        }, {
          text: '确定',
          handler: () => {
            // if (confirmUrl !== null && confirmUrl !== undefined) {
            //   router.navigateByUrl(confirmUrl);
            // } else {
            //   console.log('Confirm Okay');
            // }
            this.selectTotalNum();
          }
        }
      ]
    });
    await alert.present();
  }
		  // 弹框提示
		  async noDataToast() {
		    const toast = await this.ToastController.create({
		      message: '查询失败!!',
		      duration: 1000,
		      position: 'middle',
		      cssClass: 'hometosat' /*cssClass必须写在全局*/
		    });
		    toast.present();
		  }


方法调用:

/**
     * @description: 根据学习量查询单词数据去除学习记录表数据
     * @param {type} recordNum
     * @return:  无
     * @author: ght
    */
  selectTotalNumber() {
    this.recordNum = window.localStorage.getItem('studyNumber');
    this.userId = window.localStorage.getItem('userId');
    const url = 'english-web/word/queryWordData/' + this.recordNum + '/' + this.userId ;

    this.http.get(url).subscribe(
      res => {
        if (res.json().code === ResponseCode.SUCCESSCODE) {
          if (res.json().data.length === 0) {
             this.presentAlertNoData(this.alertController, '优秀的你已经把所有单词都学完了,是否再学习一遍?', this.router, 'home-main');
          } else {
            this.pictureList = res.json().data;
            // 打开就显示数据
            this.picture1 = this.pictureList[0].wordPicture1;
            this.picture2 = this.pictureList[0].wordPicture2;
            this.picture3 = this.pictureList[0].wordPicture3;
            this.picture4 = this.pictureList[0].wordPicture4;
            this.audio = this.pictureList[0].audio;
          }
        } else if (res.json().code === ResponseCode.FAILCODE) {
          this.noDataToast();
        }
      }
    );
  }

发布了255 篇原创文章 · 获赞 221 · 访问量 23万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览