This commit is contained in:
Paidax
2025-11-11 11:33:43 +08:00
parent 51a417ea20
commit dea071e25f
31 changed files with 348 additions and 110 deletions
@@ -81,12 +81,9 @@ const importAndMap = {
<el-option
v-for="field in dbFieldOptions"
:key="field.value"
:label="field.label + '(' + field.value + ')'"
:label="field.label"
:value="field.value"
>
<span style="float: left">{{ field.value }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ field.label }}</span>
</el-option>
></el-option>
</el-select>
</template>
</el-table-column>
@@ -104,7 +101,7 @@ const importAndMap = {
:key="col"
:prop="col"
:label="col"
/>
></el-table-column>
</el-table>
</div>
</div>
@@ -164,7 +161,18 @@ const importAndMap = {
{ value: "arrivalAtSchoolDate", label: "来校时间" },
{ value: "teachingTime", label: "从教年月" },
{ value: "expectedLeaveSchoolDate", label: "预计/最后离校时间" },
]
],
excelToDbFieldMap:{
loginname: ['工号', '员工编号', '职工号', '学号', '账号', 'ID', '编号'],
username: ['姓名', '名字', '全名', '人员姓名'],
sex: ['性别', '男女性别'],
birthday: ['出生日期', '出生年月', '生日', 'DOB'],
mobile: ['电话', '手机号', '联系电话', '手机'],
idCard: ['身份证', '身份证号', '证件号码'],
arrivalAtSchoolDate: ['来校时间', '入职时间', '入职日期', '入职年月'],
}
}
},
computed: {
@@ -219,11 +227,12 @@ const importAndMap = {
this.headers = jsonData[0].filter(h => h)
this.rawData = jsonData.slice(1)
// 初始化字段选择列表(所有字段默认可编辑?或让用户选)
// 初始化字段选择列表
this.headerList = this.headers.map((h, idx) => ({
name: h,
sample: this.rawData[0] ? this.rawData[0][idx] : '',
selected: true // 默认都允许修改,也可以让用户决定
selected: true,
dbField: this.autoMatchDbField(h)
}))
this.$message.success('成功加载 ' + this.rawData.length + ' 条数据,共 ' + this.headers.length + ' 个字段')
@@ -256,6 +265,29 @@ const importAndMap = {
this.fileList = []
},
// 自动匹配数据库字段
autoMatchDbField(excelHeader) {
const cleanHeader = (excelHeader || '').toString().trim();
if (!cleanHeader) return '';
// 遍历所有数据库字段
for (const [dbField, keywords] of Object.entries(this.excelToDbFieldMap)) {
if (keywords.some(keyword => cleanHeader.includes(keyword))) {
return dbField;
}
}
// 如果没匹配上,也可以尝试精确匹配
const exactMatch = this.dbFieldOptions.find(opt =>
opt.label === cleanHeader || opt.value === cleanHeader
);
if (exactMatch) {
return exactMatch.value;
}
return ''; // 未匹配
},
generatePreview() {
try {
this.previewData = this.rawData.slice(0, 5).map(row => {
@@ -314,7 +346,7 @@ const importAndMap = {
} finally {
this.submitting = false
}
}
},
},
mounted() {
const s = document.createElement("script")