index.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. export interface DialogShowOptions {
  2. title: string
  3. content: string
  4. path: string
  5. image: string
  6. }
  7. export enum HonorDialogType {
  8. Badge = 'badge',
  9. Certificate = 'certificate',
  10. }
  11. export interface HonorDialogOptions {
  12. title?: string
  13. content?: string
  14. image?: string
  15. type?: HonorDialogType
  16. onLoad?: () => void
  17. }
  18. // export const HonorDialogSymbol: InjectionKey<{
  19. // show: (options: DialogShowOptions) => void
  20. // }> = Symbol.for('HonorDialogContext')
  21. export const HonorDialogSymbol = Symbol.for('HonorDialogContext')
  22. // export const useHonorDialog = () => {
  23. // const honorDialog = inject(HonorDialogSymbol)
  24. // // if (!honorDialog) {
  25. // // throw new Error('useHonorDialog must be used inside setup()')
  26. // // }
  27. // const show = computed(() => honorDialog?.show)
  28. // return {
  29. // show,
  30. // }
  31. // }
  32. export const useHonorDialog = () => {
  33. const dialogOption = ref({})
  34. // inject(HonorDialogSymbol, dialogOption)
  35. // const honorDialog = inject(HonorDialogSymbol)
  36. // console.log(honorDialog)
  37. provide(HonorDialogSymbol, dialogOption)
  38. // if (!honorDialog) {
  39. // throw new Error('useHonorDialog must be used inside setup()')
  40. // }
  41. const show = (option: HonorDialogOptions) => {
  42. return new Promise((resolve, reject) => {
  43. const options = {
  44. ...option,
  45. }
  46. dialogOption.value = {
  47. ...options,
  48. ...{
  49. show: true,
  50. onConfirm: (res) => {
  51. resolve(res)
  52. },
  53. onCancel: (res) => {
  54. reject(res)
  55. },
  56. },
  57. }
  58. })
  59. }
  60. return {
  61. show,
  62. }
  63. }