diff --git a/web/src/assets/recommend.json b/web/src/assets/recommend.json new file mode 100644 index 00000000..71f62a6b --- /dev/null +++ b/web/src/assets/recommend.json @@ -0,0 +1,8 @@ +[ + { + "key": "awesome-chatgpt-prompts-zh", + "desc": "ChatGPT 中文调教指南", + "downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json", + "url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh" + } +] \ No newline at end of file diff --git a/web/src/components/common/PromptStore/index.vue b/web/src/components/common/PromptStore/index.vue new file mode 100644 index 00000000..49a6c0f9 --- /dev/null +++ b/web/src/components/common/PromptStore/index.vue @@ -0,0 +1,429 @@ + + + \ No newline at end of file diff --git a/web/src/components/common/index.ts b/web/src/components/common/index.ts index 16b6d108..d8f03ec6 100644 --- a/web/src/components/common/index.ts +++ b/web/src/components/common/index.ts @@ -3,5 +3,6 @@ import NaiveProvider from './NaiveProvider/index.vue' import SvgIcon from './SvgIcon/index.vue' import UserAvatar from './UserAvatar/index.vue' import Setting from './Setting/index.vue' +import PromptStore from './PromptStore/index.vue' -export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting } +export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore } diff --git a/web/src/store/modules/index.ts b/web/src/store/modules/index.ts index b33b51b5..c6ff33c6 100644 --- a/web/src/store/modules/index.ts +++ b/web/src/store/modules/index.ts @@ -2,3 +2,4 @@ export * from './app' export * from './chat' export * from './user' export * from './auth' +export * from './prompt' diff --git a/web/src/store/modules/prompt/helper.ts b/web/src/store/modules/prompt/helper.ts new file mode 100644 index 00000000..973438d3 --- /dev/null +++ b/web/src/store/modules/prompt/helper.ts @@ -0,0 +1,18 @@ +import { ss } from '@/utils/storage' + +const LOCAL_NAME = 'promptStore' + +export type PromptList = [] + +export interface PromptStore { + promptList: PromptList +} + +export function getLocalPromptList(): PromptStore { + const promptStore: PromptStore | undefined = ss.get(LOCAL_NAME) + return promptStore ?? { promptList: [] } +} + +export function setLocalPromptList(promptStore: PromptStore): void { + ss.set(LOCAL_NAME, promptStore) +} \ No newline at end of file diff --git a/web/src/store/modules/prompt/index.ts b/web/src/store/modules/prompt/index.ts new file mode 100644 index 00000000..869400f3 --- /dev/null +++ b/web/src/store/modules/prompt/index.ts @@ -0,0 +1,17 @@ +import { defineStore } from 'pinia' +import type { PromptStore } from './helper' +import { getLocalPromptList, setLocalPromptList } from './helper' + +export const usePromptStore = defineStore('prompt-store', { + state: (): PromptStore => getLocalPromptList(), + + actions: { + updatePromptList(promptList: []) { + this.$patch({ promptList }) + setLocalPromptList({ promptList }) + }, + getPromptList() { + return this.$state + }, + }, +}) \ No newline at end of file diff --git a/web/src/views/chat/index.vue b/web/src/views/chat/index.vue index 1d030a6b..492f772d 100644 --- a/web/src/views/chat/index.vue +++ b/web/src/views/chat/index.vue @@ -3,6 +3,8 @@ import { computed, onMounted, onUnmounted, ref } from 'vue' import { v4 as uuidv4 } from 'uuid' import { useRoute } from 'vue-router' import { NButton, NInput, NModal, useDialog, useMessage } from 'naive-ui' +import { storeToRefs } from 'pinia' +import { NAutoComplete, NButton, NInput, useDialog, useMessage } from 'naive-ui' import html2canvas from 'html2canvas' import { Message } from './components' import { useScroll } from './hooks/useScroll' @@ -38,8 +40,40 @@ const chatSession = computed(() => chatStore.getChatSessionByUuid(uuid)) const prompt = ref('') const loading = ref(false) + const showModal = ref(false) +// 添加PromptStore +const promptStore = usePromptStore() +// 使用storeToRefs,保证store修改后,联想部分能够重新渲染 +const { promptList: promptTemplate } = storeToRefs(promptStore) + + +// 可优化部分 +// 搜索选项计算,这里使用value作为索引项,所以当出现重复value时渲染异常(多项同时出现选中效果) +// 理想状态下其实应该是key作为索引项,但官方的renderOption会出现问题,所以就需要value反renderLabel实现 +const searchOptions = computed(() => { + if (prompt.value.startsWith('/')) { + return promptTemplate.value.filter((item: { key: string }) => item.key.toLowerCase().includes(prompt.value.substring(1).toLowerCase())).map((obj: { value: any }) => { + return { + label: obj.value, + value: obj.value, + } + }) + } + else { + return [] + } +}) +// value反渲染key +const renderOption = (option: { label: string }) => { + for (const i of promptTemplate.value) { + if (i.value === option.label) + return [i.key] + } + return [] +} + function handleSubmit() { onConversationStream() } @@ -510,10 +544,14 @@ function getDataFromResponseText(responseText: string): string { - + + + import type { CSSProperties } from 'vue' -import { computed, watch } from 'vue' +import { computed, watch, ref } from 'vue' import { NButton, NLayoutSider } from 'naive-ui' import List from './List.vue' @@ -15,6 +15,7 @@ const appStore = useAppStore() const chatStore = useChatStore() const { isMobile } = useBasicLayout() +const show = ref(false) const collapsed = computed(() => appStore.siderCollapsed) @@ -86,6 +87,11 @@ watch(
+
+ + Prompt Store + +