【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();
        }
      }
    );
  }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值