导入模版必填项加红色

master
xy 11 months ago
parent 767b6c5e0a
commit 546e1a9fd0

@ -42,7 +42,8 @@
"vue-router": "3.0.6", "vue-router": "3.0.6",
"vuedraggable": "^2.24.3", "vuedraggable": "^2.24.3",
"vuex": "3.1.0", "vuex": "3.1.0",
"xlsx": "^0.18.5" "xlsx": "^0.18.5",
"xlsx-js-style": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "4.4.4", "@vue/cli-plugin-babel": "4.4.4",

@ -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
}; };
}); });
} }

Loading…
Cancel
Save