feat(projects): 工作台部分组件调成真实数据
This commit is contained in:
30
src/views/workbench/composables/use-workbench-refresh.ts
Normal file
30
src/views/workbench/composables/use-workbench-refresh.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
/**
|
||||
* 工作台 widget 统一刷新:卡片右上角刷新按钮触发,转 loading + 执行加载动作,并发期内忽略重复点击。
|
||||
*
|
||||
* - 已接真实接口的 widget:传入 loader(内部 await 拉取并回填数据)。
|
||||
* - 尚未接接口的 mock widget:不传 loader,转一拍 loading 给出可感知反馈;接口接通后补 loader 即自动生效。
|
||||
*/
|
||||
export function useWorkbenchRefresh(loader?: () => Promise<void> | void) {
|
||||
const loading = ref(false);
|
||||
|
||||
async function refresh() {
|
||||
if (loading.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
if (loader) {
|
||||
await loader();
|
||||
} else {
|
||||
// 占位:mock widget 无真实数据源,转一拍 loading;接口接通后传入 loader 替代
|
||||
await new Promise<void>(resolve => {
|
||||
setTimeout(resolve, 400);
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { loading, refresh };
|
||||
}
|
||||
Reference in New Issue
Block a user