index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { View, ScrollView, Text } from "@tarojs/components";
  2. import Taro, { useDidShow, useRouter } from "@tarojs/taro";
  3. import NavBarNormal from "@/components/NavBarNormal/index";
  4. import PageCustom from "@/components/page-custom/index";
  5. import { useEffect, useState } from "react";
  6. import { isSuccess } from "@/utils";
  7. import ChatRecordItem from "@/components/ChatRecordItem";
  8. import { getVisitorInfo } from "@/service/visitor";
  9. import { TSessionItem, TVisitorAgent } from "@/types/visitor";
  10. import VisitorSummary from "./components/VisitorSummary";
  11. import { getVisitorSessions } from "@/service/visitor";
  12. import style from "./index.module.less";
  13. import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
  14. import EmptyData, { EmptyDataSubInfo } from "@/components/EmptyData";
  15. export default () => {
  16. const router = useRouter();
  17. const { visitorId } = router.params;
  18. const [visitor, setVisitor] = useState<TVisitorAgent>();
  19. const [totalCount, setTotalCount] = useState(0);
  20. if (!visitorId) {
  21. return <View>...</View>;
  22. }
  23. const fetchData = async () => {
  24. if (visitorId) {
  25. const response = await getVisitorInfo(visitorId);
  26. if (isSuccess(response.status)) {
  27. setVisitor(response.data);
  28. }
  29. }
  30. };
  31. const fetcher = async ([_url, { nextId, pageSize }]) => {
  32. const res = await getVisitorSessions({
  33. startId: nextId,
  34. pageSize,
  35. visitorId,
  36. });
  37. let _totalCount = res.data.totalCount;
  38. // 记录 totalCount
  39. if (_totalCount && _totalCount !== null) {
  40. setTotalCount(_totalCount);
  41. }
  42. return res.data;
  43. };
  44. const { list, loadMore } = useLoadMoreInfinite<TSessionItem[]>(
  45. createKey(`api/v1/my/visitor/sessions${visitorId}`, 5),
  46. fetcher
  47. );
  48. const newList = list.map((item: TSessionItem, itemIndex: number) => {
  49. let turns = totalCount - itemIndex;
  50. turns = turns <= 0 ? 1 : turns;
  51. return { ...item, visitTimes: turns };
  52. });
  53. const onScrollToLower = () => {
  54. loadMore();
  55. };
  56. useEffect(() => {
  57. fetchData();
  58. }, []);
  59. return (
  60. <PageCustom fullPage style={{ overflow: "hidden" }}>
  61. <NavBarNormal scrollFadeIn backText="访问详情"></NavBarNormal>
  62. {visitor ? <VisitorSummary data={visitor} /> : <></>}
  63. <View className="rounded-container-header">
  64. <View className="text-14 font-medium text-black font-pingfangSCMedium px-16 pb-14">
  65. 访问记录
  66. </View>
  67. </View>
  68. <View className="flex-1 overflow-hidden w-full">
  69. <ScrollView
  70. scrollY
  71. onScrollToLower={onScrollToLower}
  72. style={{
  73. flex: 1,
  74. height: "100%", // 高度自适应
  75. }}
  76. >
  77. <View>
  78. <View className="flex flex-col gap-16 px-16 w-full pb-100">
  79. {newList.length <= 0 && (
  80. <EmptyData type="chat">
  81. <EmptyDataSubInfo>
  82. <View>当前暂无用户访问记录</View>
  83. <View>你的智能体正在等待首次互动</View>
  84. </EmptyDataSubInfo>
  85. </EmptyData>
  86. )}
  87. {newList.map((item) => {
  88. return (
  89. <View className="w-full">
  90. <View className="text-12 text-black leading-16">
  91. {item?.msgTime.slice(0, 10)}
  92. </View>
  93. <View className="flex h-full w-full">
  94. <View className="text-14 font-normal text-black leading-20 flex flex-col items-end">
  95. <View className="text-14 leading-24">
  96. {item?.msgTime.slice(10, 16)}{" "}
  97. </View>
  98. </View>
  99. <View className="flex flex-1 w-full">
  100. <View className={style.gutterLine}>
  101. <View className={style.dot}></View>
  102. <View className={style.line}></View>
  103. <View className={style.dot}></View>
  104. </View>
  105. <View className="w-full h-full flex flex-col gap-8">
  106. <View className="text-14 leading-24 text-title">
  107. 第{" "}
  108. <Text className="text-primary text-16">
  109. {item?.visitTimes}
  110. </Text>{" "}
  111. 次访问你的智能体
  112. </View>
  113. <View className="text-12 text-gray-45">
  114. 访问时长: {item.chatSecondsDesc}
  115. </View>
  116. <View className="text-12 text-gray-45">
  117. 共进行了 {item.chatRoundCnt} 轮对话{" "}
  118. </View>
  119. <ChatRecordItem
  120. sessionId={item.sessionId}
  121. visitorId={visitorId}
  122. showMoreButton
  123. ></ChatRecordItem>
  124. </View>
  125. </View>
  126. </View>
  127. </View>
  128. );
  129. })}
  130. </View>
  131. </View>
  132. </ScrollView>
  133. </View>
  134. </PageCustom>
  135. );
  136. };