✨ 优化主数据地图回填与表单校验间距,并修复运单导入筛选与组织树定位

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-10 16:20:26 +08:00
parent ea797356ce
commit f455003014
38 changed files with 1036 additions and 182 deletions
+144 -2
View File
@@ -1091,6 +1091,136 @@ export default {
column.addDisabled = true;
this.$refs.crud.rowAdd();
},
getDeptTableRef() {
return this.$refs.crud?.$refs?.table;
},
getDeptTableScrollWrap() {
const table = this.getDeptTableRef();
const root = table?.$el || this.$refs.crud?.$el;
if (!root || typeof root.querySelector !== 'function') {
return null;
}
return (
root.querySelector('.el-table__body-wrapper .el-scrollbar__wrap') ||
root.querySelector('.el-scrollbar__wrap') ||
root.querySelector('.el-table__body-wrapper')
);
},
getDeptTableScrollTop() {
const wrap = this.getDeptTableScrollWrap();
return wrap ? wrap.scrollTop : 0;
},
restoreDeptTableScroll(scrollTop) {
const wrap = this.getDeptTableScrollWrap();
if (!wrap) {
return;
}
wrap.scrollTop = scrollTop;
},
findDeptRowById(list, id) {
if (!Array.isArray(list) || id === undefined || id === null || id === '') {
return null;
}
for (let index = 0; index < list.length; index += 1) {
const item = list[index];
if (String(item.id) === String(id)) {
return item;
}
const child = this.findDeptRowById(item.children, id);
if (child) {
return child;
}
}
return null;
},
syncLazyTreeAfterAdd(row, parentId) {
const table = this.getDeptTableRef();
if (!table || !parentId || String(parentId) === '0') {
return;
}
const parentRow = this.findDeptRowById(this.data, parentId);
if (parentRow) {
parentRow.hasChildren = true;
if (!Array.isArray(parentRow.children)) {
parentRow.children = [];
}
if (!parentRow.children.some(item => String(item.id) === String(row.id))) {
parentRow.children.push(row);
}
}
const lazyMapRef = table.store?.states?.lazyTreeNodeMap;
const treeDataRef = table.store?.states?.treeData;
const lazyMap = lazyMapRef?.value ?? lazyMapRef;
const treeData = treeDataRef?.value ?? treeDataRef;
const mapKey =
(lazyMap && Object.prototype.hasOwnProperty.call(lazyMap, parentId) && parentId) ||
(lazyMap && Object.prototype.hasOwnProperty.call(lazyMap, String(parentId)) && String(parentId)) ||
(parentRow && parentRow.id);
if (mapKey !== undefined && mapKey !== null && lazyMap) {
const currentChildren = Array.isArray(lazyMap[mapKey])
? lazyMap[mapKey]
: parentRow?.children || [];
const nextChildren = currentChildren.some(item => String(item.id) === String(row.id))
? [...currentChildren]
: [...currentChildren, row];
if (
Object.prototype.hasOwnProperty.call(lazyMap, mapKey) &&
typeof table.updateKeyChildren === 'function'
) {
table.updateKeyChildren(mapKey, nextChildren);
} else if (lazyMapRef && Object.prototype.hasOwnProperty.call(lazyMapRef, 'value')) {
// 首次挂子节点:直接写入懒加载缓存,避免再次 treeLoad 导致滚动回顶
lazyMapRef.value = {
...lazyMapRef.value,
[mapKey]: nextChildren,
};
} else {
lazyMap[mapKey] = nextChildren;
}
}
if (treeData && parentRow) {
const treeKey = Object.prototype.hasOwnProperty.call(treeData, parentRow.id)
? parentRow.id
: Object.prototype.hasOwnProperty.call(treeData, String(parentRow.id))
? String(parentRow.id)
: parentRow.id;
const nextNode = {
...(treeData[treeKey] || {}),
lazy: true,
loaded: true,
loading: false,
expanded: true,
hasChildren: true,
};
if (treeDataRef && Object.prototype.hasOwnProperty.call(treeDataRef, 'value')) {
treeDataRef.value = {
...treeDataRef.value,
[treeKey]: nextNode,
};
} else {
treeData[treeKey] = nextNode;
}
}
if (parentRow && typeof table.toggleRowExpansion === 'function') {
table.toggleRowExpansion(parentRow, true);
}
},
scrollDeptRowIntoView(rowId) {
if (rowId === undefined || rowId === null || rowId === '') {
return;
}
const table = this.getDeptTableRef();
const root = table?.$el || this.$refs.crud?.$el;
if (!root || typeof root.querySelector !== 'function') {
return;
}
const rowEl =
root.querySelector(`tr[data-row-key="${rowId}"]`) ||
root.querySelector(`tr[data-row-key='${rowId}']`);
if (rowEl && typeof rowEl.scrollIntoView === 'function') {
rowEl.scrollIntoView({ block: 'nearest', behavior: 'auto' });
}
},
rowSave(row, done, loading) {
row.tenantId = row.tenantId || this.userInfo.tenantId || website.tenantId;
row.deptCode = String(row.deptCode || '').trim();
@@ -1107,6 +1237,7 @@ export default {
loading();
return;
}
const scrollTop = this.getDeptTableScrollTop();
add(row).then(
res => {
// 获取新增数据的相关字段
@@ -1114,12 +1245,22 @@ export default {
row.id = data.id;
row.deptCategoryName = data.deptCategoryName;
row.tenantId = data.tenantId;
if (row.hasChildren === undefined || row.hasChildren === null) {
row.hasChildren = false;
}
this.$message({
type: 'success',
message: '操作成功!',
});
// 数据回调进行刷新
// 数据回调进行刷新(局部插入,避免整树重载跳回顶部)
done(row);
this.$nextTick(() => {
this.syncLazyTreeAfterAdd(row, this.normalizeParentId(row.parentId));
this.restoreDeptTableScroll(scrollTop);
this.$nextTick(() => {
this.scrollDeptRowIntoView(row.id);
});
});
},
error => {
window.console.log(error);
@@ -1265,7 +1406,8 @@ export default {
done();
},
beforeClose(done) {
this.parentId = '';
// 保持为根级查询条件,避免关闭弹窗后若触发重载时 parentId 为空导致整树重置
this.parentId = 0;
this.parentDeptCode = '';
this.parentDept = null;
const column = this.findColumn(this.option.column, 'parentId');
+1 -1
View File
@@ -1471,7 +1471,7 @@ export default {
}
.user-edit-dialog .el-form-item {
margin-bottom: 14px;
margin-bottom: 24px;
}
.user-edit-dialog .el-form-item__label {