金诚优选前端代码
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.

111 lines
3.3 KiB

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