|
@@ -0,0 +1,85 @@
|
|
|
+<template>
|
|
|
+ <div id="index">
|
|
|
+ <el-row justify="space-around" style="padding: 10px">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-upload class="button" action="/files/web/cxyy_import/upload" :show-file-list="false" :on-success="onSuccess" accept=".xlsx">
|
|
|
+ <el-button type="primary">选择excel模板文件</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12" style="text-align: right">
|
|
|
+ <el-button type="primary" @click="toDownload()">下载模板文件</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-table :data="resultList" border>
|
|
|
+ <el-table-column align="center" label="处理内容" prop="key"></el-table-column>
|
|
|
+ <el-table-column align="center" label="处理条数" prop="num">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ getText(row) }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <c-dialog :dialog="dialog" @toClose="toClose">
|
|
|
+ <template v-slot:info>
|
|
|
+ <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
|
|
|
+ {{ errorList }}
|
|
|
+ </el-col>
|
|
|
+ </template>
|
|
|
+ </c-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { get, isNumber } from 'lodash-es'
|
|
|
+import { UtilStore } from '@/store/api/util'
|
|
|
+const utilStore = UtilStore()
|
|
|
+// 加载中
|
|
|
+const loading = ref(false)
|
|
|
+
|
|
|
+const dialog = ref({ title: '信息管理', show: false, type: '1' })
|
|
|
+
|
|
|
+const resultList = ref([])
|
|
|
+// 请求
|
|
|
+onMounted(async () => {
|
|
|
+ loading.value = true
|
|
|
+ loading.value = false
|
|
|
+})
|
|
|
+// 下载导出模板
|
|
|
+const toDownload = () => {
|
|
|
+ window.open('/cxyyAdmin/导入模板.xlsx')
|
|
|
+}
|
|
|
+const getText = (data) => {
|
|
|
+ const num = get(data, 'num')
|
|
|
+ const errorList = get(data, 'errorList')
|
|
|
+ if (errorList || num === 'error') {
|
|
|
+ return '处理发生错误'
|
|
|
+ } else {
|
|
|
+ if (isNumber(num)) return `成功处理 ${num} 条数据`
|
|
|
+ }
|
|
|
+}
|
|
|
+// 上传Excel
|
|
|
+const onSuccess = async (response, file) => {
|
|
|
+ const msgbox = ElMessage({ message: '正在导入中,请稍后...', center: true, duration: 0 })
|
|
|
+ try {
|
|
|
+ const res = await utilStore.toImport({ url: response.uri })
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ if (res.data[0].errorList) {
|
|
|
+ ElMessageBox.alert(res.data[0].errorList, '错误提示', {
|
|
|
+ confirmButtonText: 'OK'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ ElMessage({ message: '导入成功', type: 'success' })
|
|
|
+ }
|
|
|
+ resultList.value = res.data
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ } finally {
|
|
|
+ msgbox.close()
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style scoped lang="scss"></style>
|