123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { USER_INFO } from '../../../constant'
- let _debounceTimeout = null
- let _throttleRunning = false
- /**
- * 防抖
- * @param {Function} 执行函数
- * @param {Number} delay 延时ms
- */
- export const debounce = (fn, delay = 500) => {
- clearTimeout(_debounceTimeout)
- _debounceTimeout = setTimeout(() => {
- fn()
- }, delay)
- }
- /**
- * 节流
- * @param {Function} 执行函数
- * @param {Number} delay 延时ms
- */
- export const throttle = (fn, delay = 500) => {
- if (_throttleRunning) {
- return
- }
- _throttleRunning = true
- fn()
- setTimeout(() => {
- _throttleRunning = false
- }, delay)
- }
- /**
- * toast
- */
- export const msg = (title = '', param = {}) => {
- if (!title) return
- uni.showToast({
- title,
- duration: param.duration || 1500,
- mask: param.mask || false,
- icon: param.icon || 'none'
- })
- }
- /**
- * 检查登录
- * @return {Boolean}
- */
- export const isLogin = (options = {}) => {
- const userInfo = uni.getStorageSync(USER_INFO)
- if (userInfo) {
- return true
- }
- if (options.nav !== false) {
- uni.navigateTo({
- url: '/pages/login'
- })
- }
- return false
- }
|