// import { useRoute } from 'vue-router'; import { ref } from 'vue'; import { NButton, useDialog, NIcon } from 'naive-ui'; import type { Size } from 'naive-ui/es/select/src/interface'; import { EyeOutline, Send, TrashOutline, Search, RefreshSharp, ReturnUpBack, AddOutline, DocumentTextOutline, CreateOutline, SettingsOutline, LockClosedOutline, LockOpenOutline, CloudDownloadOutline, CheckmarkSharp, CloseSharp } from '@vicons/ionicons5'; // import * from '@vicons/ionicons5' // type BtnType = 'del' | 'add' | 'back' | 'edit' | 'info'; // function debounce(func, delay) { // let timerId; // // eslint-disable-next-line func-names // return function (...args) { // clearTimeout(timerId); // timerId = setTimeout(() => { // // eslint-disable-next-line no-invalid-this // func.apply(this, args); // }, delay); // }; // } const downFlag = ref(false); function throttle(func, delay) { let isThrottled = false; // eslint-disable-next-line func-names return function (...args) { if (!isThrottled) { // eslint-disable-next-line no-invalid-this func.apply(this, args); isThrottled = true; setTimeout(() => { isThrottled = false; }, delay); } }; } // eslint-disable-next-line max-params export function useAddBtn( fun: () => void = () => { console.log('新增'); }, size: undefined | Size = 'small', value: string = '新增', permission: string = '' ) { return ( {value} ); } // eslint-disable-next-line max-params export function useDownBtn( fun: () => void = () => { console.log('下载'); }, size: undefined | Size = 'small', value: string = '下载', hasPermi: string = '', permission: string[] = [] ) { async function click() { downFlag.value = true; await fun(); setTimeout(() => { downFlag.value = false; }, 1000); } return ( {value} ); } // eslint-disable-next-line max-params export function useLockBtn( fun: () => void = () => { console.log('冻结'); }, size: undefined | Size = 'small', content: string = '确定要冻结吗?', value: string = '冻结', hasPermi: string = '', permission: string[] = [] ) { const dialog = useDialog(); function delDialog() { return dialog.warning({ title: '提示', content, style: { borderRadius: '10px' }, positiveText: '确定', negativeText: '取消', maskClosable: false, onClose: () => { console.log(1); }, onPositiveClick: () => { fun(); }, onNegativeClick: () => { console.log(1); } }); } return ( {value} ); } // eslint-disable-next-line max-params export function useUnlockBtn( fun: () => void = () => { console.log('冻结'); }, size: undefined | Size = 'small', content: string = '确定要解除冻结吗?', value: string = '解冻', hasPermi: string = '', permission: string[] = [] ) { const dialog = useDialog(); function delDialog() { return dialog.warning({ title: '提示', content, style: { borderRadius: '10px' }, positiveText: '确定', negativeText: '取消', maskClosable: false, onClose: () => { console.log(1); }, onPositiveClick: () => { fun(); }, onNegativeClick: () => { console.log(1); } }); } return ( {value} ); } // eslint-disable-next-line max-params export function useDelBtn( fun: () => void = () => { console.log('删除'); }, size: undefined | Size = 'small', content: string = '确定要删除吗?', disabled: boolean = false, value: string = '删除', permission: string = '' ) { const dialog = useDialog(); function delDialog() { return dialog.warning({ title: '提示', content, style: { borderRadius: '10px' }, positiveText: '确定', negativeText: '取消', maskClosable: false, onClose: () => { console.log(1); }, onPositiveClick: () => { fun(); }, onNegativeClick: () => { console.log(1); } }); } return ( {value} ); } // 编辑按钮 // eslint-disable-next-line max-params export function useEditBtn( fun: () => void = () => { console.log('编辑'); }, size: undefined | Size = 'small', value: string = '编辑', color: string | undefined = undefined, permission: string = '' ) { return ( {value} ); } // 明细按钮 // eslint-disable-next-line max-params export function useInfoBtn( fun: () => void = () => { console.log('明细'); }, size: undefined | Size = 'small', value: string = '明细', color: string | undefined = undefined ) { return ( {value} ); } // export function usePublicBtn(fun: Function, data: { // btnType: string, // size: undefined | Size = 'small', // value: string = '下发', // color: string | undefined = '#FFD700', // disabled: boolean = false, // hasPermi: string = '', // permission: string[] = [] // }) { // const typeS = { // add: AddOutline, // edit: CreateOutline, // det: DocumentTextOutline, // send: Send, // get: CheckmarkSharp, // reject: CloseSharp, // lock: LockClosedOutline // }; // return ( // // // {value} // // ); // } // eslint-disable-next-line max-params export function useBtn( fun: () => void = () => { console.log('下发'); }, type: 'add' | 'edit' | 'det' | 'send' | 'info' | 'get' | 'reject' | 'lock' = 'info', size: undefined | Size = 'small', value: string = '下发', color: string | undefined = '#FFD700', disabled: boolean = false, hasPermi: string = '', permission: string[] = [] ) { const typeS = { add: AddOutline, edit: CreateOutline, det: DocumentTextOutline, send: Send, get: CheckmarkSharp, reject: CloseSharp, lock: LockClosedOutline }; return ( {value} ); } // 设置按钮 // eslint-disable-next-line max-params export function useSetBtn( fun: () => void = () => { console.log('设置'); }, size: undefined | Size = 'small', value: string = '设置', color: string | undefined = undefined, hasPermi: string = '', permission: string[] = [] ) { return ( {value} ); } // 搜索框搜索和重置 export function useSearchBtn( search: () => void = () => { console.log('搜索'); }, reset: () => void = () => { console.log('重置'); }, size: undefined | Size = 'medium' ) { return (
搜索 重置
); } // 返回按钮 // eslint-disable-next-line max-params export function useBackBtn( fun: () => void = () => { window.history.go(-1); }, size: undefined | Size = 'small', value: string = '返回', color: string | undefined = undefined ) { // const route = useRoute(); // function back() { // if (route.query.back) { // window.history.go(-1); // } else { // fun(); // } // } return ( {value} ); } const Icon = { EyeOutline, Send, TrashOutline, Search, RefreshSharp, ReturnUpBack, AddOutline, DocumentTextOutline, CreateOutline, SettingsOutline, LockClosedOutline, LockOpenOutline, CloudDownloadOutline, CheckmarkSharp, CloseSharp }; interface btnType { fun: () => void; size?: Size; icon?: keyof typeof Icon; color?: string; text?: string; hasPermi?: string; permission?: string[]; type?: 'primary' | 'success' | 'warning' | 'error'; } export function customBtn(config: btnType) { const { fun, size, icon, color, text, hasPermi, permission, type } = config; // console.log(Icon[icon], 11, SettingsOutline); if (!hasPermi && !permission) { return ( {icon ? : ''} {text} ); } else if (hasPermi && permission) { return ( {icon ? : ''} {text} ); } else if (hasPermi) { return ( {icon ? : ''} {text} ); } return ( {icon ? : ''} {text} ); }