Files
mp-10579/src/views/credit/components/CreditImportModal.vue
赵忠林 d32fd4f711 feat(api): 添加百色中学和诊所相关API接口
- 新增百色中学报名记录相关接口和数据模型
- 新增百色中学分部、班级、年代、年级管理接口
- 新增百色中学捐款记录和排行相关接口
- 新增诊所挂号和医生入驻申请接口
- 添加相应的数据传输对象和搜索参数模型
- 实现分页查询、增删改查等基础操作接口
- 集成请求处理和错误处理机制
2026-01-07 14:44:06 +08:00

104 lines
2.6 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="templateName"> 下载导入模板 </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 props = defineProps<{
visible: boolean;
title: string;
templatePath: string;
templateName?: string;
importRequest: (file: File) => Promise<string>;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 导入请求状态
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 templateName = computed(
() => props.templateName || '导入模板.xlsx'
);
/* 上传 */
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;
}
loading.value = true;
props
.importRequest(file)
.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>