Files
zhgh_whcp/target/classes/static/components/module/activity/ActivityImportUser.vue
T
2026-01-08 14:58:16 +08:00

236 lines
7.4 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>
<div style="padding: 20px 50px">
<el-timeline>
<el-timeline-item timestamp="下载模板" placement="top">
<el-card>
<el-button size="medium" style="width: 200px"
@click="$downLoad('/platform/activity/basic/scope/downloadImport')" icon="el-icon-download">下载模板
</el-button>
</el-card>
</el-timeline-item>
<el-timeline-item timestamp="上传文件" placement="top">
<el-card>
<el-form>
<el-upload
action="#"
name="file"
ref="upload"
:on-remove="
(file, fileList) => {
importData.fileList = fileHandleRemove(file, fileList)
importResult = {
errorCount: 0,
successCount: 0,
totalCount: 0,
errorList: []
}
}
"
:on-change="
(file, fileList) => {
importData.fileList = fileHandleChange(file, fileList, { type: ['xls', 'xlsx'] })
}
"
:auto-upload="false"
:limit="1"
:file-list="importData.fileList"
>
<el-button size="medium" type="" icon="el-icon-upload" style="width: 200px">选择文件</el-button>
<div class="el-upload__tip" slot="tip" style="color: #f56c6c">只能上传 xls/xlsx 文件</div>
</el-upload>
</el-form>
</el-card>
</el-timeline-item>
<el-timeline-item placement="top" timestamp="导入结果">
<el-card shadow="never">
<p>总记录数:{{ errorInfoData.totalCount }}</p>
<p>
成功数:
<span class="text-success">{{ errorInfoData.successCount }}</span>
</p>
<p>
错误数:
<span class="text-danger">{{ errorInfoData.errorCount }}</span>
</p>
<el-link @click="exportErrors" type="primary" v-if="errorInfoData.errorCount > 0">下载错误记录</el-link>
</el-card>
</el-timeline-item>
</el-timeline>
<div style="text-align: right">
<span slot="footer" class="dialog-footer">
<el-button @click="clearImportDialog" type="primary"
:disabled="importLoading">取 消</el-button>
<el-button type="primary" @click="clearSearchCnd"
:loading="importLoading">清空查询条件</el-button>
<el-button type="primary" @click="doImport" :loading="importLoading">核对人员</el-button>
<el-button type="primary" @click="doImportSearch"
:loading="importLoading">查询人员</el-button>
</span>
</div>
</div>
</template>
<script>
module.exports = {
props: {
exists_login_name_redis_key: {type: String, required: ""},
group_id: {type: Number, required: ""},
do_import_url: {type: String, required: ""}
},
mounted() {
const s = document.createElement("script")
s.type = "text/javascript"
s.src = "/assets/platform/plugins/xlsx/xlsx.full.min.js"
document.body.appendChild(s)
},
data() {
return {
importData: {
fileList: [],
isFlag: false
},
errorInfoData: {
totalCount: 0,
successCount: 0,
errorCount: 0,
errorList: 0
},
importLoading: false,
doImportUrl:""
}
},
methods: {
clearImportDialog() {
this.$emit("clear_import_dialog")
},
clearSearchCnd() {
this.importData = {
fileList: [],
}
this.errorInfoData = {
totalCount: 0,
successCount: 0,
errorCount: 0,
errorList: [],
}
$.get('/platform/activity/basic/scope/clearSearchCnd', {existsLoginNameRedisKey: this.exists_login_name_redis_key}).then(res => {
if (res.code === 0) {
this.$emit("flush", this.exists_login_name_redis_key)
this.$message.success(res.msg)
} else {
this.$message.error(res.msg)
}
})
},
resetImportData() {
this.importData = {
fileList: [],
}
this.errorInfoData = {
totalCount: 0,
successCount: 0,
errorCount: 0,
errorList: 0
}
},
doImportSearch() {
this.$emit("flush", this.exists_login_name_redis_key)
this.clearImportDialog()
},
doImport() {
if (this.importData.fileList.length === 0) {
this.$message.error({
title: "错误",
message: "请选择文件!"
})
return
}
const data = new FormData()
data.append("groupId", this.group_id)
this.importData.fileList.forEach((val) => {
data.append("file", val.raw, val.raw.name)
})
this.importLoading = true
this.$axios.post(this.do_import_url, data).then((res) => {
if (res.code === 0) {
if (res.data.errorList && res.data.errorList.length > 0) {
this.$message.warning("核对失败")
} else {
this.$message.success("核对成功")
}
this.errorInfoData = res.data
this.$emit("flush", res.data.existsLoginNameRedisKey)
} else {
this.$message.warning("核对失败")
}
this.importLoading = false
})
},
exportErrors() {
const data = this.errorInfoData.errorList
// 创建工作簿
const workbook = XLSX.utils.book_new()
// 创建工作表
const worksheet = XLSX.utils.json_to_sheet(data)
// 将工作表添加到工作簿
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1")
// 将工作簿转换为二进制对象
const excelBuffer = XLSX.write(workbook, {bookType: "xlsx", type: "array"})
// 将二进制对象转换为Blob对象
const blob = new Blob([excelBuffer], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})
// 创建下载链接并设置相关属性
const url = window.URL.createObjectURL(blob)
const link = document.createElement("a")
link.href = url
link.download = "错误记录.xlsx"
// 模拟点击下载链接
document.body.appendChild(link)
link.click()
// 清理下载链接
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
},
fileHandleRemove(file, fileList) {
return fileList
},
fileHandleChange(file, fileList, {type, size}) {
const removeFile = () => {
fileList.splice(fileList.findIndex((v) => v === file))
}
if (!file.size) {
this.$message.warning("您选择的是空文件")
removeFile()
}
if (type && type.length && !type.includes(file.name.split(".").pop().toLowerCase())) {
this.$message.warning(`文件只能是 ${type.map((v) => v.toUpperCase()).join("/")} 格式`)
removeFile()
}
if (size && !file.size < size) {
this.$message.warning(`文件大小不能超过 ${size / 1024 / 1024}MB`)
removeFile()
}
return fileList
}
}
}
</script>
<style>
.el-card__body {
padding: 25px;
}
</style>