|
|
|
@ -40,7 +40,8 @@
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import * as XLSX from "xlsx";
|
|
|
|
import XLSX from "xlsx-js-style";
|
|
|
|
|
|
|
|
// import * as XLSX from "xlsx";
|
|
|
|
import { saveAs } from "file-saver";
|
|
|
|
import { saveAs } from "file-saver";
|
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
import { imports } from "@/api/system/baseForm";
|
|
|
|
import { imports } from "@/api/system/baseForm";
|
|
|
|
@ -80,6 +81,16 @@ export default {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
uploadSuccess(response) {
|
|
|
|
uploadSuccess(response) {
|
|
|
|
|
|
|
|
this.headers.forEach(header => {
|
|
|
|
|
|
|
|
if (header._params) {
|
|
|
|
|
|
|
|
response.forEach(row => {
|
|
|
|
|
|
|
|
if (row.hasOwnProperty(header.key)) {
|
|
|
|
|
|
|
|
console.log(header.key, header._params, row[header.key])
|
|
|
|
|
|
|
|
row[header.key] = header._params.find(i => i.key == row[header.key]) ? header._params.find(i => i.key == row[header.key]).value : row[header.key]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
this.tableList = response;
|
|
|
|
this.tableList = response;
|
|
|
|
this.$message({
|
|
|
|
this.$message({
|
|
|
|
message: `上传成功`,
|
|
|
|
message: `上传成功`,
|
|
|
|
@ -88,9 +99,28 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
exportExcel(sheetName) {
|
|
|
|
exportExcel(sheetName) {
|
|
|
|
|
|
|
|
function numberToLetter(num) {
|
|
|
|
|
|
|
|
// 检查输入是否为非负整数
|
|
|
|
|
|
|
|
if (num < 0 || !Number.isInteger(num)) {
|
|
|
|
|
|
|
|
throw new Error("请输入一个非负整数");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 计算对应的字母
|
|
|
|
|
|
|
|
return String.fromCharCode(65 + num);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = [this.headers.map((header) => header.title)];
|
|
|
|
const data = [this.headers.map((header) => header.title)];
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
const ws = XLSX.utils.aoa_to_sheet(data);
|
|
|
|
const ws = XLSX.utils.aoa_to_sheet(data);
|
|
|
|
|
|
|
|
this.headers.forEach((header, index) => {
|
|
|
|
|
|
|
|
if (header.required) {
|
|
|
|
|
|
|
|
ws[`${numberToLetter(index)}1`].s = {
|
|
|
|
|
|
|
|
font: {
|
|
|
|
|
|
|
|
bold: true,
|
|
|
|
|
|
|
|
color: { rgb: "FFFF0000" }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
|
|
const wbout = XLSX.write(wb, {
|
|
|
|
const wbout = XLSX.write(wb, {
|
|
|
|
bookType: "xlsx",
|
|
|
|
bookType: "xlsx",
|
|
|
|
@ -122,11 +152,14 @@ export default {
|
|
|
|
watch: {
|
|
|
|
watch: {
|
|
|
|
formInfo(newVal) {
|
|
|
|
formInfo(newVal) {
|
|
|
|
if (newVal && newVal instanceof Array) {
|
|
|
|
if (newVal && newVal instanceof Array) {
|
|
|
|
|
|
|
|
console.log(33, newVal)
|
|
|
|
this.table = this.headers = newVal.map((i) => {
|
|
|
|
this.table = this.headers = newVal.map((i) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
key: i.field,
|
|
|
|
key: i.field,
|
|
|
|
title: i.name,
|
|
|
|
title: i.name,
|
|
|
|
width: 200
|
|
|
|
width: 200,
|
|
|
|
|
|
|
|
required: !!i.validation?.find(i => i === 'required'),
|
|
|
|
|
|
|
|
_params: i._params
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|