zs il y a 8 mois
Parent
commit
e405940084
4 fichiers modifiés avec 100 ajouts et 0 suppressions
  1. BIN
      public/导入模板.xlsx
  2. 1 0
      src/lang/package/zh-cn/menus.js
  3. 14 0
      src/store/api/util.js
  4. 85 0
      src/views/import/index.vue

BIN
public/导入模板.xlsx


+ 1 - 0
src/lang/package/zh-cn/menus.js

@@ -41,6 +41,7 @@ export default {
   directory: '目录管理',
   incubator: '全省孵化基地情况',
   elevenHatch: '孵化基地情况',
+  import:'数据导入',
   log: '日志管理',
   log_opera: '操作日志'
 }

+ 14 - 0
src/store/api/util.js

@@ -0,0 +1,14 @@
+import { defineStore } from 'pinia'
+import { AxiosWrapper } from '@/utils/axios-wrapper'
+const axios = new AxiosWrapper()
+export const UtilStore = defineStore('util', () => {
+  const toImport = async (payload) => {
+    const res = await axios.$post(`/util/toImport`, payload)
+    return res
+  }
+  const toExport = async (payload) => {
+    const res = await axios.$post(`/util/toExport`, payload)
+    return res
+  }
+  return { toImport, toExport }
+})

+ 85 - 0
src/views/import/index.vue

@@ -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>