|
@@ -36,12 +36,33 @@ export default function Index() {
|
|
});
|
|
});
|
|
return res.data;
|
|
return res.data;
|
|
};
|
|
};
|
|
- const { list, loadMore, setSize, pages, pageIndex, mutate } = useLoadMoreInfinite<TVisitorChat[]>(
|
|
|
|
- createKey(`getVisitorDislikeMessages${agentId}`),
|
|
|
|
- fetcher
|
|
|
|
- );
|
|
|
|
|
|
+ const { list, loadMore, setSize, pages, pageIndex, mutate } =
|
|
|
|
+ useLoadMoreInfinite<TVisitorChat[]>(
|
|
|
|
+ createKey(`getVisitorDislikeMessages${agentId}`),
|
|
|
|
+ fetcher
|
|
|
|
+ );
|
|
|
|
+ const qaList: { user?: TVisitorChat; assistant?: TVisitorChat }[] = [];
|
|
|
|
+
|
|
|
|
+ // 从数组中提取问答对
|
|
|
|
+ // 暂定奇数行是用户的提问,偶数行是助手的回答
|
|
|
|
+ // 其中有些只有用户提问,但由于错误或网络问题导致没有助手回答需要跳过
|
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
|
+ const item: { user?: TVisitorChat; assistant?: TVisitorChat } = {};
|
|
|
|
+ if (list[i].role === "user") {
|
|
|
|
+ item.user = list[i];
|
|
|
|
+ if (list[i + 1]?.role === "assistant") {
|
|
|
|
+ item.assistant = list[i + 1];
|
|
|
|
+ qaList.push(item);
|
|
|
|
+ i++; // 跳过下一个元素,因为它已经被配对了
|
|
|
|
+ }else{
|
|
|
|
+ continue; // 如果下一个不是 assistant,则跳过当前 user
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- const dislikeList = list.filter((_item) => _item.role === 'assistant');
|
|
|
|
|
|
+ // console.log(qaList);
|
|
|
|
+
|
|
|
|
+ // const dislikeList = list.filter((_item) => _item.role === 'assistant');
|
|
|
|
|
|
const handleEdit = (item: TVisitorChat) => {
|
|
const handleEdit = (item: TVisitorChat) => {
|
|
Taro.navigateTo({
|
|
Taro.navigateTo({
|
|
@@ -51,7 +72,6 @@ export default function Index() {
|
|
|
|
|
|
// 删除问答项
|
|
// 删除问答项
|
|
const handleDeleteItem = async (item: TVisitorChat) => {
|
|
const handleDeleteItem = async (item: TVisitorChat) => {
|
|
-
|
|
|
|
showModal({
|
|
showModal({
|
|
content: "确定删除该问答项吗?",
|
|
content: "确定删除该问答项吗?",
|
|
onConfirm: async () => {
|
|
onConfirm: async () => {
|
|
@@ -66,21 +86,21 @@ export default function Index() {
|
|
// }
|
|
// }
|
|
// 1. 乐观更新:立即移除数据
|
|
// 1. 乐观更新:立即移除数据
|
|
mutate((currentPages) => {
|
|
mutate((currentPages) => {
|
|
- if(currentPages === undefined) return currentPages;
|
|
|
|
|
|
+ if (currentPages === undefined) return currentPages;
|
|
// 创建全新的 pages 数组(深拷贝)
|
|
// 创建全新的 pages 数组(深拷贝)
|
|
const newPages = currentPages.map((page, index) => {
|
|
const newPages = currentPages.map((page, index) => {
|
|
// 如果不是目标页,直接返回原引用(避免不必要的重渲染)
|
|
// 如果不是目标页,直接返回原引用(避免不必要的重渲染)
|
|
if (index !== pageIndex - 1) return page;
|
|
if (index !== pageIndex - 1) return page;
|
|
-
|
|
|
|
|
|
+
|
|
// 创建目标页的新副本
|
|
// 创建目标页的新副本
|
|
return {
|
|
return {
|
|
...page, // 复制其他属性
|
|
...page, // 复制其他属性
|
|
- data: page.data.filter(_item => _item.msgId !== item.msgId)
|
|
|
|
|
|
+ data: page.data.filter((_item) => _item.msgId !== item.msgId),
|
|
};
|
|
};
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
return newPages;
|
|
return newPages;
|
|
- }, false) // 不重新验证
|
|
|
|
|
|
+ }, false); // 不重新验证
|
|
}
|
|
}
|
|
},
|
|
},
|
|
});
|
|
});
|
|
@@ -96,7 +116,7 @@ export default function Index() {
|
|
};
|
|
};
|
|
|
|
|
|
useDidShow(() => {
|
|
useDidShow(() => {
|
|
- mutate()
|
|
|
|
|
|
+ mutate();
|
|
});
|
|
});
|
|
|
|
|
|
const createCardOptions = (item: TVisitorChat) => {
|
|
const createCardOptions = (item: TVisitorChat) => {
|
|
@@ -126,8 +146,72 @@ export default function Index() {
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
<View className="pb-80">
|
|
<View className="pb-80">
|
|
- {dislikeList.length <=0 ? <View className="pt-24"><EmptyData type="box" /> </View>: <></>}
|
|
|
|
- {dislikeList.map((item) => {
|
|
|
|
|
|
+ {qaList.length <= 0 ? (
|
|
|
|
+ <View className="pt-24">
|
|
|
|
+ <EmptyData type="box" />{" "}
|
|
|
|
+ </View>
|
|
|
|
+ ) : (
|
|
|
|
+ <></>
|
|
|
|
+ )}
|
|
|
|
+ {/* {dislikeList.length <=0 ? <View className="pt-24"><EmptyData type="box" /> </View>: <></>} */}
|
|
|
|
+ {qaList.map((item) => {
|
|
|
|
+ if (!item.assistant) {
|
|
|
|
+ return <></>;
|
|
|
|
+ }
|
|
|
|
+ return (
|
|
|
|
+ <View className="flex flex-col gap-16 px-16 mb-16">
|
|
|
|
+ <CardEditable buttons={createCardOptions(item.assistant)}>
|
|
|
|
+ <View className="flex items-start mb-8 gap-8">
|
|
|
|
+ <View className="flex-center h-28">
|
|
|
|
+ <IconQ />
|
|
|
|
+ </View>
|
|
|
|
+ <View className="flex-1 font-medium text-14 leading-28">
|
|
|
|
+ {item.user?.content}
|
|
|
|
+ </View>
|
|
|
|
+ </View>
|
|
|
|
+
|
|
|
|
+ <View className="flex items-start gap-8">
|
|
|
|
+ <View className="flex-center h-28">
|
|
|
|
+ <IconA />
|
|
|
|
+ </View>
|
|
|
|
+ <View className="flex-1 text-12 leading-20 text-gray-45 truncate">
|
|
|
|
+ <View className="truncate">
|
|
|
|
+ {item.assistant.content}
|
|
|
|
+ </View>
|
|
|
|
+
|
|
|
|
+ {!!item.assistant?.correctionLinks?.length && (
|
|
|
|
+ <View className="pb-12">
|
|
|
|
+ {item.assistant.correctionLinks.map((link) => {
|
|
|
|
+ return (
|
|
|
|
+ <View>
|
|
|
|
+ 查看链接 <Text>{link}</Text>
|
|
|
|
+ </View>
|
|
|
|
+ );
|
|
|
|
+ })}
|
|
|
|
+ </View>
|
|
|
|
+ )}
|
|
|
|
+ {!!item?.assistant.correctionPics?.length && (
|
|
|
|
+ <View className="pb-12">
|
|
|
|
+ {item.assistant.correctionPics.map((pic) => {
|
|
|
|
+ return (
|
|
|
|
+ <View>
|
|
|
|
+ <Image
|
|
|
|
+ src={pic}
|
|
|
|
+ mode="widthFix"
|
|
|
|
+ className="w-full"
|
|
|
|
+ ></Image>
|
|
|
|
+ </View>
|
|
|
|
+ );
|
|
|
|
+ })}
|
|
|
|
+ </View>
|
|
|
|
+ )}
|
|
|
|
+ </View>
|
|
|
|
+ </View>
|
|
|
|
+ </CardEditable>
|
|
|
|
+ </View>
|
|
|
|
+ );
|
|
|
|
+ })}
|
|
|
|
+ {/* {dislikeList.map((item) => {
|
|
return (
|
|
return (
|
|
<View className="flex flex-col gap-16 px-16 mb-16">
|
|
<View className="flex flex-col gap-16 px-16 mb-16">
|
|
<CardEditable buttons={createCardOptions(item)}>
|
|
<CardEditable buttons={createCardOptions(item)}>
|
|
@@ -180,7 +264,7 @@ export default function Index() {
|
|
</CardEditable>
|
|
</CardEditable>
|
|
</View>
|
|
</View>
|
|
);
|
|
);
|
|
- })}
|
|
|
|
|
|
+ })} */}
|
|
</View>
|
|
</View>
|
|
</ScrollView>
|
|
</ScrollView>
|
|
</View>
|
|
</View>
|