fix: The form failed to parse when there are labels in the internal data (#3980)
parent
4ade65ee00
commit
2f12c61337
|
|
@ -12,7 +12,7 @@
|
||||||
:class="sendMessage && type !== 'log' ? 'cursor' : 'disabled'"
|
:class="sendMessage && type !== 'log' ? 'cursor' : 'disabled'"
|
||||||
>
|
>
|
||||||
<el-space :size="8" alignment="flex-start">
|
<el-space :size="8" alignment="flex-start">
|
||||||
<AppIcon iconName="app-edit" class="color-primary" style="margin-top: 3px;"></AppIcon>
|
<AppIcon iconName="app-edit" class="color-primary" style="margin-top: 3px"></AppIcon>
|
||||||
{{ item.content }}
|
{{ item.content }}
|
||||||
</el-space>
|
</el-space>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -48,6 +48,7 @@ import HtmlRander from './HtmlRander.vue'
|
||||||
import EchartsRander from './EchartsRander.vue'
|
import EchartsRander from './EchartsRander.vue'
|
||||||
import FormRander from './FormRander.vue'
|
import FormRander from './FormRander.vue'
|
||||||
import ReasoningRander from './ReasoningRander.vue'
|
import ReasoningRander from './ReasoningRander.vue'
|
||||||
|
import { nanoid } from 'nanoid'
|
||||||
config({
|
config({
|
||||||
markdownItConfig(md) {
|
markdownItConfig(md) {
|
||||||
md.renderer.rules.image = (tokens, idx, options, env, self) => {
|
md.renderer.rules.image = (tokens, idx, options, env, self) => {
|
||||||
|
|
@ -204,16 +205,68 @@ const split_form_rander = (result: Array<any>) => {
|
||||||
return [...x, ...y]
|
return [...x, ...y]
|
||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
function extractFormRanderContent(html: string) {
|
||||||
|
const results = []
|
||||||
|
const startTag = '<form_rander>'
|
||||||
|
const endTag = '</form_rander>'
|
||||||
|
|
||||||
|
let startIndex = html.indexOf(startTag)
|
||||||
|
|
||||||
|
while (startIndex !== -1) {
|
||||||
|
let endIndex = html.indexOf(endTag, startIndex)
|
||||||
|
let depth = 1
|
||||||
|
let tempIndex = startIndex + startTag.length
|
||||||
|
|
||||||
|
// 查找匹配的结束标签
|
||||||
|
while (depth > 0 && tempIndex < html.length) {
|
||||||
|
const nextStart = html.indexOf(startTag, tempIndex)
|
||||||
|
const nextEnd = html.indexOf(endTag, tempIndex)
|
||||||
|
|
||||||
|
if (nextStart !== -1 && nextStart < nextEnd) {
|
||||||
|
depth++
|
||||||
|
tempIndex = nextStart + startTag.length
|
||||||
|
} else if (nextEnd !== -1) {
|
||||||
|
depth--
|
||||||
|
tempIndex = nextEnd + endTag.length
|
||||||
|
if (depth === 0) {
|
||||||
|
endIndex = nextEnd
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex !== -1) {
|
||||||
|
// 提取内容(去掉开始和结束标签)
|
||||||
|
const contentStart = startIndex + startTag.length
|
||||||
|
const content = html.substring(contentStart, endIndex)
|
||||||
|
results.push(content)
|
||||||
|
startIndex = html.indexOf(startTag, endIndex + endTag.length)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
const _split_form_rander = (source: string, form_rander_list: Array<string>) => {
|
||||||
|
const uuid = nanoid()
|
||||||
|
if (form_rander_list.length > 0) {
|
||||||
|
form_rander_list.forEach((item) => {
|
||||||
|
source = source.replace(`<form_rander>${item}</form_rander>`, uuid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return source
|
||||||
|
.split(uuid)
|
||||||
|
.filter((item) => item !== undefined)
|
||||||
|
.filter((item) => !form_rander_list?.includes(item))
|
||||||
|
}
|
||||||
const split_form_rander_ = (source: string, type: string) => {
|
const split_form_rander_ = (source: string, type: string) => {
|
||||||
const temp_md_quick_question_list = source.match(/<form_rander>[\d\D]*?<\/form_rander>/g)
|
const temp_md_quick_question_list = extractFormRanderContent(source)
|
||||||
const md_quick_question_list = temp_md_quick_question_list
|
const md_quick_question_list = temp_md_quick_question_list
|
||||||
? temp_md_quick_question_list.filter((i) => i)
|
? temp_md_quick_question_list.filter((i) => i)
|
||||||
: []
|
: []
|
||||||
const split_quick_question_value = source
|
const split_quick_question_value = _split_form_rander(source, md_quick_question_list)
|
||||||
.split(/<form_rander>[\d\D]*?<\/form_rander>/g)
|
|
||||||
.filter((item) => item !== undefined)
|
|
||||||
.filter((item) => !md_quick_question_list?.includes(item))
|
|
||||||
const result = Array.from(
|
const result = Array.from(
|
||||||
{ length: md_quick_question_list.length + split_quick_question_value.length },
|
{ length: md_quick_question_list.length + split_quick_question_value.length },
|
||||||
(v, i) => i,
|
(v, i) => i,
|
||||||
|
|
@ -223,12 +276,11 @@ const split_form_rander_ = (source: string, type: string) => {
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
type: 'form_rander',
|
type: 'form_rander',
|
||||||
content: md_quick_question_list[Math.floor(index / 2)]
|
content: md_quick_question_list[Math.floor(index / 2)],
|
||||||
.replace('<form_rander>', '')
|
|
||||||
.replace('</form_rander>', ''),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export default {
|
||||||
RadioRow: 'Radio Row',
|
RadioRow: 'Radio Row',
|
||||||
UploadInput: 'File upload',
|
UploadInput: 'File upload',
|
||||||
TextareaInput: 'Multiline Input',
|
TextareaInput: 'Multiline Input',
|
||||||
|
MultiRow: 'Multi Row',
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
label: 'Default',
|
label: 'Default',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue