当容器被设置隐藏时,同步清除容器内所有字段的校验规则。
parent
6faeb92363
commit
45e8f43967
|
@ -1,4 +1,4 @@
|
|||
import {generateId} from "@/utils/util";
|
||||
import {generateId, traverseFieldWidgetsOfContainer} from "@/utils/util";
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
|
@ -15,6 +15,10 @@ export default {
|
|||
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.callSetHidden()
|
||||
},
|
||||
|
||||
methods: {
|
||||
unregisterFromRefList() { //销毁容器组件时注销组件ref
|
||||
if ((this.refList !== null) && !!this.widget.options.name) {
|
||||
|
@ -23,11 +27,33 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
/* 主动触发setHidden()方法,以清空被隐藏容器内字段组件的校验规则!! */
|
||||
callSetHidden() {
|
||||
if (this.widget.options.hidden === true) {
|
||||
this.setHidden(true)
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------- 以下为组件支持外部调用的API方法 begin ------------------//
|
||||
/* 提示:用户可自行扩充这些方法!!! */
|
||||
|
||||
setHidden(flag) {
|
||||
this.widget.options.hidden = flag
|
||||
|
||||
/* 容器被隐藏后,需要同步清除容器内部字段组件的校验规则 */
|
||||
let clearRulesFn = (fieldWidget) => {
|
||||
let fwName = fieldWidget.options.name
|
||||
let fwRef = this.getWidgetRef(fwName)
|
||||
if (flag && !!fwRef && !!fwRef.clearFieldRules) {
|
||||
fwRef.clearFieldRules()
|
||||
}
|
||||
|
||||
if (!flag && !!fwRef && !!fwRef.buildFieldRules) {
|
||||
fwRef.buildFieldRules()
|
||||
}
|
||||
}
|
||||
|
||||
traverseFieldWidgetsOfContainer(this.widget, clearRulesFn)
|
||||
},
|
||||
|
||||
activeTab(tabIndex) { //tabIndex从0计数
|
||||
|
|
|
@ -119,21 +119,21 @@ export const loadRemoteScript = function(srcPath, callback) { /*加载远程js
|
|||
}
|
||||
|
||||
export function traverseFieldWidgets(widgetList, handler) {
|
||||
widgetList.map(w => {
|
||||
widgetList.forEach(w => {
|
||||
if (w.formItemFlag) {
|
||||
handler(w)
|
||||
} else if (w.type === 'grid') {
|
||||
w.cols.map(col => {
|
||||
w.cols.forEach(col => {
|
||||
traverseFieldWidgets(col.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'table') {
|
||||
w.rows.map(row => {
|
||||
row.cols.map(cell => {
|
||||
w.rows.forEach(row => {
|
||||
row.cols.forEach(cell => {
|
||||
traverseFieldWidgets(cell.widgetList, handler)
|
||||
})
|
||||
})
|
||||
} else if (w.type === 'tab') {
|
||||
w.tabs.map(tab => {
|
||||
w.tabs.forEach(tab => {
|
||||
traverseFieldWidgets(tab.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'sub-form') {
|
||||
|
@ -145,23 +145,23 @@ export function traverseFieldWidgets(widgetList, handler) {
|
|||
}
|
||||
|
||||
export function traverseContainWidgets(widgetList, handler) {
|
||||
widgetList.map(w => {
|
||||
widgetList.forEach(w => {
|
||||
if (w.category === 'container') {
|
||||
handler(w)
|
||||
}
|
||||
|
||||
if (w.type === 'grid') {
|
||||
w.cols.map(col => {
|
||||
w.cols.forEach(col => {
|
||||
traverseContainWidgets(col.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'table') {
|
||||
w.rows.map(row => {
|
||||
row.cols.map(cell => {
|
||||
w.rows.forEach(row => {
|
||||
row.cols.forEach(cell => {
|
||||
traverseContainWidgets(cell.widgetList, handler)
|
||||
})
|
||||
})
|
||||
} else if (w.type === 'tab') {
|
||||
w.tabs.map(tab => {
|
||||
w.tabs.forEach(tab => {
|
||||
traverseContainWidgets(tab.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'sub-form') {
|
||||
|
@ -173,23 +173,23 @@ export function traverseContainWidgets(widgetList, handler) {
|
|||
}
|
||||
|
||||
export function traverseAllWidgets(widgetList, handler) {
|
||||
widgetList.map(w => {
|
||||
widgetList.forEach(w => {
|
||||
handler(w)
|
||||
|
||||
if (w.type === 'grid') {
|
||||
w.cols.map(col => {
|
||||
w.cols.forEach(col => {
|
||||
handler(col)
|
||||
traverseAllWidgets(col.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'table') {
|
||||
w.rows.map(row => {
|
||||
row.cols.map(cell => {
|
||||
w.rows.forEach(row => {
|
||||
row.cols.forEach(cell => {
|
||||
handler(cell)
|
||||
traverseAllWidgets(cell.widgetList, handler)
|
||||
})
|
||||
})
|
||||
} else if (w.type === 'tab') {
|
||||
w.tabs.map(tab => {
|
||||
w.tabs.forEach(tab => {
|
||||
traverseAllWidgets(tab.widgetList, handler)
|
||||
})
|
||||
} else if (w.type === 'sub-form') {
|
||||
|
@ -200,6 +200,51 @@ export function traverseAllWidgets(widgetList, handler) {
|
|||
})
|
||||
}
|
||||
|
||||
function handleWidgetForTraverse(widget, handler) {
|
||||
if (!!widget.category) {
|
||||
traverseFieldWidgetsOfContainer(widget, handler)
|
||||
} else if (widget.formItemFlag) {
|
||||
handler(widget)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历容器内的字段组件
|
||||
* @param con
|
||||
* @param handler
|
||||
*/
|
||||
export function traverseFieldWidgetsOfContainer(con, handler) {
|
||||
if (con.type === 'grid') {
|
||||
con.cols.forEach(col => {
|
||||
col.widgetList.forEach(cw => {
|
||||
handleWidgetForTraverse(cw, handler)
|
||||
})
|
||||
})
|
||||
} else if (con.type === 'table') {
|
||||
con.rows.forEach(row => {
|
||||
row.cols.forEach(cell => {
|
||||
cell.widgetList.forEach(cw => {
|
||||
handleWidgetForTraverse(cw, handler)
|
||||
})
|
||||
})
|
||||
})
|
||||
} else if (con.type === 'tab') {
|
||||
con.tabs.forEach(tab => {
|
||||
tab.widgetList.forEach(cw => {
|
||||
handleWidgetForTraverse(cw, handler)
|
||||
})
|
||||
})
|
||||
} else if (con.type === 'sub-form') {
|
||||
con.widgetList.forEach(cw => {
|
||||
handleWidgetForTraverse(cw, handler)
|
||||
})
|
||||
} else if (con.category === 'container') { //自定义容器
|
||||
con.widgetList.forEach(cw => {
|
||||
handleWidgetForTraverse(cw, handler)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function copyToClipboard(content, clickEvent, $message, successMsg, errorMsg) {
|
||||
const clipboard = new Clipboard(clickEvent.target, {
|
||||
text: () => content
|
||||
|
|
Loading…
Reference in New Issue