feat: 实现后台管理前端全部页面与登录布局
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<n-card :title="t('pages.outbound.import')" :bordered="false">
|
||||
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">{{ t('pages.outbound.tip') }}</n-alert>
|
||||
<n-space>
|
||||
<n-button @click="downloadTemplate">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('common.action.downloadTemplate') }}
|
||||
</n-button>
|
||||
<n-upload
|
||||
:show-file-list="false"
|
||||
accept=".xlsx,.xls"
|
||||
:custom-request="doImport"
|
||||
:disabled="importing || !auth.canWrite"
|
||||
>
|
||||
<n-button type="primary" :loading="importing">
|
||||
<template #icon><n-icon :component="CloudUploadOutline" /></template>
|
||||
{{ t('pages.outbound.selectFile') }}
|
||||
</n-button>
|
||||
</n-upload>
|
||||
</n-space>
|
||||
|
||||
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
|
||||
<n-space align="center" size="large">
|
||||
<n-statistic :label="t('common.label.total')" :value="result.total" />
|
||||
<n-statistic :label="t('pages.outbound.successCount')">
|
||||
<span style="color: #138a72">{{ result.successCount }}</span>
|
||||
</n-statistic>
|
||||
<n-statistic :label="t('pages.outbound.failCount')">
|
||||
<span style="color: #c0392b">{{ result.failCount }}</span>
|
||||
</n-statistic>
|
||||
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
|
||||
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ t('pages.outbound.downloadResult') }}
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { UploadCustomRequestOptions } from 'naive-ui';
|
||||
import { DownloadOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
||||
import { jobApi, outboundApi, post } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
|
||||
const { t } = useI18n();
|
||||
const auth = useAuthStore();
|
||||
const importing = ref(false);
|
||||
const result = ref<any>(null);
|
||||
|
||||
async function downloadTemplate() {
|
||||
await downloadFile('/outbound/import/template', 'outbound-import-template.xlsx');
|
||||
}
|
||||
|
||||
async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions) {
|
||||
importing.value = true;
|
||||
result.value = null;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file.file as File);
|
||||
const res: any = await post('/outbound/import', fd, { headers: { 'Content-Type': 'multipart/form-data' } });
|
||||
const jobId = res.jobId;
|
||||
let job: any = null;
|
||||
for (let i = 0; i < 40; i++) {
|
||||
await new Promise((r) => setTimeout(r, 700));
|
||||
job = await jobApi.get(jobId);
|
||||
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
|
||||
}
|
||||
result.value = job;
|
||||
message.success(t('common.msg.operationSuccess'));
|
||||
onFinish();
|
||||
} catch (e) {
|
||||
message.error((e as Error)?.message || 'import failed');
|
||||
onError();
|
||||
} finally {
|
||||
importing.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user