import { Modal } from 'ant-design-vue' import { createVNode } from 'vue' import { ExclamationCircleOutlined } from '@ant-design/icons-vue' import { message } from 'ant-design-vue/es' //todo export async function confirmDeleteItem( type: string, id: number, functionDelete: (id: number) => Promise, refreshTable: () => void ) { Modal.confirm({ title: `آیا از حذف ${type} اطمینان دارید؟`, icon: createVNode(ExclamationCircleOutlined), okText: 'تایید', okType: 'danger', centered: true, cancelText: 'انصراف', async onOk() { // console.log('OK'); // await deleteItem(id) // loading.value = true // table?.value?.spinTable(true) // @ts-ignore try { await functionDelete(id) refreshTable() console.log('finall') message.success('با موفقیت حذف شد') } catch (e) { console.error(e) // message.error('خطا در حذف') } // setTimeout(Math.random() > 0.5 ? resolve : reject, 1000) // table?.value?.fetch() // loading.value = false // table?.value?.spinTable(false) }, onCancel() { console.log('Cancel') } }) } export async function confirmActOnApi( title: string, id: number, functionApi: (id: number) => Promise, refreshTable: () => void ) { Modal.confirm({ title: title, icon: createVNode(ExclamationCircleOutlined), okText: 'تایید', okType: 'danger', centered: true, cancelText: 'انصراف', async onOk() { // console.log('OK'); // await deleteItem(id) // loading.value = true // table?.value?.spinTable(true) // @ts-ignore try { await functionApi(id) refreshTable() // console.log('finall') message.success('با موفقیت انجام شد') } catch (e) { console.error(e) // message.error('خطا در حذف') } // setTimeout(Math.random() > 0.5 ? resolve : reject, 1000) // table?.value?.fetch() // loading.value = false // table?.value?.spinTable(false) }, onCancel() { console.log('Cancel') } }) } export default async function baseConfirm( title: string, actionFunction: () => void, ) { Modal.confirm({ title: title, icon: createVNode(ExclamationCircleOutlined), okText: 'تایید', okType: 'danger', centered: true, cancelText: 'انصراف', async onOk() { // console.log('OK'); // await deleteItem(id) // loading.value = true // table?.value?.spinTable(true) // @ts-ignore try { await actionFunction() // console.log('finall') // message.success('با موفقیت انجام شد') } catch (e) { console.error(e) // message.error('خطا در حذف') } // setTimeout(Math.random() > 0.5 ? resolve : reject, 1000) // table?.value?.fetch() // loading.value = false // table?.value?.spinTable(false) }, onCancel() { console.log('Cancel') } }) }