From 3456d43874d5598ceb82ef23fa7258fb77ec3adf Mon Sep 17 00:00:00 2001 From: leeing <372711472@qq.com> Date: Fri, 30 Aug 2024 16:59:38 +0800 Subject: [PATCH] update 10.3.3 --- react/src/YXUIKit/im-kit-ui/package.json | 6 +- .../chat/components/ChatAITranslate/index.tsx | 12 +++- react/src/components/IMApp/index.tsx | 65 ++++++++++++------- 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/react/src/YXUIKit/im-kit-ui/package.json b/react/src/YXUIKit/im-kit-ui/package.json index e6e0205..bff882a 100644 --- a/react/src/YXUIKit/im-kit-ui/package.json +++ b/react/src/YXUIKit/im-kit-ui/package.json @@ -1,6 +1,6 @@ { "name": "@xkit-yx/im-kit-ui", - "version": "10.3.1", + "version": "10.3.3", "description": "云信即时通讯组件", "license": "MIT", "main": "lib/index.js", @@ -54,7 +54,7 @@ }, "dependencies": { "@ant-design/icons": "^5.0.1", - "@xkit-yx/im-store-v2": "^0.2.0", + "@xkit-yx/im-store-v2": "^0.2.1", "@xkit-yx/utils": "^0.7.1", "antd": "^4.16.3", "mobx": "^6.6.1", @@ -63,5 +63,5 @@ "react-string-replace": "^1.1.0", "react-virtualized": "^9.22.5" }, - "gitHead": "45e04861b1ab80e65b14e6b57c9fd1de60a9a1b0" + "gitHead": "92925c6ca2358ac833adfd557c54b79e0345a01e" } diff --git a/react/src/YXUIKit/im-kit-ui/src/chat/components/ChatAITranslate/index.tsx b/react/src/YXUIKit/im-kit-ui/src/chat/components/ChatAITranslate/index.tsx index 18cdc5d..1929693 100644 --- a/react/src/YXUIKit/im-kit-ui/src/chat/components/ChatAITranslate/index.tsx +++ b/react/src/YXUIKit/im-kit-ui/src/chat/components/ChatAITranslate/index.tsx @@ -19,6 +19,8 @@ export interface ChatAITranslateProps { prefix?: string } +const defaultLangs = ['英语', '日语', '韩语', '俄语', '法语', '德语'] + export const ChatAITranslate: FC = observer( ({ inputValue, setInputValue, onClose, visible, prefix = 'chat' }) => { const _prefix = `${prefix}-ai-translate` @@ -28,7 +30,11 @@ export const ChatAITranslate: FC = observer( const aiErrorMap = getAIErrorMap(t) - const options = store.aiUserStore.getAITranslateLangs().map((lang) => ({ + const options = ( + store.aiUserStore.getAITranslateLangs().length + ? store.aiUserStore.getAITranslateLangs() + : defaultLangs + ).map((lang) => ({ label: lang, value: lang, })) @@ -37,10 +43,10 @@ export const ChatAITranslate: FC = observer( ? store.aiUserStore.aiResMsgs[0] : '' - const [selectedLang, setSelectedLang] = useState(options[0].value) + const [selectedLang, setSelectedLang] = useState(options[0]?.value || '') const resetState = () => { - setSelectedLang(options[0].value) + setSelectedLang(options[0]?.value || '') } useEffect(() => { diff --git a/react/src/components/IMApp/index.tsx b/react/src/components/IMApp/index.tsx index 25504f0..fa6a328 100644 --- a/react/src/components/IMApp/index.tsx +++ b/react/src/components/IMApp/index.tsx @@ -54,12 +54,18 @@ import { import { LocalOptions } from '@xkit-yx/im-store-v2/dist/types/types' import V2NIM, { V2NIMConst } from 'nim-web-sdk-ng' import { V2NIMAIUser } from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/V2NIMAIService' -import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/src/chat/components/ChatP2pMessageList' +import { + NIMInitializeOptions, + NIMOtherOptions, +} from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/NIMInterface' +import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/es/chat/components/ChatP2pMessageList' interface IMContainerProps { appkey: string //传入您的App Key account: string // 传入您的云信IM账号 token: string // 传入您的Token + initOptions?: NIMInitializeOptions + otherOptions?: NIMOtherOptions onLogout?: () => void changeLanguage?: (value: 'zh' | 'en') => void } @@ -319,7 +325,6 @@ const IMApp: React.FC = observer((props) => { [nim.V2NIMConversationIdUtil, nim.V2NIMMessageCreator, store.msgStore] ) - const renderContent = useCallback(() => { return ( <> @@ -341,7 +346,7 @@ const IMApp: React.FC = observer((props) => { className={classNames('chat-icon', { active: model === 'chat', })} - onClick={goChat} + onClick={() => setModel('chat')} >
{t('session')}
@@ -430,11 +435,10 @@ const IMApp: React.FC = observer((props) => { teamMsgReceiptVisible, renderP2pCustomMessage, store.sysMsgStore, - store.msgStore, - nim.V2NIMMessageCreator, - nim.V2NIMConversationIdUtil, needMention, teamManagerVisible, + afterAcceptApplyFriend, + goChat, ]) return ( @@ -456,7 +460,7 @@ const IMApp: React.FC = observer((props) => { }) const IMAppContainer: React.FC = (props) => { - const { appkey, account, token, onLogout } = props + const { appkey, account, token, initOptions, otherOptions, onLogout } = props // 国际化语言类型 const [curLanguage, setCurLanguage] = useState<'zh' | 'en'>('zh') // 添加好友是否需要验证 @@ -566,26 +570,41 @@ const IMAppContainer: React.FC = (props) => { }, []) const nim = useMemo(() => { - const nim = V2NIM.getInstance({ - appkey, - account, - token, - debugLevel: 'debug', - apiVersion: 'v2', - }) + console.log( + 'V2NIM.getInstance: ', + { + appkey, + debugLevel: 'debug', + apiVersion: 'v2', + ...initOptions, + }, + otherOptions + ) + const nim = V2NIM.getInstance( + { + appkey, + debugLevel: 'debug', + apiVersion: 'v2', + ...initOptions, + }, + otherOptions + ) return nim - }, [account, token, appkey]) + }, [appkey, initOptions, otherOptions]) useEffect(() => { - nim.V2NIMLoginService.login(account, token, { - retryCount: 5, - }) - - return () => { - nim.V2NIMLoginService.logout() + if (account && token) { + nim.V2NIMLoginService.login(account, token, { + retryCount: 5, + }) } - }, [nim, account, token]) + }, [account, token, nim.V2NIMLoginService]) + + const handleLogout = useCallback(async () => { + await nim.V2NIMLoginService.logout() + onLogout?.() + }, [onLogout, nim.V2NIMLoginService]) return ( @@ -598,7 +617,7 @@ const IMAppContainer: React.FC = (props) => { singleton={true} >