import { delNeConfigData } from '@/api/ne/neConfig'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { currentCoreUid } from '@/hooks/useCoreUid'; import { message } from 'ant-design-vue'; import { reactive } from 'vue'; /** * 批量删除array * @param param 父级传入 { t, neTypeSelect, fnActiveConfigNode } * @returns */ export default function useArrayBatch({ t, neTypeSelect, fnActiveConfigNode, }: any) { /**状态属性 */ const batchState = reactive({ open: false, loading: false, //批量删除 paramName: '', startIndex: 1, num: 1, }); /**对话框表格信息导入弹出窗口 */ function modalBatchOpen(paramName: string) { batchState.paramName = paramName; batchState.open = true; } function modalBatchClose() { if (batchState.loading) { message.error({ content: 'Delete is in progress, please wait for it to complete', duration: 3, }); return; } batchState.open = false; batchState.loading = false; batchState.startIndex = 1; batchState.num = 1; fnActiveConfigNode('#'); } async function modalBatchOk() { let okNum = 0; let failNum = 0; const endIndex = batchState.startIndex + batchState.num - 1; for (let i = endIndex; i >= batchState.startIndex; i--) { const res = await delNeConfigData({ neType: neTypeSelect.value[0], neUid: neTypeSelect.value[1], coreUid: currentCoreUid(), paramName: batchState.paramName, loc: `${i}`, }); if (res.code === RESULT_CODE_SUCCESS) { okNum++; } else { failNum++; break; } } if (okNum > 0) { message.success({ content: `Successfully deleted ${okNum} items`, duration: 3, }); } if (failNum > 0) { message.error({ content: `Delete failed, please check the index range`, duration: 3, }); } modalBatchClose(); } return { batchState, modalBatchOpen, modalBatchClose, modalBatchOk, }; }