|
|
@@ -1,64 +1,155 @@
|
|
|
<template>
|
|
|
- <el-card v-if="props.modelValue" class="pop-card">
|
|
|
- <template #header>
|
|
|
- <div class="flex justify-between items-center pop-head">
|
|
|
- <div style="font-size: 16px">批量导入</div>
|
|
|
- <el-icon :size="16" class="mr-3" @click="updateValue(false)"><Close /></el-icon
|
|
|
- ></div>
|
|
|
- </template>
|
|
|
- <div class="upload-content">
|
|
|
- <el-upload
|
|
|
- ref="upload"
|
|
|
- class="upload-demo"
|
|
|
- drag
|
|
|
- action="http://localhost:8092/api/user/import"
|
|
|
- :headers="headers"
|
|
|
- :with-credentials="true"
|
|
|
- :auto-upload="false"
|
|
|
- :before-upload="beforeUpload"
|
|
|
- :on-success="handleUploadSuccess"
|
|
|
- :on-error="handleUploadError"
|
|
|
- style="width: 384px; height: 192px; border-radius: 8px"
|
|
|
- >
|
|
|
- <el-icon class="el-icon--upload" style="width: 33px; height: 42px"><Document /></el-icon>
|
|
|
- <div class="el-upload__text">
|
|
|
- <div style="font-size: 16px">点击或将文件拖拽到这里上传</div>
|
|
|
- <div style="font-size: 14px; color: rgba(0, 0, 0, 0.45)"
|
|
|
- >文件只支持:.xlsx .xls .仅支持上传一个文件</div
|
|
|
- ></div
|
|
|
+ <div v-if="props.modelValue">
|
|
|
+ <el-card v-if="cardVisible" class="pop-card">
|
|
|
+ <template #header>
|
|
|
+ <div class="flex justify-between items-center pop-head">
|
|
|
+ <div style="font-size: 16px">批量导入</div>
|
|
|
+ <el-icon :size="16" class="mr-3" @click="updateValue(false)"><Close /></el-icon
|
|
|
+ ></div>
|
|
|
+ </template>
|
|
|
+ <div class="upload-content">
|
|
|
+ <el-upload
|
|
|
+ ref="upload"
|
|
|
+ class="upload-demo"
|
|
|
+ drag
|
|
|
+ action="http://localhost:8092/api/user/import"
|
|
|
+ :headers="headers"
|
|
|
+ :with-credentials="true"
|
|
|
+ :auto-upload="false"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ :on-success="handleUploadSuccess"
|
|
|
+ style="width: 384px; height: 192px; border-radius: 8px"
|
|
|
>
|
|
|
- </el-upload>
|
|
|
- <div style="margin-top: 52px; margin-left: 288px; display: flex">
|
|
|
- <el-button @click="handleDownload" style="margin-right: 10px">下载模板</el-button>
|
|
|
- <el-button type="primary" @click="handleImport">导入</el-button></div
|
|
|
- ></div
|
|
|
+ <el-icon class="el-icon--upload" style="width: 33px; height: 42px"><Document /></el-icon>
|
|
|
+ <div class="el-upload__text">
|
|
|
+ <div style="font-size: 16px">点击或将文件拖拽到这里上传</div>
|
|
|
+ <div style="font-size: 14px; color: rgba(0, 0, 0, 0.45)"
|
|
|
+ >文件只支持:.xlsx .xls .仅支持上传一个文件</div
|
|
|
+ ></div
|
|
|
+ >
|
|
|
+ </el-upload>
|
|
|
+ <div style="margin-top: 52px; margin-left: 288px; display: flex">
|
|
|
+ <el-button @click="handleDownload" style="margin-right: 10px">下载模板</el-button>
|
|
|
+ <el-button type="primary" @click="handleImport">导入</el-button></div
|
|
|
+ ></div
|
|
|
+ >
|
|
|
+ </el-card>
|
|
|
+ <!-- //上传成功 -->
|
|
|
+ <el-dialog
|
|
|
+ v-model="DialogVisibleSuc"
|
|
|
+ title="Warning"
|
|
|
+ width="30%"
|
|
|
+ @close="
|
|
|
+ () => {
|
|
|
+ emits('update:modelValue', false);
|
|
|
+ }
|
|
|
+ "
|
|
|
+ align-center
|
|
|
+ >
|
|
|
+ <template #header="{ titleId, titleClass }">
|
|
|
+ <div class="my-header">
|
|
|
+ <h4 :id="titleId" :class="titleClass" style="display: flex">
|
|
|
+ <el-icon style="margin-top: 2px"><CircleCheck /></el-icon
|
|
|
+ ><div style="margin-left: 14px">导入成功</div></h4
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <span> 已成功添加{{ sucCount }}条用户信息</span>
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="handleRightComfirm"> 确定 </el-button>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
+ <!-- 上传失败 -->
|
|
|
+ <el-dialog
|
|
|
+ v-model="DialogVisibleErr"
|
|
|
+ title="Warning"
|
|
|
+ width="30%"
|
|
|
+ @close="
|
|
|
+ () => {
|
|
|
+ emits('update:modelValue', false);
|
|
|
+ }
|
|
|
+ "
|
|
|
+ align-center
|
|
|
>
|
|
|
- </el-card>
|
|
|
+ <template #header="{ titleId, titleClass }">
|
|
|
+ <div class="my-header">
|
|
|
+ <h4 :id="titleId" :class="titleClass" style="display: flex">
|
|
|
+ <el-icon style="margin-top: 2px"><Warning /></el-icon>
|
|
|
+ <div style="margin-left: 14px">导入失败</div></h4
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <ul v-for="(item, index) in errDetail" :key="index">
|
|
|
+ <li v-if="index < 3">{{ item }} </li>
|
|
|
+ <li v-else v-show="showMore">{{ item }}</li>
|
|
|
+ </ul>
|
|
|
+ <div v-if="errDetail.length > 3 && !showMore" @click="showMore = true" class="more-link"
|
|
|
+ >更多</div
|
|
|
+ >
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="handleErrComfirm"> 确定 </el-button>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog></div
|
|
|
+ >
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
- import { Close, Document } from '@element-plus/icons-vue';
|
|
|
- import { ref } from 'vue';
|
|
|
+ import { Close, Document, CircleCheck, Warning } from '@element-plus/icons-vue';
|
|
|
+ import { nextTick, ref } from 'vue';
|
|
|
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
|
|
|
import { downloadByUrl } from '@/utils/file/download';
|
|
|
// import templateUrl from './templete.xlsx';
|
|
|
import { useUserStore } from '@/store/modules/user';
|
|
|
+ import { onMounted } from 'vue';
|
|
|
// http://localhost:8092/api/user/import
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
+ onMounted(() => {
|
|
|
+ console.log('111');
|
|
|
+
|
|
|
+ console.log('props.modelValue', props.modelValue);
|
|
|
+
|
|
|
+ cardVisible.value = props.modelValue;
|
|
|
+ });
|
|
|
+
|
|
|
+ // const emit = defineEmits()
|
|
|
+ // const emit = defineEmits<{
|
|
|
+ // (e: 'change'): unknown;
|
|
|
+ // }>();
|
|
|
+ // const emit = defineEmits(['change']);
|
|
|
+
|
|
|
+ // const emit = defineEmits<{
|
|
|
+ // (e: 'onOk'): unknown;
|
|
|
+ // (e: 'onClose'): unknown;
|
|
|
+ // }>();
|
|
|
+
|
|
|
const headers = {
|
|
|
Satoken: userStore.getToken,
|
|
|
Tenantid: userStore.getTenantId,
|
|
|
};
|
|
|
|
|
|
+ const cardVisible = ref<boolean>(true);
|
|
|
+
|
|
|
+ //对话框
|
|
|
+ const DialogVisibleSuc = ref<boolean>(false);
|
|
|
+ const DialogVisibleErr = ref<boolean>(false);
|
|
|
+
|
|
|
+ //更多
|
|
|
+ const showMore = ref(false);
|
|
|
+
|
|
|
const isSuc = ref<boolean>(true);
|
|
|
const errDetail = ref<string[]>([]);
|
|
|
const sucCount = ref<number>(0);
|
|
|
// console.log('headers', headers);
|
|
|
|
|
|
const props = defineProps<{ modelValue: boolean }>();
|
|
|
- const emits = defineEmits(['update:modelValue']);
|
|
|
+ const emits = defineEmits(['update:modelValue', 'change']);
|
|
|
|
|
|
const updateValue = (value) => {
|
|
|
emits('update:modelValue', value);
|
|
|
@@ -73,8 +164,6 @@
|
|
|
};
|
|
|
const handleImport = async () => {
|
|
|
upload.value!.submit();
|
|
|
-
|
|
|
- // emits('update:modelValue', false);
|
|
|
};
|
|
|
|
|
|
const beforeUpload = (file) => {
|
|
|
@@ -91,13 +180,37 @@
|
|
|
console.log('response', response);
|
|
|
isSuc.value = response.data.isSuc;
|
|
|
errDetail.value = response.data.failedInfo;
|
|
|
- sucCount.value = response.data.sucCount;
|
|
|
- console.log(isSuc.value, errDetail.value);
|
|
|
+ sucCount.value = response.data.sucCount || 0;
|
|
|
+ console.log('errDetail', errDetail.value);
|
|
|
+
|
|
|
+ if (isSuc.value) {
|
|
|
+ DialogVisibleSuc.value = true;
|
|
|
+ DialogVisibleErr.value = false;
|
|
|
+ } else {
|
|
|
+ DialogVisibleSuc.value = false;
|
|
|
+ DialogVisibleErr.value = true;
|
|
|
+ }
|
|
|
+ cardVisible.value = false;
|
|
|
+ // emits('update:modelValue', false);
|
|
|
};
|
|
|
- const handleUploadError = (err, file, fileList) => {
|
|
|
- console.log('222');
|
|
|
- console.log(err);
|
|
|
+
|
|
|
+ const handleRightComfirm = () => {
|
|
|
+ DialogVisibleSuc.value = false;
|
|
|
+ emits('update:modelValue', false);
|
|
|
+ emits('change');
|
|
|
+ };
|
|
|
+ const handleErrComfirm = () => {
|
|
|
+ DialogVisibleErr.value = false;
|
|
|
+ emits('update:modelValue', false);
|
|
|
+ emits('change');
|
|
|
};
|
|
|
+
|
|
|
+ // const handleUploadError = (err, file, fileList) => {
|
|
|
+ // console.log('222');
|
|
|
+ // console.log(err);
|
|
|
+ // };
|
|
|
+
|
|
|
+ //对话框
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
@@ -105,4 +218,8 @@
|
|
|
margin-left: 96px;
|
|
|
margin-top: 36px;
|
|
|
}
|
|
|
+
|
|
|
+ .more-link {
|
|
|
+ color: #1890ff;
|
|
|
+ }
|
|
|
</style>
|