refactor(admin): 收敛后台接口封装与页面状态逻辑
- 简化绑定和日志接口的查询、序列化与前端数据请求路径 - 统一登录流程与前端 API 调用层,补充后台图标依赖 - 抽取通用异步状态处理,减少多个管理页面的重复逻辑
This commit is contained in:
25
frontend/src/composables/useAsyncAction.js
Normal file
25
frontend/src/composables/useAsyncAction.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import { humanizeError } from '../api'
|
||||
|
||||
export function useAsyncAction() {
|
||||
const loading = ref(false)
|
||||
|
||||
async function run(task, fallbackMessage) {
|
||||
loading.value = true
|
||||
try {
|
||||
return await task()
|
||||
} catch (error) {
|
||||
ElMessage.error(humanizeError(error, fallbackMessage))
|
||||
throw error
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
run,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user