|
@@ -72,7 +72,7 @@ export default {
|
|
// 注意 _开头的变量会被VUE忽略掉?! 比如this._modelSnapshot -> undefined
|
|
// 注意 _开头的变量会被VUE忽略掉?! 比如this._modelSnapshot -> undefined
|
|
// TODO: _dependencyTree 其实不需要每次都全量组建,有优化空间
|
|
// TODO: _dependencyTree 其实不需要每次都全量组建,有优化空间
|
|
_modelSnapshot: null, // {} model传入时的快照,用于重置功能
|
|
_modelSnapshot: null, // {} model传入时的快照,用于重置功能
|
|
- _modelKeys: null, //[] 读取model属性名,对应imports中的condition-key,仅保留参与条件运算的key,允许model挂载一些其它属性
|
|
|
|
|
|
+ _modelKeys: null, // [] 读取model属性名,对应imports中的condition-key,仅保留参与条件运算的key,允许model挂载一些其它属性
|
|
_dependencyTree: null, // {key1:[childKeys],key2:[childKeys]} // 因为条件影响向下传递,只需要两级,递归算法会读取所有依赖
|
|
_dependencyTree: null, // {key1:[childKeys],key2:[childKeys]} // 因为条件影响向下传递,只需要两级,递归算法会读取所有依赖
|
|
_restoreProcessing: false // 正处于还原过程
|
|
_restoreProcessing: false // 正处于还原过程
|
|
}
|
|
}
|
|
@@ -191,11 +191,11 @@ export default {
|
|
return this._modelKeys?.some(k => this.model[k])
|
|
return this._modelKeys?.some(k => this.model[k])
|
|
},
|
|
},
|
|
getConditionLabel(key, code) {
|
|
getConditionLabel(key, code) {
|
|
- let condition = this.conditionsOutput.find(c => c.key == key)
|
|
|
|
|
|
+ const condition = this.conditionsOutput.find(c => c.key == key)
|
|
return condition?.list.find(i => i.code == code)?.label
|
|
return condition?.list.find(i => i.code == code)?.label
|
|
},
|
|
},
|
|
isRequired(key) {
|
|
isRequired(key) {
|
|
- return this.finalRules.hasOwnProperty(key)
|
|
|
|
|
|
+ return Object.hasOwnProperty.call(this.finalRules, key)
|
|
},
|
|
},
|
|
// 公共API 重写部分 供独立模式挂载主体重写
|
|
// 公共API 重写部分 供独立模式挂载主体重写
|
|
singleChangedAction(model, key) {
|
|
singleChangedAction(model, key) {
|
|
@@ -236,11 +236,11 @@ export default {
|
|
this._rebuildAllConditions().then(() => this._triggerEventIfNeed())
|
|
this._rebuildAllConditions().then(() => this._triggerEventIfNeed())
|
|
},
|
|
},
|
|
_readEffectiveModelKeys(model) {
|
|
_readEffectiveModelKeys(model) {
|
|
- let allKeys = Object.keys(model)
|
|
|
|
|
|
+ const allKeys = Object.keys(model)
|
|
if (!allKeys.length) return allKeys
|
|
if (!allKeys.length) return allKeys
|
|
if (!this.ignoreUnmatched) return allKeys
|
|
if (!this.ignoreUnmatched) return allKeys
|
|
|
|
|
|
- let unmatched = []
|
|
|
|
|
|
+ const unmatched = []
|
|
allKeys.forEach(key => {
|
|
allKeys.forEach(key => {
|
|
if (!this.imports.some(i => i.key == key)) {
|
|
if (!this.imports.some(i => i.key == key)) {
|
|
unmatched.push(key)
|
|
unmatched.push(key)
|
|
@@ -288,7 +288,7 @@ export default {
|
|
console.log(`发现依赖缺省,请检查model.${key}是否存在:`, key, dependencyCheckLink, fromKey)
|
|
console.log(`发现依赖缺省,请检查model.${key}是否存在:`, key, dependencyCheckLink, fromKey)
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
- let selfChildren = this._dependencyTree[key] || []
|
|
|
|
|
|
+ const selfChildren = this._dependencyTree[key] || []
|
|
if (fromKey && !selfChildren.includes(fromKey)) selfChildren.push(fromKey)
|
|
if (fromKey && !selfChildren.includes(fromKey)) selfChildren.push(fromKey)
|
|
this._dependencyTree[key] = selfChildren
|
|
this._dependencyTree[key] = selfChildren
|
|
const matchCondition = this.imports.find(c => c.key == key)
|
|
const matchCondition = this.imports.find(c => c.key == key)
|
|
@@ -341,7 +341,7 @@ export default {
|
|
// 处理显示对象
|
|
// 处理显示对象
|
|
/* TODO: 现在还不确定一个条件同时依赖多个条件的情况是否能正常工作,
|
|
/* TODO: 现在还不确定一个条件同时依赖多个条件的情况是否能正常工作,
|
|
理论上一个依赖多个可以强制转换成单依赖,因为交互时用户也无法同时点两个条件 */
|
|
理论上一个依赖多个可以强制转换成单依赖,因为交互时用户也无法同时点两个条件 */
|
|
- let displayList = list.map(item => ({
|
|
|
|
|
|
+ const displayList = list.map(item => ({
|
|
code: condition.getCode(item),
|
|
code: condition.getCode(item),
|
|
label: condition.getLabel(item),
|
|
label: condition.getLabel(item),
|
|
_raw: item // 原数据引用提供一份
|
|
_raw: item // 原数据引用提供一份
|
|
@@ -353,7 +353,7 @@ export default {
|
|
}
|
|
}
|
|
// 校验当前值还是否有效
|
|
// 校验当前值还是否有效
|
|
const currentVal = this.model[condition.key]
|
|
const currentVal = this.model[condition.key]
|
|
- let displayValue = condition.transferToEffectiveDisplayValue(currentVal, displayList)
|
|
|
|
|
|
+ const displayValue = condition.transferToEffectiveDisplayValue(currentVal, displayList)
|
|
if (!condition.codeEquals(currentVal, displayValue)) {
|
|
if (!condition.codeEquals(currentVal, displayValue)) {
|
|
// 初始化过程和还原过程不改值
|
|
// 初始化过程和还原过程不改值
|
|
if (isConditionRequired) {
|
|
if (isConditionRequired) {
|
|
@@ -379,8 +379,8 @@ export default {
|
|
this.conditionsOutputTemporary[condition.key] = wrappedList
|
|
this.conditionsOutputTemporary[condition.key] = wrappedList
|
|
},
|
|
},
|
|
_getDependentParamAndCacheKey(condition) {
|
|
_getDependentParamAndCacheKey(condition) {
|
|
- let cacheKey = '',
|
|
|
|
- param = {}
|
|
|
|
|
|
+ let cacheKey = ''
|
|
|
|
+ let param = {}
|
|
condition.dependentKeys.forEach(key => {
|
|
condition.dependentKeys.forEach(key => {
|
|
const currentVal = this.model[key]
|
|
const currentVal = this.model[key]
|
|
cacheKey += `${key}_${currentVal}$`
|
|
cacheKey += `${key}_${currentVal}$`
|
|
@@ -486,7 +486,7 @@ export default {
|
|
const formFields = formRef.fields
|
|
const formFields = formRef.fields
|
|
const shouldDelay = localFields.length > 0 && formFields.length == 0
|
|
const shouldDelay = localFields.length > 0 && formFields.length == 0
|
|
|
|
|
|
- const invoker = function(){
|
|
|
|
|
|
+ const invoker = function() {
|
|
formRef.validate((valid, errors) => {
|
|
formRef.validate((valid, errors) => {
|
|
if (valid) resolve(valid)
|
|
if (valid) resolve(valid)
|
|
else reject(errors) // 经这一步转化,可以外抛errors
|
|
else reject(errors) // 经这一步转化,可以外抛errors
|
|
@@ -494,7 +494,7 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
// NOTE: 5.14 hht 这里因为form组件的校验要在子组件加载好之后才能生效
|
|
// NOTE: 5.14 hht 这里因为form组件的校验要在子组件加载好之后才能生效
|
|
- if (shouldDelay) this.$nextTick(()=> invoker())
|
|
|
|
|
|
+ if (shouldDelay) this.$nextTick(() => invoker())
|
|
else invoker()
|
|
else invoker()
|
|
})
|
|
})
|
|
}
|
|
}
|