Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加awesome-chatgpt-prompts-en,并为json文件添加代理 #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/assets/recommend.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"key": "chatgpt-prompt-collection",
"desc": "Nothing1024收集整理的prompts",
"downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json",
"url": "https://github.com/Nothing1024/chatgpt-prompt-collection"
"key": "awesome-chatgpt-prompts-en",
"desc": "ChatGPT English Prompts",
"downloadUrl": "https://ghproxy.com/https://raw.githubusercontent.com/luckywangxi/awesome-chatgpt-prompts-en/main/awesome-chatgpt-prompts-en.json",
"url": "https://github.com/f/awesome-chatgpt-prompts"
},
{
"key": "awesome-chatgpt-prompts-zh",
"desc": "ChatGPT 中文调教指南",
"downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json",
"downloadUrl": "https://ghproxy.com/https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json",
"url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh"
}
]
32 changes: 15 additions & 17 deletions src/views/chat/hooks/useScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ type ScrollElement = HTMLDivElement | null

interface ScrollReturn {
scrollRef: Ref<ScrollElement>
scrollToBottom: () => Promise<void>
scrollToBottom: (hasScroll?: boolean) => Promise<void>
scrollToTop: () => Promise<void>
scrollToBottomIfAtBottom: () => Promise<void>
}

export function useScroll(): ScrollReturn {
const scrollRef = ref<ScrollElement>(null)
const isScroll = ref<boolean>(false)

const scrollToBottom = async () => {
await nextTick()
if (scrollRef.value)
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
const scrollToBottom = async (hasScroll?: boolean) => {
if (
scrollRef.value &&
(scrollRef.value.scrollTop + scrollRef.value.clientHeight ===
scrollRef.value.scrollHeight ||
!!hasScroll)
)
isScroll.value = true;
else isScroll.value = false;

await nextTick();
if (scrollRef.value && isScroll.value)
scrollRef.value.scrollTop = scrollRef.value.scrollHeight;
}

const scrollToTop = async () => {
Expand All @@ -25,20 +34,9 @@ export function useScroll(): ScrollReturn {
scrollRef.value.scrollTop = 0
}

const scrollToBottomIfAtBottom = async () => {
await nextTick()
if (scrollRef.value) {
const threshold = 50 // 阈值,表示滚动条到底部的距离阈值
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
if (distanceToBottom <= threshold)
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
}
}

return {
scrollRef,
scrollToBottom,
scrollToTop,
scrollToBottomIfAtBottom,
}
}
11 changes: 8 additions & 3 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang='ts'>
import type { Ref } from "vue";
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
Expand All @@ -16,6 +17,7 @@ import { useChatStore, usePromptStore } from '@/store'
import { fetchChatAPIProcess } from '@/api'
import { t } from '@/locales'


let controller = new AbortController()

const openLongReply = import.meta.env.VITE_GLOB_OPEN_LONG_REPLY === 'true'
Expand All @@ -40,6 +42,7 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.

const prompt = ref<string>('')
const loading = ref<boolean>(false)
const inputRef = ref<Ref | null>(null)

// 添加PromptStore
const promptStore = usePromptStore()
Expand Down Expand Up @@ -74,7 +77,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: null },
},
)
scrollToBottom()
scrollToBottom(true);

loading.value = true
prompt.value = ''
Expand All @@ -98,7 +101,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } },
},
)
scrollToBottom()
scrollToBottom(true);

try {
let lastText = ''
Expand Down Expand Up @@ -452,7 +455,8 @@ const footerClass = computed(() => {
})

onMounted(() => {
scrollToBottom()
scrollToBottom(true)
if (inputRef.value) inputRef.value.focus();
})

onUnmounted(() => {
Expand Down Expand Up @@ -533,6 +537,7 @@ onUnmounted(() => {
<NAutoComplete v-model:value="prompt" :options="searchOptions" :render-label="renderOption">
<template #default="{ handleInput, handleBlur, handleFocus }">
<NInput
ref="inputRef"
v-model:value="prompt"
type="textarea"
:placeholder="placeholder"
Expand Down