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.
		
		
		
		
		
			
		
			
				
					
					
						
							112 lines
						
					
					
						
							3.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							112 lines
						
					
					
						
							3.3 KiB
						
					
					
				
								let _throttleRunning = false;
							 | 
						|
								export default{
							 | 
						|
									data(){
							 | 
						|
										return {
							 | 
						|
											pageScrollTop: 0, // 页面距离顶部的距离
							 | 
						|
										}
							 | 
						|
									},
							 | 
						|
									onPageScroll(res) {
							 | 
						|
										this.pageScrollTop = res.scrollTop;
							 | 
						|
									},
							 | 
						|
									methods: {
							 | 
						|
										$isRight(val){
							 | 
						|
											return this.$shared.isRight(val);
							 | 
						|
										},
							 | 
						|
										$check(str, type) {
							 | 
						|
											switch (type) {
							 | 
						|
												case 'mobile': //手机号码
							 | 
						|
													return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
							 | 
						|
												case 'tel': //座机
							 | 
						|
													return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
							 | 
						|
												case 'card': //身份证
							 | 
						|
													return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
							 | 
						|
												case 'mobileCode': //6位数字验证码
							 | 
						|
													return /^[0-9]{6}$/.test(str)
							 | 
						|
												case 'pwd': //密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
							 | 
						|
													return /^([a-zA-Z0-9_]){6,20}$/.test(str)
							 | 
						|
												case 'payPwd': //支付密码 6位纯数字
							 | 
						|
													return /^[0-9]{6}$/.test(str)
							 | 
						|
												case 'postal': //邮政编码
							 | 
						|
													return /[1-9]\d{5}(?!\d)/.test(str);
							 | 
						|
												case 'QQ': //QQ号
							 | 
						|
													return /^[1-9][0-9]{4,9}$/.test(str);
							 | 
						|
												case 'email': //邮箱
							 | 
						|
													return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
							 | 
						|
												case 'money': //金额(小数点2位)
							 | 
						|
													return /^\d*(?:\.\d{0,2})?$/.test(str);
							 | 
						|
												case 'URL': //网址
							 | 
						|
													return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
							 | 
						|
												case 'IP': //IP
							 | 
						|
													return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
							 | 
						|
												case 'date': //日期时间
							 | 
						|
													return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/
							 | 
						|
														.test(str)
							 | 
						|
												case 'number': //数字
							 | 
						|
													return /^[0-9]$/.test(str);
							 | 
						|
												case 'english': //英文
							 | 
						|
													return /^[a-zA-Z]+$/.test(str);
							 | 
						|
												case 'chinese': //中文
							 | 
						|
													return /^[\\u4E00-\\u9FA5]+$/.test(str);
							 | 
						|
												case 'lower': //小写
							 | 
						|
													return /^[a-z]+$/.test(str);
							 | 
						|
												case 'upper': //大写
							 | 
						|
													return /^[A-Z]+$/.test(str);
							 | 
						|
												case 'HTML': //HTML标记
							 | 
						|
													return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
							 | 
						|
												default:
							 | 
						|
													return true;
							 | 
						|
											}
							 | 
						|
										},
							 | 
						|
										$msg(title = '', param = {}) {
							 | 
						|
											return new Promise((resolve, reject) => {
							 | 
						|
												if(!title){
							 | 
						|
													reject();
							 | 
						|
													return;
							 | 
						|
												}
							 | 
						|
												uni.showToast({
							 | 
						|
													title,
							 | 
						|
													duration: param.duration || 1500,
							 | 
						|
													mask: param.mask || true, // 默认应该加mask 禁止提示时操作
							 | 
						|
													icon: param.icon || 'none',
							 | 
						|
													complete: result => {
							 | 
						|
														setTimeout(() => {
							 | 
						|
															resolve();
							 | 
						|
														}, param.duration || 1500);
							 | 
						|
													}
							 | 
						|
												});
							 | 
						|
											})
							 | 
						|
										},
							 | 
						|
										$url(url, options = {}){
							 | 
						|
											this.$throttle(() => {
							 | 
						|
												if(options.type && options.type !== ''){
							 | 
						|
													if(options.type === 'redirect'){ // 关闭当前,跳转
							 | 
						|
														uni.redirectTo({ url })
							 | 
						|
													}else if(options.type === 'switch'){ // 跳转
							 | 
						|
														uni.switchTab({ url })
							 | 
						|
													}else if(options.type === 'launch'){ // 关闭所有,跳转
							 | 
						|
														uni.reLaunch({ url })
							 | 
						|
													}
							 | 
						|
												}else{
							 | 
						|
													uni.navigateTo({ url })	// 跳转
							 | 
						|
												}
							 | 
						|
											}, 100);
							 | 
						|
										},
							 | 
						|
										$throttle(fn, delay = 500) {
							 | 
						|
											if(_throttleRunning){ return; }
							 | 
						|
											_throttleRunning = true;
							 | 
						|
											fn();
							 | 
						|
											setTimeout(() => {
							 | 
						|
											    _throttleRunning = false;
							 | 
						|
											}, delay);
							 | 
						|
										},
							 | 
						|
										$toBack(){
							 | 
						|
											let pages = getCurrentPages(); // 当前页
							 | 
						|
											let beforePage = pages[pages.length - 2]; // 上个页面
							 | 
						|
											if(beforePage && beforePage.route){
							 | 
						|
												uni.navigateBack();
							 | 
						|
											}else{
							 | 
						|
												uni.reLaunch({url:'/pages/index/index/index'});
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
								}
							 |