base.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { ToastController } from 'ionic-angular';
  2. export abstract class Base
  3. {
  4. protected constructor()
  5. {
  6. }
  7. protected async presentToast(toastController:ToastController,message:string='toast message',position:string='middle') {
  8. const toast = await toastController.create({
  9. message: message,
  10. duration: 2000,
  11. position: position,
  12. });
  13. toast.present();
  14. }
  15. public async errorLog(toastController:ToastController,message:string='toast message',position:string='middle')
  16. {
  17. const toast = await toastController.create({
  18. message: message,
  19. duration: 2000,
  20. position: position,
  21. });
  22. toast.present();
  23. }
  24. public checkMobile(mobile:any):boolean
  25. {
  26. let reg = /^1[0-9]{10}$/;
  27. if(!reg.test(mobile))
  28. {
  29. return false;
  30. }
  31. return true;
  32. }
  33. public toThousands(num):string
  34. {
  35. let result = '', counter = 0,i=0;
  36. num = (num || 0).toString();
  37. for ( i = num.length - 1; i >= 0; i--)
  38. {
  39. counter++;
  40. result = num.charAt(i) + result;
  41. if (!(counter % 3) && i != 0)
  42. {
  43. result = ',' + result;
  44. }
  45. }
  46. return result;
  47. }
  48. }