Commit e48bb24238063d7da963566d6b01ee23d03ddc4c

Authored by wuxw
1 parent 7eba6f1a

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

src/components/oa/newOaWorkflowForm.vue
... ... @@ -11,28 +11,28 @@
11 11 <!-- 文本框 -->
12 12 <el-form-item v-if="item.type == 'textfield'" :label="item.label" :prop="item.key"
13 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 15 </el-input>
16 16 </el-form-item>
17 17  
18 18 <!-- 数字框 -->
19 19 <el-form-item v-if="item.type == 'number'" :label="item.label" :prop="item.key"
20 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 22 </el-input-number>
23 23 </el-form-item>
24 24  
25 25 <!-- 文本域 -->
26 26 <el-form-item v-if="item.type == 'textarea'" :label="item.label" :prop="item.key"
27 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 29 </el-input>
30 30 </el-form-item>
31 31  
32 32 <!-- 日期选择 -->
33 33 <el-form-item v-if="item.type == 'textdate'" :label="item.label" :prop="item.key"
34 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 36 value-format="yyyy-MM-dd" style="width: 100%">
37 37 </el-date-picker>
38 38 </el-form-item>
... ... @@ -40,7 +40,7 @@
40 40 <!-- 时间选择 -->
41 41 <el-form-item v-if="item.type == 'textdatetime'" :label="item.label" :prop="item.key"
42 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 44 value-format="HH:mm" style="width: 100%">
45 45 </el-time-picker>
46 46 </el-form-item>
... ... @@ -48,7 +48,7 @@
48 48 <!-- 单选框 -->
49 49 <el-form-item v-if="item.type == 'radio'" :label="item.label" :prop="item.key"
50 50 :rules="getValidationRules(item)">
51   - <el-radio-group v-model="item.value">
  51 + <el-radio-group v-model="formData[item.key]">
52 52 <el-radio v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
53 53 {{ option.label }}
54 54 </el-radio>
... ... @@ -58,7 +58,7 @@
58 58 <!-- 下拉选择 -->
59 59 <el-form-item v-if="item.type == 'select'" :label="item.label" :prop="item.key"
60 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 62 <el-option v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.label"
63 63 :value="option.value">
64 64 </el-option>
... ... @@ -68,7 +68,7 @@
68 68 <!-- 复选框 -->
69 69 <el-form-item v-if="item.type == 'checkbox'" :label="item.label" :prop="item.key"
70 70 :rules="getValidationRules(item)">
71   - <el-checkbox-group v-model="item.value">
  71 + <el-checkbox-group v-model="formData[item.key]">
72 72 <el-checkbox v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
73 73 {{ option.label }}
74 74 </el-checkbox>
... ... @@ -91,7 +91,7 @@
91 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 95 <el-button @click="_doReset">
96 96 <i class="el-icon-refresh"></i>
97 97 {{ item.label }}
... ... @@ -122,7 +122,8 @@ export default {
122 122 callBackListener: 'newOaWorkflowForm',
123 123 callBackFunction: 'fileName',
124 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 144 flowId: this.flowId
144 145 })
145 146 console.log(res)
  147 +
146 148 this.formJson = JSON.parse(res.data[0].formJson)
147 149 this.initForm()
  150 +
148 151 } catch (error) {
149 152 console.error('获取表单配置失败:', error)
150 153 this.$message.error('获取表单配置失败')
... ... @@ -152,21 +155,22 @@ export default {
152 155 },
153 156  
154 157 initForm() {
155   - this.components = this.formJson.components
  158 +
  159 + let _components = this.formJson.components
156 160 this.formData = {}
157 161  
158   - this.components.forEach(item => {
  162 + _components.forEach(item => {
159 163 if (item.type !== 'button' && item.type !== 'text') {
160   - // 初始化表单数据
161 164 if (item.type === 'checkbox') {
162   - this.formData[item.key] = []
  165 + this.$set(this.formData, item.key, []);
163 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 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 176 getValidationRules(item) {
... ... @@ -175,9 +179,19 @@ export default {
175 179 rules.push({
176 180 required: true,
177 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 191 trigger: 'blur'
179 192 })
180 193 }
  194 +
181 195 return rules
182 196 },
183 197  
... ... @@ -216,18 +230,14 @@ export default {
216 230 },
217 231  
218 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 243 _doUploadFile() {
... ...