1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- export default{
- // 密码只能是6位数字
- sixNum(str){
- let reg=/^\d{6}$/;
- if(!reg.test(str)){
- return false
- }else{
- return true
- }
- },
- // 密码由6-12位数字和字母组成
- numLetter(str){
- let reg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
- if(!reg.test(str)){
- return false
- }else{
- return true
- }
- },
- // 字符串只能由1-10位中文、数字、英文组成,且必须有中文
- chineseNumLetter(str){
- let reg = /^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9]){1,10}$/
- if(reg.test(str)){
- // console.log('第一层通过')
- let reg1 = new RegExp("[\\u4E00-\\u9FFF]+","g");
- if(reg1.test(str)){
- // console.log('第二层通过')
- return true
- }else{
- return false
- }
- }else{
- return false
- }
- },
- // 节流
- throttle(fn, wait = 200) {
- let last, timer,now;
- return function() {
- now = Date.now();
- if (last && now - last < wait) {
- clearTimeout(timer);
- timer = setTimeout(function() {
- last = now;
- fn.call(this, ...arguments);
- }, wait);
- } else {
- last = now;
- fn.call(this, ...arguments);
- }
- };
- },
- // 防抖
- debounce(fn, wait=200) {
- let timer;
- return function () {
- let context = this;
- let args = arguments;
- if (timer) clearTimeout(timer);
- timer = setTimeout(() => {
- fn.apply(context, args);
- }, wait)
- }
- },
-
- }
- // export function debounce (func, wait, immediate = true) {
- // let timeout
- // return function () {
- // if (timeout) clearTimeout(timeout)
- // if (immediate) {
- // var callNow = !timeout
- // timeout = setTimeout(() => {
- // timeout = null
- // }, wait)
- // if (callNow) func.apply(this, arguments)
- // } else {
- // timeout = setTimeout(function () {
- // func.apply(context, args)
- // }, wait)
- // }
- // }
- // }
|