mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2026-01-22 15:40:21 +08:00
style: lint
This commit is contained in:
@@ -10,10 +10,10 @@
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
/**
|
||||
* @desc 格式化时间
|
||||
* @param {(Object|string|number)} time
|
||||
* @param {(object | string | number)} time
|
||||
* @param {string} format
|
||||
* @returns {string | null}
|
||||
* @returns {string | null} 格式化后的时间字符串
|
||||
*
|
||||
*/
|
||||
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(time).format(format)
|
||||
@@ -24,19 +24,19 @@ export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc 函数节流
|
||||
* @param {Function} fn
|
||||
* @param {Number} wait
|
||||
* @returns {Function}
|
||||
* @param {number} wait
|
||||
* @returns {Function} 节流函数
|
||||
*
|
||||
*/
|
||||
export function throttle(fn, wait) {
|
||||
var context, args
|
||||
var previous = 0
|
||||
let context, args
|
||||
let previous = 0
|
||||
|
||||
return function () {
|
||||
var now = +new Date()
|
||||
return function (...argArr) {
|
||||
const now = +new Date()
|
||||
context = this
|
||||
args = arguments
|
||||
args = argArr
|
||||
if (now - previous > wait) {
|
||||
fn.apply(context, args)
|
||||
previous = now
|
||||
@@ -45,16 +45,15 @@ export function throttle(fn, wait) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
* @param {Function} func
|
||||
* @param {Function} method
|
||||
* @param {number} wait
|
||||
* @param {boolean} immediate
|
||||
* @return {*}
|
||||
* @return {*} 防抖函数
|
||||
*/
|
||||
export function debounce(method, wait, immediate) {
|
||||
let timeout
|
||||
return function (...args) {
|
||||
let context = this
|
||||
const context = this
|
||||
if (timeout) {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
@@ -64,14 +63,15 @@ export function debounce(method, wait, immediate) {
|
||||
* 如果定时器不存在,则立即执行,并设置一个定时器,wait毫秒后将定时器置为null
|
||||
* 这样确保立即执行后wait毫秒内不会被再次触发
|
||||
*/
|
||||
let callNow = !timeout
|
||||
const callNow = !timeout
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null
|
||||
}, wait)
|
||||
if (callNow) {
|
||||
method.apply(context, args)
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// 如果immediate为false,则函数wait毫秒后执行
|
||||
timeout = setTimeout(() => {
|
||||
/**
|
||||
@@ -85,12 +85,11 @@ export function debounce(method, wait, immediate) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc 睡一会儿,让子弹暂停一下
|
||||
* @param {number} time 毫秒数
|
||||
* @returns
|
||||
* @returns 睡一会儿,让子弹暂停一下
|
||||
*/
|
||||
export function sleep(time) {
|
||||
return new Promise((resolve) => setTimeout(resolve, time))
|
||||
return new Promise(resolve => setTimeout(resolve, time))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,8 @@ let isConfirming = false
|
||||
export function resolveResError(code, message) {
|
||||
switch (code) {
|
||||
case 401:
|
||||
if (isConfirming) return
|
||||
if (isConfirming)
|
||||
return
|
||||
isConfirming = true
|
||||
$dialog.confirm({
|
||||
title: '提示',
|
||||
@@ -31,7 +32,8 @@ export function resolveResError(code, message) {
|
||||
return false
|
||||
case 11007:
|
||||
case 11008:
|
||||
if (isConfirming) return
|
||||
if (isConfirming)
|
||||
return
|
||||
isConfirming = true
|
||||
$dialog.confirm({
|
||||
title: '提示',
|
||||
|
||||
@@ -20,7 +20,7 @@ export function setupInterceptors(axiosInstance) {
|
||||
const { accessToken } = useAuthStore()
|
||||
if (accessToken) {
|
||||
// token: Bearer + xxx
|
||||
config.headers.Authorization = 'Bearer ' + accessToken
|
||||
config.headers.Authorization = `Bearer ${accessToken}`
|
||||
}
|
||||
|
||||
return config
|
||||
@@ -42,7 +42,7 @@ export function setupInterceptors(axiosInstance) {
|
||||
// 根据code处理对应的操作,并返回处理后的message
|
||||
const message = resolveResError(code, data?.message ?? statusText)
|
||||
|
||||
//需要错误提醒
|
||||
// 需要错误提醒
|
||||
!config?.noNeedTip && message && window.$message?.error(message)
|
||||
return Promise.reject({ code, message, error: data ?? response })
|
||||
}
|
||||
|
||||
@@ -99,28 +99,27 @@ export function isEmpty(val) {
|
||||
}
|
||||
|
||||
/**
|
||||
* * 类似mysql的IFNULL函数
|
||||
* * 第一个参数为null/undefined/'' 则返回第二个参数作为备用值,否则返回第一个参数
|
||||
* @param {Number|Boolean|String} val
|
||||
* @param {Number|Boolean|String} def
|
||||
* @returns
|
||||
* 类似mysql的IFNULL函数
|
||||
*
|
||||
* @param {number | boolean | string} val
|
||||
* @param {number | boolean | string} def
|
||||
* @returns 第一个参数为null | undefined | '' 则返回第二个参数作为备用值,否则返回第一个参数
|
||||
*/
|
||||
export function ifNull(val, def = '') {
|
||||
return isNullOrWhitespace(val) ? def : val
|
||||
}
|
||||
|
||||
export function isUrl(path) {
|
||||
const reg =
|
||||
/(((^https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)$/
|
||||
const reg = /^https?:\/\/[-\w+&@#/%?=~|!:,.;]+[-\w+&@#/%=~|]$/
|
||||
return reg.test(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {Boolean}
|
||||
* @returns {boolean} 是否是外部链接
|
||||
*/
|
||||
export function isExternal(path) {
|
||||
return /^(https?:|mailto:|tel:)/.test(path)
|
||||
return /^https?:|mailto:|tel:/.test(path)
|
||||
}
|
||||
|
||||
export const isServer = typeof window === 'undefined'
|
||||
|
||||
@@ -16,7 +16,8 @@ export function setupMessage(NMessage) {
|
||||
static instance
|
||||
constructor() {
|
||||
// 单例模式
|
||||
if (Message.instance) return Message.instance
|
||||
if (Message.instance)
|
||||
return Message.instance
|
||||
Message.instance = this
|
||||
this.message = {}
|
||||
this.removeTimer = {}
|
||||
@@ -37,7 +38,7 @@ export function setupMessage(NMessage) {
|
||||
|
||||
showMessage(type, content, option = {}) {
|
||||
if (Array.isArray(content)) {
|
||||
return content.forEach((msg) => NMessage[type](msg, option))
|
||||
return content.forEach(msg => NMessage[type](msg, option))
|
||||
}
|
||||
|
||||
if (!option.key) {
|
||||
@@ -48,7 +49,8 @@ export function setupMessage(NMessage) {
|
||||
if (currentMessage) {
|
||||
currentMessage.type = type
|
||||
currentMessage.content = content
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.message[option.key] = NMessage[type](content, {
|
||||
...option,
|
||||
duration: 0,
|
||||
@@ -109,7 +111,7 @@ export function setupNaiveDiscreteApi() {
|
||||
}))
|
||||
const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{ configProviderProps }
|
||||
{ configProviderProps },
|
||||
)
|
||||
|
||||
window.$loadingBar = loadingBar
|
||||
|
||||
@@ -35,7 +35,8 @@ class Storage {
|
||||
|
||||
getItem(key, def = null) {
|
||||
const val = this.storage.getItem(this.getKey(key))
|
||||
if (!val) return def
|
||||
if (!val)
|
||||
return def
|
||||
try {
|
||||
const data = JSON.parse(val)
|
||||
const { value, time, expire } = data
|
||||
@@ -44,7 +45,8 @@ class Storage {
|
||||
}
|
||||
this.remove(key)
|
||||
return def
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
this.remove(key)
|
||||
return def
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user