From bb6c23c24c085339331f72a3ecd2ff32022c024c Mon Sep 17 00:00:00 2001 From: DebugIsFalse <511418503@qq.com> Date: Mon, 27 May 2024 15:37:54 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=88=A0=E9=99=A4=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/i/SearchHistory.vue | 23 +++++++++++++++++++++-- composables/useRequest.js | 5 ++++- pages/search/[id].vue | 5 ++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/components/i/SearchHistory.vue b/components/i/SearchHistory.vue index 1b31a0f..734c0f1 100644 --- a/components/i/SearchHistory.vue +++ b/components/i/SearchHistory.vue @@ -27,6 +27,7 @@ @click="handleClickItem" >
{{ item.title }}
+ 删除 @@ -59,6 +60,7 @@ @click="handleClose" >
{{ item.title }}
+ 删除 @@ -69,11 +71,28 @@ const emits = defineEmits(['sign', 'clear']) const Layout = inject('Layout') const { $isSignIn } = useUserStore() const searchHistory = ref([]) +const isOpenHistory = ref(false) +const query = ref('') function handleClear () { emits('clear') + handleRemoveRecords() +} +function handleRemoveRecordItem (id) { + searchHistory.value = searchHistory.value.filter(item => item.c_id !== id) + handleRemoveRecords([id]) +} +function handleRemoveRecords (ids) { + if (!ids) { + ids = searchHistory.value.map(item => item.c_id) + } + useRequest('/v1/chat/completion/remove', { + method: 'post', + body: ids, + headers: { + 'Content-Type': 'application/json' + } + }) } -const isOpenHistory = ref(false) -const query = ref('') function handleOpen () { if (!$isSignIn) emits('sign') else { diff --git a/composables/useRequest.js b/composables/useRequest.js index 9f9ce1e..c5e4f7f 100644 --- a/composables/useRequest.js +++ b/composables/useRequest.js @@ -25,7 +25,10 @@ const request = async (url, options = {}) => { console.log('[ResponseError]', request) } } - + if (options && options.headers) { + Object.assign(config.headers, options.headers) + delete options.headers + } return useFetch(fullUrl, Object.assign(config, options)); } diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 5e19f8a..46f6905 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -252,8 +252,11 @@ function initSearchItemInfo (info) { } function initSearchRecords (records) { data.value = records.map(item => { - const { answer, actions } = item + let { answer, actions } = item const historyItem = { article: answer, desLoading: false, searchLoading: false, ansLoading: false } + // todo ?action为啥成了string? + actions = typeof actions === 'string' ? JSON.parse(actions) : actions + console.log(actions) // 处理搜索过程 actions && actions.forEach(child => { const childAction = child.action -- GitLab