1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* 1.整合表单Rules处理
* 2.整合常用跳转函数
*/
import Utils from "~/utils";
export default {
methods: {
/**
* 表单校验 rules 的赋值
* @returns void
*/
generateFormRules(skipDefault) {
let keySet = new Set(Object.keys(this.checkRules).concat(Object.keys(this.defaultRules)))
console.log('keySet', keySet)
const res = {};
for (let key of keySet.keys()) {
res[key] = this.checkRules[key] || this.defaultRules[key];
}
this.rules = res;
console.log("rules", this.rules);
},
/**
* 触发方式
* @param {String} prop item属性
* @returns
*/
getTriggerType(prop) {
const modelForm = this.root ? this.root.$refs.modelForm : this.$refs.modelForm
const fields = modelForm.fields;
for (let i = 0; i < fields.length; i++) {
const field = fields[i];
if (field.prop === prop) {
// select、checkbox使用change触发
const ele = field.$children[1] ? field.$children[1].$children[0] : field.$children[0].$children[0]
if (ele.$el.className.startsWith("el-select") || ele.$el.className.startsWith("el-checkbox")) {
return "change";
}
return "blur";
}
}
return "blur";
},
/**
* 表单有些 tab 是通过 v-if 控制的,这些表单项初始时的 trigger 均为 blur,需要手动更新
*/
updateRulesTrigger() {
const rules = this.root.rules
for (const key in rules) {
if (Object.hasOwnProperty.call(rules, key)) {
const rule = rules[key];
const triggerType = this.getTriggerType(key)
for (let i = 0; i < rule.length; i++) {
const r = rule[i];
if (r.validator && r.trigger !== triggerType) {
r.trigger = triggerType;
}
}
}
}
},
showBackendErrors(fieldErrors) {
// 清除之前的校验状态
if (!this.$refs.modelForm) {
return
}
if (!this.isChecking) {
this.$refs.modelForm.clearValidate();
} else {
// 当 checkAll 操作时,由面板切换所触发的 executeRule 请求时,不清空 checkAll 的错误信息
this.isChecking = false;
}
const fields = this.$refs.modelForm.fields;
const tab = Utils.positioningErrorMsg(fieldErrors, fields);
return tab;
},
// 添加isModify字段
changeModify () {
let prop = this.$parent.prop
// 查询条件使用时,不存在prop,不用触发isModify字段的维护
if (!prop) {
return
}
if (!this.root) {
return
}
let tempObj = this.root.model
let propArr = prop.split('.')
propArr.pop()
let curProp = null
if (propArr && propArr.length > 0) {
while (curProp = propArr.shift()) {
if (tempObj[curProp]) {
tempObj = tempObj[curProp]
}
}
}
let propKey = prop.substring(prop.lastIndexOf(".") + 1)
if (!tempObj.modifySet) {
this.$set(tempObj, 'modifySet', [propKey])
} else {
if (!tempObj.modifySet.includes(propKey)) {
tempObj.modifySet.push(propKey)
}
}
// 对于markSet和markSetX处理
// 区分总行修改还是分行修改
let ignoreModFlg = this.root.model.trnInfo && this.root.model.trnInfo.sptHldflg
if (!ignoreModFlg) {
// 分行修改添加markSet
if (!tempObj.markSet) {
this.$set(tempObj, 'markSet', [propKey])
} else {
if (!tempObj.markSet.includes(propKey)) {
tempObj.markSet.push(propKey)
}
}
// 同时如果总行修改的markSetX存在要删掉
if (tempObj.markSetX && tempObj.markSetX.length > 0 && tempObj.markSetX.includes(propKey)) {
let indMarkSetX = tempObj.markSetX.indexOf(propKey)
tempObj.markSetX.splice(indMarkSetX, 1)
}
} else {
// 总行修改添加masksetX
if (!tempObj.markSetX) {
this.$set(tempObj, 'markSetX', [propKey])
} else {
if (!tempObj.markSetX.includes(propKey)) {
tempObj.markSetX.push(propKey)
}
}
}
console.log('model', this.root.model)
},
// 自定义添加modifySet
customAddModify (modelObj, prop) {
if (modelObj && modelObj.modifySet && modelObj.modifySet.length) {
if (!modelObj.modifySet.includes(prop)) {
modelObj.modifySet.push(prop)
}
} else {
this.$set(modelObj, 'modifySet', [prop])
}
// 对于markSet和markSetX处理
if (this.root && this.root.model) {
// 区分总行修改还是分行修改
let ignoreModFlg = this.root.model.trnInfo && this.root.model.trnInfo.sptHldflg
if (!ignoreModFlg) {
// 分行修改添加markSet
if (!modelObj.markSet) {
this.$set(modelObj, 'markSet', [prop])
} else {
if (!modelObj.markSet.includes(prop)) {
modelObj.markSet.push(prop)
}
}
// 同时如果总行修改的markSetX存在要删掉
if (modelObj.markSetX && modelObj.markSetX.length > 0 && modelObj.markSetX.includes(prop)) {
let indMarkSetX = modelObj.markSetX.indexOf(prop)
modelObj.markSetX.splice(indMarkSetX, 1)
}
} else {
// 总行修改添加masksetX
if (!modelObj.markSetX) {
this.$set(modelObj, 'markSetX', [prop])
} else {
if (!modelObj.markSetX.includes(prop)) {
modelObj.markSetX.push(prop)
}
}
}
}
console.log('customAdd', modelObj, prop)
},
// 自定义去除modifySet
customRemoveModify (modelObj, prop) {
if (modelObj && modelObj.modifySet && modelObj.modifySet.length && modelObj.modifySet.includes(prop)) {
let ind = modelObj.modifySet.indexOf(prop)
modelObj.modifySet.splice(ind, 1)
}
// markset相关的删除处理
if (modelObj && modelObj.markSet && modelObj.markSet.length && modelObj.markSet.includes(prop)) {
let ind = modelObj.markSet.indexOf(prop)
modelObj.markSet.splice(ind, 1)
}
// marksetX相关的删除处理
if (modelObj && modelObj.markSetX && modelObj.markSetX.length && modelObj.markSetX.includes(prop)) {
let ind = modelObj.markSetX.indexOf(prop)
modelObj.markSetX.splice(ind, 1)
}
console.log('customRemove', modelObj, prop)
},
// 自定义校验去掉后端校验失败的状态
customValidateClear () {
let prop = this.$parent.prop
if (!prop) {
return
}
if (!this.root) {
return
}
let modelFormDom = this.root.$refs['modelForm']
if (modelFormDom) {
let backendValidateKeyList = this.root.rules.backendValidateKeyList
let formFields = this.root.$refs['modelForm'].fields
for (let i = 0; i < formFields.length; i++) {
const field = formFields[i];
if (field.prop === prop && backendValidateKeyList && backendValidateKeyList.includes(field.prop)) {
field.validateState = 'success';
field.validateMessage = null;
}
}
}
},
},
computed: {
isInDisplay() {
return this.$store.state.Status.mode === 'display'
}
}
}