1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- export interface DialogShowOptions {
- title: string
- content: string
- path: string
- image: string
- }
- export interface HonorDialogOptions {
- title?: string
- content?: string
- image?: string
- type?: 'badge' | 'certificate'
- onLoad?: () => void
- }
- // export const HonorDialogSymbol: InjectionKey<{
- // show: (options: DialogShowOptions) => void
- // }> = Symbol.for('HonorDialogContext')
- export const HonorDialogSymbol = Symbol.for('HonorDialogContext')
- // export const useHonorDialog = () => {
- // const honorDialog = inject(HonorDialogSymbol)
- // // if (!honorDialog) {
- // // throw new Error('useHonorDialog must be used inside setup()')
- // // }
- // const show = computed(() => honorDialog?.show)
- // return {
- // show,
- // }
- // }
- export const useHonorDialog = () => {
- const dialogOption = ref({})
- // inject(HonorDialogSymbol, dialogOption)
- // const honorDialog = inject(HonorDialogSymbol)
- // console.log(honorDialog)
- provide(HonorDialogSymbol, dialogOption)
- // if (!honorDialog) {
- // throw new Error('useHonorDialog must be used inside setup()')
- // }
- const show = (option: HonorDialogOptions) => {
- return new Promise((resolve, reject) => {
- const options = {
- ...option,
- }
- dialogOption.value = {
- ...options,
- ...{
- show: true,
- onConfirm: (res) => {
- resolve(res)
- },
- onCancel: (res) => {
- reject(res)
- },
- },
- }
- })
- }
- return {
- show,
- }
- }
|