1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-12-28 12:10:20 +08:00

refactor: folders

This commit is contained in:
张传龙
2022-09-18 20:05:40 +08:00
parent bdbe9b8483
commit 6664ae8f7b
45 changed files with 138 additions and 139 deletions

2
src/utils/auth/index.js Normal file
View File

@@ -0,0 +1,2 @@
export * from './auth'
export * from './token'

View File

@@ -1,4 +1,4 @@
import { lStorage } from './cache'
import { lStorage } from '@/utils'
import api from '@/api'
const TOKEN_CODE = 'access_token'

View File

@@ -0,0 +1,76 @@
import dayjs from 'dayjs'
/**
* @desc 格式化时间
* @param {(Object|string|number)} time
* @param {string} format
* @returns {string | null}
*/
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(time).format(format)
}
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
return formatDateTime(date, format)
}
/**
* @desc 函数节流
* @param {Function} fn
* @param {Number} wait
* @returns {Function}
*/
export function throttle(fn, wait) {
var context, args
var previous = 0
return function () {
var now = +new Date()
context = this
args = arguments
if (now - previous > wait) {
fn.apply(context, args)
previous = now
}
}
}
/**
* @desc 函数防抖
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(method, wait, immediate) {
let timeout
return function (...args) {
let context = this
if (timeout) {
clearTimeout(timeout)
}
// 立即执行需要两个条件一是immediate为true二是timeout未被赋值或被置为null
if (immediate) {
/**
* 如果定时器不存在则立即执行并设置一个定时器wait毫秒后将定时器置为null
* 这样确保立即执行后wait毫秒内不会被再次触发
*/
let callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) {
method.apply(context, args)
}
} else {
// 如果immediate为false则函数wait毫秒后执行
timeout = setTimeout(() => {
/**
* args是一个类数组对象所以使用fn.apply
* 也可写作method.call(context, ...args)
*/
method.apply(context, args)
}, wait)
}
}
}

View File

@@ -0,0 +1,4 @@
export * from './common'
export * from './is'
export * from './icon'
export * from './naiveTools'

View File

@@ -1,4 +1,4 @@
import { isNullOrUndef } from '@/utils/is'
import { isNullOrUndef } from '@/utils'
export function setupMessage(NMessage) {
let loadingMessage = null

View File

@@ -1,7 +1,5 @@
import { useUserStore } from '@/store/modules/user'
import { isNullOrUndef } from '@/utils/is'
import { removeToken } from '@/utils/token'
import { toLogin } from '@/utils/auth'
import { useUserStore } from '@/store'
import { isNullOrUndef, removeToken, toLogin } from '@/utils'
export function addBaseParams(params) {
if (!params.userId) {

View File

@@ -14,6 +14,6 @@ export function createAxios(options = {}) {
return service
}
export default createAxios({
export const request = createAxios({
baseURL: import.meta.env.VITE_BASE_API,
})

View File

@@ -1,5 +1,4 @@
import { getToken } from '@/utils/token'
import { toLogin } from '@/utils/auth'
import { getToken, toLogin } from '@/utils'
import { resolveResError } from './helpers'
export function reqResolve(config) {

View File

@@ -1,76 +1,4 @@
import dayjs from 'dayjs'
/**
* @desc 格式化时间
* @param {(Object|string|number)} time
* @param {string} format
* @returns {string | null}
*/
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(time).format(format)
}
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
return formatDateTime(date, format)
}
/**
* @desc 函数节流
* @param {Function} fn
* @param {Number} wait
* @returns {Function}
*/
export function throttle(fn, wait) {
var context, args
var previous = 0
return function () {
var now = +new Date()
context = this
args = arguments
if (now - previous > wait) {
fn.apply(context, args)
previous = now
}
}
}
/**
* @desc 函数防抖
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(method, wait, immediate) {
let timeout
return function (...args) {
let context = this
if (timeout) {
clearTimeout(timeout)
}
// 立即执行需要两个条件一是immediate为true二是timeout未被赋值或被置为null
if (immediate) {
/**
* 如果定时器不存在则立即执行并设置一个定时器wait毫秒后将定时器置为null
* 这样确保立即执行后wait毫秒内不会被再次触发
*/
let callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) {
method.apply(context, args)
}
} else {
// 如果immediate为false则函数wait毫秒后执行
timeout = setTimeout(() => {
/**
* args是一个类数组对象所以使用fn.apply
* 也可写作method.call(context, ...args)
*/
method.apply(context, args)
}, wait)
}
}
}
export * from './common'
export * from './storage'
export * from './http'
export * from './auth'

View File

@@ -1,4 +1,4 @@
import { isNullOrUndef } from '@/utils/is'
import { isNullOrUndef } from '@/utils'
class Storage {
constructor(option) {