时空网前端
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.

99 lines
3.0 KiB

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