addMemberBatch.vue
4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
<div>
<br>
<el-upload
ref="uploadRef"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
:on-error="onError"
class="upload"
drag
name="file"
>
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<template #tip>
<div class="el-upload__tip text-center">
<br>
<span>仅允许导入xls、xlsx格式文件。</span>
<!-- 会员 -->
<el-link href="/file/member.xls" type="primary" target="_blank">下载模板</el-link>
</div>
</template>
</el-upload>
<br>
<div style="text-align: center;">
<el-button type="primary" :loading="loading" @click="submitFileForm">确 定</el-button>
</div>
<!-- <ErrorVue ref="ErrorVueRef" />-->
<el-dialog v-model="showDialog" width="400" center title="导入结果">
<div class="row">
<span class="">导入成功:{{ form.rightCount }}条</span>
</div>
<div v-if="result==0" class="row">
<span class="error">导入失败:{{ form.errCount }}条</span>
</div>
<br>
<br>
<div style="text-align: center">
<el-button type="primary" @click="showDialog=false">确定</el-button>
<el-button v-if="form.result==0" type="warning" @click="downloadExcel">导出错误信息</el-button>
</div>
</el-dialog>
</div>
</template>
<script setup>
import { reactive } from '@vue/runtime-core'
import { getToken } from '@/utils/auth'
import { getCurrentInstance, ref, onMounted } from 'vue'
// import ErrorVue from './Error.vue'
const { proxy } = getCurrentInstance()
// const emit = defineEmits(['uploaded'])
const show = ref(false)
const showDialog = ref(false)
const loading = ref(false)
const form = ref()
const result = ref()
const upload = reactive({
// 是否禁用上传
isUploading: false,
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: ''
})
onMounted(() => {
upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importPersonMember`
})
function submitFileForm() {
loading.value = true
proxy.$refs['uploadRef'].submit()
}
const handleFileUploadProgress = (event, file, fileList) => {
upload.isUploading = true
}
const handleFileSuccess = (response, file, fileList) => {
loading.value = true
show.value = false
upload.isUploading = false
proxy.$refs['uploadRef'].handleRemove(file)
try {
form.value = response.data
result.value = response.data.result
showDialog.value = true
} catch (e) {
console.log(e)
if (response.code == 500) return proxy.$modal.msgError(response.msg)
} finally {
loading.value = false
}
console.log(response)
// if (response.data.result == 0) {
// // 导入失败
// // proxy.$alert(
// // "<div v-for='(item,index) in res.data.list' :key='index' style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
// // item.data +
// // '</div>',
// // '导入结果',
// // { dangerouslyUseHTMLString: true }
// // )
// // proxy.$refs['ErrorVueRef'].open(response.data.list)
// form.value = response.data
// showDialog.value = true
// }
// else {
// proxy.$alert(
// // 导入成功
// "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
// response.msg +
// '</div>',
// '导入结果',
// { dangerouslyUseHTMLString: true }
// )
// }
loading.value = false
}
// 下载
function downloadExcel() {
proxy.download(
`/person/info/exportImportPersonMemberResult`, { info: JSON.stringify(form.value.info) }, `导入结果${new Date().getTime()}.xlsx`
)
}
</script>
<style lang="scss" scoped>
:deep(.upload){
.el-upload-list__item {
width: 100%;
height: 50px;
line-height: 50px;
}
}
.row{
text-align: center;
font-size: 18px;
}
.error{
color: red;
}
.success{
color: #e6a23c;
}
</style>