时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

  1. export default{
  2. data(){
  3. return {
  4. pageScrollTop: 0, // 页面距离顶部的距离
  5. }
  6. },
  7. onLoad(option){
  8. },
  9. onPageScroll(res) {
  10. this.pageScrollTop = res.scrollTop;
  11. },
  12. // 页面转发分享
  13. async onShareAppMessage(res) {
  14. },
  15. methods: {
  16. $check(str, type) {
  17. switch (type) {
  18. case 'mobile': //手机号码
  19. return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
  20. case 'tel': //座机
  21. return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
  22. case 'card': //身份证
  23. return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
  24. case 'mobileCode': //6位数字验证码
  25. return /^[0-9]{6}$/.test(str)
  26. case 'pwd': //密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
  27. return /^([a-zA-Z0-9_]){6,20}$/.test(str)
  28. case 'payPwd': //支付密码 6位纯数字
  29. return /^[0-9]{6}$/.test(str)
  30. case 'postal': //邮政编码
  31. return /[1-9]\d{5}(?!\d)/.test(str);
  32. case 'QQ': //QQ号
  33. return /^[1-9][0-9]{4,9}$/.test(str);
  34. case 'email': //邮箱
  35. return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
  36. case 'money': //金额(小数点2位)
  37. return /^\d*(?:\.\d{0,2})?$/.test(str);
  38. case 'URL': //网址
  39. return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
  40. case 'IP': //IP
  41. return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
  42. case 'date': //日期时间
  43. return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/
  44. .test(str)
  45. case 'number': //数字
  46. return /^[0-9]$/.test(str);
  47. case 'english': //英文
  48. return /^[a-zA-Z]+$/.test(str);
  49. case 'chinese': //中文
  50. return /^[\\u4E00-\\u9FA5]+$/.test(str);
  51. case 'lower': //小写
  52. return /^[a-z]+$/.test(str);
  53. case 'upper': //大写
  54. return /^[A-Z]+$/.test(str);
  55. case 'HTML': //HTML标记
  56. return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
  57. default:
  58. return true;
  59. }
  60. },
  61. $msg(title = '', param = {}) {
  62. if(!title) return;
  63. uni.showToast({
  64. title,
  65. duration: param.duration || 1500,
  66. mask: param.mask || true, // 默认应该加mask 禁止提示时操作
  67. icon: param.icon || 'none'
  68. });
  69. },
  70. $url(url, options = {}){
  71. this.$u.throttle(() => {
  72. if(options.type && options.type !== ''){
  73. if(options.type === 'redirect'){ // 关闭当前,跳转
  74. uni.redirectTo({ url })
  75. }else if(options.type === 'switch'){ // 跳转
  76. uni.switchTab({ url })
  77. }else if(options.type === 'launch'){ // 关闭所有,跳转
  78. uni.reLaunch({ url })
  79. }
  80. }else{
  81. uni.navigateTo({ url }) // 跳转
  82. }
  83. }, 100);
  84. },
  85. $toBack(){
  86. let pages = getCurrentPages(); // 当前页
  87. let beforePage = pages[pages.length - 2]; // 上个页面
  88. if(beforePage && beforePage.route){
  89. uni.navigateBack();
  90. }else{
  91. uni.switchTab({url:'/pages/index/index'});
  92. }
  93. }
  94. }
  95. }