提交 f7c6e4a1 编写于 作者: View Design's avatar View Design

搜索记录数据放🍍

上级 a3fabe25
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
<script setup> <script setup>
const { $setRepo } = useReposStore() const { $setRepo } = useReposStore()
const { $repos } = storeToRefs(useReposStore()) const { $repos } = storeToRefs(useReposStore())
const { $getSearchHistory } = useSearchStore()
const emits = defineEmits([ 'search' ]) const emits = defineEmits([ 'search' ])
const query = ref('') const query = ref('')
const selectedRepo = ref('keycloak') const selectedRepo = ref('keycloak')
...@@ -66,6 +67,7 @@ const handleSearch = async () => { ...@@ -66,6 +67,7 @@ const handleSearch = async () => {
emits('search') emits('search')
nextTick(() => { nextTick(() => {
loading.value = false loading.value = false
$getSearchHistory()
}) })
} }
nextTick(async () => { nextTick(async () => {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/> />
</div> </div>
<div v-if="$isSignIn" class="flex flex-col gap-2 border-l border-gray-200 dark:border-gray-800 pl-2 ml-5"> <div v-if="$isSignIn" class="flex flex-col gap-2 border-l border-gray-200 dark:border-gray-800 pl-2 ml-5">
<template v-for="(item, index) in searchHistory" :key="index"> <template v-for="(item, index) in $searchHistory" :key="index">
<UButton <UButton
class="flex group" class="flex group"
color="gray" color="gray"
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</div> </div>
<UDivider /> <UDivider />
<div class="flex flex-col p-2"> <div class="flex flex-col p-2">
<template v-for="(item, index) in searchHistory" :key="index"> <template v-for="(item, index) in $searchHistory" :key="index">
<UButton <UButton
class="flex group" class="flex group"
color="gray" color="gray"
...@@ -87,8 +87,9 @@ ...@@ -87,8 +87,9 @@
<script setup> <script setup>
const emits = defineEmits(['sign', 'clear']) const emits = defineEmits(['sign', 'clear'])
const Layout = inject('Layout') const Layout = inject('Layout')
const { $isSignIn } = useUserStore() const { $isSignIn } = storeToRefs(useUserStore())
const searchHistory = ref([]) const { $searchHistory } = storeToRefs(useSearchStore())
const { $getSearchHistory } = useSearchStore()
const isOpenHistory = ref(false) const isOpenHistory = ref(false)
const query = ref('') const query = ref('')
function handleClear () { function handleClear () {
...@@ -96,18 +97,20 @@ function handleClear () { ...@@ -96,18 +97,20 @@ function handleClear () {
handleRemoveRecords() handleRemoveRecords()
} }
function handleRemoveRecordItem (id) { function handleRemoveRecordItem (id) {
searchHistory.value = searchHistory.value.filter(item => item.c_id !== id)
handleRemoveRecords([id]) handleRemoveRecords([id])
} }
async function handleRemoveRecords (ids) { async function handleRemoveRecords (ids) {
if (!ids) { if (!ids) {
ids = searchHistory.value.map(item => item.c_id) ids = $searchHistory.value.map(item => item.c_id)
} }
const { data} = await useRequest('/v1/chat/completion/remove', { const { data} = await useRequest('/v1/chat/completion/remove', {
method: 'post', method: 'post',
body: ids body: ids
}) })
if (data.value) navigateTo('/') if (data.value) {
$getSearchHistory()
navigateTo('/')
}
} }
function handleOpen () { function handleOpen () {
if (!$isSignIn) emits('sign') if (!$isSignIn) emits('sign')
...@@ -121,11 +124,8 @@ function handleClose () { ...@@ -121,11 +124,8 @@ function handleClose () {
function handleClickItem () { function handleClickItem () {
Layout.handleCloseAside() Layout.handleCloseAside()
} }
async function getUserHistory () {
const { data } = await useRequest('/v1/chat/completion/list')
searchHistory.value = data.value.data
}
nextTick(() => { nextTick(() => {
$isSignIn && getUserHistory() $getSearchHistory()
}) })
</script> </script>
import { defineStore } from 'pinia'
export const useSearchStore = defineStore('search', () => {
const { $isSignIn } = useUserStore()
const $searchHistory = ref([])
async function $getSearchHistory () {
if (!$isSignIn) return
const { data } = await useRequest('/v1/chat/completion/list')
$searchHistory.value = data.value.data
}
return { $searchHistory, $getSearchHistory }
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册