From 19b5a121468743e52333c6146025c0ab6da37319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E4=B8=9C=E6=9E=97?= Date: Wed, 5 Jan 2022 17:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ecology/lake.js | 8 +- src/api/ecology/special-lake.js | 5 +- src/views/water/lake/collect/index.vue | 390 +++++++++---------------- 3 files changed, 143 insertions(+), 260 deletions(-) diff --git a/src/api/ecology/lake.js b/src/api/ecology/lake.js index 1134e78..4574a73 100644 --- a/src/api/ecology/lake.js +++ b/src/api/ecology/lake.js @@ -1,6 +1,11 @@ import axios from 'axios'; // ----------------------列表----------------------- const pageBillUrl = '/lakeLibrary/lakeLibraryInnerCityBill/page'; + +const getInnerData = function (data) { + return axios.get(pageBillUrl,{params:data}) +} + // 添加 const saveLakeBill = function (data) { return axios.post("/lakeLibrary/lakeLibraryInnerCityBill/importBatch",data) @@ -75,6 +80,7 @@ export { getHistoryyears, getColumnOptions, statisticSourceUrl, - statisticYearUrl + statisticYearUrl, + getInnerData } diff --git a/src/api/ecology/special-lake.js b/src/api/ecology/special-lake.js index e6b02fb..0f3eca4 100644 --- a/src/api/ecology/special-lake.js +++ b/src/api/ecology/special-lake.js @@ -1,6 +1,9 @@ import axios from 'axios'; // ----------------------列表----------------------- const pageBillUrl = '/lakeLibrary/lakeLibrarySpecialBill/page'; +const getSpecialData = function (data) { + return axios.get(pageBillUrl,{params:data}) +} // 添加 const saveLakeBill = function (data) { return axios.post("/lakeLibrary/lakeLibrarySpecialBill/importBatch",data) @@ -72,6 +75,6 @@ export { avgUrl, getHistoryyears, getColumnOptions, - + getSpecialData } diff --git a/src/views/water/lake/collect/index.vue b/src/views/water/lake/collect/index.vue index 08f3d5f..47aa459 100644 --- a/src/views/water/lake/collect/index.vue +++ b/src/views/water/lake/collect/index.vue @@ -83,6 +83,12 @@ import { DownOutlined } from "@ant-design/icons-vue"; // import {saveLakeBill} from "@/api/ecology/lake"; // import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake"; import {importCityOther,importCppointCity,importSpecial} from "@/api/ecology/water/lake/import"; + import { + getInnerData + } from "@/api/ecology/lake"; +import { + getSpecialData + } from "@/api/ecology/special-lake"; export default { name: "LakeCollectIndex", @@ -94,9 +100,27 @@ export default { data() { return { activeKey: "water", + waterData:[], + specialData:[] }; }, + created(){ + this.reload() + }, methods: { + + getInnerData(){ + getInnerData({page: 1, limit: 1000}).then(res=>{ + this.waterData = res.data.data + }) + }, + getSpecialData(){ + getSpecialData({page: 1, limit: 1000}).then(res=>{ + this.specialData = res.data.data + }) + }, + + // 模板下载 download (name,url){ var a = document.createElement("a"); @@ -111,121 +135,66 @@ export default { document.getElementById(e.key).click() }, /* 导入本地excel文件 */ - importFileInnerCity(file) { - const hide = this.$message.loading("导入中..", 0); + importFileCity(file,hide){ const formData = new FormData(); formData.append('file', file); - importCityOther(formData).then(res=>{ - console.log(res) - if(!res.data.code){ - Modal.success({ title:res.data.msg, }); - }else{ - Modal.error({ title:res.data.msg || '文件导入失败', }); + importCityOther(formData).then(res=>{ + console.log(res) + if(!res.data.code){ + Modal.success({ title:res.data.msg, }); + this.reload() + }else{ + Modal.error({ title:res.data.msg || '文件导入失败', }); + } + + hide() + }).catch(err=>{ + console.log(err) + Modal.error({ title:err.data.msg || '文件导入失败', }); + hide() + }) + }, + + importFileInnerCity(file) { + const hide = this.$message.loading("导入中..", 0); + + const table = this.waterData; + let isHas = false; + if(Array.isArray(table) && table.length>0){ + table.forEach(item=>{ + if(item.billName==file.name){ + isHas = true } - - hide() - }).catch(err=>{ - console.log(err) - Modal.error({ title:err.data.msg || '文件导入失败', }); - hide() - }) + }) + } - // let reader = new FileReader(); - // reader.onload = (e) => { - // try { - // let data = new Uint8Array(e.target.result); - // let workbook = XLSX.read(data, { - // type: "array", - // }); - // //0.昼间数据 1.夜间数据 2.其他信息 - // let sheetNames = workbook.SheetNames; - // // 解析成二维数组 - // let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { - // header: 1, - // }); - - // const reportDate = aoa[2][0].replace(/[^\d]+/g, "-"); - - // const lakeList = aoa.filter( - // (item) => { - // return item.length >= 24 && item[0] && !item[0].includes("点位名称"); - // } - // ); - - - // // 解析成对象数组 - // const billName = file.name; - // const billData = utils.toInnerCityLakeObjData(lakeList, reportDate); - // if (!billData || billData.length == 0) { - // hide() - // Modal.error({ - // title: "导入失败", - // content: "找不到数据", - // }); - // return; - // } - // const tasks = []; - // if (billData.length > 0) { - // tasks.push( - // saveLakeBill({ - // reportTime: new Date(reportDate).getTime(), - // billName: billName, - // regionLevel: "市级", - // lakeLibraryInnerCityList: billData, - // }) - // ); - // } - - - // // 上传到服务器 - - // Promise.all(tasks) - // .then((res) => { - // if (res[0].data.code == 0) { - // Modal.success({ - // title: "导入成功", - // content: `成功导入${billData.length}条数据`, - // }); - // this.$refs.water && this.$refs.water.reload(); - // } else { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // } - - // }) - // .catch(() => { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // }) - // .finally(() => { - // hide(); - // }); - // } catch (error) { - // hide(); - // Modal.error({ - // title: "导入失败", - // content: error.message, - // }); - // } - // // console.log(billData); - // }; - // reader.readAsArrayBuffer(file); + if(isHas){ + const _this = this; + Modal.confirm({ + title: '有重复数据,确认是否覆盖?', + onOk() { + _this.importFileCity(file,hide) + }, + onCancel() { + console.log('Cancel'); + hide() + }, + }); + }else{ + this.importFileCity(file,hide) + } return false; }, - importFileWuxiang(file) { - const hide = this.$message.loading("导入中..", 0); - const formData = new FormData(); + importWuXiang(file,hide){ + const formData = new FormData(); formData.append('file', file); importCppointCity(formData).then(res=>{ console.log(res) if(!res.data.code){ Modal.success({ title:res.data.msg, }); + this.reload() }else{ Modal.error({ title:res.data.msg || '文件导入失败', }); } @@ -235,95 +204,45 @@ export default { Modal.error({ title:err.data.msg || '文件导入失败', }); hide() }) + }, + importFileWuxiang(file) { + const hide = this.$message.loading("导入中..", 0); + const table = this.waterData; + let isHas = false; + if(Array.isArray(table) && table.length>0){ + table.forEach(item=>{ + if(item.billName==file.name){ + isHas = true + } + }) + } - // let reader = new FileReader(); - // reader.onload = (e) => { - // try { - // let data = new Uint8Array(e.target.result); - // let workbook = XLSX.read(data, { - // type: "array", - // }); - // let sheetNames = workbook.SheetNames; - // // 解析成二维数组 - // let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { - // header: 1, - // }); - // const lakeList = aoa.filter( - // (item) => { - // return item.length >= 24 && item[0] && !item[0].includes("点位名称"); - // } - // ); - // // 解析成对象数组 - // const billName = file.name; - // const billData = utils.toWuxiangLakeObjData(lakeList); - // if (!billData || billData.length == 0) { - // hide() - // Modal.error({ - // title: "导入失败", - // content: "找不到数据", - // }); - // return; - // } - // const tasks = []; - // if (billData.length > 0) { - // tasks.push( - // saveLakeBill({ - // billName: billName, - // lakeLibraryInnerCityList: billData, - // }) - // ); - // } - - - // // 上传到服务器 - - // Promise.all(tasks) - // .then((res) => { - // if (res[0].data.code == 0) { - // Modal.success({ - // title: "导入成功", - // content: `成功导入${billData.length}条数据`, - // }); - // this.$refs.water && this.$refs.water.reload(); - // } else { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // } - - // }) - // .catch(() => { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // }) - // .finally(() => { - // hide(); - // }); - // } catch (error) { - // hide(); - // Modal.error({ - // title: "导入失败", - // content: error.message, - // }); - // } - // // console.log(billData); - // }; - // reader.readAsArrayBuffer(file); - + if(isHas){ + const _this = this; + Modal.confirm({ + title: '有重复数据,确认是否覆盖?', + onOk() { + _this.importWuXiang(file,hide) + }, + onCancel() { + console.log('Cancel'); + hide() + }, + }); + }else{ + this.importWuXiang(file,hide) + } return false; }, - importFileSpecial(file) { - const hide = this.$message.loading("导入中..", 0); + + importSpecialFile(file,hide){ const formData = new FormData(); formData.append('file', file); importSpecial(formData).then(res=>{ - console.log(res) if(!res.data.code){ Modal.success({ title:res.data.msg, }); + this.reload() }else{ Modal.error({ title:res.data.msg || '文件导入失败', }); } @@ -333,87 +252,42 @@ export default { Modal.error({ title:err.data.msg || '文件导入失败', }); hide() }) + }, - // let reader = new FileReader(); - // reader.onload = (e) => { - // try { - // let data = new Uint8Array(e.target.result); - // let workbook = XLSX.read(data, { - // type: "array", - // }); - // let sheetNames = workbook.SheetNames; - // // 解析成二维数组 - // let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { - // header: 1, - // }); - // const lakeList = aoa.filter( - // (item) => { - // return item.length >= 24 && item[1] && !item[1].includes("测站名称"); - // } - // ); - // // 解析成对象数组 - // const billName = file.name; - // const billData = utils.toSpecialLakeData(lakeList); - // if (!billData || billData.length == 0) { - // hide() - // Modal.error({ - // title: "导入失败", - // content: "找不到数据", - // }); - // return; - // } - // const tasks = []; - // if (billData.length > 0) { - // tasks.push( - // saveSpecialLake({ - // billName: billName, - // lakeLibrarySpecialList: billData, - // }) - // ); - // } + importFileSpecial(file) { + const hide = this.$message.loading("导入中..", 0); + const table = this.specialData; + let isHas = false; + if(Array.isArray(table) && table.length>0){ + table.forEach(item=>{ + if(item.billName==file.name){ + isHas = true + } + }) + } - - // // 上传到服务器 - - // Promise.all(tasks) - // .then((res) => { - // if (res[0].data.code == 0) { - // Modal.success({ - // title: "导入成功", - // content: `成功导入${billData.length}条数据`, - // }); - // this.$refs.special && this.$refs.special.reload(); - // } else { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // } - - // }) - // .catch(() => { - // Modal.error({ - // title: "导入失败", - // content: "数据上传出错", - // }); - // }) - // .finally(() => { - // hide(); - // }); - // } catch (error) { - // hide(); - // Modal.error({ - // title: "导入失败", - // content: error.message, - // }); - // } - // // console.log(billData); - // }; - // reader.readAsArrayBuffer(file); + if(isHas){ + const _this = this; + Modal.confirm({ + title: '有重复数据,确认是否覆盖?', + onOk() { + _this.importSpecialFile(file,hide) + }, + onCancel() { + console.log('Cancel'); + hide() + }, + }); + }else{ + this.importSpecialFile(file,hide) + } return false; }, - + reload(){ + this.getInnerData() + this.getSpecialData() + } }, };