This commit is contained in:
2025-06-16 10:09:19 +08:00
commit 7a066b3026
428 changed files with 50385 additions and 0 deletions

View File

@ -0,0 +1,22 @@
const PROMISE = Symbol('$$promise')
export default class Fetcher {
get [Symbol.toStringTag]() {
return '[object Fetcher]'
}
constructor() {
this[PROMISE] = new Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
}
async source() {
return this[PROMISE]
}
async abort() {
;(await this.source())?.abort()
}
}

View File

@ -0,0 +1,16 @@
export default function adapter(config) {
return new Promise((resolve, reject) => {
const requestTask = uni.request({
...config,
complete: result => {
// 根据状态码判断要执行的触发的状态
const response = { config, ...result }
!config.validateStatus || config.validateStatus(result.statusCode)
? resolve(response)
: reject(response)
}
})
config.fetcher?.resolve(requestTask)
})
}