feat: 添加常用函数

This commit is contained in:
Your Name
2024-12-26 18:37:09 +08:00
parent f8abb65023
commit ecd30a2e82
3 changed files with 68 additions and 2 deletions
+28 -1
View File
@@ -1,7 +1,7 @@
import { pages, subPackages, tabBar } from '@/pages.json'
import { isMp } from './platform'
const getLastPage = () => {
export const getLastPage = () => {
// getCurrentPages() 至少有1个元素,所以不再额外判断
// const lastPage = getCurrentPages().at(-1)
// 上面那个在低版本安卓中打包回报错,所以改用下面这个【虽然我加了src/interceptions/prototype.ts,但依然报错】
@@ -176,3 +176,30 @@ export const getEnvBaseUploadUrl = () => {
return baseUploadUrl
}
export function mergeStep(wrapped: (...rest: any[]) => Promise<any>) {
let _mergeStepRequestInstance: any = null
return async function (...args) {
if (this?._mergeStepRequestInstance ?? _mergeStepRequestInstance)
return this?._mergeStepRequestInstance ?? _mergeStepRequestInstance
if (this) {
this._mergeStepRequestInstance = wrapped.apply(this, args)
} else {
_mergeStepRequestInstance = wrapped(...args)
}
if (
Object.prototype.toString.call(
this?._mergeStepRequestInstance ?? _mergeStepRequestInstance,
) === '[object Promise]'
) {
;(this?._mergeStepRequestInstance ?? _mergeStepRequestInstance).finally(() => {
if (this?._mergeStepRequestInstance) {
this._mergeStepRequestInstance = null
} else {
_mergeStepRequestInstance = null
}
})
}
return _mergeStepRequestInstance
}
}