import { closeToast, showLoadingToast, type ToastWrapperInstance } from 'vant' interface ApiType { api: (data?: T) => Promise<{ code: string; msg: string; data: K }> params?: object } export const useCreatePageData = (apis: ApiType[]) => { return Promise.all(apis.map((item: ApiType) => item.api(item.params))) } // 提交loading export const useSubmitLoading = (message = '提交中...') => { showLoadingToast({ duration: 0, overlay: true, forbidClick: true, message }) } useSubmitLoading.close = () => { closeToast() } // 将日期转为数组 export const handleDateToArray = (date: Date) => { return [date.getFullYear().toString(), (date.getMonth() + 1).toString().padStart(2, '0'), date.getDate().toString().padStart(2, '0')] } window.isBgWhite = ref(true) export const isBgWhite = window.isBgWhite // 获取loading export const loadingData = reactive({ if: null as null | boolean, type: 'enter', show: false }) window.useLoading = (ob: { type: 'enter' | 'submit'; show: boolean } = { type: 'enter', show: true }) => { loadingData.if ??= true return Object.assign(loadingData, ob) } // 提示弹窗 export const tipDialogData = reactive({ if: null as null | boolean, show: false, showCloseIcon: false, showCancelBtn: false, cancelBtnName: '', title: '', html: '', btnName: '', callback: (() => {}) as (result: boolean) => void | Promise, }) window.useTipDialog = ( callback: (result: boolean) => void | Promise, config: { title: string html: string btnName: string showCloseIcon?: boolean showCancelBtn?: boolean cancelBtnName?: string }, ) => { tipDialogData.showCancelBtn = false Object.assign(tipDialogData, config) tipDialogData.if ??= true tipDialogData.show = true tipDialogData.callback = callback }