//防抖 延迟执行 export function debounce(fn, delay = 500) { let timer return function() { let args = arguments if (timer) clearTimeout(timer) timer = setTimeout(() => { timer = null fn.apply(this, args) }, delay) } } //节流 首次执行 export function throttle(fn, delay = 1000) { let last = 0 return function() { let now = new Date() if (now - last > delay) { fn.apply(this, arguments) last = now } } } //提示 const toast = (msg, mask = true, icon = 'none', duration = 1500) => { uni.showToast({ title: String(msg), icon: icon, mask: mask, duration: duration, }) } //加载 const loading = (msg = '努力加载中', mask = true) => { uni.showLoading({ title: String(msg), mask: mask, }) } //json参数转url参数 const jsonToUrl = (path, param) => { let url = path let arr = [] if (param) arr = Object.keys(param) if (arr.length && arr.length != 0) { let str = arr.map(key => `${key}=${decodeURIComponent(param[key])}`).join('&') url = `${path}${path ? '?' : ''}${str}` } return url } //url参数转json参数 const urlToJson = (url) => { let path = url let param = {} if (url.indexOf('?') != -1) { path = url.substr(0, url.indexOf('?')) let arr = url.split("?")[1].split("&") arr.forEach(i=>{ if (i.split("=")[1] && i.split("=")[1] != 'undefined') param[i.split("=")[0]] = i.split("=")[1] }) } return { path, param } } //url获取指定参数 const getQuery = (key) => { let query = window.location.search.substring(1); let vars = query.split("&"); for (let i=0;i n) { while(k < n && ds[1].substring(0, ++k) == '0') { b0 += '0' } d = Number(ds[1].substring(0, n)) carryD = Math.round(Number('0.' + ds[1].substring(n, len))) len = (d + carryD).toString().length if (len > n) { return Number(ds[0]) + 1 } else if (len == n) { return Number(ds[0] + '.' + (d + carryD)) } return Number(ds[0] + '.' + b0 + (d + carryD)) } } catch (e) {} return arg } //输出 export default { toast, loading, jsonToUrl, urlToJson, getQuery, }