Browse Source

导入excle

master
mch 2 years ago
parent
commit
7876878cd6
  1. 663
      package-lock.json
  2. 1
      package.json
  3. 17
      src/views/common-settings/SampleGroup.vue
  4. 192
      src/views/fee-settings/ItemTemplate.vue

663
package-lock.json
File diff suppressed because it is too large
View File

1
package.json

@ -11,6 +11,7 @@
"axios": "^1.3.3",
"crypto-js": "^4.1.1",
"element-ui": "^2.15.13",
"exceljs": "^4.3.0",
"moment": "^2.29.4",
"sortablejs": "^1.15.0",
"vue": "^2.6.14",

17
src/views/common-settings/SampleGroup.vue

@ -503,14 +503,15 @@ export default {
//
ischangs(v) {
itemtypeid(v).then((res) => {
this.ites = res.data;
let dq = res.data;
if (dq.length > 0) {
dq.forEach((element) => {
let bb = { displayName: element.displayName, id: element.id };
this.ites.push(bb);
});
}
this.ites = res.data;
this.ites[1] = {};
// let dq = res.data;
// if (dq.length > 0) {
// dq.forEach((element) => {
// let bb = { displayName: element.displayName, id: element.id };
// this.ites.push(bb);
// });
// }
});
},
//

192
src/views/fee-settings/ItemTemplate.vue

@ -174,6 +174,33 @@
</div>
<!-- 按钮区域 -->
<div style="margin-left: 10px; margin-top: 5%">
<div style="">
<!-- undate -->
<el-row>
<div class="el-form-item__content">
<el-upload
ref="upload"
accept=".xls,.xlsx"
action="#"
:auto-upload="false"
:multiple="false"
:file-list="fileList"
:before-upload="beforeUpload"
:http-request="uploadHttpRequest"
:on-remove="fileRemove"
:on-change="fileChange"
>
<el-button size="small" type="primary">选择文件</el-button>
</el-upload>
</div>
</el-row>
<!-- -->
<!-- <el-button type="primary" @click="exportexc">导出excel</el-button> -->
</div>
<el-button type="primary" @click="parseImportData(importData)"
>parse</el-button
>
<el-button type="primary" @click="add">新增</el-button>
<el-button
type="primary"
@ -181,6 +208,7 @@
style="margin-left: 0; margin-top: 10px"
>编辑</el-button
>
<input type="file" accept=".xlsx" @change="onFileChange" />
<div style="margin-top: 10px">
<el-button type="danger" @click="delets">删除</el-button>
</div>
@ -201,9 +229,22 @@
>
</div>
</div>
<!-- 选择文件之后的弹框 -->
<el-dialog title="提示" :visible.sync="filepopupdialogVisible" width="50%">
<el-table :data="importData" style="width: 100%"> </el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="filepopupdialogVisible = false"> </el-button>
<el-button type="primary" @click="filepopupdialogVisible = false"
> </el-button
>
</span>
</el-dialog>
<!-- -->
</div>
</template>
<script>
import ExcelJS from "exceljs";
import { rowDrop } from "@/components/publicjs/public";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { getporjectlists } from "@/request/commonapi";
@ -213,6 +254,7 @@ export default {
components: { compTable },
data() {
return {
filepopupdialogVisible: false,
ary1: [],
ary2: [],
nums: 0,
@ -294,6 +336,8 @@ export default {
rightdata: [], //
isdislob: true,
flitvalues: [],
fileList: [],
importData: [],
};
},
created() {
@ -302,12 +346,156 @@ export default {
},
mounted() {
this.rowDrop();
this.getdiagnosisitem()
// this.getdiagnosisitem();
},
methods: {
onFileChange(event) {
//
const file = event.target.files[0];
// Excel
this.importExcelFile(file);
},
importExcelFile(file) {
this.filepopupdialogVisible = true;
console.log("333");
// 簿
const workbook = new ExcelJS.Workbook();
// Excel
const reader = new FileReader();
console.log(reader);
reader.onload = () => {
const buffer = reader.result;
const typedArray = new Uint8Array(buffer);
const blob = new Blob([typedArray], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
// BlobExcel
workbook.xlsx.load(blob).then((workbook) => {
//
const worksheet = workbook.getWorksheet(1);
// Excel
worksheet.eachRow((row, rowNumber) => {
// const rowData = row.values;
// this.rowData = row.values;
// console.log(this.rowData,'rowdata');
// console.log(rowData);
//console.log('row,rowNumber',row,rowNumber);
this.importData.push(row.values);
// console.log(`${rowNumber}${rowData}`);
});
});
};
reader.readAsArrayBuffer(file);
},
parseImportData(importData) {
console.log("importData", importData.length, importData);
importData.forEach((item) => {
item.forEach((item2) => {
// this.$set(item2[0], "name", true);
item2[0]['names']=true
console.log(item2);
// console.log(item2);
});
// console.log(item,'item',item.length);
});
},
// false
beforeUpload(file) {
console.log(file);
console.log("333");
console.log("2222");
//
const isType = file.type === "application/vnd.ms-excel";
const isTypeComputer =
file.type ===
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
const fileType = isType || isTypeComputer;
if (!fileType) {
this.$message.error("上传文件只能是xls/xlsx格式!");
}
// 10M
const fileLimit = file.size / 1024 / 1024 < 10;
if (!fileLimit) {
this.$message.error("上传文件大小不超过10M!");
}
return fileType && fileLimit;
},
uploadHttpRequest(param) {
const formData = new FormData(); //FormDataappend('key', value)
formData.append("file", param.file); //
formData.append("uploadType", this.rulesType);
const url = `${this.myBaseURL}/operation/ruleImport/importData`; //
axios
.post(url, formData)
.then((res) => {
const {
data: { code, mark },
} = res;
if (code === 0) {
param.onSuccess(); // 绿
this.uploadMark = mark;
}
return this.countData(this.uploadMark); // mark promise便
})
.then((res) => {
//
const {
data: { code, data },
} = res;
if (code === 0) {
console.log("统计结果", data);
}
})
.catch((err) => {
console.log("失败", err);
param.onError(); //
});
},
//
countFile(mark) {
return new Promise((resolve, reject) => {
axios
.get(`/operation/ruleImport/countData?mark=${mark}`)
.then((res) => {
resolve(res);
})
.catch((error) => {
reject(error);
});
});
},
// http-request
submitUpload() {
this.$refs.upload.submit();
},
//
fileChange(file, fileList) {
if (fileList.length > 0) {
this.fileList = [fileList[fileList.length - 1]]; //
}
},
//
fileRemove(file, fileList) {
if (fileList.length < 1) {
this.uploadDisabled = true; //
console.log(file);
}
},
exportexc() {
// console.log('1');
},
// getdiagnosisitem() {
// getapi("/api/app/item").then((res) => {
// console.log(res);
// });
// },

Loading…
Cancel
Save