fix(web): code review pass — scroll watch, SSE same-origin, store concurrency, modal reset, admin validation

This commit is contained in:
2026-05-04 20:58:48 +08:00
parent ff283013da
commit b8d29d8ea7
11 changed files with 145 additions and 85 deletions
+12 -1
View File
@@ -54,6 +54,7 @@
<NButton
type="primary"
:loading="saving"
:disabled="!canSave"
@click="save"
>
保存
@@ -66,7 +67,7 @@
</template>
<script setup lang="ts">
import { h, onMounted, ref } from 'vue'
import { computed, h, onMounted, ref } from 'vue'
import {
NButton,
NDataTable,
@@ -105,6 +106,15 @@ const saving = ref(false)
const msg = useMessage()
const dlg = useDialog()
const canSave = computed(() => {
const f = form.value
return (
!!f.display_name.trim() &&
!!f.base_url.trim() &&
(!!editing.value || !!f.api_key.trim())
)
})
const providerOpts: { label: string; value: LLMProvider }[] = [
{ label: 'Anthropic', value: 'anthropic' },
{ label: 'OpenAI / Compatible', value: 'openai' },
@@ -196,6 +206,7 @@ async function save() {
api_key: form.value.api_key,
})
}
msg.success('已保存')
showForm.value = false
await reload()
} catch (e) {
+13
View File
@@ -117,6 +117,7 @@
<NButton
type="primary"
:loading="saving"
:disabled="!canSave"
@click="save"
>
保存
@@ -210,6 +211,17 @@ const endpointOpts = computed(() =>
})),
)
const canSave = computed(() => {
const f = form.value
return (
!!f.endpoint_id &&
!!f.model_id.trim() &&
!!f.display_name.trim() &&
f.context_window > 0 &&
f.max_output_tokens > 0
)
})
const endpointName = (id: string) =>
endpoints.value.find((e) => e.id === id)?.display_name ?? id
@@ -347,6 +359,7 @@ async function save() {
}
await llmAdminApi.createModel(body)
}
msg.success('已保存')
showForm.value = false
await reload()
} catch (e) {
+16 -1
View File
@@ -150,8 +150,23 @@ onMounted(async () => {
}
})
// 路由 conversationId 切换:在 /chat ↔ /chat/:id 同组件复用时同步状态。
watch(
() => chat.messages.length,
() => route.params.conversationId,
async (cid) => {
if (typeof cid === 'string' && cid !== '') {
if (chat.currentConversation?.id !== cid) {
await chat.openConversation(cid)
}
} else {
chat.closeCurrent()
}
},
)
// 流式输出时 messages.length 不变,只 content 增长 —— 同时观察末消息内容长度。
watch(
() => [chat.messages.length, chat.messages.at(-1)?.content?.length ?? 0],
() => {
nextTick(() => {
const el = scrollEl.value
@@ -116,6 +116,25 @@ watch(
{ immediate: true },
)
// 每次从外部重新打开时把表单还原到初始状态。
watch(
() => props.show,
(open) => {
if (open) reset()
},
)
function reset() {
form.value = { model_id: '', template_id: null, system_prompt: '' }
if (props.projectId) {
mountKind.value = 'project'
mountID.value = props.projectId
} else {
mountKind.value = null
mountID.value = ''
}
}
function update(v: boolean) {
emit('update:show', v)
}
@@ -57,6 +57,11 @@ async function upload(opts: UploadCustomRequestOptions) {
opts.onError()
return
}
if (f.type.startsWith('audio/') && !props.modelCapabilities?.audio) {
msg.error('当前模型不支持音频')
opts.onError()
return
}
if (f.size > 20 * 1024 * 1024) {
msg.error('单文件不能超过 20 MB')
opts.onError()
@@ -161,6 +161,7 @@ async function save() {
scope: form.value.scope,
})
}
msg.success('已保存')
showForm.value = false
await reload()
} catch (e) {