feat: ask优化
This commit is contained in:
parent
d728ea05c0
commit
be3c8e0c75
@ -10,8 +10,8 @@ import UserInfo from '@/components/owner/userName';
|
|||||||
import { checkAuthStatus } from '@/lib/auth';
|
import { checkAuthStatus } from '@/lib/auth';
|
||||||
import { fetchApi } from '@/lib/server-api-util';
|
import { fetchApi } from '@/lib/server-api-util';
|
||||||
import { CountData, UserInfoDetails } from '@/types/user';
|
import { CountData, UserInfoDetails } from '@/types/user';
|
||||||
import { useRouter } from 'expo-router';
|
import { useFocusEffect, usePathname, useRouter } from 'expo-router';
|
||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FlatList, StyleSheet, View } from 'react-native';
|
import { FlatList, StyleSheet, View } from 'react-native';
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
@ -20,6 +20,7 @@ export default function OwnerPage() {
|
|||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkAuth = async () => {
|
const checkAuth = async () => {
|
||||||
@ -54,18 +55,24 @@ export default function OwnerPage() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 设计轮询获取数量统计
|
// 设计轮询获取数量统计
|
||||||
useEffect(() => {
|
useFocusEffect(
|
||||||
// 将轮询间隔增加到5秒,减少服务器压力和电池消耗
|
useCallback(() => {
|
||||||
const interval = setInterval(() => {
|
// 当页面获取焦点时开始轮询
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
getCountData();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
// 立即执行一次
|
||||||
getCountData();
|
getCountData();
|
||||||
}, 5000);
|
|
||||||
return () => clearInterval(interval);
|
// 当页面失去焦点时清除定时器
|
||||||
}, []);
|
return () => clearInterval(interval);
|
||||||
|
}, []) // 空依赖数组,因为 getCountData 是稳定的
|
||||||
|
);
|
||||||
|
|
||||||
// 初始化获取用户信息
|
// 初始化获取用户信息
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
getCountData();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -49,14 +49,15 @@ const MessageItem = ({ setCancel, cancel = true, t, insets, item, sessionId, set
|
|||||||
style={[
|
style={[
|
||||||
styles.messageBubble,
|
styles.messageBubble,
|
||||||
isUser ? styles.userBubble : styles.aiBubble,
|
isUser ? styles.userBubble : styles.aiBubble,
|
||||||
{ marginRight: item.content.text == "正在寻找,请稍等..." ? 0 : isUser ? 0 : 10 }
|
{ marginRight: item.content.text == "keepSearchIng" ? 0 : isUser ? 0 : 10 }
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<View className={`${isUser ? 'bg-bgPrimary' : 'bg-aiBubble'}`}>
|
<View className={`${isUser ? 'bg-bgPrimary' : 'bg-aiBubble'}`}>
|
||||||
<Text style={isUser ? styles.userText : styles.aiText}>
|
<Text style={isUser ? styles.userText : styles.aiText}>
|
||||||
{!isUser
|
{!isUser
|
||||||
?
|
? item.content.text == "keepSearchIng"
|
||||||
sessionId ? item.content.text : item.content.text == "正在寻找,请稍等..." ? <Loading /> : item.content.text
|
? <Loading />
|
||||||
|
: item.content.text
|
||||||
: item.content.text
|
: item.content.text
|
||||||
}
|
}
|
||||||
</Text>
|
</Text>
|
||||||
@ -142,7 +143,7 @@ const MessageItem = ({ setCancel, cancel = true, t, insets, item, sessionId, set
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
item.content.text == "正在寻找,请稍等..."
|
item.content.text == "keepSearchIng"
|
||||||
&&
|
&&
|
||||||
<Text style={{ color: "d9d9d9" }}>
|
<Text style={{ color: "d9d9d9" }}>
|
||||||
{t("ask:ask.think")}
|
{t("ask:ask.think")}
|
||||||
@ -245,12 +246,12 @@ const styles = StyleSheet.create({
|
|||||||
userBubble: {
|
userBubble: {
|
||||||
alignSelf: 'flex-end',
|
alignSelf: 'flex-end',
|
||||||
backgroundColor: '#FFB645',
|
backgroundColor: '#FFB645',
|
||||||
marginLeft: '20%',
|
marginLeft: 10,
|
||||||
},
|
},
|
||||||
aiBubble: {
|
aiBubble: {
|
||||||
alignSelf: 'flex-start',
|
alignSelf: 'flex-start',
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
marginRight: '20%',
|
marginRight: 10,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
borderColor: '#e5e5ea',
|
borderColor: '#e5e5ea',
|
||||||
},
|
},
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export default function AskHello({ setUserMessages, setConversationId, setIsHell
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
content: {
|
content: {
|
||||||
text: "正在寻找,请稍等..."
|
text: "keepSearchIng"
|
||||||
},
|
},
|
||||||
role: 'Assistant',
|
role: 'Assistant',
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
@ -41,7 +41,7 @@ export default function AskHello({ setUserMessages, setConversationId, setIsHell
|
|||||||
newMessages.push(response);
|
newMessages.push(response);
|
||||||
}
|
}
|
||||||
return newMessages.filter((item: Message) =>
|
return newMessages.filter((item: Message) =>
|
||||||
item?.content?.text !== '正在寻找,请稍等...'
|
item?.content?.text !== 'keepSearchIng'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,7 +82,7 @@ export default function SendMessage(props: Props) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
content: {
|
content: {
|
||||||
text: "正在寻找,请稍等..."
|
text: "keepSearchIng"
|
||||||
},
|
},
|
||||||
role: 'Assistant',
|
role: 'Assistant',
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
@ -100,7 +100,7 @@ export default function SendMessage(props: Props) {
|
|||||||
newMessages.push(response);
|
newMessages.push(response);
|
||||||
}
|
}
|
||||||
return newMessages.filter((item: Message) =>
|
return newMessages.filter((item: Message) =>
|
||||||
item?.content?.text !== '正在寻找,请稍等...'
|
item?.content?.text !== 'keepSearchIng'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +116,7 @@ export default function SendMessage(props: Props) {
|
|||||||
newMessages.push(response);
|
newMessages.push(response);
|
||||||
}
|
}
|
||||||
return newMessages.filter((item: Message) =>
|
return newMessages.filter((item: Message) =>
|
||||||
item?.content?.text !== '正在寻找,请稍等...'
|
item?.content?.text !== 'keepSearchIng'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user