index.ts 1.5 KB

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