common.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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[34578]\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. removeNull(obj){
  83. var newObj = {};
  84. if(obj != undefined && obj != null) {
  85. for(var key in obj) {
  86. if(obj[key] === undefined || obj[key] === null || obj[key] === '') {
  87. //
  88. } else {
  89. newObj[key] = obj[key];
  90. }
  91. }
  92. }
  93. return newObj;
  94. }
  95. }