uniapp 手机网络环境提示

422 阅读1分钟
uni.getNetworkType({
      complete: e => {
          let networkType = e.networkType || 'none';
          switch (networkType) {
              case 'none':
                if (this.$netWorkTypeBox) {
                  return;
                }

                this.$netWorkTypeBox = true;

                // uni.showModal({
                // 	title: '当前无网络',
                // 	content: '请检查您的网络链接',
                // 	showCancel: false,
                // 	confirmText: '取消',
                // 	success: () => {
                // 		this.$netWorkTypeBox = false;
                // 	}
                // });
                uni.showToast({
                title: '当前无网络,请检查您的网络链接',
                icon:'none',
                duration: 1000
                });
                // this.$g.show.msg('当前无网络,请检查您的网络链接');
                break;
              case '2g':
              case '3g':
              case '4g':
              case '5g':
                uni.showToast({
                title: '当前为非Wi-Fi环境,请注意流量消耗',
                icon:'none',
                duration: 1000
                });
                // this.$g.show.msg('当前为非Wi-Fi环境,请注意流量消耗');
                break;
            }
        }
      });