Commit e48bb24238063d7da963566d6b01ee23d03ddc4c

Authored by wuxw
1 parent 7eba6f1a

v1.9 oa 工作流表單必填問題處理

src/components/oa/newOaWorkflowForm.vue
@@ -11,28 +11,28 @@ @@ -11,28 +11,28 @@
11 <!-- 文本框 --> 11 <!-- 文本框 -->
12 <el-form-item v-if="item.type == 'textfield'" :label="item.label" :prop="item.key" 12 <el-form-item v-if="item.type == 'textfield'" :label="item.label" :prop="item.key"
13 :rules="getValidationRules(item)"> 13 :rules="getValidationRules(item)">
14 - <el-input v-model="item.value" :placeholder="item.description" clearable> 14 + <el-input v-model="formData[item.key]" :placeholder="item.description" clearable>
15 </el-input> 15 </el-input>
16 </el-form-item> 16 </el-form-item>
17 17
18 <!-- 数字框 --> 18 <!-- 数字框 -->
19 <el-form-item v-if="item.type == 'number'" :label="item.label" :prop="item.key" 19 <el-form-item v-if="item.type == 'number'" :label="item.label" :prop="item.key"
20 :rules="getValidationRules(item)"> 20 :rules="getValidationRules(item)">
21 - <el-input-number v-model="item.value" :placeholder="item.description" :min="0" style="width: 100%"> 21 + <el-input-number v-model="formData[item.key]" :placeholder="item.description" :min="0" style="width: 100%">
22 </el-input-number> 22 </el-input-number>
23 </el-form-item> 23 </el-form-item>
24 24
25 <!-- 文本域 --> 25 <!-- 文本域 -->
26 <el-form-item v-if="item.type == 'textarea'" :label="item.label" :prop="item.key" 26 <el-form-item v-if="item.type == 'textarea'" :label="item.label" :prop="item.key"
27 :rules="getValidationRules(item)"> 27 :rules="getValidationRules(item)">
28 - <el-input v-model="item.value" type="textarea" :rows="4" :placeholder="item.description"> 28 + <el-input v-model="formData[item.key]" type="textarea" :rows="4" :placeholder="item.description">
29 </el-input> 29 </el-input>
30 </el-form-item> 30 </el-form-item>
31 31
32 <!-- 日期选择 --> 32 <!-- 日期选择 -->
33 <el-form-item v-if="item.type == 'textdate'" :label="item.label" :prop="item.key" 33 <el-form-item v-if="item.type == 'textdate'" :label="item.label" :prop="item.key"
34 :rules="getValidationRules(item)"> 34 :rules="getValidationRules(item)">
35 - <el-date-picker v-model="item.value" type="date" :placeholder="item.description" format="yyyy-MM-dd" 35 + <el-date-picker v-model="formData[item.key]" type="date" :placeholder="item.description" format="yyyy-MM-dd"
36 value-format="yyyy-MM-dd" style="width: 100%"> 36 value-format="yyyy-MM-dd" style="width: 100%">
37 </el-date-picker> 37 </el-date-picker>
38 </el-form-item> 38 </el-form-item>
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
40 <!-- 时间选择 --> 40 <!-- 时间选择 -->
41 <el-form-item v-if="item.type == 'textdatetime'" :label="item.label" :prop="item.key" 41 <el-form-item v-if="item.type == 'textdatetime'" :label="item.label" :prop="item.key"
42 :rules="getValidationRules(item)"> 42 :rules="getValidationRules(item)">
43 - <el-time-picker v-model="item.value" :placeholder="item.description" format="HH:mm" 43 + <el-time-picker v-model="formData[item.key]" :placeholder="item.description" format="HH:mm"
44 value-format="HH:mm" style="width: 100%"> 44 value-format="HH:mm" style="width: 100%">
45 </el-time-picker> 45 </el-time-picker>
46 </el-form-item> 46 </el-form-item>
@@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
48 <!-- 单选框 --> 48 <!-- 单选框 -->
49 <el-form-item v-if="item.type == 'radio'" :label="item.label" :prop="item.key" 49 <el-form-item v-if="item.type == 'radio'" :label="item.label" :prop="item.key"
50 :rules="getValidationRules(item)"> 50 :rules="getValidationRules(item)">
51 - <el-radio-group v-model="item.value"> 51 + <el-radio-group v-model="formData[item.key]">
52 <el-radio v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value"> 52 <el-radio v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
53 {{ option.label }} 53 {{ option.label }}
54 </el-radio> 54 </el-radio>
@@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
58 <!-- 下拉选择 --> 58 <!-- 下拉选择 -->
59 <el-form-item v-if="item.type == 'select'" :label="item.label" :prop="item.key" 59 <el-form-item v-if="item.type == 'select'" :label="item.label" :prop="item.key"
60 :rules="getValidationRules(item)"> 60 :rules="getValidationRules(item)">
61 - <el-select v-model="item.value" :placeholder="item.description" style="width: 100%" clearable> 61 + <el-select v-model="formData[item.key]" :placeholder="item.description" style="width: 100%" clearable>
62 <el-option v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.label" 62 <el-option v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.label"
63 :value="option.value"> 63 :value="option.value">
64 </el-option> 64 </el-option>
@@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
68 <!-- 复选框 --> 68 <!-- 复选框 -->
69 <el-form-item v-if="item.type == 'checkbox'" :label="item.label" :prop="item.key" 69 <el-form-item v-if="item.type == 'checkbox'" :label="item.label" :prop="item.key"
70 :rules="getValidationRules(item)"> 70 :rules="getValidationRules(item)">
71 - <el-checkbox-group v-model="item.value"> 71 + <el-checkbox-group v-model="formData[item.key]">
72 <el-checkbox v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value"> 72 <el-checkbox v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
73 {{ option.label }} 73 {{ option.label }}
74 </el-checkbox> 74 </el-checkbox>
@@ -91,7 +91,7 @@ @@ -91,7 +91,7 @@
91 </el-form-item> 91 </el-form-item>
92 92
93 <!-- 重置按钮 --> 93 <!-- 重置按钮 -->
94 - <el-form-item v-if="item.type == 'button' && item.action == 'reset'" class="text-right"> 94 + <el-form-item v-if="item.type == 'button' && item.action == 'reset'" class="text-right">
95 <el-button @click="_doReset"> 95 <el-button @click="_doReset">
96 <i class="el-icon-refresh"></i> 96 <i class="el-icon-refresh"></i>
97 {{ item.label }} 97 {{ item.label }}
@@ -122,7 +122,8 @@ export default { @@ -122,7 +122,8 @@ export default {
122 callBackListener: 'newOaWorkflowForm', 122 callBackListener: 'newOaWorkflowForm',
123 callBackFunction: 'fileName', 123 callBackFunction: 'fileName',
124 submitLoading: false, 124 submitLoading: false,
125 - showUploadComponent: false 125 + showUploadComponent: false,
  126 + flowId: null
126 } 127 }
127 }, 128 },
128 129
@@ -143,8 +144,10 @@ export default { @@ -143,8 +144,10 @@ export default {
143 flowId: this.flowId 144 flowId: this.flowId
144 }) 145 })
145 console.log(res) 146 console.log(res)
  147 +
146 this.formJson = JSON.parse(res.data[0].formJson) 148 this.formJson = JSON.parse(res.data[0].formJson)
147 this.initForm() 149 this.initForm()
  150 +
148 } catch (error) { 151 } catch (error) {
149 console.error('获取表单配置失败:', error) 152 console.error('获取表单配置失败:', error)
150 this.$message.error('获取表单配置失败') 153 this.$message.error('获取表单配置失败')
@@ -152,21 +155,22 @@ export default { @@ -152,21 +155,22 @@ export default {
152 }, 155 },
153 156
154 initForm() { 157 initForm() {
155 - this.components = this.formJson.components 158 +
  159 + let _components = this.formJson.components
156 this.formData = {} 160 this.formData = {}
157 161
158 - this.components.forEach(item => { 162 + _components.forEach(item => {
159 if (item.type !== 'button' && item.type !== 'text') { 163 if (item.type !== 'button' && item.type !== 'text') {
160 - // 初始化表单数据  
161 if (item.type === 'checkbox') { 164 if (item.type === 'checkbox') {
162 - this.formData[item.key] = [] 165 + this.$set(this.formData, item.key, []);
163 } else if (item.type === 'radio' || item.type === 'select') { 166 } else if (item.type === 'radio' || item.type === 'select') {
164 - this.formData[item.key] = item.values && item.values.length > 0 ? item.values[0].value : '' 167 + this.$set(this.formData, item.key, item.values && item.values.length > 0 ? item.values[0].value : '');
165 } else { 168 } else {
166 - this.formData[item.key] = '' 169 + this.$set(this.formData, item.key, '');
167 } 170 }
168 } 171 }
169 - }) 172 + });
  173 + this.components = _components
170 }, 174 },
171 175
172 getValidationRules(item) { 176 getValidationRules(item) {
@@ -175,9 +179,19 @@ export default { @@ -175,9 +179,19 @@ export default {
175 rules.push({ 179 rules.push({
176 required: true, 180 required: true,
177 message: `${item.label}不能为空`, 181 message: `${item.label}不能为空`,
  182 + trigger: item.type === 'select' ? 'change' : 'blur'
  183 + })
  184 + }
  185 +
  186 + // 添加其他验证规则,如正则表达式
  187 + if (item.validate && item.validate.pattern) {
  188 + rules.push({
  189 + pattern: new RegExp(item.validate.pattern),
  190 + message: item.validate.customMessage || `${item.label}格式不正确`,
178 trigger: 'blur' 191 trigger: 'blur'
179 }) 192 })
180 } 193 }
  194 +
181 return rules 195 return rules
182 }, 196 },
183 197
@@ -216,18 +230,14 @@ export default { @@ -216,18 +230,14 @@ export default {
216 }, 230 },
217 231
218 _doReset() { 232 _doReset() {
219 - let _that = this;  
220 - _that.components.forEach(item => {  
221 - item.value = "";  
222 - if (item.type == 'textdate' || item.type == 'textdatetime') {  
223 - item.value = "请选择";  
224 - }  
225 -  
226 - if (item.type == "radio" || item.type == "select") {  
227 - item.valueIndex = 0; 233 + this.$refs.form.resetFields()
  234 + // 特殊处理复选框
  235 + Object.keys(this.formData).forEach(key => {
  236 + const component = this.components.find(c => c.key === key)
  237 + if (component && component.type === 'checkbox') {
  238 + this.formData[key] = []
228 } 239 }
229 - });  
230 - this.$forceUpdate(); 240 + })
231 }, 241 },
232 242
233 _doUploadFile() { 243 _doUploadFile() {