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

搜索记录数据放🍍

上级 a3fabe25
......@@ -37,6 +37,7 @@
<script setup>
const { $setRepo } = useReposStore()
const { $repos } = storeToRefs(useReposStore())
const { $getSearchHistory } = useSearchStore()
const emits = defineEmits([ 'search' ])
const query = ref('')
const selectedRepo = ref('keycloak')
......@@ -66,6 +67,7 @@ const handleSearch = async () => {
emits('search')
nextTick(() => {
loading.value = false
$getSearchHistory()
})
}
nextTick(async () => {
......
......@@ -18,7 +18,7 @@
/>
</div>
<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
class="flex group"
color="gray"
......@@ -60,7 +60,7 @@
</div>
<UDivider />
<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
class="flex group"
color="gray"
......@@ -87,8 +87,9 @@
<script setup>
const emits = defineEmits(['sign', 'clear'])
const Layout = inject('Layout')
const { $isSignIn } = useUserStore()
const searchHistory = ref([])
const { $isSignIn } = storeToRefs(useUserStore())
const { $searchHistory } = storeToRefs(useSearchStore())
const { $getSearchHistory } = useSearchStore()
const isOpenHistory = ref(false)
const query = ref('')
function handleClear () {
......@@ -96,18 +97,20 @@ function handleClear () {
handleRemoveRecords()
}
function handleRemoveRecordItem (id) {
searchHistory.value = searchHistory.value.filter(item => item.c_id !== id)
handleRemoveRecords([id])
}
async function handleRemoveRecords (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', {
method: 'post',
body: ids
})
if (data.value) navigateTo('/')
if (data.value) {
$getSearchHistory()
navigateTo('/')
}
}
function handleOpen () {
if (!$isSignIn) emits('sign')
......@@ -121,11 +124,8 @@ function handleClose () {
function handleClickItem () {
Layout.handleCloseAside()
}
async function getUserHistory () {
const { data } = await useRequest('/v1/chat/completion/list')
searchHistory.value = data.value.data
}
nextTick(() => {
$isSignIn && getUserHistory()
$getSearchHistory()
})
</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.
先完成此消息的编辑!
想要评论请 注册