Files
mp-vue/src/views/credit/creditCompany/components/credit-company-related-import.vue
赵忠林 82ac209505 style(api): 统一代码风格并修复语法问题
- 统一import语句的空格格式
- 修复分号缺失问题
- 调整函数参数换行格式以符合规范
- 删除多余空行保持代码整洁
- 修复字符串拼接的换行格式问题
2026-01-21 00:26:14 +08:00

108 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- 企业详情子表导入弹窗 -->
<template>
<ele-modal
:width="520"
:footer="null"
:title="title"
:visible="visible"
@update:visible="updateVisible"
>
<a-spin :spinning="loading">
<a-upload-dragger
accept=".xls,.xlsx"
:show-upload-list="false"
:customRequest="doUpload"
style="padding: 24px 0; margin-bottom: 16px"
>
<p class="ant-upload-drag-icon">
<cloud-upload-outlined />
</p>
<p class="ant-upload-hint">将文件拖到此处或点击上传</p>
</a-upload-dragger>
</a-spin>
<div class="ele-text-center">
<span>只能上传xlsxlsx文件</span>
<a :href="templateUrl" :download="`${title}.xlsx`">下载导入模板</a>
</div>
</ele-modal>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { message } from 'ant-design-vue/es';
import { CloudUploadOutlined } from '@ant-design/icons-vue';
import { API_BASE_URL } from '@/config/setting';
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
const props = defineProps<{
// 是否打开弹窗
visible: boolean;
// 弹窗标题
title: string;
// 模板下载相对路径(保持与当前接口域名一致)
templatePath: string;
// 当前企业ID用于导入关联
companyId?: number;
// 导入方法:必须支持传 companyId
importFn: (file: File, companyId?: number) => Promise<string>;
}>();
// 导入请求状态
const loading = ref(false);
const templateUrl = computed(() => {
const base = (localStorage.getItem('ApiUrl') || API_BASE_URL || '').replace(
/\/$/,
''
);
const path = (props.templatePath || '').startsWith('/')
? props.templatePath
: `/${props.templatePath}`;
return `${base}${path}`;
});
/* 上传 */
const doUpload = ({ file }) => {
if (
![
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
].includes(file.type)
) {
message.error('只能选择 excel 文件');
return false;
}
if (file.size / 1024 / 1024 > 10) {
message.error('大小不能超过 10MB');
return false;
}
if (!props.companyId) {
message.error('缺少企业ID无法导入');
return false;
}
loading.value = true;
props
.importFn(file, props.companyId)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
return false;
};
/* 更新 visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
</script>