shanyunduo.cheng

excel导入和基本校验

1 +import service from "../utils/request";
1 import request from '@/utils/request' 2 import request from '@/utils/request'
2 3
3 // 查询航班种类 4 // 查询航班种类
...@@ -15,3 +16,14 @@ export function downLoadTemplate(templateResourceName) { ...@@ -15,3 +16,14 @@ export function downLoadTemplate(templateResourceName) {
15 responseType:'blob', 16 responseType:'blob',
16 }) 17 })
17 } 18 }
19 +
20 +export function importFlight(file, type){
21 + let formData = new FormData();
22 + formData.append("file", file);
23 + formData.append("type", type);
24 + return request({
25 + url:'/flightInfoImport/importFlight',
26 + method:'post',
27 + data:formData
28 + })
29 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
13 </el-form-item> 13 </el-form-item>
14 <el-form-item> 14 <el-form-item>
15 <el-upload 15 <el-upload
16 - action="https://jsonplaceholder.typicode.com/posts/" 16 + action="/flightInfoImport/importFlight"
17 + name="file"
18 + :http-request="uploadExcel"
17 :on-remove="handleRemove" 19 :on-remove="handleRemove"
18 :limit="1" 20 :limit="1"
19 :on-exceed="handleExceed" 21 :on-exceed="handleExceed"
...@@ -31,8 +33,6 @@ ...@@ -31,8 +33,6 @@
31 </el-form-item> 33 </el-form-item>
32 </el-form> 34 </el-form>
33 35
34 - <el-button @click="clearFilter" size="small">清除所有过滤器</el-button>
35 -
36 <el-table 36 <el-table
37 ref="filterTable" 37 ref="filterTable"
38 :data="tableData" 38 :data="tableData"
...@@ -40,12 +40,18 @@ ...@@ -40,12 +40,18 @@
40 size="small" 40 size="small"
41 border 41 border
42 > 42 >
43 - <el-table-column label="行号" prop="line" fixed> </el-table-column> 43 + <el-table-column label="行号" prop="line" fixed width="50" align="center">
44 + </el-table-column>
44 45
45 - <el-table-column label="错误信息" prop="errorMessage" fixed> 46 + <el-table-column label="错误信息" prop="errorMessage" fixed width="200">
47 + <template slot-scope="scope">
48 + <div v-for="(m,key) in scope.row.errorMessage" :key="key">{{ m }}</div>
49 + </template>
46 </el-table-column> 50 </el-table-column>
47 51
48 - <el-table-column label="index"></el-table-column> 52 + <el-table-column v-if="tableData.length == 0" ></el-table-column>
53 +
54 + <el-table-column v-for="(value,key) in this.tableData[0]" :key="key" v-if="key != 'errorMessage' && key != 'line'" :label="key" :prop="key" width="120"></el-table-column>
49 </el-table> 55 </el-table>
50 </div> 56 </div>
51 </template> 57 </template>
...@@ -53,7 +59,11 @@ ...@@ -53,7 +59,11 @@
53 </template> 59 </template>
54 60
55 <script> 61 <script>
56 -import { filghtKindData, downLoadTemplate } from "@/api/flightInfoImport"; 62 +import {
63 + filghtKindData,
64 + downLoadTemplate,
65 + importFlight,
66 +} from "@/api/flightInfoImport";
57 67
58 export default { 68 export default {
59 data() { 69 data() {
...@@ -64,26 +74,7 @@ export default { ...@@ -64,26 +74,7 @@ export default {
64 region: "", 74 region: "",
65 }, 75 },
66 fileList: [], 76 fileList: [],
67 - tableData: [ 77 + tableData: [],
68 - { line: "1", errorMessage: "error" },
69 - { line: "1", errorMessage: "error" },
70 - { line: "1", errorMessage: "error" },
71 - { line: "1", errorMessage: "error" },
72 - { line: "1", errorMessage: "error" },
73 - { line: "1", errorMessage: "error" },
74 - { line: "1", errorMessage: "error" },
75 - { line: "1", errorMessage: "error" },
76 - { line: "1", errorMessage: "error" },
77 - { line: "1", errorMessage: "error" },
78 - { line: "1", errorMessage: "error" },
79 - { line: "1", errorMessage: "error" },
80 - { line: "1", errorMessage: "error" },
81 - { line: "1", errorMessage: "error" },
82 - { line: "1", errorMessage: "error" },
83 - { line: "1", errorMessage: "error" },
84 - { line: "1", errorMessage: "error" },
85 - { line: "1", errorMessage: "error" },
86 - ],
87 }; 78 };
88 }, 79 },
89 methods: { 80 methods: {
...@@ -119,33 +110,37 @@ export default { ...@@ -119,33 +110,37 @@ export default {
119 URL.revokeObjectURL(link.href); //释放url 110 URL.revokeObjectURL(link.href); //释放url
120 document.body.removeChild(link); //释放标签 111 document.body.removeChild(link); //释放标签
121 } else { 112 } else {
122 - this.$message.error('下载失败'); 113 + this.$message.error("下载失败");
123 } 114 }
124 }); 115 });
125 } 116 }
126 }, 117 },
118 + uploadExcel(option) {
119 + //上传excel
120 + const file = option.file;
121 + console.log(option);
122 + importFlight(file, this.form.type).then((res) => {
123 + if (res.code != 200) {
124 + this.$message.error(res.msg);
125 + } else {
126 + this.tableData = res.data;
127 + }
128 + });
129 + },
127 handleRemove(file, fileList) { 130 handleRemove(file, fileList) {
131 + //清掉上传的文件
128 this.tableData = []; 132 this.tableData = [];
133 + this.fileList = [];
129 }, 134 },
130 handleExceed(files) { 135 handleExceed(files) {
136 + //重复上传文件
131 let file = {}; 137 let file = {};
132 file.file = files[0]; 138 file.file = files[0];
133 file.name = files[0].name; 139 file.name = files[0].name;
134 this.fileList = []; 140 this.fileList = [];
135 this.fileList.push(file); 141 this.fileList.push(file);
136 - }, 142 +
137 - clearFilter() { 143 + this.uploadExcel(file);
138 - this.$refs.filterTable.clearFilter();
139 - },
140 - formatter(row, column) {
141 - return row.address;
142 - },
143 - filterTag(value, row) {
144 - return row.tag === value;
145 - },
146 - filterHandler(value, row, column) {
147 - const property = column["property"];
148 - return row[property] === value;
149 }, 144 },
150 }, 145 },
151 created() { 146 created() {
......