- 优化 Dashboard、Bindings、Logs、Settings 的布局、筛选区与信息层级 - 增加筛选状态同步、未保存提醒、运行时反馈和趋势表视图 - 补充跳转主内容、aria live、键盘导航与移动端触控细节
37 lines
756 B
JavaScript
37 lines
756 B
JavaScript
import { ref } from 'vue'
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
import { humanizeError } from '../api'
|
|
import { announcePolite } from '../utils/liveRegion'
|
|
|
|
export function useAsyncAction() {
|
|
const loading = ref(false)
|
|
const errorMessage = ref('')
|
|
|
|
function clearError() {
|
|
errorMessage.value = ''
|
|
}
|
|
|
|
async function run(task, fallbackMessage) {
|
|
loading.value = true
|
|
clearError()
|
|
try {
|
|
return await task()
|
|
} catch (error) {
|
|
errorMessage.value = humanizeError(error, fallbackMessage)
|
|
announcePolite(errorMessage.value)
|
|
ElMessage.error(errorMessage.value)
|
|
throw error
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
return {
|
|
clearError,
|
|
errorMessage,
|
|
loading,
|
|
run,
|
|
}
|
|
}
|