Skip to content

Commit

Permalink
feat: 🎸 add copyQA contextMenu (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingryan authored May 19, 2023
1 parent 93d534c commit eb74ca3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
edit: 'Edit',
delete: 'Delete',
copy: 'Copy',
copyQA: 'CopyQA',
newChat: 'New Chat',
editChat: 'Edit Chat',
saveSuccess: 'save success',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
edit: '编辑',
delete: '删除',
copy: '复制',
copyQA: '复制QA',
newChat: '新建聊天',
editChat: '编辑聊天',
saveSuccess: '导出成功',
Expand Down
19 changes: 19 additions & 0 deletions src/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ export const useChatStore = defineStore(ID, {
this.chatCache[index].uptime = uptime;
this.reloadRoute(id);
},
/**
* get user's chat context by id and index
* @param id chat id
* @param dataIndex data index
*/
selectContextQA(id: number, dataIndex: number) {
const cacheIndex = this.getCacheIndex(id);
const contextData = [];
if (cacheIndex !== -1) {
const data = this.chatCache[cacheIndex].data[dataIndex];
contextData.push(data);
if (data.role === 'user') {
contextData.push(this.chatCache[cacheIndex].data[dataIndex + 1]);
} else {
contextData.unshift(this.chatCache[cacheIndex].data[dataIndex - 1]);
}
}
return contextData;
},

/**
* remove single record at cache by id
Expand Down
13 changes: 13 additions & 0 deletions src/views/chat/components/message/Text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
chatStore.removeCache(+id, index);
}
function copyQA(index: number) {
const contextList = chatStore.selectContextQA(+id, index);
const copyContent = `### ${contextList[0].content} \n${contextList[1].content}`;
copy(copyContent);
}
const contextMenuTheme = computed(() => {
return appStore.theme === 'dark' ? 'mac dark' : 'mac';
});
Expand All @@ -103,6 +109,13 @@
}),
onClick: () => copy(props.content),
},
{
label: t('common.copyQA'),
icon: h('i', {
class: 'fa-solid fa-copy',
}),
onClick: () => copyQA(index),
},
],
zIndex: 60,
minWidth: 100,
Expand Down

0 comments on commit eb74ca3

Please sign in to comment.