useProgress.ts 725 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { ref } from 'vue'
  2. /** 全局进度管理 */
  3. const visible = ref(false)
  4. const progress = ref(0)
  5. const text = ref('')
  6. export function useProgress() {
  7. /**
  8. * 显示进度
  9. */
  10. function show(t = '加载中') {
  11. text.value = t
  12. progress.value = 0
  13. visible.value = true
  14. }
  15. /**
  16. * 更新进度
  17. */
  18. function update(p: number, t?: string) {
  19. progress.value = Math.min(100, Math.max(0, p))
  20. if (t) text.value = t
  21. }
  22. /**
  23. * 隐藏进度
  24. */
  25. function hide() {
  26. visible.value = false
  27. progress.value = 0
  28. }
  29. return {
  30. visible,
  31. progress,
  32. text,
  33. show,
  34. update,
  35. hide
  36. }
  37. }