组织表单提交造成的页面刷新 | 解决页面恢复的概率性崩溃

This commit is contained in:
锦恢 2025-04-12 01:58:47 +08:00
parent b1515e9ac3
commit f1b3f6fbad
8 changed files with 50 additions and 31 deletions

View File

@ -39,7 +39,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { addNewTab, tabs, setActiveTab, closeTab } from './panel'; import { addNewTab, tabs, closeTab } from './panel';
defineComponent({ name: 'main-panel' }); defineComponent({ name: 'main-panel' });
@ -51,7 +51,17 @@ function pageAddNewTab() {
// debug debug // debug debug
if (route.name !== 'debug') { if (route.name !== 'debug') {
router.push('/debug'); router.replace('/debug');
}
}
function setActiveTab(index: number) {
if (index >= 0 && index < tabs.content.length) {
tabs.activeIndex = index;
// debug
if (route.name !== 'debug') {
router.replace('/debug');
}
} }
} }

View File

@ -34,14 +34,7 @@ export const tabs = reactive<{
], ],
activeIndex: 0, activeIndex: 0,
get activeTab() { get activeTab() {
return this.content[this.activeIndex] || { return this.content[this.activeIndex];
name: 'blank',
icon: 'icon-blank',
type: 'blank',
component: undefined,
componentIndex: -1,
storage: {},
};
} }
}); });
@ -84,11 +77,6 @@ export function addNewTab() {
tabs.activeIndex = tabs.content.length - 1; tabs.activeIndex = tabs.content.length - 1;
} }
export function setActiveTab(index: number) {
if (index >= 0 && index < tabs.content.length) {
tabs.activeIndex = index;
}
}
export function closeTab(index: number) { export function closeTab(index: number) {
if (tabs.content.length <= 1) return; // 至少保留一个标签页 if (tabs.content.length <= 1) return; // 至少保留一个标签页

View File

@ -7,10 +7,14 @@
<el-form-item v-for="param in currentPrompt?.params" :key="param.name" <el-form-item v-for="param in currentPrompt?.params" :key="param.name"
:label="param.name" :prop="param.name"> :label="param.name" :prop="param.name">
<el-input v-if="param.type === 'string'" v-model="formData[param.name]" <el-input v-if="param.type === 'string'" v-model="formData[param.name]"
:placeholder="param.placeholder || `请输入${param.name}`" /> :placeholder="param.placeholder || `请输入${param.name}`"
@keydown.enter.prevent="handleSubmit"
/>
<el-input-number v-else-if="param.type === 'number'" v-model="formData[param.name]" <el-input-number v-else-if="param.type === 'number'" v-model="formData[param.name]"
:placeholder="param.placeholder || `请输入${param.name}`" /> :placeholder="param.placeholder || `请输入${param.name}`"
@keydown.enter.prevent="handleSubmit"
/>
<el-switch v-else-if="param.type === 'boolean'" v-model="formData[param.name]" /> <el-switch v-else-if="param.type === 'boolean'" v-model="formData[param.name]" />
</el-form-item> </el-form-item>
@ -51,6 +55,7 @@ const tab = tabs.content[props.tabId];
const tabStorage = tab.storage as PromptStorage; const tabStorage = tab.storage as PromptStorage;
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
// TODO: formData tabStorage
const formData = ref<Record<string, any>>({}); const formData = ref<Record<string, any>>({});
const loading = ref(false); const loading = ref(false);
const responseData = ref<PromptsGetResponse>(); const responseData = ref<PromptsGetResponse>();

View File

@ -8,10 +8,12 @@
:label="param.name" :prop="param.name"> :label="param.name" :prop="param.name">
<!-- 根据不同类型渲染不同输入组件 --> <!-- 根据不同类型渲染不同输入组件 -->
<el-input v-if="param.type === 'string'" v-model="formData[param.name]" <el-input v-if="param.type === 'string'" v-model="formData[param.name]"
:placeholder="param.placeholder || `请输入${param.name}`" /> :placeholder="param.placeholder || `请输入${param.name}`"
@keydown.enter.prevent="handleSubmit" />
<el-input-number v-else-if="param.type === 'number'" v-model="formData[param.name]" <el-input-number v-else-if="param.type === 'number'" v-model="formData[param.name]"
:placeholder="param.placeholder || `请输入${param.name}`" /> :placeholder="param.placeholder || `请输入${param.name}`"
@keydown.enter.prevent="handleSubmit" />
<el-switch v-else-if="param.type === 'boolean'" v-model="formData[param.name]" /> <el-switch v-else-if="param.type === 'boolean'" v-model="formData[param.name]" />
</el-form-item> </el-form-item>

View File

@ -17,6 +17,7 @@
v-if="property.type === 'string'" v-if="property.type === 'string'"
v-model="formData[name]" v-model="formData[name]"
:placeholder="t('enter') + ' ' + (property.title || name)" :placeholder="t('enter') + ' ' + (property.title || name)"
@keydown.enter.prevent="handleExecute"
/> />
<el-input-number <el-input-number
@ -24,6 +25,7 @@
v-model="formData[name]" v-model="formData[name]"
controls-position="right" controls-position="right"
:placeholder="t('enter') + ' ' + (property.title || name)" :placeholder="t('enter') + ' ' + (property.title || name)"
@keydown.enter.prevent="handleExecute"
/> />
<el-switch <el-switch

View File

@ -3,7 +3,7 @@ import { llmManager, llms } from "@/views/setting/llm";
import { pinkLog } from "@/views/setting/util"; import { pinkLog } from "@/views/setting/util";
import I18n from '@/i18n/index'; import I18n from '@/i18n/index';
import { debugModes, tabs } from "@/components/main-panel/panel"; import { debugModes, tabs } from "@/components/main-panel/panel";
import { markRaw } from "vue"; import { markRaw, ref } from "vue";
interface SaveTabItem { interface SaveTabItem {
name: string; name: string;
@ -18,6 +18,8 @@ interface SaveTab {
currentIndex: number currentIndex: number
} }
export const panelLoaded = ref(false);
export function loadPanels() { export function loadPanels() {
const bridge = useMessageBridge(); const bridge = useMessageBridge();
@ -53,6 +55,7 @@ export function loadPanels() {
tabs.activeIndex = persistTab.currentIndex; tabs.activeIndex = persistTab.currentIndex;
} }
panelLoaded.value = true;
}, { once: true }); }, { once: true });
bridge.postMessage({ bridge.postMessage({

View File

@ -1,9 +1,9 @@
<template> <template>
<div style="height: 100%;"> <div style="height: 100%;">
<Welcome v-show="!tabs.activeTab.component"></Welcome> <Welcome v-show="!haveActiveTab"></Welcome>
<!-- 如果存在激活标签页则根据标签页进行渲染 --> <!-- 如果存在激活标签页则根据标签页进行渲染 -->
<div v-show="tabs.activeTab.component" style="height: 100%;"> <div v-show="haveActiveTab" style="height: 100%;">
<component <component
v-show="tab === tabs.activeTab" v-show="tab === tabs.activeTab"
v-for="(tab, index) of tabs.content" v-for="(tab, index) of tabs.content"
@ -22,6 +22,15 @@ import Welcome from './welcome.vue';
import { tabs } from '@/components/main-panel/panel'; import { tabs } from '@/components/main-panel/panel';
defineComponent({ name: 'debug' }); defineComponent({ name: 'debug' });
const haveActiveTab = computed(() => {
const activeTab = tabs.activeTab;
if (activeTab) {
return true;
}
return false;
});
</script> </script>
<style> <style>

View File

@ -1,5 +1,5 @@
{ {
"currentIndex": 1, "currentIndex": 0,
"tabs": [ "tabs": [
{ {
"name": "工具", "name": "工具",
@ -11,12 +11,12 @@
} }
}, },
{ {
"name": "工具", "name": "资源",
"icon": "icon-tool", "icon": "icon-file",
"type": "blank", "type": "blank",
"componentIndex": 2, "componentIndex": 0,
"storage": { "storage": {
"currentToolName": "add" "currentResourceName": "greeting"
} }
} }
] ]