feat: 导入License
This commit is contained in:
@@ -65,6 +65,19 @@ export function updateLicense(data: LicenseApi.License) {
|
||||
return requestClient.put('/license/license/update', data);
|
||||
}
|
||||
|
||||
/** 下载导入模板 */
|
||||
export function importTemplate() {
|
||||
return requestClient.download('/license/license/get-import-template');
|
||||
}
|
||||
|
||||
/** 导入License */
|
||||
export function importLicense(file: File, updateSupport: boolean) {
|
||||
return requestClient.upload('/license/license/import', {
|
||||
file,
|
||||
updateSupport,
|
||||
});
|
||||
}
|
||||
|
||||
/** 重新License */
|
||||
export function reapplyLicense(data: LicenseApi.License) {
|
||||
return requestClient.put('/license/license/reapply', data);
|
||||
|
||||
@@ -62,7 +62,7 @@ async function onDelete(row: CustomerApi.Customer) {
|
||||
async function onExport() {
|
||||
const data = await exportCustomer(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({
|
||||
fileName: `${$t('customer.customer')}.xls`,
|
||||
fileName: `${$t('customer.customer')}.xlsx`,
|
||||
source: data,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -478,3 +478,27 @@ export function useDetailSchema(): DescriptionItemSchema[] {
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 用户导入的表单 */
|
||||
export function useImportFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'file',
|
||||
label: 'License数据',
|
||||
component: 'Upload',
|
||||
rules: 'required',
|
||||
help: '仅允许导入 xls、xlsx 格式文件',
|
||||
},
|
||||
{
|
||||
fieldName: 'updateSupport',
|
||||
label: '是否覆盖',
|
||||
component: 'Switch',
|
||||
componentProps: {
|
||||
checkedChildren: '是',
|
||||
unCheckedChildren: '否',
|
||||
},
|
||||
rules: z.boolean().default(false),
|
||||
help: '是否更新已经存在的License数据',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Detail from './modules/detail.vue';
|
||||
import Form from './modules/form.vue';
|
||||
import History from './modules/history.vue';
|
||||
import ImportForm from './modules/import-form.vue';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -39,6 +40,11 @@ const [DetailModal, detailModalApi] = useVbenModal({
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [ImportModal, importModalApi] = useVbenModal({
|
||||
connectedComponent: ImportForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
@@ -105,7 +111,12 @@ async function onDelete(row: LicenseApi.License) {
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportLicense(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: 'License.xls', source: data });
|
||||
downloadFileFromBlobPart({ fileName: 'License.xlsx', source: data });
|
||||
}
|
||||
|
||||
/** 导入用户 */
|
||||
function handleImport() {
|
||||
importModalApi.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
@@ -152,6 +163,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<FormModal @success="onRefresh" />
|
||||
<DetailModal @success="onRefresh" />
|
||||
<HistoryModal @success="onRefresh" />
|
||||
<ImportModal @success="onRefresh" />
|
||||
<Grid :table-title="$t('license.list')">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
@@ -170,6 +182,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
auth: ['license:license:export'],
|
||||
onClick: onExport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.import', ['License']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.UPLOAD,
|
||||
auth: ['system:user:import'],
|
||||
onClick: handleImport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
124
apps/web-antd/src/views/license/license/modules/import-form.vue
Normal file
124
apps/web-antd/src/views/license/license/modules/import-form.vue
Normal file
@@ -0,0 +1,124 @@
|
||||
<script lang="ts" setup>
|
||||
import type { FileType } from 'ant-design-vue/es/upload/interface';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
// import { InboxOutlined } from '@vben/icons';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { Button, message, UploadDragger } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { importLicense, importTemplate } from '#/api/license/license';
|
||||
|
||||
import { useImportFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useImportFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = await formApi.getValues();
|
||||
try {
|
||||
const result = await importLicense(data.file, data.updateSupport);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
let failuresMsg: any;
|
||||
if (result.creates && result.creates.length > 0) {
|
||||
failuresMsg = h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
color: 'green',
|
||||
},
|
||||
},
|
||||
[failuresMsg, `新增成功:${result.creates.join(',')}`],
|
||||
);
|
||||
}
|
||||
if (result.updates && result.updates.length > 0) {
|
||||
failuresMsg = h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
color: 'blue',
|
||||
},
|
||||
},
|
||||
[failuresMsg, `更新成功:${result.updates.join(',')}`],
|
||||
);
|
||||
}
|
||||
for (const key in result.failures) {
|
||||
failuresMsg = h(
|
||||
'div',
|
||||
{
|
||||
style: {
|
||||
color: 'red',
|
||||
},
|
||||
},
|
||||
[failuresMsg, `导入失败:${key},失败原因:${result.failures[key]}`],
|
||||
);
|
||||
}
|
||||
message.info(failuresMsg, 10);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 上传前 */
|
||||
function beforeUpload(file: FileType) {
|
||||
formApi.setFieldValue('file', file);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 下载模版 */
|
||||
async function handleDownload() {
|
||||
const data = await importTemplate();
|
||||
downloadFileFromBlobPart({ fileName: 'License导入模板.xlsx', source: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="导入License" class="w-1/3">
|
||||
<Form class="mx-4">
|
||||
<template #file>
|
||||
<div class="w-full">
|
||||
<UploadDragger
|
||||
:max-count="1"
|
||||
accept=".xls,.xlsx"
|
||||
:before-upload="beforeUpload"
|
||||
>
|
||||
<!-- <Button type="primary"> 选择 Excel 文件 </Button> -->
|
||||
<p class="ant-upload-drag-icon">
|
||||
<!-- <InboxOutlined /> -->
|
||||
<span class="icon-[ep--upload-filled] size-12"></span>
|
||||
</p>
|
||||
|
||||
<p class="ant-upload-text">点击或拖拽Excel文件上传</p>
|
||||
</UploadDragger>
|
||||
</div>
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<Button @click="handleDownload"> 下载导入模板 </Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -73,7 +73,7 @@ async function onDelete(row: ProjectApi.Project) {
|
||||
async function onExport() {
|
||||
const data = await exportProject(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({
|
||||
fileName: `${$t('project.project')}.xls`,
|
||||
fileName: `${$t('project.project')}.xlsx`,
|
||||
source: data,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user