Check.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as Info from './Info'
  2. class Check{
  3. static lngLat(lng,lat){
  4. let msg = ''
  5. let result = false
  6. if(lat == null || lng == null || lat == undefined || lng == undefined){
  7. msg = Check.addHeader("经纬度不能为null")
  8. return Check.message(msg,result)
  9. }
  10. if(Check.isNumber(lat) || Check.isNumber(lng)){
  11. msg = Check.addHeader("经纬度应为数字")
  12. return Check.message(msg,result)
  13. }
  14. if(lat<-90 || lat>90){
  15. msg = Check.addHeader("纬度lat应该大于-90小于90")
  16. return Check.message(msg,result)
  17. }
  18. if(lng<-180 || lng>180){
  19. msg = Check.addHeader("经度lng应该大于-180小于180")
  20. return Check.message(msg,result)
  21. }
  22. if(msg == ''){
  23. result = true
  24. }
  25. return Check.message(msg,result)
  26. }
  27. static isNumber(str){
  28. if(str == null || undefined){
  29. return false
  30. }
  31. if((typeof str=='string')&&str.constructor==String){
  32. return false
  33. }
  34. if(!isNaN(str)){
  35. return false
  36. }
  37. return true
  38. }
  39. static notEmpty(name,str){
  40. let result = false;
  41. if(str == null || undefined){
  42. result = false
  43. }
  44. if((typeof str=='string') && str.constructor==String && str !=''){
  45. result = true
  46. }else{
  47. result = false
  48. }
  49. return Check.message(Check.addHeader(name+"必须为字符串且不能为空"),result);
  50. }
  51. static addHeader(str){
  52. return Info.version+":"+str
  53. }
  54. static message(msg,isPass){
  55. return {msg:msg,isPass:isPass}
  56. }
  57. }
  58. export default Check