| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import { ref } from 'vue'
- import { useI18n } from 'vue-i18n'
- interface PopupOptions {
- title?: string
- content?: string
- cancelText?: string
- confirmText?: string
- width?: number
- showCancel?: boolean
- // confirmBtnType?: 'primary' | 'danger'
- }
- interface PopupState {
- visible: boolean
- title: string
- content: string
- cancelText: string
- confirmText: string
- showCancel: boolean
- // confirmBtnType: 'primary' | 'danger'
- resolve: ((value: boolean) => void) | null
- }
- const popupState = ref<PopupState>({
- visible: false,
- title: '',
- content: '',
- cancelText: '',
- confirmText: '',
- showCancel: true,
- // confirmBtnType: 'primary',
- resolve: null
- })
- export function usePopup() {
- const { t } = useI18n()
- const confirm = (options: PopupOptions = {}): Promise<boolean> => {
- return new Promise((resolve) => {
- console.log(options,'dia')
- popupState.value = {
- visible: true,
- title: options.title || t('Msg.SystemPrompt'),
- content: options.content || '',
- showCancel: options.showCancel != undefined ? options.showCancel: true,
- cancelText: options.cancelText || t('Btn.Cancel'),
- confirmText: options.confirmText || t('Btn.Confirm'),
- // confirmBtnType: options.confirmBtnType || 'primary',
- resolve
- }
- })
- }
- const close = () => {
- if (popupState.value.resolve) {
- popupState.value.resolve(false)
- popupState.value.resolve = null
- }
- popupState.value.visible = false
- }
- const handleConfirm = () => {
- if (popupState.value.resolve) {
- popupState.value.resolve(true)
- popupState.value.resolve = null
- }
- popupState.value.visible = false
- }
- return {
- popupState,
- confirm,
- close,
- handleConfirm
- }
- }
|