ui.uvue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <cl-confirm ref="confirmRef"></cl-confirm>
  3. <cl-confirm ref="tipsRef"></cl-confirm>
  4. <cl-toast ref="toastRef"></cl-toast>
  5. </template>
  6. <script setup lang="ts">
  7. import { ref } from "vue";
  8. import type { ClConfirmAction, ClConfirmOptions, ClToastOptions } from "../../types";
  9. import { createUi, type UiInstance } from "../../hooks";
  10. import { t } from "@/locale";
  11. defineOptions({
  12. name: "cl-page-ui"
  13. });
  14. // 确认弹窗实例
  15. const confirmRef = ref<ClConfirmComponentPublicInstance | null>(null);
  16. // 提示弹窗实例
  17. const tipsRef = ref<ClConfirmComponentPublicInstance | null>(null);
  18. // 提示弹窗实例
  19. const toastRef = ref<ClToastComponentPublicInstance | null>(null);
  20. /**
  21. * 显示确认弹窗
  22. * @param options ClConfirmOptions 弹窗配置项
  23. */
  24. function showConfirm(options: ClConfirmOptions) {
  25. if (confirmRef.value != null) {
  26. confirmRef.value!.open(options);
  27. }
  28. }
  29. /**
  30. * 显示提示弹窗
  31. * @param message 提示消息
  32. * @param callback 回调函数
  33. */
  34. function showTips(message: string, callback: (action: ClConfirmAction) => void) {
  35. if (tipsRef.value != null) {
  36. tipsRef.value!.open({
  37. title: t("提示"),
  38. message,
  39. callback,
  40. showCancel: false
  41. } as ClConfirmOptions);
  42. }
  43. }
  44. /**
  45. * 显示提示弹窗
  46. * @param options ClToastOptions 弹窗配置项
  47. */
  48. function showToast(options: ClToastOptions) {
  49. if (toastRef.value != null) {
  50. toastRef.value!.open(options);
  51. }
  52. }
  53. // 注册当前页面的 UiInstance 实例
  54. createUi({
  55. showConfirm,
  56. showTips,
  57. showToast
  58. } as UiInstance);
  59. </script>