feat(admin): 添加比赛管理页面功能优化
refactor(utils): 为工具函数添加注释并导出新模块 feat(utils): 新增防抖和节流工具函数 docs(utils): 为现有工具类添加中文注释 style(admin): 优化比赛配置页面UI样式 feat(admin): 实现比赛基础信息表单双向绑定 feat(admin): 新增页面头部公共组件 feat(admin): 完善分组管理自动生成逻辑 feat(admin): 增强题目配置功能与交互 fix(admin): 修复表单数据更新死循环问题
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
/**
|
||||
* 加密解密工具类
|
||||
*/
|
||||
export class Crypto<T extends object> {
|
||||
/** Secret */
|
||||
secret: string
|
||||
|
||||
@ -2,3 +2,4 @@ export * from './crypto'
|
||||
export * from './klona'
|
||||
export * from './nanoid'
|
||||
export * from './storage'
|
||||
export * from './tool'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { nanoid } from 'nanoid'
|
||||
|
||||
/**
|
||||
* 生成 NanoID
|
||||
*/
|
||||
export { nanoid }
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import localforage from 'localforage'
|
||||
|
||||
/**
|
||||
* 本地存储工具类
|
||||
*/
|
||||
/** The storage type */
|
||||
export type StorageType = 'local' | 'session'
|
||||
|
||||
|
||||
55
packages/utils/src/tool.ts
Normal file
55
packages/utils/src/tool.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 防抖函数
|
||||
* @param func 需要执行的函数
|
||||
* @param wait 等待时间(毫秒)
|
||||
* @param immediate 是否立即执行
|
||||
*/
|
||||
export function debounce<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
wait: number,
|
||||
immediate = false,
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
return function (this: any, ...args: Parameters<T>) {
|
||||
// 直接使用 this,避免本地变量别名
|
||||
|
||||
if (timeout)
|
||||
clearTimeout(timeout)
|
||||
|
||||
if (immediate) {
|
||||
const callNow = !timeout
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null
|
||||
}, wait)
|
||||
if (callNow)
|
||||
func.apply(this, args)
|
||||
}
|
||||
else {
|
||||
timeout = setTimeout(() => {
|
||||
func.apply(this, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节流函数
|
||||
* @param func 需要执行的函数
|
||||
* @param wait 等待时间(毫秒)
|
||||
*/
|
||||
export function throttle<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
wait: number,
|
||||
): (...args: Parameters<T>) => void {
|
||||
let previous = 0
|
||||
|
||||
return function (this: any, ...args: Parameters<T>) {
|
||||
const now = Date.now()
|
||||
|
||||
if (now - previous > wait) {
|
||||
func.apply(this, args)
|
||||
previous = now
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user