海南旅游项目 前端仓库
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.

122 lines
3.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. export default{
  2. data(){
  3. return {
  4. pageScrollTop: 0, // 页面距离顶部的距离
  5. }
  6. },
  7. onPageScroll(res) {
  8. this.pageScrollTop = res.scrollTop;
  9. },
  10. methods: {
  11. $isRight(val){
  12. return this.$shared.isRight(val);
  13. },
  14. $check(str, type) {
  15. switch (type) {
  16. case 'mobile': //手机号码
  17. return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
  18. case 'tel': //座机
  19. return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
  20. case 'card': //身份证
  21. return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
  22. case 'mobileCode': //6位数字验证码
  23. return /^[0-9]{6}$/.test(str)
  24. case 'pwd': //密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
  25. return /^([a-zA-Z0-9_]){6,20}$/.test(str)
  26. case 'payPwd': //支付密码 6位纯数字
  27. return /^[0-9]{6}$/.test(str)
  28. case 'postal': //邮政编码
  29. return /[1-9]\d{5}(?!\d)/.test(str);
  30. case 'QQ': //QQ号
  31. return /^[1-9][0-9]{4,9}$/.test(str);
  32. case 'email': //邮箱
  33. return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
  34. case 'money': //金额(小数点2位)
  35. return /^\d*(?:\.\d{0,2})?$/.test(str);
  36. case 'URL': //网址
  37. return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
  38. case 'IP': //IP
  39. return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
  40. case 'date': //日期时间
  41. return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/
  42. .test(str)
  43. case 'number': //数字
  44. return /^[0-9]$/.test(str);
  45. case 'english': //英文
  46. return /^[a-zA-Z]+$/.test(str);
  47. case 'chinese': //中文
  48. return /^[\\u4E00-\\u9FA5]+$/.test(str);
  49. case 'lower': //小写
  50. return /^[a-z]+$/.test(str);
  51. case 'upper': //大写
  52. return /^[A-Z]+$/.test(str);
  53. case 'HTML': //HTML标记
  54. return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
  55. default:
  56. return true;
  57. }
  58. },
  59. $msg(title = '', param = {}) {
  60. if(!title) return;
  61. uni.showToast({
  62. title,
  63. duration: param.duration || 1500,
  64. mask: param.mask || true, // 默认应该加mask 禁止提示时操作
  65. icon: param.icon || 'none'
  66. });
  67. },
  68. $url(url, options = {}){
  69. this.$u.throttle(() => {
  70. if(options.type && options.type !== ''){
  71. if(options.type === 'redirect'){ // 关闭当前,跳转
  72. uni.redirectTo({ url })
  73. }else if(options.type === 'switch'){ // 跳转
  74. uni.switchTab({ url })
  75. }else if(options.type === 'launch'){ // 关闭所有,跳转
  76. uni.reLaunch({ url })
  77. }
  78. }else{
  79. uni.navigateTo({ url }) // 跳转
  80. }
  81. }, 100);
  82. },
  83. $toBack(){
  84. let pages = getCurrentPages(); // 当前页
  85. let beforePage = pages[pages.length - 2]; // 上个页面
  86. if(beforePage && beforePage.route){
  87. uni.navigateBack();
  88. }else{
  89. uni.switchTab({url:'/pages/index/index'});
  90. }
  91. },
  92. $timer(value, fmt) {
  93. if(!value) return;
  94. let newTime = new Date(value)
  95. if(!fmt){
  96. fmt = 'yyyy-MM-dd hh:mm';
  97. }
  98. if(/(y+)/.test(fmt)) {
  99. fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length));
  100. }
  101. let o = {
  102. 'M+': newTime.getMonth() + 1,
  103. 'd+': newTime.getDate(),
  104. 'h+': newTime.getHours(),
  105. 'm+': newTime.getMinutes(),
  106. 's+': newTime.getSeconds()
  107. };
  108. function padLeftZero(str) {
  109. return ('00'+str).substr(str.length);
  110. }
  111. // 遍历这个对象
  112. for (let k in o) {
  113. if (new RegExp(`(${k})`).test(fmt)) {
  114. // console.log(`${k}`)
  115. let str = o[k] + '';
  116. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
  117. }
  118. }
  119. return fmt;
  120. },
  121. }
  122. }