common.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. removeNull(obj){
  68. var newObj = {};
  69. if(obj != undefined && obj != null) {
  70. for(var key in obj) {
  71. if(obj[key] === undefined || obj[key] === null || obj[key] === '') {
  72. //
  73. } else {
  74. newObj[key] = obj[key];
  75. }
  76. }
  77. }
  78. return newObj;
  79. }
  80. }