Skip to content

Commit

Permalink
fix(Form): 修复组件父级隐藏状态下,会执行校验问题
Browse files Browse the repository at this point in the history
  • Loading branch information
D-xuanmo committed Oct 13, 2024
1 parent ce6a012 commit b1fedf2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/dl-common/src/form/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormModels, IDetailTableItem, IFormModelItem } from '../types'
import { FormModels, IDetailTableItem, IFormModelItem, IRenderModel } from '../types'
import { markRaw, reactive, ref, UnwrapNestedRefs } from 'vue'
import { createRandomID, deepCopy, isEmpty, isObject } from '@xuanmo/utils'
import { validator } from '../../validator'
Expand Down Expand Up @@ -263,10 +263,24 @@ class FormStore {
* 获取父级信息
* @param id
*/
public getParent<T>(id: string) {
public getParent<T extends IRenderModel>(id: string) {
return this.getModel<T>(this.getModel(this.getModelIdByDataKey(id))?.layout.parent)
}

/**
* 获取父级集合
* @param id
*/
public getParents(id: string) {
const parents: IRenderModel[] = []
let parent = this.getParent<IRenderModel>(id)
while (parent) {
parents.push(parent)
parent = this.getParent<IRenderModel>(parent.id)
}
return parents
}

/**
* 获取明细表 id
* @param id
Expand Down
7 changes: 7 additions & 0 deletions packages/dl-common/src/form/store/view-linkage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ export class ViewLinkageStore {
}

getDisplay(id: IRenderModel['id']) {
const parents = this.formStore.getParents(id)
if (parents.length) {
for (let i = 0; i < parents.length; i++) {
// 如果任意父级为隐藏,则当前组件也为隐藏
if (!this.displayMap.get(parents[i].id)) return false
}
}
return this.displayMap.get(id)
}

Expand Down

0 comments on commit b1fedf2

Please sign in to comment.