refactor(http): 移除.promise调用并实现无感刷新token

- 移除所有API调用中的.promise后缀,简化调用方式
- 在http.ts中实现双token无感刷新机制
- 移除测试用的sleep延迟和取消请求相关代码
- 优化401错误处理,支持双token模式自动刷新
This commit is contained in:
feige996
2025-09-25 14:54:18 +08:00
parent 780491290d
commit a4a720fef5
6 changed files with 103 additions and 30 deletions

View File

@@ -6,10 +6,11 @@ const loading = ref(false)
const error = ref<Error | null>(null)
const data = ref<UserItem>()
// openapi 请求示例
async function getUserInfo() {
try {
loading.value = true
const res = await (await infoUsingGet({})).promise
const res = await infoUsingGet({})
console.log(res)
data.value = res
error.value = null
@@ -22,7 +23,9 @@ async function getUserInfo() {
loading.value = false
}
}
const { data: data2, loading: loading2, run, cancel } = useRequest(() => listAllUsingGet({}), {
// openapi + useRequest 请求示例
const { data: data2, loading: loading2, run } = useRequest(() => listAllUsingGet({}), {
immediate: false,
})
</script>
@@ -50,9 +53,6 @@ const { data: data2, loading: loading2, run, cancel } = useRequest(() => listAll
<button type="primary" size="mini" class="w-160px" @click="run">
发送请求
</button>
<button type="default" size="mini" class="w-160px" @click="cancel">
取消请求
</button>
</view>
<view class="text-xl">
请求数据如下