Merge branch 'dev-scheduling' of http://42.192.7.176:3000/suojin/jonhon-mes-web into dev-scheduling
commit
b0446a7eeb
23 changed files with 13132 additions and 1973 deletions
@ -0,0 +1,289 @@ |
|||||||
|
<template> |
||||||
|
<basic-container> |
||||||
|
<avue-crud |
||||||
|
:option="option" |
||||||
|
:table-loading="loading" |
||||||
|
:data="data" |
||||||
|
v-model="form" |
||||||
|
v-model:page="page" |
||||||
|
ref="crud" |
||||||
|
@row-del="rowDel" |
||||||
|
@row-update="rowUpdate" |
||||||
|
@row-save="rowSave" |
||||||
|
@search-change="searchChange" |
||||||
|
@search-reset="searchReset" |
||||||
|
@selection-change="selectionChange" |
||||||
|
@current-change="currentChange" |
||||||
|
@size-change="sizeChange" |
||||||
|
@refresh-change="refreshChange" |
||||||
|
@on-load="onLoad" |
||||||
|
:before-open="beforeOpen" |
||||||
|
> |
||||||
|
<template #menu-left> </template> |
||||||
|
<template #menu-right> </template> |
||||||
|
<template #menu="{ row }"> </template> |
||||||
|
|
||||||
|
<template #heatTreat="scope"> </template> |
||||||
|
</avue-crud> |
||||||
|
</basic-container> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
import { |
||||||
|
getListSintTempCurve, |
||||||
|
removeSintTempCurve, |
||||||
|
addSintTempCurve, |
||||||
|
updateSintTempCurve, |
||||||
|
} from '@/api/productionSchedulingPlan/basic'; |
||||||
|
export default { |
||||||
|
components: {}, |
||||||
|
data() { |
||||||
|
return { |
||||||
|
form: {}, |
||||||
|
selectionList: [], |
||||||
|
query: {}, |
||||||
|
loading: false, |
||||||
|
page: { |
||||||
|
pageSize: 10, |
||||||
|
currentPage: 1, |
||||||
|
total: 0, |
||||||
|
}, |
||||||
|
option: { |
||||||
|
columnSort: true, |
||||||
|
tip: false, |
||||||
|
height: 'auto', |
||||||
|
calcHeight: 32, |
||||||
|
simplePage: false, |
||||||
|
searchShow: true, |
||||||
|
searchMenuSpan: 6, |
||||||
|
searchIcon: true, |
||||||
|
searchIndex: 3, |
||||||
|
tree: false, |
||||||
|
border: true, |
||||||
|
index: true, |
||||||
|
selection: false, |
||||||
|
addBtn: true, |
||||||
|
editBtn: true, |
||||||
|
viewBtn: false, |
||||||
|
delBtn: true, |
||||||
|
editBtnText: '修改', |
||||||
|
labelWidth: 120, |
||||||
|
menuWidth: 120, |
||||||
|
dialogWidth: 900, |
||||||
|
dialogClickModal: false, |
||||||
|
searchEnter: true, |
||||||
|
excelBtn: false, |
||||||
|
filterBtn: true, |
||||||
|
searchShowBtn: false, |
||||||
|
excelBtn: true, |
||||||
|
showOverflowTooltip: true, |
||||||
|
addBtnIcon: ' ', |
||||||
|
viewBtnIcon: ' ', |
||||||
|
delBtnIcon: ' ', |
||||||
|
editBtnIcon: ' ', |
||||||
|
gridBtn: false, |
||||||
|
searchLabelPosition: 'left', |
||||||
|
searchGutter: 24, |
||||||
|
searchSpan: 6, |
||||||
|
menuAlign: 'left', |
||||||
|
gridBtn: false, |
||||||
|
searchMenuPosition: 'right', |
||||||
|
align: 'center', |
||||||
|
column: [ |
||||||
|
{ |
||||||
|
label: '工序', |
||||||
|
prop: 'processId', |
||||||
|
search: true, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
type: 'select', |
||||||
|
filterable: true, |
||||||
|
dicUrl: '/blade-scheduling/processSet/findList', |
||||||
|
props: { |
||||||
|
label: 'name', |
||||||
|
value: 'id', |
||||||
|
}, |
||||||
|
change: (val, row) => { |
||||||
|
this.onChangeData(val.item, 'processId'); |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '工序', |
||||||
|
prop: 'processName', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
hide: true, |
||||||
|
display: false, |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '设备名称', |
||||||
|
prop: 'equipName', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
}, |
||||||
|
|
||||||
|
{ |
||||||
|
label: '设备分类', |
||||||
|
prop: 'equipType', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
type: 'select', |
||||||
|
dicData: [ |
||||||
|
{ |
||||||
|
label: '产线设备', |
||||||
|
value: '0', |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '普通设备', |
||||||
|
value: '1', |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '玻璃粉牌号', |
||||||
|
prop: 'glassCode', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
}, |
||||||
|
|
||||||
|
{ |
||||||
|
label: '设定温度', |
||||||
|
prop: 'temperature', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
|
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '备注', |
||||||
|
prop: 'remarks', |
||||||
|
search: false, |
||||||
|
sortable: true, |
||||||
|
span: 12, |
||||||
|
|
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
|
||||||
|
data: [], |
||||||
|
}; |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
beforeOpen(done, type) { |
||||||
|
if (['edit', 'view'].includes(type)) { |
||||||
|
this.form.processId = this.form.processId+'' |
||||||
|
// this.form.craftId = this.form.craftId+'' |
||||||
|
// this.form.workCenterId = this.form.workCenterId+'' |
||||||
|
} |
||||||
|
done(); |
||||||
|
}, |
||||||
|
onChangeData(val, type) { |
||||||
|
if (val && type == 'workCenterId') { |
||||||
|
this.form.workCenterName = val.wcCode; |
||||||
|
} |
||||||
|
if (val && type == 'equipName') { |
||||||
|
this.form.equipName = val.deviceName; |
||||||
|
} |
||||||
|
if (val && type == 'craftId') { |
||||||
|
this.form.craftName = val.caName; |
||||||
|
} |
||||||
|
if (val && type == 'processId') { |
||||||
|
this.form.processName = val.name; |
||||||
|
} |
||||||
|
}, |
||||||
|
rowSave(row, done, loading) { |
||||||
|
addSintTempCurve(row).then( |
||||||
|
() => { |
||||||
|
this.onLoad(this.page); |
||||||
|
this.$message({ |
||||||
|
type: 'success', |
||||||
|
message: '操作成功!', |
||||||
|
}); |
||||||
|
done(); |
||||||
|
}, |
||||||
|
error => { |
||||||
|
window.console.log(error); |
||||||
|
loading(); |
||||||
|
} |
||||||
|
); |
||||||
|
}, |
||||||
|
rowUpdate(row, index, done, loading) { |
||||||
|
updateSintTempCurve(row).then( |
||||||
|
() => { |
||||||
|
this.onLoad(this.page); |
||||||
|
this.$message({ |
||||||
|
type: 'success', |
||||||
|
message: '操作成功!', |
||||||
|
}); |
||||||
|
done(); |
||||||
|
}, |
||||||
|
error => { |
||||||
|
window.console.log(error); |
||||||
|
loading(); |
||||||
|
} |
||||||
|
); |
||||||
|
}, |
||||||
|
rowDel(row) { |
||||||
|
this.$confirm('确定将选择数据删除?', { |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
type: 'warning', |
||||||
|
}) |
||||||
|
.then(() => { |
||||||
|
return removeSintTempCurve(row.id); |
||||||
|
}) |
||||||
|
.then(() => { |
||||||
|
this.onLoad(this.page); |
||||||
|
this.$message({ |
||||||
|
type: 'success', |
||||||
|
message: '操作成功!', |
||||||
|
}); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
searchReset() { |
||||||
|
this.query = {}; |
||||||
|
this.onLoad(this.page); |
||||||
|
}, |
||||||
|
searchChange(params, done) { |
||||||
|
this.query = params; |
||||||
|
this.page.currentPage = 1; |
||||||
|
this.onLoad(this.page, params); |
||||||
|
done(); |
||||||
|
}, |
||||||
|
selectionChange(list) { |
||||||
|
this.selectionList = list; |
||||||
|
}, |
||||||
|
selectionClear() { |
||||||
|
this.selectionList = []; |
||||||
|
this.$refs.crud.toggleSelection(); |
||||||
|
}, |
||||||
|
|
||||||
|
currentChange(currentPage) { |
||||||
|
this.page.currentPage = currentPage; |
||||||
|
}, |
||||||
|
sizeChange(pageSize) { |
||||||
|
this.page.pageSize = pageSize; |
||||||
|
}, |
||||||
|
refreshChange() { |
||||||
|
this.onLoad(this.page, this.query); |
||||||
|
}, |
||||||
|
onLoad(page, params = {}) { |
||||||
|
this.loading = true; |
||||||
|
getListSintTempCurve(page.currentPage, page.pageSize, Object.assign(params, this.query)).then( |
||||||
|
res => { |
||||||
|
this.data = res.data.data.records; |
||||||
|
this.loading = false; |
||||||
|
this.page.total = res.data.data.total; |
||||||
|
this.selectionClear(); |
||||||
|
} |
||||||
|
); |
||||||
|
}, |
||||||
|
}, |
||||||
|
mounted() {}, |
||||||
|
}; |
||||||
|
</script> |
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@ |
|||||||
|
<template> |
||||||
|
<basic-container> |
||||||
|
<dashboardIndex></dashboardIndex> |
||||||
|
</basic-container> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
import dashboardIndex from "./container.vue"; |
||||||
|
export default { |
||||||
|
components: { dashboardIndex }, |
||||||
|
data() { |
||||||
|
return {}; |
||||||
|
}, |
||||||
|
methods: {} |
||||||
|
}; |
||||||
|
</script> |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,346 @@ |
|||||||
|
<template> |
||||||
|
<el-dialog title="新增" append-to-body :modelValue="openShow" width="70%" @close="closeDialog"> |
||||||
|
<div style="margin-bottom: 12px"> |
||||||
|
<el-button type="primary" @click="addTable">插入一行</el-button> |
||||||
|
<el-button type="danger" @click="delTable">删除选中行</el-button> |
||||||
|
</div> |
||||||
|
|
||||||
|
<!-- 单个 Form 包裹整个表格 --> |
||||||
|
<el-form |
||||||
|
ref="tableForm" |
||||||
|
:model="form" |
||||||
|
:rules="formRules" |
||||||
|
label-width="0px" |
||||||
|
> |
||||||
|
<!-- 全局错误提示 --> |
||||||
|
<div v-if="formError" class="error-message" style="color: #f56c6c; margin-bottom: 10px;"> |
||||||
|
{{ formError }} |
||||||
|
</div> |
||||||
|
|
||||||
|
<el-table :data="form.tableData" @select="selectChange" border> |
||||||
|
<el-table-column type="selection" width="55"></el-table-column> |
||||||
|
|
||||||
|
<!-- 作业中心(绑定数组字段) --> |
||||||
|
<el-table-column align="center" label="模板名称"> |
||||||
|
<template #header> |
||||||
|
<span><i style="color: red">*</i>模板名称</span> |
||||||
|
</template> |
||||||
|
<template #default="scope"> |
||||||
|
<!-- prop 格式:数组名[索引].字段名 --> |
||||||
|
<!-- 模板名称 --> |
||||||
|
<el-form-item :prop="`tableData[${scope.$index}].name`" :rules="formRules.name"> |
||||||
|
<el-input v-model="scope.row.name" ></el-input> |
||||||
|
<!-- <el-select |
||||||
|
v-model="scope.row.name" |
||||||
|
placeholder="请选择" |
||||||
|
style="width: 100%" |
||||||
|
> |
||||||
|
<el-option |
||||||
|
v-for="item in wcData" |
||||||
|
:key="item.id" |
||||||
|
:value="item.id" |
||||||
|
:label="item.wcName" |
||||||
|
></el-option> |
||||||
|
</el-select> --> |
||||||
|
</el-form-item> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
|
||||||
|
<!-- 作业中心 --> |
||||||
|
<el-table-column align="center" label="作业中心"> |
||||||
|
<template #header> |
||||||
|
<span><i style="color: red">*</i>作业中心</span> |
||||||
|
</template> |
||||||
|
<template #default="scope"> |
||||||
|
<el-form-item :prop="`tableData[${scope.$index}].wcId`" :rules="formRules.wcId"> |
||||||
|
<el-select |
||||||
|
v-model="scope.row.wcId" |
||||||
|
placeholder="请选择" |
||||||
|
style="width: 100%" |
||||||
|
> |
||||||
|
<el-option v-for="item in workList" :key="item.id" :label="item.wcName" :value="item.id"></el-option> |
||||||
|
</el-select> |
||||||
|
</el-form-item> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
|
||||||
|
<!-- 工序 --> |
||||||
|
<el-table-column align="center" label="工序"> |
||||||
|
<template #header> |
||||||
|
<span><i style="color: red">*</i>工序</span> |
||||||
|
</template> |
||||||
|
<template #default="scope"> |
||||||
|
<el-form-item :prop="`tableData[${scope.$index}].ppsId`" :rules="formRules.ppsId"> |
||||||
|
<el-select |
||||||
|
v-model="scope.row.ppsId" |
||||||
|
remote |
||||||
|
:remote-method="remoteMethod" |
||||||
|
:loading="loading" |
||||||
|
reserve-keyword |
||||||
|
clearable |
||||||
|
filterable |
||||||
|
placeholder="请输入并搜索工序" |
||||||
|
style="width: 100%" |
||||||
|
> |
||||||
|
<el-option |
||||||
|
v-for="item in processList" |
||||||
|
:key="item.id" |
||||||
|
:label="item.processName" |
||||||
|
:value="item.id" |
||||||
|
></el-option> |
||||||
|
</el-select> |
||||||
|
</el-form-item> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<!-- 线上/下 --> |
||||||
|
<el-table-column align="center" label="线上/下"> |
||||||
|
<template #default="scope"> |
||||||
|
<el-form-item :prop="`tableData[${scope.$index}].line`" :rules="formRules.line"> |
||||||
|
<div style="width:100%;display: flex;justify-content: center;"> |
||||||
|
<el-switch |
||||||
|
v-model="scope.row.line" |
||||||
|
size="large" |
||||||
|
active-text="线上" |
||||||
|
inactive-text="线下" |
||||||
|
/> |
||||||
|
</div> |
||||||
|
</el-form-item> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
</el-table> |
||||||
|
</el-form> |
||||||
|
|
||||||
|
<template #footer> |
||||||
|
<span class="dialog-footer"> |
||||||
|
<el-button @click="closeDialog">取 消</el-button> |
||||||
|
<el-button type="primary" @click="submitForm">确 定</el-button> |
||||||
|
</span> |
||||||
|
</template> |
||||||
|
</el-dialog> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
// import { getWorkCenterList } from '@/api/processManagement/addQuantity.js'; |
||||||
|
// // import { submitBatchData } from '@/api/processManagement/periodical.js'; // 实际提交接口 |
||||||
|
import {getWorkList,getProcessList,addRecords} from '@/api/qualityManagement/inspectionArchiving/rbFilePreserve' |
||||||
|
|
||||||
|
export default { |
||||||
|
props: { |
||||||
|
showDialog: { type: Boolean, default: false }, |
||||||
|
moldAddMore: { type: Boolean, default: false }, |
||||||
|
tabPosition: { type: String, default: '' }, |
||||||
|
}, |
||||||
|
data() { |
||||||
|
return { |
||||||
|
openShow: false, |
||||||
|
wcData: [], |
||||||
|
workList:[], |
||||||
|
processList: [], // 用于远程搜索的工序列表 |
||||||
|
loading: false, // 搜索加载状态 |
||||||
|
formError: '', // 全局错误提示 |
||||||
|
|
||||||
|
// 单个表单模型:包含表格所有行数据 |
||||||
|
form: { |
||||||
|
tableData: [] // 表格数据数组(直接绑定到 Form 模型) |
||||||
|
}, |
||||||
|
|
||||||
|
// 统一校验规则:支持数组项校验 |
||||||
|
formRules: { |
||||||
|
// 表格数据数组的整体校验(可选:如最少1行数据) |
||||||
|
tableData: [ |
||||||
|
{ |
||||||
|
required: true, |
||||||
|
message: '请至少添加一行数据', |
||||||
|
trigger: 'submit', |
||||||
|
type: 'array' // 明确类型为数组 |
||||||
|
}, |
||||||
|
{ |
||||||
|
validator: (rule, value, callback) => { |
||||||
|
if (value.length === 0) { |
||||||
|
callback(new Error('请至少添加一行数据')); |
||||||
|
} else { |
||||||
|
callback(); |
||||||
|
} |
||||||
|
}, |
||||||
|
trigger: 'submit' |
||||||
|
} |
||||||
|
], |
||||||
|
|
||||||
|
// 数组中每一项的 name 字段校验 |
||||||
|
name: [ |
||||||
|
{ required: true, message: '请输入模板名称', trigger: ['change', 'submit'] } |
||||||
|
], |
||||||
|
|
||||||
|
// 数组中每一项的 wcId 字段校验 |
||||||
|
wcId: [ |
||||||
|
{ |
||||||
|
required: true, |
||||||
|
message: '请选择作业中心', |
||||||
|
trigger: ['change', 'submit'] |
||||||
|
} |
||||||
|
], |
||||||
|
|
||||||
|
// 数组中每一项的 ppsId 字段校验 |
||||||
|
ppsId: [ |
||||||
|
{ required: true, message: '请选择工序', trigger: ['blur', 'submit'] }, |
||||||
|
] |
||||||
|
} |
||||||
|
}; |
||||||
|
}, |
||||||
|
mounted() { |
||||||
|
this.openShow = this.showDialog; |
||||||
|
this.getWorkCenterList(); |
||||||
|
// 初始添加一行(可选) |
||||||
|
if (this.moldAddMore && this.form.tableData.length === 0) { |
||||||
|
this.addTable(); |
||||||
|
} |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
getWorkCenterList() { |
||||||
|
getWorkList().then(res => { |
||||||
|
this.workList = res.data.data || []; |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
selectChange(list, row) { |
||||||
|
row._select = !row._select; |
||||||
|
}, |
||||||
|
|
||||||
|
// 新增一行(直接push到表单模型的 tableData 中) |
||||||
|
addTable() { |
||||||
|
this.form.tableData.push({ |
||||||
|
_select: false, // 选择状态 |
||||||
|
name: '', // 作业中心ID |
||||||
|
wcId: '', // 槽号/检查项 |
||||||
|
ppsId: '' // 维护内容 |
||||||
|
}); |
||||||
|
}, |
||||||
|
remoteMethod(query){ |
||||||
|
console.log('query---------------',query) |
||||||
|
if (!query.trim()) { |
||||||
|
this.processList = []; |
||||||
|
return; |
||||||
|
} |
||||||
|
if (query) { |
||||||
|
this.loading = true |
||||||
|
getProcessList({ |
||||||
|
processName:query |
||||||
|
}).then(res =>{ |
||||||
|
this.processList = res.data.data.records; |
||||||
|
this.loading = false |
||||||
|
}) |
||||||
|
} else { |
||||||
|
this.processList = []; |
||||||
|
} |
||||||
|
}, |
||||||
|
// 删除选中行 |
||||||
|
delTable() { |
||||||
|
this.form.tableData = this.form.tableData.filter(row => !row._select); |
||||||
|
}, |
||||||
|
|
||||||
|
closeDialog() { |
||||||
|
this.openShow = false; |
||||||
|
this.$emit('closeDialog'); |
||||||
|
// 重置表单 |
||||||
|
this.form.tableData = []; |
||||||
|
this.formError = ''; |
||||||
|
this.$refs.tableForm?.resetFields(); |
||||||
|
}, |
||||||
|
|
||||||
|
// 提交表单(单次校验所有行) |
||||||
|
submitForm() { |
||||||
|
this.formError = ''; |
||||||
|
|
||||||
|
// 调用单个 Form 的校验方法 |
||||||
|
this.$refs.tableForm.validate((isValid, invalidFields) => { |
||||||
|
if (!isValid) { |
||||||
|
// 校验失败:显示提示并滚动到第一个错误字段 |
||||||
|
this.formError = '存在未完善的字段,请检查表格中的红色提示'; |
||||||
|
|
||||||
|
this.$nextTick(() => { |
||||||
|
// 找到第一个错误字段并滚动到视图 |
||||||
|
const firstError = document.querySelector('.el-form-item.is-error'); |
||||||
|
if (firstError) { |
||||||
|
firstError.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
||||||
|
} |
||||||
|
}); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 校验通过:准备提交数据(过滤无用字段) |
||||||
|
const submitData = this.form.tableData.map(row => { |
||||||
|
const { _select, ...validData } = row; // 剔除选择状态字段 |
||||||
|
return validData; |
||||||
|
}); |
||||||
|
|
||||||
|
// 调用接口提交(实际项目替换) |
||||||
|
try { |
||||||
|
// const res = await submitBatchData(submitData); |
||||||
|
// if (res.code === 200) { |
||||||
|
// this.$message.success('提交成功'); |
||||||
|
// this.closeDialog(); |
||||||
|
// this.$emit('submitSuccess', submitData); |
||||||
|
// } else { |
||||||
|
// this.$message.error(res.msg || '提交失败'); |
||||||
|
// } |
||||||
|
|
||||||
|
// // 演示用 |
||||||
|
// this.$message.success('提交成功'); |
||||||
|
// this.closeDialog(); |
||||||
|
// this.$emit('submitSuccess', submitData); |
||||||
|
submitData.map(item => { |
||||||
|
item.line = item.line ? 1 : 0 |
||||||
|
}) |
||||||
|
console.log('submitData',submitData) |
||||||
|
addRecords(submitData).then(res => { |
||||||
|
if(res.data.code === 200){ |
||||||
|
this.$message.success('新增成功'); |
||||||
|
this.closeDialog(); |
||||||
|
} |
||||||
|
}) |
||||||
|
} catch (err) { |
||||||
|
this.$message.error('网络错误,请稍后重试'); |
||||||
|
console.error('提交失败:', err); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
}, |
||||||
|
}; |
||||||
|
</script> |
||||||
|
|
||||||
|
<style lang="scss" scoped> |
||||||
|
// 优化表单字段样式 |
||||||
|
:deep(.el-table .el-form-item) { |
||||||
|
margin-bottom: 0; // 去掉默认边距 |
||||||
|
} |
||||||
|
|
||||||
|
// 错误提示样式优化 |
||||||
|
:deep(.el-form-item__error) { |
||||||
|
font-size: 12px; |
||||||
|
white-space: nowrap; |
||||||
|
z-index: 10; |
||||||
|
background: #fff; |
||||||
|
padding: 2px 4px; |
||||||
|
border: 1px solid #f56c6c; |
||||||
|
border-radius: 4px; |
||||||
|
} |
||||||
|
|
||||||
|
// 表格行高适配 textarea |
||||||
|
.el-table__row { |
||||||
|
height: 80px !important; |
||||||
|
} |
||||||
|
|
||||||
|
.el-table__cell { |
||||||
|
vertical-align: middle !important; |
||||||
|
} |
||||||
|
|
||||||
|
.error-message { |
||||||
|
font-size: 14px; |
||||||
|
line-height: 1.5; |
||||||
|
} |
||||||
|
:deep(.el-table .el-table__cell) { |
||||||
|
height: 50px !important; |
||||||
|
padding: 0 !important; |
||||||
|
line-height: 50px !important; |
||||||
|
} |
||||||
|
</style> |
||||||
@ -0,0 +1,196 @@ |
|||||||
|
<template> |
||||||
|
<div class="form-table-demo"> |
||||||
|
<el-form |
||||||
|
ref="formRef" |
||||||
|
:model="form" |
||||||
|
:rules="formRules" |
||||||
|
label-width="100px" |
||||||
|
> |
||||||
|
<!-- 其他表单字段(可选) --> |
||||||
|
<el-form-item label="表单名称" prop="name"> |
||||||
|
<el-input v-model="form.name"></el-input> |
||||||
|
</el-form-item> |
||||||
|
|
||||||
|
<!-- 表格嵌套:绑定到form的tableData数组 --> |
||||||
|
<el-form-item label="日期列表" prop="tableData"> |
||||||
|
<el-table |
||||||
|
:data="form.tableData" |
||||||
|
border |
||||||
|
style="width: 100%; margin-top: 10px" |
||||||
|
@row-click="handleRowClick" |
||||||
|
> |
||||||
|
<el-table-column label="序号" type="index" width="60"></el-table-column> |
||||||
|
<el-table-column label="日期" prop="date"> |
||||||
|
<template #default="scope"> |
||||||
|
<!-- 表格行内的日期选择器,绑定到行数据的date字段 --> |
||||||
|
<el-date-picker |
||||||
|
v-model="scope.row.date" |
||||||
|
type="date" |
||||||
|
placeholder="选择日期" |
||||||
|
style="width: 100%" |
||||||
|
@change="() => validateSingleRow(scope.row)" |
||||||
|
></el-date-picker> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
<el-table-column label="操作" width="100"> |
||||||
|
<template #default="scope"> |
||||||
|
<el-button |
||||||
|
type="text" |
||||||
|
icon="el-icon-delete" |
||||||
|
@click="handleDeleteRow(scope.$index)" |
||||||
|
> |
||||||
|
删除 |
||||||
|
</el-button> |
||||||
|
</template> |
||||||
|
</el-table-column> |
||||||
|
</el-table> |
||||||
|
|
||||||
|
<!-- 添加行按钮 --> |
||||||
|
<el-button |
||||||
|
type="primary" |
||||||
|
icon="el-icon-plus" |
||||||
|
size="mini" |
||||||
|
style="margin-top: 10px" |
||||||
|
@click="handleAddRow" |
||||||
|
> |
||||||
|
添加行 |
||||||
|
</el-button> |
||||||
|
</el-form-item> |
||||||
|
|
||||||
|
<!-- 提交按钮 --> |
||||||
|
<el-form-item> |
||||||
|
<el-button type="primary" @click="handleSubmit">提交</el-button> |
||||||
|
<el-button @click="handleReset">重置</el-button> |
||||||
|
</el-form-item> |
||||||
|
</el-form> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
export default { |
||||||
|
name: "FormTableDateCheck", |
||||||
|
data() { |
||||||
|
// 自定义校验:表格行内日期必填 |
||||||
|
const validateDateRequired = (rule, value, callback) => { |
||||||
|
// 遍历表格数据,检查每一行的date是否为空 |
||||||
|
const hasEmpty = value.some((row) => !row.date); |
||||||
|
if (hasEmpty) { |
||||||
|
callback(new Error("请填写所有行的日期")); |
||||||
|
} else { |
||||||
|
// 先清空重复日期的错误提示(避免残留) |
||||||
|
this.$refs.formRef.clearValidate("tableData"); |
||||||
|
callback(); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
// 自定义校验:表格日期是否重复(核心:只提示一次) |
||||||
|
const validateDateDuplicate = (rule, value, callback) => { |
||||||
|
if (value.length === 0) { |
||||||
|
callback(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 提取所有非空日期,转换为字符串(统一格式) |
||||||
|
const dateList = value |
||||||
|
.map((row) => (row.date ? this.formatDate(row.date) : "")) |
||||||
|
.filter((date) => date); |
||||||
|
|
||||||
|
// 判断是否有重复 |
||||||
|
const isDuplicate = dateList.length !== new Set(dateList).size; |
||||||
|
if (isDuplicate) { |
||||||
|
callback(new Error("表格中存在重复的日期,请修改")); |
||||||
|
} else { |
||||||
|
callback(); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
return { |
||||||
|
// 表单数据 |
||||||
|
form: { |
||||||
|
name: "", // 其他表单字段 |
||||||
|
tableData: [ |
||||||
|
// 初始表格行数据 |
||||||
|
{ date: "" }, |
||||||
|
], |
||||||
|
}, |
||||||
|
|
||||||
|
// 表单校验规则 |
||||||
|
formRules: { |
||||||
|
name: [ |
||||||
|
{ required: true, message: "请输入表单名称", trigger: "blur" }, |
||||||
|
], |
||||||
|
tableData: [ |
||||||
|
{ required: true, validator: validateDateRequired, trigger: "change" }, |
||||||
|
{ validator: validateDateDuplicate, trigger: "change" }, |
||||||
|
], |
||||||
|
}, |
||||||
|
}; |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
// 格式化日期为字符串(解决Date对象比较的问题) |
||||||
|
formatDate(date) { |
||||||
|
if (typeof date === "string") return date; |
||||||
|
const year = date.getFullYear(); |
||||||
|
const month = String(date.getMonth() + 1).padStart(2, "0"); |
||||||
|
const day = String(date.getDate()).padStart(2, "0"); |
||||||
|
return `${year}-${month}-${day}`; |
||||||
|
}, |
||||||
|
|
||||||
|
// 校验单行数据(可选:实时校验) |
||||||
|
validateSingleRow(row) { |
||||||
|
this.$refs.formRef.validateField("tableData"); |
||||||
|
}, |
||||||
|
|
||||||
|
// 添加表格行 |
||||||
|
handleAddRow() { |
||||||
|
this.form.tableData.push({ date: "" }); |
||||||
|
// 新增行后触发校验(避免空行影响) |
||||||
|
this.$nextTick(() => { |
||||||
|
this.$refs.formRef.validateField("tableData"); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
// 删除表格行 |
||||||
|
handleDeleteRow(index) { |
||||||
|
this.form.tableData.splice(index, 1); |
||||||
|
// 删除行后触发校验 |
||||||
|
this.$nextTick(() => { |
||||||
|
this.$refs.formRef.validateField("tableData"); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
// 表单提交 |
||||||
|
handleSubmit() { |
||||||
|
this.$refs.formRef.validate((valid) => { |
||||||
|
if (valid) { |
||||||
|
// 校验通过,执行提交逻辑 |
||||||
|
alert("表单校验通过,可提交数据"); |
||||||
|
console.log("表单数据:", this.form); |
||||||
|
} else { |
||||||
|
// 校验失败,ElementUI会自动显示错误提示 |
||||||
|
console.log("表单校验失败"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
// 表单重置 |
||||||
|
handleReset() { |
||||||
|
this.$refs.formRef.resetFields(); |
||||||
|
// 重置表格数据为初始状态 |
||||||
|
this.form.tableData = [{ date: "" }]; |
||||||
|
}, |
||||||
|
|
||||||
|
// 表格行点击(可选:自定义逻辑) |
||||||
|
handleRowClick(row) { |
||||||
|
console.log("点击行数据:", row); |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
|
</script> |
||||||
|
|
||||||
|
<style scoped> |
||||||
|
.form-table-demo { |
||||||
|
padding: 20px; |
||||||
|
} |
||||||
|
</style> |
||||||
Loading…
Reference in new issue