Skip to content

Commit e7ce1d0

Browse files
authored
refactor: Optimize front-end request processing for bigintege fields (#559)
1 parent 0d4bd64 commit e7ce1d0

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"github-markdown-css": "^5.8.1",
3131
"highlight.js": "^11.11.1",
3232
"html2canvas": "^1.4.1",
33+
"json-bigint": "^1.0.0",
3334
"lodash": "^4.17.21",
3435
"lodash-es": "^4.17.21",
3536
"markdown-it": "^14.1.0",
@@ -47,6 +48,7 @@
4748
"@eslint/migrate-config": "^1.5.0",
4849
"@types/crypto-js": "^4.2.2",
4950
"@types/element-resize-detector": "^1.1.6",
51+
"@types/json-bigint": "^1.0.4",
5052
"@types/markdown-it": "^14.1.2",
5153
"@types/node": "^22.14.1",
5254
"@typescript-eslint/eslint-plugin": "^8.34.0",

frontend/src/utils/request.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useCache } from '@/utils/useCache'
1212
import { getLocale } from './utils'
1313
import { useAssistantStore } from '@/stores/assistant'
1414
import { useRouter } from 'vue-router'
15+
import JSONBig from 'json-bigint'
1516
// import { i18n } from '@/i18n'
1617
// const t = i18n.global.t
1718
const assistantStore = useAssistantStore()
@@ -61,6 +62,22 @@ class HttpService {
6162
'Content-Type': 'application/json',
6263
...config?.headers,
6364
},
65+
// add transformResponse to bigint
66+
transformResponse: [
67+
function (data) {
68+
try {
69+
return JSONBig.parse(data) // use JSON-bigint
70+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
71+
} catch (e) {
72+
try {
73+
return JSON.parse(data)
74+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
75+
} catch (parseError) {
76+
return data
77+
}
78+
}
79+
},
80+
],
6481
...config,
6582
})
6683

@@ -442,7 +459,7 @@ class HttpService {
442459
export const request = new HttpService({
443460
baseURL: import.meta.env.VITE_API_BASE_URL,
444461
})
445-
/*
462+
/*
446463
const showLicenseKeyError = (msg?: string) => {
447464
ElMessageBox.confirm(t('license.error_tips'), {
448465
confirmButtonType: 'primary',

frontend/src/views/chat/ChatListContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ function onChatRenamed(chat: Chat) {
230230
{{ t('qa.new_chat') }}
231231
</el-button>
232232
<el-input
233-
@click.stop
234233
v-model="search"
235234
:prefix-icon="Search"
236235
class="search"
237236
name="quick-search"
238237
autocomplete="off"
239238
:placeholder="t('qa.chat_search')"
240239
clearable
240+
@click.stop
241241
/>
242242
</el-header>
243243
<el-main class="chat-list">

frontend/src/views/chat/answer/ChartAnswer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import BaseAnswer from './BaseAnswer.vue'
33
import { Chat, chatApi, ChatInfo, type ChatMessage, ChatRecord, questionApi } from '@/api/chat.ts'
44
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
55
import ChartBlock from '@/views/chat/chat-block/ChartBlock.vue'
6+
import JSONBig from 'json-bigint'
67
78
const props = withDefaults(
89
defineProps<{
@@ -141,7 +142,7 @@ const sendMessage = async () => {
141142
for (const str of split) {
142143
let data
143144
try {
144-
data = JSON.parse(str.replace('data:{', '{'))
145+
data = JSONBig.parse(str.replace('data:{', '{'))
145146
} catch (err) {
146147
console.error('JSON string:', str)
147148
throw err
@@ -198,7 +199,6 @@ const sendMessage = async () => {
198199
if (!_currentChat.value.datasource) {
199200
_currentChat.value.datasource = data.id
200201
}
201-
_currentChat.value.records[index.value].chart = data.content
202202
break
203203
case 'finish':
204204
emits('finish', currentRecord.id)

0 commit comments

Comments
 (0)