diff --git a/.github/workflows/pr-chatbot-review.yml b/.github/workflows/pr-chatbot-review.yml index 445d1d9c..d93efa7b 100644 --- a/.github/workflows/pr-chatbot-review.yml +++ b/.github/workflows/pr-chatbot-review.yml @@ -27,7 +27,7 @@ jobs: 'src/**/*.ts' \ 'src/**/*.tsx' \ 'src-tauri/**/*.rs') - + # 如果没有相关文件变更,设置一个提示信息 if [ -z "$DIFF" ]; then echo "NO_CHANGES=true" >> $GITHUB_ENV @@ -77,14 +77,14 @@ jobs: with: script: | const OpenAI = require('openai'); - + const openai = new OpenAI({ apiKey: process.env.DASHSCOPE_API_KEY, baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1" }); - + const diff = process.env.DIFF; - + try { const completion = await openai.chat.completions.create({ model: "qwen-plus", @@ -104,19 +104,19 @@ jobs: temperature: 0.7, max_tokens: 1000 }); - + const analysis = completion.choices[0].message.content; core.setOutput('analysis', analysis); - + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `## PR 代码分析 + body: ` + PR 代码分析 ${analysis} - --- *这是由通义千问 AI 自动生成的 PR 分析,仅供参考。*` }); } catch (error) { @@ -138,4 +138,4 @@ jobs: --- *这是自动生成的通知。*` - }); \ No newline at end of file + }); \ No newline at end of file diff --git a/src/components/rightBox/chatBox/ChatMain.vue b/src/components/rightBox/chatBox/ChatMain.vue index cd3e73b9..4794aa09 100644 --- a/src/components/rightBox/chatBox/ChatMain.vue +++ b/src/components/rightBox/chatBox/ChatMain.vue @@ -481,7 +481,7 @@ const { selectKey, emojiList, scrollTop -} = useChatMain(props.activeItem) +} = useChatMain() const { handlePopoverUpdate } = usePopover(selectKey, 'image-chat-main') watch( diff --git a/src/hooks/useChatMain.ts b/src/hooks/useChatMain.ts index 996d4480..6dc38321 100644 --- a/src/hooks/useChatMain.ts +++ b/src/hooks/useChatMain.ts @@ -1,6 +1,6 @@ import { useCommon } from '@/hooks/useCommon.ts' import { MittEnum, MsgEnum, PowerEnum } from '@/enums' -import { MessageType, SessionItem } from '@/services/types.ts' +import { MessageType } from '@/services/types.ts' import { useMitt } from '@/hooks/useMitt.ts' import { useChatStore } from '@/stores/chat.ts' import apis from '@/services/apis.ts' @@ -10,9 +10,12 @@ import { useGlobalStore } from '@/stores/global.ts' import { isDiffNow } from '@/utils/ComputedTime.ts' import { writeText } from '@tauri-apps/plugin-clipboard-manager' import { translateText } from '@/services/translate' +import { useSettingStore } from '@/stores/setting.ts' -export const useChatMain = (activeItem?: SessionItem) => { +export const useChatMain = () => { const { removeTag, openMsgSession, userUid } = useCommon() + const settingStore = useSettingStore() + const { chat } = storeToRefs(settingStore) const globalStore = useGlobalStore() const chatStore = useChatStore() const userStore = useUserStore()?.userInfo @@ -37,29 +40,6 @@ export const useChatMain = (activeItem?: SessionItem) => { const historyIndex = ref(0) /** 当前点击的用户的key */ const selectKey = ref() - /** 计算出触发页脚后的历史消息下标 */ - const itemComputed = computed(() => { - return items.value.filter((item) => item.accountId !== userUid.value).length - }) - - /**! 模拟信息列表 */ - const items = ref( - Array.from({ length: 5 }, (_, i) => ({ - value: `${i}安老师`, - key: i, - accountId: activeItem?.roomId, - avatar: activeItem?.avatar, - content: '123', - type: MsgEnum.TEXT, - reply: MsgEnum.RECALL - ? { - accountName: '', - content: '', - key: '' - } - : null - })) - ) /** 通用右键菜单 */ const commonMenuList = ref([ @@ -73,7 +53,7 @@ export const useChatMain = (activeItem?: SessionItem) => { icon: 'translate', click: async (item: MessageType) => { const content = item.message.body.content - const result = await translateText(content, 'tencent') + const result = await translateText(content, chat.value.translate) // 将翻译结果添加到消息中 if (!item.message.body.translatedText) { item.message.body.translatedText = { @@ -171,9 +151,8 @@ export const useChatMain = (activeItem?: SessionItem) => { { label: '复制', icon: 'copy', - click: async (item: any) => { - const content = items.value[item.key].content - await handleCopy(content) + click: async (item: MessageType) => { + await handleCopy(item.message.body.content) } }, ...commonMenuList.value, @@ -318,9 +297,8 @@ export const useChatMain = (activeItem?: SessionItem) => { activeBubble.value = item.message.id // 启用键盘监听 const handleKeyPress = (e: KeyboardEvent) => { - if (e.ctrlKey && e.key === 'c') { - const content = items.value[item.message.id].content - handleCopy(content) + if ((e.ctrlKey && e.key === 'c') || (e.metaKey && e.key === 'c')) { + handleCopy(item.message.body.content) // 取消监听键盘事件,以免多次绑定 document.removeEventListener('keydown', handleKeyPress) } @@ -333,14 +311,12 @@ export const useChatMain = (activeItem?: SessionItem) => { handleMsgClick, handleConfirm, handleItemType, - items, activeBubble, floatFooter, historyIndex, tips, modalShow, specialMenuList, - itemComputed, optionsList, report, selectKey, diff --git a/src/services/translate.ts b/src/services/translate.ts index ae60a8f0..4db57bf1 100644 --- a/src/services/translate.ts +++ b/src/services/translate.ts @@ -1,5 +1,6 @@ import { fetch } from '@tauri-apps/plugin-http' import CryptoJS from 'crypto-js' +import { TranslateProvider } from './types.ts' // 有道云翻译接口响应类型 interface YoudaoResponse { @@ -24,9 +25,6 @@ interface TranslateResult { provider: string } -// 支持的翻译服务提供商类型 -type TranslateProvider = 'youdao' | 'tencent' - // 签名计算工具对象 const signUtils = { /** diff --git a/src/services/types.ts b/src/services/types.ts index d891923d..113bb2d5 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -440,6 +440,10 @@ export type MsgReadUnReadCountType = { /** 未读数 */ unReadCount: number | null } + +// 支持的翻译服务提供商类型 +export type TranslateProvider = 'youdao' | 'tencent' + /* ======================================================== */ /**! 模拟信息数据的类型 */ export type MockItem = { diff --git a/src/stores/setting.ts b/src/stores/setting.ts index f493a1d6..54c91682 100644 --- a/src/stores/setting.ts +++ b/src/stores/setting.ts @@ -25,7 +25,8 @@ export const useSettingStore = defineStore(StoresEnum.SETTING, { }, chat: { sendKey: 'Enter', - isDouble: true + isDouble: true, + translate: 'tencent' }, page: { shadow: true, diff --git a/src/typings/stores.d.ts b/src/typings/stores.d.ts index 65f795d8..d139b3e5 100644 --- a/src/typings/stores.d.ts +++ b/src/typings/stores.d.ts @@ -48,6 +48,8 @@ declare namespace STO { sendKey: string /** 是否双击打开独立会话窗口 */ isDouble: boolean + /** 翻译提供商 */ + translate: 'youdao' | 'tencent' } /** 界面设置 */ page: { diff --git a/src/views/moreWindow/settings/General.vue b/src/views/moreWindow/settings/General.vue index fa0ea6e0..4d9e533a 100644 --- a/src/views/moreWindow/settings/General.vue +++ b/src/views/moreWindow/settings/General.vue @@ -77,10 +77,22 @@ - + + + + + 翻译提供商 + + @@ -135,7 +147,7 @@ import { useSettingStore } from '@/stores/setting.ts' import { CloseBxEnum, ShowModeEnum } from '@/enums' import { topicsList } from './model.tsx' -import { sendOptions, fontOptions } from './config.ts' +import { sendOptions, fontOptions, translateOptions } from './config.ts' import { type } from '@tauri-apps/plugin-os' import { NSwitch } from 'naive-ui' import { invoke } from '@tauri-apps/api/core' diff --git a/src/views/moreWindow/settings/config.ts b/src/views/moreWindow/settings/config.ts index 3f72b6ca..3cc1e569 100644 --- a/src/views/moreWindow/settings/config.ts +++ b/src/views/moreWindow/settings/config.ts @@ -36,6 +36,18 @@ const sendOptions = [ } ] +/** 翻译提供商的选项 */ +const translateOptions = [ + { + label: '腾讯云翻译', + value: 'tencent' + }, + { + label: '有道云翻译', + value: 'youdao' + } +] + /** 字体 */ const fontOptions = [ { @@ -47,4 +59,4 @@ const fontOptions = [ value: 'AliFangYuan' } ] -export { sideOptions, sendOptions, fontOptions } +export { sideOptions, sendOptions, fontOptions, translateOptions }