133 lines
3.3 KiB
JavaScript
133 lines
3.3 KiB
JavaScript
/**
|
|
* Deotaland工具函数库
|
|
* 提供常用的工具函数和辅助方法
|
|
*/
|
|
|
|
// 导入各个工具模块
|
|
import * as stringUtils from './utils/string.js'
|
|
import * as arrayUtils from './utils/array.js'
|
|
import * as objectUtils from './utils/object.js'
|
|
import * as dateUtils from './utils/date.js'
|
|
import * as fileUtils from './utils/file.js'
|
|
import * as validateUtils from './utils/validate.js'
|
|
import * as formatUtils from './utils/format.js'
|
|
import * as environmentUtils from './utils/environment.js'
|
|
import { request as requestUtils } from './utils/request.js'
|
|
import * as adminApi from './api/FrontendDesigner/index.js';
|
|
import * as clientApi from './api/frontend/index.js';
|
|
import { MeshyServer } from './servers/meshyserver.js';
|
|
import { GiminiServer } from './servers/giminiserver.js';
|
|
import { FileServer } from './servers/fileserver.js';
|
|
import { XiaozhiServer } from './servers/xiaozhiserve.js';
|
|
import prompt from './servers/prompt.js';
|
|
import { PayServer } from './servers/payserver.js';
|
|
import { LogistIcsService } from './servers/logisticsservice.js';
|
|
import * as orderStatus from './utils/orderStatus.js';
|
|
import { WechatBus } from './utils/wechaBus.js';
|
|
// 合并所有工具函数
|
|
const deotalandUtils = {
|
|
string: stringUtils,
|
|
array: arrayUtils,
|
|
object: objectUtils,
|
|
date: dateUtils,
|
|
file: fileUtils,
|
|
validate: validateUtils,
|
|
format: formatUtils,
|
|
environment: environmentUtils,
|
|
request: requestUtils,
|
|
FileServer,
|
|
adminApi,
|
|
clientApi,
|
|
MeshyServer,
|
|
GiminiServer,
|
|
XiaozhiServer,
|
|
prompt,
|
|
PayServer,
|
|
LogistIcsService,
|
|
orderStatus,
|
|
WechatBus,
|
|
isWeChatBrowser,
|
|
// 全局常用方法
|
|
debounce: stringUtils.debounce || createDebounce(),
|
|
throttle: stringUtils.throttle || createThrottle(),
|
|
deepClone: objectUtils.deepClone,
|
|
isEmpty: objectUtils.isEmpty,
|
|
pick: objectUtils.pick,
|
|
omit: objectUtils.omit,
|
|
}
|
|
|
|
// 导出默认导出
|
|
export default deotalandUtils
|
|
|
|
// 命名导出
|
|
export {
|
|
stringUtils,
|
|
arrayUtils,
|
|
objectUtils,
|
|
dateUtils,
|
|
fileUtils,
|
|
FileServer,
|
|
validateUtils,
|
|
formatUtils,
|
|
environmentUtils,
|
|
requestUtils,
|
|
adminApi,
|
|
clientApi,
|
|
MeshyServer,
|
|
prompt,
|
|
GiminiServer,
|
|
XiaozhiServer,
|
|
PayServer,
|
|
LogistIcsService,
|
|
orderStatus,
|
|
WechatBus,
|
|
isWeChatBrowser,
|
|
}
|
|
function isWeChatBrowser() {
|
|
const ua = navigator.userAgent.toLowerCase()
|
|
return ua.indexOf('micromessenger') !== -1
|
|
}
|
|
/**
|
|
* 创建防抖函数
|
|
*/
|
|
function createDebounce(fn, delay = 300, immediate = false) {
|
|
let timeout
|
|
return function (...args) {
|
|
const context = this
|
|
const callNow = immediate && !timeout
|
|
clearTimeout(timeout)
|
|
timeout = setTimeout(() => {
|
|
timeout = null
|
|
if (!immediate) fn.apply(context, args)
|
|
}, delay)
|
|
if (callNow) fn.apply(context, args)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建节流函数
|
|
*/
|
|
function createThrottle(fn, delay = 300) {
|
|
let timeout
|
|
let previous = 0
|
|
return function (...args) {
|
|
const context = this
|
|
const now = Date.now()
|
|
const remaining = delay - (now - previous)
|
|
|
|
if (remaining <= 0 || remaining > delay) {
|
|
if (timeout) {
|
|
clearTimeout(timeout)
|
|
timeout = null
|
|
}
|
|
previous = now
|
|
fn.apply(context, args)
|
|
} else if (!timeout) {
|
|
timeout = setTimeout(() => {
|
|
previous = Date.now()
|
|
timeout = null
|
|
fn.apply(context, args)
|
|
}, remaining)
|
|
}
|
|
}
|
|
} |