|
@@ -1,7 +1,7 @@
|
|
|
|
|
|
import { Injectable } from "@angular/core";
|
|
import { Injectable } from "@angular/core";
|
|
import { Observable } from 'rxjs';
|
|
import { Observable } from 'rxjs';
|
|
-import { PopoverController, AlertController, PickerController, ToastController, ActionSheetController, Platform } from '@ionic/angular';
|
|
|
|
|
|
+import { PopoverController, AlertController, PickerController, ToastController, ActionSheetController, Platform, LoadingController } from '@ionic/angular';
|
|
import { EventService } from 'src/app/shared/servers/envent.service';
|
|
import { EventService } from 'src/app/shared/servers/envent.service';
|
|
declare enum LocalFileSystem {
|
|
declare enum LocalFileSystem {
|
|
PERSISTENT= 0,
|
|
PERSISTENT= 0,
|
|
@@ -19,6 +19,8 @@ export class BusinessesHelper {
|
|
static loadingObject: Array<any> = [];
|
|
static loadingObject: Array<any> = [];
|
|
readonly IsMobile: boolean = false;
|
|
readonly IsMobile: boolean = false;
|
|
private AlertIsExist = false;
|
|
private AlertIsExist = false;
|
|
|
|
+ private LoadingIsExist = false;
|
|
|
|
+ private Loading = null;
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
public popover: PopoverController,
|
|
public popover: PopoverController,
|
|
@@ -29,10 +31,33 @@ export class BusinessesHelper {
|
|
public actionSheetController: ActionSheetController,
|
|
public actionSheetController: ActionSheetController,
|
|
public platform: Platform,
|
|
public platform: Platform,
|
|
public toastController: ToastController,
|
|
public toastController: ToastController,
|
|
|
|
+ public loadingController:LoadingController
|
|
) {
|
|
) {
|
|
this.IsMobile = this.platform.is('cordova');
|
|
this.IsMobile = this.platform.is('cordova');
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 断言是否真机环境
|
|
|
|
+ */
|
|
|
|
+ assertIsMobile(): void {
|
|
|
|
+ if (this.isNotMobile()) {
|
|
|
|
+ this.toast('请使用真机调试');
|
|
|
|
+ throw new Error('请使用真机调试');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 是否真机环境
|
|
|
|
+ */
|
|
|
|
+ isMobile(): boolean {
|
|
|
|
+ return this.IsMobile;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 是否真机环境
|
|
|
|
+ */
|
|
|
|
+ isNotMobile(): boolean {
|
|
|
|
+ return !this.isMobile();
|
|
|
|
+ }
|
|
|
|
+
|
|
// 提示框
|
|
// 提示框
|
|
async tip(msg:string, butText = '确定', icon?: string , callback?: Function) {
|
|
async tip(msg:string, butText = '确定', icon?: string , callback?: Function) {
|
|
let message = `<div>${msg}</div>`;
|
|
let message = `<div>${msg}</div>`;
|
|
@@ -93,7 +118,6 @@ export class BusinessesHelper {
|
|
await confirm.present();
|
|
await confirm.present();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* alert弹框,默认只有确定按钮,当存在取消回调函数则会显示取消按钮
|
|
* alert弹框,默认只有确定按钮,当存在取消回调函数则会显示取消按钮
|
|
* 注:如果存在打开的alert则不再打开
|
|
* 注:如果存在打开的alert则不再打开
|
|
@@ -135,8 +159,66 @@ export class BusinessesHelper {
|
|
buttons
|
|
buttons
|
|
}).then(alert => alert.present());
|
|
}).then(alert => alert.present());
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 显示提示信息
|
|
|
|
+ * 建议优先调用 NativeService.toast
|
|
|
|
+ */
|
|
|
|
+ toast(message: string = '操作成功', duration:any=200,color:any='warning', position: 'top' | 'bottom' | 'middle' = 'middle'): void {
|
|
|
|
+ const opts = { message, duration, color, position, showCloseButton: true, closeButtonText: '✖' };
|
|
|
|
+ console.log(opts)
|
|
|
|
+ this.toastController.create(opts).then(toast => toast.present());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 统一调用此方法显示loading
|
|
|
|
+ */
|
|
|
|
+ async showLoading() {
|
|
|
|
+ const loading = await this.loadingController.create({
|
|
|
|
+ spinner: 'crescent',
|
|
|
|
+ mode:'ios',
|
|
|
|
+ duration: 1000,
|
|
|
|
+ message: 'Please wait...',
|
|
|
|
+ translucent: true,
|
|
|
|
+ cssClass: 'custom-class custom-loading'
|
|
|
|
+ });
|
|
|
|
+ return await loading.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 统一调用此方法显示loading
|
|
|
|
+ */
|
|
|
|
+ showLoadingTest(message: string = ''): void {
|
|
|
|
+ if (this.LoadingIsExist) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.LoadingIsExist = true;
|
|
|
|
+ this.loadingController.create({
|
|
|
|
+ spinner: 'crescent', // dots https://ionicframework.com/docs/api/spinner
|
|
|
|
+ duration: 1000,
|
|
|
|
+ mode:'ios',
|
|
|
|
+ message: 'Please wait...'
|
|
|
|
+ }).then(loading => {
|
|
|
|
+ // loadingController.create异步方法,调用loading.present()前有可能已经调用hideLoading方法
|
|
|
|
+ if (this.LoadingIsExist) {
|
|
|
|
+ loading.present();
|
|
|
|
+ this.Loading = loading;
|
|
|
|
+ } else {
|
|
|
|
+ loading.dismiss();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 关闭loading
|
|
|
|
+ */
|
|
|
|
+ hideLoading(): void {
|
|
|
|
+ this.LoadingIsExist = false;
|
|
|
|
+ if (this.Loading) {
|
|
|
|
+ this.Loading.dismiss();
|
|
|
|
+ this.Loading = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
async presentActionSheet(param?:any,emit?:String,allback?: Function) {
|
|
async presentActionSheet(param?:any,emit?:String,allback?: Function) {
|
|
@@ -187,38 +269,6 @@ export class BusinessesHelper {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 断言是否真机环境
|
|
|
|
- */
|
|
|
|
- assertIsMobile(): void {
|
|
|
|
- if (this.isNotMobile()) {
|
|
|
|
- this.toast('请使用真机调试');
|
|
|
|
- throw new Error('请使用真机调试');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 是否真机环境
|
|
|
|
- */
|
|
|
|
- isMobile(): boolean {
|
|
|
|
- return this.IsMobile;
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 是否真机环境
|
|
|
|
- */
|
|
|
|
- isNotMobile(): boolean {
|
|
|
|
- return !this.isMobile();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 显示提示信息
|
|
|
|
- * 建议优先调用 NativeService.toast
|
|
|
|
- */
|
|
|
|
- toast(message: string = '操作成功', duration: number = 2500, position: 'top' | 'bottom' | 'middle' = 'middle'): void {
|
|
|
|
- const opts = {message, duration, color: 'dark', position, showCloseButton: true, closeButtonText: '✖'};
|
|
|
|
- this.toastController.create(opts).then(toast => toast.present());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|