企业户调整

master
lion 2 weeks ago
parent 7362ae12e4
commit 44b2ea08a0

@ -37,7 +37,7 @@
<template v-else-if="q.edit_input !== 'section'">
<view v-if="q.edit_input === 'checkbox'" class="dimension-help">最少选择{{ q.config.min_choices || 1 }}项<text v-if="q.config.max_choices > 0">,最多选择{{ q.config.max_choices }}项</text>,已选择{{ q.value.length }}项</view>
<SurveyField :field="q" :value="q.value" @uploading="setUploading(q, $event)" :disabled="submitting" @input="setValue(q, $event)" @focus="focus(q)" @blur="keyboardOpen = false" />
<view v-for="opt in notesFor(q)" :key="opt.key" class="other-input"><text>{{ opt.value }} · 补充说明</text><u-input v-model="q.option_texts[opt.key]" type="textarea" :placeholder="q.config.option_notes[opt.key].placeholder || '请填写补充说明'" :disabled="submitting" :maxlength="10000" /></view>
<view v-for="opt in notesFor(q)" :key="opt.key" class="other-input"><text>{{ opt.value }} · 补充说明</text><u-input :value="q.option_texts[opt.key] || ''" type="textarea" :placeholder="q.config.option_notes[opt.key].placeholder || '请填写补充说明'" :disabled="submitting" :maxlength="10000" :cursor-spacing="80" @input="setOptionText(q.id, opt.key, $event)" @focus="focus(q)" @blur="setOptionText(q.id, opt.key, $event); keyboardOpen = false" /></view>
<view v-if="q.show_other" class="other-input"><text>补充说明</text><text v-if="q.config.other_required" class="required-mark">*</text><u-input v-model="q.other_text" type="textarea" :placeholder="q.config.other_placeholder || '请填写补充说明'" :disabled="submitting" :maxlength="10000" :cursor-spacing="80" @focus="focus(q)" @blur="keyboardOpen = false" /></view>
</template>
</view>
@ -239,6 +239,17 @@ export default {
if (!q.show_other) q.other_text = ''
if (this.errorId === q.id) this.errorId = null
},
setOptionText(questionId, optionKey, value) {
if (this.profileRequired || this.submitting) return
// Mini-program nested v-for event datasets contain serialized question copies.
// Resolve the original answer by ID instead of mutating the rendered copy.
const question = this.questionList.find(q => String(q.id) === String(questionId))
if (!question) return
const text = value && value.detail ? value.detail.value : value
if (!question.option_texts || typeof question.option_texts !== 'object' || Array.isArray(question.option_texts)) this.$set(question, 'option_texts', {})
this.$set(question.option_texts, String(optionKey), text == null ? '' : String(text))
if (String(this.errorId) === String(question.id)) this.errorId = null
},
setDimension(q, dim, value) {
if (this.profileRequired || this.submitting) return
this.$set(q.value, dim.field, value)

@ -0,0 +1,51 @@
import fs from 'node:fs'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const Vue = require('../../sz-kjsxy-web/node_modules/vue')
const helperSource = fs.readFileSync(new URL('../common/survey.js', import.meta.url), 'utf8')
const helpers = await import('data:text/javascript;base64,' + Buffer.from(helperSource).toString('base64'))
const pageSource = fs.readFileSync(new URL('../packages/surveyFill/index.vue', import.meta.url), 'utf8')
const script = pageSource.split('<script>')[1].split('</script>')[0]
.replace(/import[\s\S]*?from\s+['"][^'"]+['"]/g, '').replace('export default', 'return')
const imports = ['prepareQuestions', 'required', 'showOther', 'firstError', 'progress', 'submission', 'formatDescription', 'fillUserFields', 'visibleQuestions', 'selectedNotes']
const page = new Function('SurveyField', ...imports, script)({}, ...imports.map(name => name === 'formatDescription' ? helpers.descriptionHtml : helpers[name]))
const vm = new Vue(page)
vm.questionList = helpers.prepareQuestions([
{ id: 30, field: 'evening', name: '晚上:参加的主题及人数', edit_input: 'checkbox', need_fill: true, config: { min_choices: 1, max_choices: 3, option_notes: { tax: { required: true }, law: { required: true } } }, select_item: [{ key: 'tax', value: '财税' }, { key: 'law', value: '法律' }, { key: 'hr', value: '人力资源' }] },
{ id: 31, field: 'other', name: '另一题', edit_input: 'radio', config: { option_notes: { '0': { required: true } } }, select_item: [{ key: '0', value: '其他' }] }
])
vm.setValue(vm.questionList[0], ['tax'])
const detached = JSON.parse(JSON.stringify(vm.shownQuestions[0]))
Vue.set(detached.option_texts, 'tax', '国际税,2人')
assert.match(helpers.firstError(vm.questionList).message, /请填写补充说明/) // Reproduce the old serialized-event update.
vm.errorId = 30
vm.setOptionText(detached.id, 'tax', '国际税,2人')
await Vue.nextTick()
assert.equal(vm.questionList[0].option_texts.tax, '国际税,2人')
assert.equal(vm.errorId, null)
assert.equal(helpers.firstError(vm.questionList), null)
assert.deepEqual(helpers.submission(vm.questionList)[0].option_texts, { tax: '国际税,2人' })
// Input and blur can supply either plain text (u-input) or a native detail object.
vm.setOptionText('30', 'tax', { detail: { value: '国际税,3人' } })
assert.equal(helpers.submission(vm.questionList)[0].option_texts.tax, '国际税,3人')
vm.setValue(vm.questionList[0], ['tax', 'law'])
assert.match(helpers.firstError(vm.questionList).message, /请填写补充说明/)
vm.setOptionText(30, 'law', '合同,1人')
assert.equal(helpers.firstError(vm.questionList), null)
vm.setValue(vm.questionList[1], '0')
vm.setOptionText(31, 0, '另一题的说明')
assert.equal(helpers.submission(vm.questionList)[1].option_texts['0'], '另一题的说明')
assert.equal(vm.questionList[0].option_texts.tax, '国际税,3人')
vm.setValue(vm.questionList[0], ['law'])
assert.deepEqual(helpers.submission(vm.questionList)[0].option_texts, { law: '合同,1人' })
vm.setOptionText(30, 'law', ' ')
assert.match(helpers.firstError(vm.questionList).message, /请填写补充说明/)
vm.setOptionText(30, 'law', '')
assert.match(helpers.firstError(vm.questionList).message, /请填写补充说明/)
vm.setOptionText(30, 'law', '正常内容')
vm.submitting = true
vm.setOptionText(30, 'law', '提交期间不得覆盖')
assert.equal(vm.questionList[0].option_texts.law, '正常内容')
vm.$destroy()
console.log('Survey option notes: serialized event regression, reactive input, blur synchronization, independent options and required validation passed')
Loading…
Cancel
Save