导入问题
This commit is contained in:
@@ -44,7 +44,8 @@ export const importSensitiveUserData = (data: any) => {
|
|||||||
return createAxios({
|
return createAxios({
|
||||||
url: MAPPING_PATH + '/importSensitiveUserData',
|
url: MAPPING_PATH + '/importSensitiveUserData',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data
|
data: data,
|
||||||
|
responseType: 'blob'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
draggable
|
draggable
|
||||||
class='cn-operate-dialog'
|
class='cn-operate-dialog'
|
||||||
v-model='eventDataUploadVisible'
|
v-model='eventDataUploadVisible'
|
||||||
:title='title'
|
:title='title'
|
||||||
style='width: 415px;'
|
style='width: 415px;'
|
||||||
top='25vh'
|
top='25vh'
|
||||||
>
|
>
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<el-form :inline='false' :model='form' label-width='120px' ref='formRef'>
|
<el-form :inline='false' :model='form' label-width='120px' ref='formRef'>
|
||||||
<el-form-item label='用户数据文件'>
|
<el-form-item label='用户数据文件'>
|
||||||
<el-upload
|
<el-upload
|
||||||
v-model:file-list='fileList'
|
v-model:file-list='fileList'
|
||||||
ref='uploadEventData'
|
ref='uploadEventData'
|
||||||
action=''
|
action=''
|
||||||
:limit='1'
|
:limit='1'
|
||||||
:on-exceed='handleExceed'
|
:on-exceed='handleExceed'
|
||||||
:auto-upload='false'
|
:auto-upload='false'
|
||||||
:on-change='choose'
|
:on-change='choose'
|
||||||
>
|
>
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<el-button type='primary'>选择数据文件</el-button>
|
<el-button type='primary'>选择数据文件</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class='dialog-footer'>
|
<span class='dialog-footer'>
|
||||||
<el-button @click='eventDataUploadVisible = false'>取消</el-button>
|
<el-button @click='eventDataUploadVisible = false'>取消</el-button>
|
||||||
<el-button type='primary' @click='submit'>确认</el-button>
|
<el-button type='primary' @click='submit'>确认</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
@@ -53,62 +53,93 @@ const uploadEventData = ref<UploadInstance>()
|
|||||||
|
|
||||||
// 注意不要和表单ref的命名冲突
|
// 注意不要和表单ref的命名冲突
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
file: null
|
file: null
|
||||||
})
|
})
|
||||||
|
|
||||||
//弹出界面,默认选择用户的第一个生产线的第一条进线进行数据导入
|
//弹出界面,默认选择用户的第一个生产线的第一条进线进行数据导入
|
||||||
const open = async (text: string) => {
|
const open = async (text: string) => {
|
||||||
title.value = text
|
title.value = text
|
||||||
resetForm()
|
resetForm()
|
||||||
form.file = null
|
form.file = null
|
||||||
fileList.value = []
|
fileList.value = []
|
||||||
eventDataUploadVisible.value = true
|
eventDataUploadVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//重置表单内容
|
//重置表单内容
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
if (formRef.value) {
|
if (formRef.value) {
|
||||||
formRef.value.resetFields()
|
formRef.value.resetFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择待上传文件
|
* 选择待上传文件
|
||||||
*/
|
*/
|
||||||
const choose = (e: any) => {
|
const choose = (e: any) => {
|
||||||
form.file = e.raw
|
form.file = e.raw
|
||||||
}
|
}
|
||||||
const handleExceed: UploadProps['onExceed'] = files => {
|
const handleExceed: UploadProps['onExceed'] = files => {
|
||||||
uploadEventData.value!.clearFiles()
|
uploadEventData.value!.clearFiles()
|
||||||
const file = files[0] as UploadRawFile
|
const file = files[0] as UploadRawFile
|
||||||
file.uid = genFileId()
|
file.uid = genFileId()
|
||||||
uploadEventData.value!.handleStart(file)
|
uploadEventData.value!.handleStart(file)
|
||||||
fileList.value = [{ name: file.name, url: '' }]
|
fileList.value = [{ name: file.name, url: '' }]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交用户表单数据
|
* 提交用户表单数据
|
||||||
*/
|
*/
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (form.file) {
|
if (form.file) {
|
||||||
formRef.value.validate(async (valid: any) => {
|
formRef.value.validate(async (valid: any) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let data = new FormData()
|
let data = new FormData()
|
||||||
data.append('file', form.file)
|
data.append('file', form.file)
|
||||||
await importSensitiveUserData(data).then((res: any) => {
|
await importSensitiveUserData(data).then((res: any) => {
|
||||||
if (res.code == 'A0000') {
|
debugger
|
||||||
ElMessage.success('导入成功')
|
if(res.type === 'application/json'){
|
||||||
tableStore.index()
|
// 说明是普通对象数据,读取信息
|
||||||
eventDataUploadVisible.value = false
|
const fileReader = new FileReader()
|
||||||
} else {
|
fileReader.onloadend = () => {
|
||||||
ElMessage.error('导入失败,请检查表格文件')
|
try {
|
||||||
}
|
const jsonData = JSON.parse(fileReader.result)
|
||||||
|
// 后台信息
|
||||||
|
if (jsonData.code === 'A0000') {
|
||||||
|
ElMessage.success('导入成功')
|
||||||
|
} else {
|
||||||
|
ElMessage.error('导入失败,请查看下载附件!')
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileReader.readAsText(res)
|
||||||
|
|
||||||
|
}else{
|
||||||
|
ElMessage.error('导入失败,请查看下载附件!')
|
||||||
|
let blob = new Blob([res], {
|
||||||
|
type: 'application/vnd.ms-excel'
|
||||||
|
})
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = '敏感及重要用户失败列表'
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
link.remove()
|
||||||
|
}
|
||||||
|
}).finally(
|
||||||
|
() => {
|
||||||
|
tableStore.index()
|
||||||
|
eventDataUploadVisible.value = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
})
|
ElMessage.error('请选择数据文件')
|
||||||
} else {
|
}
|
||||||
ElMessage.error('请选择数据文件')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ open })
|
defineExpose({ open })
|
||||||
@@ -116,6 +147,6 @@ defineExpose({ open })
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.el-form-item__content div {
|
.el-form-item__content div {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user