diff --git a/projects/translate-h5/src/assets/translate/archives-equipment.png b/projects/translate-h5/src/assets/translate/archives-equipment.png index 8b1afea..996ee10 100644 Binary files a/projects/translate-h5/src/assets/translate/archives-equipment.png and b/projects/translate-h5/src/assets/translate/archives-equipment.png differ diff --git a/projects/translate-h5/src/assets/translate/def-avatar.png b/projects/translate-h5/src/assets/translate/def-avatar.png new file mode 100644 index 0000000..2823e75 Binary files /dev/null and b/projects/translate-h5/src/assets/translate/def-avatar.png differ diff --git a/projects/translate-h5/src/layout/main/index.less b/projects/translate-h5/src/layout/main/index.less index fe18e79..941792f 100644 --- a/projects/translate-h5/src/layout/main/index.less +++ b/projects/translate-h5/src/layout/main/index.less @@ -1,11 +1,14 @@ .main-layout { height: 100%; .layout-content { + --bottom: 0; + --bottom: constant(safe-area-inset-bottom); + --bottom: env(safe-area-inset-bottom); height: 100%; overflow-y: auto; - // padding-bottom: 150px; - padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/ - padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/ + // padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/ + // padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/ + padding-bottom: calc(var(--bottom) + 44px); } .layout-tab { diff --git a/projects/translate-h5/src/layout/main/mainLayout.tsx b/projects/translate-h5/src/layout/main/mainLayout.tsx index ee6202c..2e4de3f 100644 --- a/projects/translate-h5/src/layout/main/mainLayout.tsx +++ b/projects/translate-h5/src/layout/main/mainLayout.tsx @@ -1,7 +1,8 @@ import React from "react"; -import { NavBar, SafeArea } from "antd-mobile"; +import { NavBar, SafeArea, TabBar } from "antd-mobile"; import { useNavigate } from "react-router-dom"; import "./index.less"; +import { Translate, Electrocardiogram, GithubOne, Blossom, User } from "@icon-park/react"; interface MainLayoutProps { children: React.ReactNode; @@ -20,30 +21,42 @@ const MainLayout: React.FC = ({ }) => { const navigate = useNavigate(); // const location = useLocation(); + const [pathname, setPathname] = React.useState(location.pathname); + const tabs = [ + { + key: "/translate", + title: "宠物翻译", + icon: , + }, + { + key: "/translate/archives", + title: "情绪监控", + icon: , + }, + { + key: "/translate/mood", + title: "我的宠物", + icon: , + }, + // { + // key: "/translate/mood", + // title: "宠物服务", + // icon: , + // }, + // { + // key: "/translate/mood", + // title: "个人中心", - // const tabs = [ - // { - // key: "/", - // title: "宠物翻译", - // icon: , - // }, - // { - // key: "/set", - // title: "待办", - // icon: , - // }, - // { - // key: "/message", - // title: "消息", - // icon: , - // }, - // { - // key: "/me", - // title: "我的", + // icon: , + // }, + ]; - // icon: , - // }, - // ]; + const setRouteActive = (value: string) => { + console.log(value); + + setPathname(value); + navigate(value); + }; const goBack = () => { // 打印路由栈 @@ -68,15 +81,11 @@ const MainLayout: React.FC = ({
{children}
- {/* setRouteActive(value)} - safeArea={true} - > + setRouteActive(value)} safeArea={true}> {tabs.map((item) => ( ))} - */} +
); diff --git a/projects/translate-h5/src/view/home/translate/component/message/index.tsx b/projects/translate-h5/src/view/home/translate/component/message/index.tsx index de323f9..98ce820 100644 --- a/projects/translate-h5/src/view/home/translate/component/message/index.tsx +++ b/projects/translate-h5/src/view/home/translate/component/message/index.tsx @@ -1,9 +1,10 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Avatar, Divider, Space, SpinLoading, Toast } from "antd-mobile"; import { VoiceIcon } from "@workspace/shared"; import { Message } from "../../../types"; import "./index.less"; import { Refresh } from "@icon-park/react"; +import DefAvatar from "@/assets/translate/def-avatar.png"; interface DefinedProps { data: Message[]; @@ -48,7 +49,7 @@ function Index(props: DefinedProps) { }; const renderAvatar = (item: Message) => { - return ; + return ; }; const refreshMessage = async (messageId: number, e: React.MouseEvent) => { @@ -107,7 +108,10 @@ function Index(props: DefinedProps) { {item.isTranslating && !item.isRefresh ? "" : item.petName ?? "未知宠物"} - + + {!(item.isTranslating && !item.isRefresh) && ( + + )} {item.createTime}
playAudio(item.id, item.contentText)}> @@ -122,7 +126,7 @@ function Index(props: DefinedProps) {
))} -
+
); } diff --git a/projects/translate-h5/src/view/home/translate/index.tsx b/projects/translate-h5/src/view/home/translate/index.tsx index 1dbc3d3..344fbb5 100644 --- a/projects/translate-h5/src/view/home/translate/index.tsx +++ b/projects/translate-h5/src/view/home/translate/index.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { Image, Toast } from "antd-mobile"; import MessageCom from "./component/message"; import VoiceRecord from "./component/voice"; @@ -35,6 +35,15 @@ function Index(props: DefinedProps) { const [visible, setVisible] = useState(false); const [dialogId, setDialogId] = useState(0); + // 创建稳定化的消息字符串(排除 isTranslating 字段变化的影响) + const stableMessagesString = useMemo(() => { + const stableMessages = messages.map((msg) => { + const { isTranslating, isRefresh, ...rest } = msg; + return rest; + }); + return JSON.stringify(stableMessages); + }, [messages]); + useEffect(() => { setCurrentLanguage(menuItems[0]); fetchInitialMessages(); @@ -75,7 +84,7 @@ function Index(props: DefinedProps) { scrollToBottom(); }); } - }, [messages, scrollToBottom]); + }, [stableMessagesString, scrollToBottom]); //完成录音 const onRecordingComplete = useCallback( diff --git a/projects/translate-h5/vite.config.ts b/projects/translate-h5/vite.config.ts index acd3ddf..913c185 100644 --- a/projects/translate-h5/vite.config.ts +++ b/projects/translate-h5/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ // basicSsl() // target: "https://petshy.tashowz.com", // http://192.168.1.231:48080 - plugins: [react(), basicSsl()], + plugins: [react()], server: { port: 3000, host: "0.0.0.0",