common.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import ajax from '@/utils/request.js'
  2. export default {
  3. getuid() {
  4. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  5. var r = Math.random() * 16 | 0,
  6. v = c == 'x' ? r : (r & 0x3 | 0x8);
  7. return v.toString(16);
  8. });
  9. },
  10. // 提示信息
  11. toast(msg, icon = 'none', duration = 2000, mask) {
  12. uni.showToast({
  13. "icon": icon,
  14. "title": msg,
  15. "mask": mask || false,
  16. "duration": duration
  17. })
  18. },
  19. showLoading(msg) {
  20. uni.showLoading({
  21. 'title': msg,
  22. 'mask': true
  23. })
  24. },
  25. hidingLoading() {
  26. uni.hideLoading();
  27. },
  28. // 提示信息 底部
  29. toastBottom(msg, icon = 'none', duration = 2000, mask = false) {
  30. uni.showToast({
  31. "icon": icon,
  32. "title": msg,
  33. "mask": mask,
  34. "duration": duration,
  35. "position": 'bottom'
  36. })
  37. },
  38. // 路由跳转
  39. to(url) {
  40. uni.navigateTo({
  41. url: url,
  42. animationType: 'slide-in-right',
  43. animationDuration: 300
  44. })
  45. },
  46. toBar(url) {
  47. uni.switchTab({
  48. url: url
  49. })
  50. },
  51. // 返回上一页
  52. back() {
  53. uni.navigateBack({
  54. delta: 1,
  55. animationType: 'pop-out',
  56. animationDuration: 200
  57. })
  58. },
  59. // 验证邮箱
  60. isEmail(email) {
  61. let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
  62. if (!reg.test(email)) {
  63. this.$common.toast('请输入正确邮箱格式')
  64. }
  65. return reg.test(email)
  66. },
  67. // 正则验证是否为手机号
  68. isPhone (str) {
  69. str = str + '';
  70. if((/^1[345678]\d{9}$/.test(str))){
  71. return true;
  72. }
  73. return false;
  74. },
  75. isNum (str) {
  76. str = str + '';
  77. if((/^[0-9]*$/.test(str))||(/^[0-9]+(.[0-9]{1})?$/.test(str))){
  78. return true;
  79. }
  80. return false;
  81. },
  82. isCarNo(str){
  83. str=str+'';
  84. let reg=/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/
  85. if(reg.test(str)){
  86. return true;
  87. }
  88. return false;
  89. },
  90. removeNull(obj){
  91. var newObj = {};
  92. if(obj != undefined && obj != null) {
  93. for(var key in obj) {
  94. if(obj[key] === undefined || obj[key] === null || obj[key] === '') {
  95. //
  96. } else {
  97. newObj[key] = obj[key];
  98. }
  99. }
  100. }
  101. return newObj;
  102. }
  103. }