common.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. export default {
  2. getuid() {
  3. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  4. var r = Math.random() * 16 | 0,
  5. v = c == 'x' ? r : (r & 0x3 | 0x8);
  6. return v.toString(16);
  7. });
  8. },
  9. // 提示信息
  10. toast(msg, icon = 'none', duration = 2000, mask) {
  11. uni.showToast({
  12. "icon": icon,
  13. "title": msg,
  14. "mask": mask || false,
  15. "duration": duration
  16. })
  17. },
  18. showLoading(msg) {
  19. uni.showLoading({
  20. 'title': msg,
  21. 'mask': true
  22. })
  23. },
  24. hidingLoading() {
  25. uni.hideLoading();
  26. },
  27. // 提示信息 底部
  28. toastBottom(msg, icon = 'none', duration = 2000, mask = false) {
  29. uni.showToast({
  30. "icon": icon,
  31. "title": msg,
  32. "mask": mask,
  33. "duration": duration,
  34. "position": 'bottom'
  35. })
  36. },
  37. // 路由跳转
  38. to(url) {
  39. uni.navigateTo({
  40. url: url,
  41. animationType: 'slide-in-right',
  42. animationDuration: 300
  43. })
  44. },
  45. toBar(url) {
  46. uni.switchTab({
  47. url: url
  48. })
  49. },
  50. // 返回上一页
  51. back() {
  52. uni.navigateBack({
  53. delta: 1,
  54. animationType: 'pop-out',
  55. animationDuration: 200
  56. })
  57. },
  58. // 验证邮箱
  59. isEmail(email) {
  60. let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
  61. if (!reg.test(email)) {
  62. this.$common.toast('请输入正确邮箱格式')
  63. }
  64. return reg.test(email)
  65. }
  66. }