rax-medical/src/components/import-dialog.vue
2023-12-28 17:58:59 +08:00

68 lines
2.0 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>
<el-dialog v-model="dialogVisible" :title="title" width="50%">
<el-upload v-model:file-list="fileList" drag accept=".xls, .xlsx" :auto-upload="false" :limit="1">
<div class="el-upload__text" style="padding: 40px 10px;font-size: 20px;">
将文件拖到此处 <em>点击上传</em>
</div>
<template #tip>
<div class="el-upload__tip" style="font-size: 16px;">
仅允许导入xlsxlsx格式文件<span class="main-color" style="cursor: pointer;"
@click="downloadTemplate">下载模板</span>
</div>
</template>
</el-upload>
<div style="text-align: right;margin-top: 20px;">
<el-button class="f18" @click="dialogVisible = false">取消</el-button>
<el-button class="f18" type="primary" @click="importData">确认</el-button>
</div>
</el-dialog>
</template>
<script lang='ts' setup>
import { onMounted, reactive, ref, toRefs, watch } from 'vue'
import type { UploadProps, UploadUserFile } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
const emit = defineEmits(['success', 'error'])
const props = defineProps({
title: String,
templateUrl: String, // 模板下载地址
importUrl: String, // 上传接口地址
})
const dialogVisible = ref(false)
const fileList = ref<UploadUserFile[]>([])
defineExpose({
open,
close
})
function open() {
dialogVisible.value = true
}
function close() {
dialogVisible.value = false
}
const downloadTemplate = () => {
window.open(props.templateUrl, '_blank')
}
const importData = () => {
// console.log(fileList.value)
if(fileList.value.length === 0) {
ElMessage.warning('请上传符合格式的xls或xlsx文件')
return
}
ElMessage.success('上传成功')
close()
emit('success')
// emit('error')
}
</script>
<style lang='scss' scoped></style>