30 lines
822 B
TypeScript
30 lines
822 B
TypeScript
import { ElLoading } from 'element-plus'
|
|
|
|
const defaultOptions = {
|
|
lock: true,
|
|
background: 'rgba(0, 0, 0, 0.35)'
|
|
} as const
|
|
|
|
/** 全屏蒙层 + 异步任务;无论成功/失败都会在 finally 关闭 */
|
|
export async function withFullscreenLoading<T>(
|
|
task: () => Promise<T>,
|
|
text = '请稍候…'
|
|
): Promise<T> {
|
|
const inst = ElLoading.service({ ...defaultOptions, text })
|
|
try {
|
|
return await task()
|
|
} finally {
|
|
inst.close()
|
|
}
|
|
}
|
|
|
|
export const fullscreenLoadingText = {
|
|
save: '正在保存,请稍候…',
|
|
delete: '正在删除,请稍候…',
|
|
batchDelete: '正在批量删除,请稍候…',
|
|
batchAudit: '正在提交审核,请稍候…',
|
|
activate: '正在生效,请稍候…',
|
|
voidAgreement: '正在作废,请稍候…',
|
|
addItems: '正在添加,请稍候…'
|
|
} as const
|