|
139 | 139 |
|
140 | 140 | export default { |
141 | 141 | name: 'FlowForm', |
| 142 | +
|
142 | 143 | components: { |
143 | 144 | FlowFormQuestion |
144 | 145 | }, |
|
301 | 302 | descriptionLink: LinkOption |
302 | 303 | } |
303 | 304 |
|
304 | | - this |
305 | | - .$slots |
306 | | - .default()[0] |
307 | | - .children |
308 | | - .filter(q => q.type && q.type.name.indexOf('Question') !== -1) |
309 | | - .forEach(q => { |
310 | | - const props = q.props |
311 | | - const componentInstance = this.getInstance(props.id) |
312 | | - let model = new QuestionModel() |
313 | | -
|
314 | | - if (componentInstance.question !== null) { |
315 | | - model = componentInstance.question |
316 | | - } |
317 | | -
|
318 | | - if (props.modelValue) { |
319 | | - model.answer = props.modelValue |
320 | | - } |
| 305 | + const defaultSlot = this.$slots.default() |
| 306 | + let children = null |
321 | 307 |
|
322 | | - Object.keys(model).forEach(key => { |
323 | | - if (props[key] !== undefined) { |
324 | | - if (typeof model[key] === 'boolean') { |
325 | | - model[key] = props[key] !== false |
326 | | - } else if (key in classMap) { |
327 | | - const |
328 | | - classReference = classMap[key], |
329 | | - options = [] |
330 | | -
|
331 | | - props[key].forEach(option => { |
332 | | - const instance = new classReference() |
333 | | -
|
334 | | - Object.keys(instance).forEach(instanceKey => { |
335 | | - if (option[instanceKey] !== undefined) { |
336 | | - instance[instanceKey] = option[instanceKey] |
337 | | - } |
338 | | - }) |
| 308 | + if (defaultSlot && defaultSlot.length) { |
| 309 | + children = defaultSlot[0].children |
| 310 | + } |
339 | 311 |
|
340 | | - options.push(instance) |
341 | | - }) |
| 312 | + if (children) { |
| 313 | + children |
| 314 | + .filter(q => q.type && q.type.name.indexOf('Question') !== -1) |
| 315 | + .forEach(q => { |
| 316 | + const props = q.props |
| 317 | + const componentInstance = this.getInstance(props.id) |
| 318 | + let model = new QuestionModel() |
342 | 319 |
|
343 | | - model[key] = options |
344 | | - } else { |
345 | | - switch(key) { |
346 | | - case 'type': |
347 | | - if (Object.values(QuestionType).indexOf(props[key]) !== -1) { |
348 | | - model[key] = props[key] |
349 | | - } else { |
350 | | - for (const questionTypeKey in QuestionType) { |
351 | | - if (questionTypeKey.toLowerCase() === props[key].toLowerCase()) { |
352 | | - model[key] = QuestionType[questionTypeKey] |
353 | | - break |
| 320 | + if (componentInstance.question !== null) { |
| 321 | + model = componentInstance.question |
| 322 | + } |
| 323 | +
|
| 324 | + if (props.modelValue) { |
| 325 | + model.answer = props.modelValue |
| 326 | + } |
| 327 | +
|
| 328 | + Object.keys(model).forEach(key => { |
| 329 | + if (props[key] !== undefined) { |
| 330 | + if (typeof model[key] === 'boolean') { |
| 331 | + model[key] = props[key] !== false |
| 332 | + } else if (key in classMap) { |
| 333 | + const |
| 334 | + classReference = classMap[key], |
| 335 | + options = [] |
| 336 | +
|
| 337 | + props[key].forEach(option => { |
| 338 | + const instance = new classReference() |
| 339 | +
|
| 340 | + Object.keys(instance).forEach(instanceKey => { |
| 341 | + if (option[instanceKey] !== undefined) { |
| 342 | + instance[instanceKey] = option[instanceKey] |
| 343 | + } |
| 344 | + }) |
| 345 | +
|
| 346 | + options.push(instance) |
| 347 | + }) |
| 348 | +
|
| 349 | + model[key] = options |
| 350 | + } else { |
| 351 | + switch(key) { |
| 352 | + case 'type': |
| 353 | + if (Object.values(QuestionType).indexOf(props[key]) !== -1) { |
| 354 | + model[key] = props[key] |
| 355 | + } else { |
| 356 | + for (const questionTypeKey in QuestionType) { |
| 357 | + if (questionTypeKey.toLowerCase() === props[key].toLowerCase()) { |
| 358 | + model[key] = QuestionType[questionTypeKey] |
| 359 | + break |
| 360 | + } |
354 | 361 | } |
355 | 362 | } |
356 | | - } |
357 | | - break |
| 363 | + break |
358 | 364 |
|
359 | | - default: |
360 | | - model[key] = props[key] |
361 | | - break |
| 365 | + default: |
| 366 | + model[key] = props[key] |
| 367 | + break |
| 368 | + } |
362 | 369 | } |
363 | 370 | } |
364 | | - } |
365 | | - }) |
| 371 | + }) |
366 | 372 |
|
367 | | - componentInstance.question = model |
| 373 | + componentInstance.question = model |
368 | 374 |
|
369 | | - model.resetOptions() |
| 375 | + model.resetOptions() |
370 | 376 |
|
371 | | - questions.push(model) |
372 | | - }) |
| 377 | + questions.push(model) |
| 378 | + }) |
| 379 | + } |
373 | 380 | } |
374 | 381 |
|
375 | 382 | return questions |
|
0 commit comments