|
@@ -4,10 +4,10 @@ import { Observable } from 'rxjs';
|
|
|
import { PopoverController, AlertController, PickerController, ToastController, ActionSheetController, Platform, LoadingController } from '@ionic/angular';
|
|
|
import { EventService } from 'src/app/shared/servers/envent.service';
|
|
|
import { ImagePicker } from '@ionic-native/image-picker/ngx';
|
|
|
-import { Camera,CameraOptions} from '@ionic-native/camera/ngx';
|
|
|
+import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
|
|
declare enum LocalFileSystem {
|
|
|
- PERSISTENT= 0,
|
|
|
- TEMPORARY= 1
|
|
|
+ PERSISTENT = 0,
|
|
|
+ TEMPORARY = 1
|
|
|
}
|
|
|
declare let window: {
|
|
|
requestFileSystem: any,
|
|
@@ -29,40 +29,40 @@ export class BusinessesHelper {
|
|
|
public alertController: AlertController,
|
|
|
public pickerCtrl: PickerController,
|
|
|
public toastCtrl: ToastController,
|
|
|
- public eventService:EventService,
|
|
|
+ public eventService: EventService,
|
|
|
public actionSheetController: ActionSheetController,
|
|
|
public platform: Platform,
|
|
|
public toastController: ToastController,
|
|
|
- public loadingController:LoadingController,
|
|
|
+ public loadingController: LoadingController,
|
|
|
private imagePicker: ImagePicker,
|
|
|
) {
|
|
|
this.IsMobile = this.platform.is('cordova');
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 断言是否真机环境
|
|
|
- */
|
|
|
- assertIsMobile(): void {
|
|
|
- if (this.isNotMobile()) {
|
|
|
- this.toast('请使用真机调试');
|
|
|
- throw new Error('请使用真机调试');
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+* 断言是否真机环境
|
|
|
+*/
|
|
|
+ assertIsMobile(): void {
|
|
|
+ if (this.isNotMobile()) {
|
|
|
+ this.toast('请使用真机调试');
|
|
|
+ throw new Error('请使用真机调试');
|
|
|
+ }
|
|
|
}
|
|
|
- /**
|
|
|
- * 是否真机环境
|
|
|
- */
|
|
|
- isMobile(): boolean {
|
|
|
- return this.IsMobile;
|
|
|
+ /**
|
|
|
+ * 是否真机环境
|
|
|
+ */
|
|
|
+ isMobile(): boolean {
|
|
|
+ return this.IsMobile;
|
|
|
}
|
|
|
- /**
|
|
|
- * 是否真机环境
|
|
|
- */
|
|
|
- isNotMobile(): 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>`;
|
|
|
if (icon === 'success') {
|
|
|
message = `<div class="alert-icon"><i></i></div><div>${msg}</div>`;
|
|
@@ -73,7 +73,7 @@ export class BusinessesHelper {
|
|
|
} else if (icon) {
|
|
|
message = `<div class="alert-icon"><i></i></div><div>${msg}</div>`;
|
|
|
}
|
|
|
- let alert =await this.alertController.create({
|
|
|
+ let alert = await this.alertController.create({
|
|
|
header: '提示框',
|
|
|
message: message,
|
|
|
buttons: [
|
|
@@ -92,27 +92,31 @@ export class BusinessesHelper {
|
|
|
}
|
|
|
|
|
|
//确认框
|
|
|
- async showConfirm(message: string, sureBackcall?: Function, canleBackcall?: Function) {
|
|
|
- const confirm =await this.alertController.create({
|
|
|
+ async showConfirm(message: string, canle?: string, sure?: string, sureBackcall?: Function, canleBackcall?: Function) {
|
|
|
+ if (!canle) {
|
|
|
+ canle = '取消'
|
|
|
+ }
|
|
|
+ if (!sure) {
|
|
|
+ sure = '确定'
|
|
|
+ }
|
|
|
+ const confirm = await this.alertController.create({
|
|
|
message: message,
|
|
|
buttons: [
|
|
|
{
|
|
|
cssClass: "tip-button-cancel",
|
|
|
- text: '取消',
|
|
|
+ text: canle,
|
|
|
handler: () => {
|
|
|
- console.log('Disagree clicked');
|
|
|
if (canleBackcall) {
|
|
|
- canleBackcall();
|
|
|
+ canleBackcall('eeeee');
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
cssClass: "tip-button-confirm",
|
|
|
- text: '确定',
|
|
|
+ text: sure,
|
|
|
handler: () => {
|
|
|
- console.log('Agree clicked');
|
|
|
if (sureBackcall) {
|
|
|
- sureBackcall();
|
|
|
+ sureBackcall('eeees');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -121,6 +125,31 @@ export class BusinessesHelper {
|
|
|
await confirm.present();
|
|
|
}
|
|
|
|
|
|
+ public async arlt(msg: String, sureBackcall?: Function, canleBackcall?: Function) {
|
|
|
+ let message = `<div>${msg}</div>`;
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '提示框',
|
|
|
+ message: message,
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '取消',
|
|
|
+ role: 'cancel',
|
|
|
+ cssClass: 'secondary',
|
|
|
+ handler: (blah) => {
|
|
|
+ canleBackcall('canleBackcall'); //很好用
|
|
|
+
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ text: '确认',
|
|
|
+ handler: () => {
|
|
|
+ sureBackcall('sureBackcall');//很好用
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* alert弹框,默认只有确定按钮,当存在取消回调函数则会显示取消按钮
|
|
|
* 注:如果存在打开的alert则不再打开
|
|
@@ -129,105 +158,105 @@ export class BusinessesHelper {
|
|
|
* @param okBackFun 成功回调
|
|
|
* @param cancelBtnFun 失败回调
|
|
|
*/
|
|
|
- alert(header = '', message = '', okBackFun = null, cancelBtnFun = null): void {
|
|
|
- // alertController.create是异步方法,所以使用AlertIsExist标志是否打开
|
|
|
- if (this.AlertIsExist) {
|
|
|
- console.log('alert已经存在,禁止重复打开');
|
|
|
- setTimeout(() => { // alert关闭的可能性比较多,不止点击确定或取消按钮
|
|
|
- this.AlertIsExist = false;
|
|
|
- }, 10000);
|
|
|
- return;
|
|
|
- }
|
|
|
- this.AlertIsExist = true;
|
|
|
- const buttons = [{
|
|
|
- text: '确定', handler: () => {
|
|
|
- this.AlertIsExist = false;
|
|
|
- okBackFun && okBackFun();
|
|
|
- }
|
|
|
- }];
|
|
|
- if (cancelBtnFun) {
|
|
|
- const cancelBtn = {
|
|
|
- text: '取消',
|
|
|
- role: 'cancel',
|
|
|
- handler: () => {
|
|
|
- this.AlertIsExist = false;
|
|
|
- cancelBtnFun();
|
|
|
- }
|
|
|
- };
|
|
|
- buttons.unshift(cancelBtn);
|
|
|
+ alert(header = '', message = '', okBackFun = null, cancelBtnFun = null): void {
|
|
|
+ // alertController.create是异步方法,所以使用AlertIsExist标志是否打开
|
|
|
+ if (this.AlertIsExist) {
|
|
|
+ console.log('alert已经存在,禁止重复打开');
|
|
|
+ setTimeout(() => { // alert关闭的可能性比较多,不止点击确定或取消按钮
|
|
|
+ this.AlertIsExist = false;
|
|
|
+ }, 10000);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.AlertIsExist = true;
|
|
|
+ const buttons = [{
|
|
|
+ text: '确定', handler: () => {
|
|
|
+ this.AlertIsExist = false;
|
|
|
+ okBackFun && okBackFun();
|
|
|
}
|
|
|
- this.alertController.create({
|
|
|
- header,
|
|
|
- message,
|
|
|
- buttons
|
|
|
- }).then(alert => alert.present());
|
|
|
+ }];
|
|
|
+ if (cancelBtnFun) {
|
|
|
+ const cancelBtn = {
|
|
|
+ text: '取消',
|
|
|
+ role: 'cancel',
|
|
|
+ handler: () => {
|
|
|
+ this.AlertIsExist = false;
|
|
|
+ cancelBtnFun();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ buttons.unshift(cancelBtn);
|
|
|
+ }
|
|
|
+ this.alertController.create({
|
|
|
+ header,
|
|
|
+ message,
|
|
|
+ buttons
|
|
|
+ }).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());
|
|
|
+ /**
|
|
|
+ * 显示提示信息
|
|
|
+ * 建议优先调用 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 {
|
|
|
+ /**
|
|
|
+ * 统一调用此方法显示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) {
|
|
|
- return;
|
|
|
+ loading.present();
|
|
|
+ this.Loading = loading;
|
|
|
+ } else {
|
|
|
+ loading.dismiss();
|
|
|
}
|
|
|
- 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;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 关闭loading
|
|
|
+ */
|
|
|
+ hideLoading(): void {
|
|
|
+ this.LoadingIsExist = false;
|
|
|
+ if (this.Loading) {
|
|
|
+ this.Loading.dismiss();
|
|
|
+ this.Loading = null;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- async presentActionSheet(param?:any,emit?:String,allback?: Function) {
|
|
|
- let object:Object;
|
|
|
+
|
|
|
+
|
|
|
+ async presentActionSheet(param?: any, emit?: String, allback?: Function) {
|
|
|
+ let object: Object;
|
|
|
const actionSheet = await this.actionSheetController.create({
|
|
|
- header:'Albums',
|
|
|
+ header: 'Albums',
|
|
|
mode: 'ios',
|
|
|
buttons: [{
|
|
|
text: '删除',
|
|
@@ -235,28 +264,28 @@ export class BusinessesHelper {
|
|
|
icon: 'trash',
|
|
|
handler: () => {
|
|
|
console.log('Delete clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}, {
|
|
|
text: '分享',
|
|
|
icon: 'share',
|
|
|
handler: () => {
|
|
|
console.log('Share clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}, {
|
|
|
text: '支付',
|
|
|
icon: 'arrow-dropright-circle',
|
|
|
handler: () => {
|
|
|
console.log('Play clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}, {
|
|
|
text: '最爱',
|
|
|
icon: 'heart',
|
|
|
handler: () => {
|
|
|
console.log('Favorite clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}, {
|
|
|
text: '取消',
|
|
@@ -264,17 +293,17 @@ export class BusinessesHelper {
|
|
|
role: 'cancel',
|
|
|
handler: () => {
|
|
|
console.log('Cancel clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
await actionSheet.present();
|
|
|
}
|
|
|
|
|
|
- async presentActionSheet1(param?:any,emit?:String,allback?: Function) {
|
|
|
- let object:Object;
|
|
|
+ async presentActionSheet1(param?: any, emit?: String, allback?: Function) {
|
|
|
+ let object: Object;
|
|
|
const actionSheet = await this.actionSheetController.create({
|
|
|
- header:'Albums',
|
|
|
+ header: 'Albums',
|
|
|
mode: 'md',
|
|
|
buttons: [{
|
|
|
text: '删除',
|
|
@@ -282,14 +311,14 @@ export class BusinessesHelper {
|
|
|
icon: 'trash',
|
|
|
handler: () => {
|
|
|
console.log('Delete clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}, {
|
|
|
text: '分享',
|
|
|
icon: 'share',
|
|
|
handler: () => {
|
|
|
console.log('Share clicked');
|
|
|
- this.eventService.event.emit(emit,object)
|
|
|
+ this.eventService.event.emit(emit, object)
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
@@ -356,8 +385,8 @@ export class BusinessesHelper {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|