feat: 【ele】文件管理新增批量删除
parent
58d36c9b49
commit
0be48ce623
|
@ -69,6 +69,13 @@ export function deleteFileConfig(id: number) {
|
||||||
return requestClient.delete(`/infra/file-config/delete?id=${id}`);
|
return requestClient.delete(`/infra/file-config/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除文件配置 */
|
||||||
|
export function deleteFileConfigList(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/file-config/delete-list?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** 测试文件配置 */
|
/** 测试文件配置 */
|
||||||
export function testFileConfig(id: number) {
|
export function testFileConfig(id: number) {
|
||||||
return requestClient.get(`/infra/file-config/test?id=${id}`);
|
return requestClient.get(`/infra/file-config/test?id=${id}`);
|
||||||
|
|
|
@ -45,6 +45,11 @@ export function deleteFile(id: number) {
|
||||||
return requestClient.delete(`/infra/file/delete?id=${id}`);
|
return requestClient.delete(`/infra/file/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除文件 */
|
||||||
|
export function deleteFileList(ids: number[]) {
|
||||||
|
return requestClient.delete(`/infra/file/delete-list?ids=${ids.join(',')}`);
|
||||||
|
}
|
||||||
|
|
||||||
/** 获取文件预签名地址 */
|
/** 获取文件预签名地址 */
|
||||||
export function getFilePresignedUrl(name: string, directory?: string) {
|
export function getFilePresignedUrl(name: string, directory?: string) {
|
||||||
return requestClient.get<InfraFileApi.FilePresignedUrlRespVO>(
|
return requestClient.get<InfraFileApi.FilePresignedUrlRespVO>(
|
||||||
|
|
|
@ -61,6 +61,7 @@ export function useGridColumns<T = InfraFileApi.File>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
title: '文件名',
|
title: '文件名',
|
||||||
|
|
|
@ -5,15 +5,16 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { InfraFileApi } from '#/api/infra/file';
|
import type { InfraFileApi } from '#/api/infra/file';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Upload } from '@vben/icons';
|
import { isEmpty, openWindow } from '@vben/utils';
|
||||||
import { openWindow } from '@vben/utils';
|
|
||||||
|
|
||||||
import { useClipboard } from '@vueuse/core';
|
import { useClipboard } from '@vueuse/core';
|
||||||
import { ElButton, ElImage, ElLoading, ElMessage } from 'element-plus';
|
import { ElButton, ElImage, ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteFile, getFilePage } from '#/api/infra/file';
|
import { deleteFile, deleteFileList, getFilePage } from '#/api/infra/file';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
@ -70,11 +71,36 @@ async function onDelete(row: InfraFileApi.File) {
|
||||||
$t('ui.actionMessage.deleteSuccess', [row.name || row.path]),
|
$t('ui.actionMessage.deleteSuccess', [row.name || row.path]),
|
||||||
);
|
);
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
} finally {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除文件 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
fullscreen: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteFileList(checkedIds.value);
|
||||||
|
loadingInstance.close();
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: InfraFileApi.File[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
/** 表格操作按钮的回调函数 */
|
||||||
function onActionClick({ code, row }: OnActionClickParams<InfraFileApi.File>) {
|
function onActionClick({ code, row }: OnActionClickParams<InfraFileApi.File>) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
@ -116,6 +142,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<InfraFileApi.File>,
|
} as VxeTableGridOptions<InfraFileApi.File>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -124,10 +154,24 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="onRefresh" />
|
||||||
<Grid table-title="文件列表">
|
<Grid table-title="文件列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton type="primary" @click="onUpload">
|
<TableAction
|
||||||
<Upload class="size-5" />
|
:actions="[
|
||||||
上传图片
|
{
|
||||||
</ElButton>
|
label: '上传图片',
|
||||||
|
type: 'primary',
|
||||||
|
icon: ACTION_ICON.UPLOAD,
|
||||||
|
onClick: onUpload,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:file:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #file-content="{ row }">
|
<template #file-content="{ row }">
|
||||||
<ElImage v-if="row.type && row.type.includes('image')" :src="row.url" />
|
<ElImage v-if="row.type && row.type.includes('image')" :src="row.url" />
|
||||||
|
|
|
@ -269,6 +269,7 @@ export function useGridColumns<T = InfraFileConfigApi.FileConfig>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '编号',
|
title: '编号',
|
||||||
|
|
|
@ -5,15 +5,17 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { InfraFileConfigApi } from '#/api/infra/file-config';
|
import type { InfraFileConfigApi } from '#/api/infra/file-config';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Plus } from '@vben/icons';
|
import { isEmpty, openWindow } from '@vben/utils';
|
||||||
import { openWindow } from '@vben/utils';
|
|
||||||
|
|
||||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
deleteFileConfig,
|
deleteFileConfig,
|
||||||
|
deleteFileConfigList,
|
||||||
getFileConfigPage,
|
getFileConfigPage,
|
||||||
testFileConfig,
|
testFileConfig,
|
||||||
updateFileConfigMaster,
|
updateFileConfigMaster,
|
||||||
|
@ -93,11 +95,36 @@ async function onDelete(row: InfraFileConfigApi.FileConfig) {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
} finally {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除文件配置 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
fullscreen: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteFileConfigList(checkedIds.value);
|
||||||
|
loadingInstance.close();
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: InfraFileConfigApi.FileConfig[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
/** 表格操作按钮的回调函数 */
|
||||||
function onActionClick({
|
function onActionClick({
|
||||||
code,
|
code,
|
||||||
|
@ -150,6 +177,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<InfraFileConfigApi.FileConfig>,
|
} as VxeTableGridOptions<InfraFileConfigApi.FileConfig>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -158,14 +189,25 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="onRefresh" />
|
||||||
<Grid table-title="文件配置列表">
|
<Grid table-title="文件配置列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['infra:file-config:create']"
|
label: $t('ui.actionTitle.create', ['文件配置']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['文件配置']) }}
|
auth: ['infra:file-config:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['infra:file-config:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue