feat: 组件的数据结构调整
This commit is contained in:
@@ -194,7 +194,7 @@ const contentBodyListCardStyle = computed(() => ({
|
||||
}));
|
||||
const contentBodyMarkdownColor = computed(() => contentBodyListToneStyle.value.color);
|
||||
|
||||
const IGNORED_FIELD_KEYS = ["container_type", "content", "components"];
|
||||
const IGNORED_FIELD_KEYS = [];
|
||||
|
||||
/// ======== Value Processing Helpers ========
|
||||
const isArrayValue = (value) => Array.isArray(value);
|
||||
@@ -239,12 +239,11 @@ const createImageEntry = (key, value) => ({
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/// ======== Render Logic ========
|
||||
const isIgnoredField = computed(() => IGNORED_FIELD_KEYS.includes(props.fieldKey));
|
||||
const isContentImageField = computed(() =>
|
||||
props.fieldKey === LONG_TEXT_KEYS.contentImage ||
|
||||
props.fieldKey === LONG_TEXT_KEYS.sceneImage
|
||||
props.fieldKey === LONG_TEXT_KEYS.sceneImage ||
|
||||
props.fieldKey === LONG_TEXT_KEYS.contentImage
|
||||
);
|
||||
const isSpotLocateField = computed(() => props.fieldKey === LONG_TEXT_KEYS.spotLocate);
|
||||
const isQuestionSuggestField = computed(() => props.fieldKey === LONG_TEXT_KEYS.questionSuggest);
|
||||
@@ -260,28 +259,34 @@ const contentImageUrl = computed(() => {
|
||||
return typeof displayValue.value === "string" ? toTrimmedText(displayValue.value) : "";
|
||||
});
|
||||
|
||||
const spotLocateValue = computed(() => {
|
||||
const value = isObjectValue(displayValue.value) ? displayValue.value : {};
|
||||
const getSpotLocateValue = (value) => {
|
||||
const spot = isObjectValue(value) ? value : {};
|
||||
|
||||
return {
|
||||
name: toTrimmedText(value.spot_name),
|
||||
description: toTrimmedText(value.spot_description),
|
||||
longitude: toFiniteNumber(value.spot_longitude),
|
||||
latitude: toFiniteNumber(value.spot_latitude),
|
||||
tag: toTrimmedText(value.spot_tag),
|
||||
name: toTrimmedText(spot.spot_name),
|
||||
description: toTrimmedText(spot.spot_description),
|
||||
longitude: toFiniteNumber(spot.spot_longitude),
|
||||
latitude: toFiniteNumber(spot.spot_latitude),
|
||||
tag: toTrimmedText(spot.spot_tag),
|
||||
};
|
||||
};
|
||||
|
||||
const spotLocateValue = computed(() => {
|
||||
return getSpotLocateValue(displayValue.value);
|
||||
});
|
||||
|
||||
const questionSuggestItems = computed(() => {
|
||||
return isArrayValue(displayValue.value)
|
||||
? displayValue.value.map((item) => toTrimmedText(item)).filter(Boolean)
|
||||
const getQuestionSuggestItems = (value) => {
|
||||
return isArrayValue(value)
|
||||
? value.map((item) => toTrimmedText(item)).filter(Boolean)
|
||||
: [];
|
||||
});
|
||||
};
|
||||
|
||||
const commodityItems = computed(() => {
|
||||
if (!isArrayValue(displayValue.value)) return [];
|
||||
const questionSuggestItems = computed(() => getQuestionSuggestItems(displayValue.value));
|
||||
|
||||
return displayValue.value
|
||||
const getCommodityItems = (value) => {
|
||||
if (!isArrayValue(value)) return [];
|
||||
|
||||
return value
|
||||
.filter((item) => isObjectValue(item))
|
||||
.map((commodity) => ({
|
||||
commodity_id: toTrimmedText(commodity.commodity_id),
|
||||
@@ -291,12 +296,14 @@ const commodityItems = computed(() => {
|
||||
commodity_photo: toTrimmedText(commodity.commodity_photo),
|
||||
}))
|
||||
.filter((commodity) => hasDisplayValue(commodity));
|
||||
});
|
||||
};
|
||||
|
||||
const photoItems = computed(() => {
|
||||
if (!isArrayValue(displayValue.value)) return [];
|
||||
const commodityItems = computed(() => getCommodityItems(displayValue.value));
|
||||
|
||||
return displayValue.value
|
||||
const getPhotoItems = (value) => {
|
||||
if (!isArrayValue(value)) return [];
|
||||
|
||||
return value
|
||||
.filter((item) => isObjectValue(item))
|
||||
.map((photo) => ({
|
||||
photo_name: toTrimmedText(photo.photo_name),
|
||||
@@ -304,10 +311,12 @@ const photoItems = computed(() => {
|
||||
photo_url: toTrimmedText(photo.photo_url),
|
||||
}))
|
||||
.filter((photo) => !!photo.photo_url);
|
||||
});
|
||||
};
|
||||
|
||||
const aigcComponetValue = computed(() => {
|
||||
const aigc = isObjectValue(displayValue.value) ? displayValue.value : {};
|
||||
const photoItems = computed(() => getPhotoItems(displayValue.value));
|
||||
|
||||
const getAigcComponetValue = (value) => {
|
||||
const aigc = isObjectValue(value) ? value : {};
|
||||
|
||||
return {
|
||||
background: toTrimmedText(aigc.background),
|
||||
@@ -315,7 +324,44 @@ const aigcComponetValue = computed(() => {
|
||||
description: toTrimmedText(aigc.description),
|
||||
jumpUrl: toTrimmedText(aigc.jumpUrl),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const aigcComponetValue = computed(() => getAigcComponetValue(displayValue.value));
|
||||
|
||||
const createRenderEntry = (key, value) => {
|
||||
if (isImageValue(value)) {
|
||||
return [createImageEntry(key, value)];
|
||||
}
|
||||
|
||||
if (isArrayValue(value)) {
|
||||
return [{
|
||||
key,
|
||||
type: "list",
|
||||
value: value.filter((item) => hasDisplayValue(item)),
|
||||
}];
|
||||
}
|
||||
|
||||
if (isObjectValue(value)) {
|
||||
return getRenderEntriesForObject(value, key);
|
||||
}
|
||||
|
||||
return [{
|
||||
key,
|
||||
type: "text",
|
||||
value: formatLeafValue(value),
|
||||
}];
|
||||
};
|
||||
|
||||
const getRenderEntriesForObject = (value = {}, parentKey = "") => {
|
||||
if (!isObjectValue(value)) return [];
|
||||
|
||||
return Object.keys(value)
|
||||
.filter((key) => hasDisplayValue(value[key]))
|
||||
.reduce((entries, key) => {
|
||||
const entryKey = parentKey ? `${parentKey}-${key}` : key;
|
||||
return entries.concat(createRenderEntry(entryKey, value[key]));
|
||||
}, []);
|
||||
};
|
||||
|
||||
const shouldRenderContentImage = computed(() => {
|
||||
return isContentImageField.value && !!contentImageUrl.value;
|
||||
@@ -345,6 +391,7 @@ const shouldRenderAigcComponet = computed(() => {
|
||||
const renderFieldEntries = computed(() => {
|
||||
if (isIgnoredField.value || !hasDisplayValue(props.value)) return [];
|
||||
const value = displayValue.value;
|
||||
|
||||
if (isImageValue(value)) {
|
||||
return [createImageEntry(props.fieldKey, value)];
|
||||
}
|
||||
@@ -358,26 +405,7 @@ const renderFieldEntries = computed(() => {
|
||||
}
|
||||
|
||||
if (isObjectValue(value)) {
|
||||
return Object.keys(value)
|
||||
.filter((key) => hasDisplayValue(value[key]))
|
||||
.map((key) => {
|
||||
const entryValue = value[key];
|
||||
if (isImageValue(entryValue)) {
|
||||
return createImageEntry(key, entryValue);
|
||||
}
|
||||
if (isArrayValue(entryValue)) {
|
||||
return {
|
||||
key,
|
||||
type: "list",
|
||||
value: entryValue.filter((item) => hasDisplayValue(item)),
|
||||
};
|
||||
}
|
||||
return {
|
||||
key,
|
||||
type: "text",
|
||||
value: formatLeafValue(entryValue),
|
||||
};
|
||||
});
|
||||
return getRenderEntriesForObject(value);
|
||||
}
|
||||
|
||||
return [{
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
:value="section.parsedValue !== null ? section.parsedValue : section.contentValue"
|
||||
/>
|
||||
|
||||
<ChatMarkdown v-else-if="section.contentKey === LONG_TEXT_KEYS.content" :text="section.contentValue" />
|
||||
|
||||
<ChatMarkdown v-else :text="section.contentValue" />
|
||||
</template>
|
||||
|
||||
@@ -65,16 +63,13 @@ const longAnswerTagStyle = computed(() => buildTagToneStyle(longAnswerTagColor.v
|
||||
|
||||
let unsubscribe = null;
|
||||
|
||||
const HIDDEN_DETAIL_SECTION_KEYS = [
|
||||
LONG_TEXT_KEYS.containerType,
|
||||
];
|
||||
const HIDDEN_DETAIL_SECTION_KEYS = [];
|
||||
|
||||
const shouldUseParsedValueView = (section) => {
|
||||
return (
|
||||
section.fromLongTextData &&
|
||||
section.contentKey !== LONG_TEXT_KEYS.tag &&
|
||||
section.contentKey !== LONG_TEXT_KEYS.title &&
|
||||
section.contentKey !== LONG_TEXT_KEYS.content &&
|
||||
!HIDDEN_DETAIL_SECTION_KEYS.includes(section.contentKey)
|
||||
);
|
||||
};
|
||||
@@ -227,7 +222,7 @@ onLoad(({ message = "", streamId = "", finished = "0", tagToneColor = "" }) => {
|
||||
answerText.value = text || "";
|
||||
longTextData.value = payload || null;
|
||||
title.value = computeTitle(
|
||||
getLongTextValue(longTextData.value, "title") || answerText.value
|
||||
getLongTextValue(longTextData.value, LONG_TEXT_KEYS.title) || answerText.value
|
||||
);
|
||||
|
||||
nextTick(() => {
|
||||
|
||||
Reference in New Issue
Block a user