feat(接口测试): 插件数据缓存

This commit is contained in:
baiqi 2024-07-09 11:55:27 +08:00 committed by 刘瑞斌
parent 53b75e2c6b
commit 4ed3cf4ee2
4 changed files with 33 additions and 4 deletions

View File

@ -0,0 +1,21 @@
import { defineStore } from 'pinia';
import { cloneDeep } from 'lodash-es';
import type { RequestCompositionState } from './types';
// 用于记录请求组合的临时插件表单数据
const useRequestCompositionStore = defineStore('visit', {
state: (): RequestCompositionState => ({
temporaryPluginFormMap: {},
}),
getters: {
pluginFormMap: (state) => state.temporaryPluginFormMap,
},
actions: {
setPluginFormMap(id: string | number, pluginForm?: Record<string, any>) {
this.temporaryPluginFormMap[id] = pluginForm ? cloneDeep(pluginForm) : {};
},
},
});
export default useRequestCompositionStore;

View File

@ -0,0 +1,7 @@
export interface TemporaryPluginForm {
[key: string]: any;
}
export interface RequestCompositionState {
temporaryPluginFormMap: TemporaryPluginForm;
}

View File

@ -451,6 +451,7 @@
import { getSocket } from '@/api/modules/project-management/commonScript';
import { getProjectOptions } from '@/api/modules/project-management/projectMember';
import { useI18n } from '@/hooks/useI18n';
import useRequestCompositionStore from '@/store/modules/api/requestComposition';
import useAppStore from '@/store/modules/app';
import useUserStore from '@/store/modules/user';
import { filterTree, filterTreeNode, getGenerateId, parseQueryParams } from '@/utils';
@ -556,6 +557,7 @@
const appStore = useAppStore();
const userStore = useUserStore();
const { t } = useI18n();
const requestCompositionStore = useRequestCompositionStore();
const loading = defineModel<boolean>('detailLoading', { default: false });
const requestVModel = defineModel<RequestParam>('request', { required: true });
@ -738,7 +740,6 @@
const localExecuteUrl = computed(() => userStore.localExecuteUrl); //
const pluginScriptMap = ref<Record<string, PluginConfig>>({}); //
const temporaryPluginFormMap: Record<string, any> = {}; // tab
const pluginLoading = ref(false);
const fApi = ref<Api>();
const currentPluginOptions = computed<Record<string, any>>(
@ -750,7 +751,7 @@
//
const handlePluginFormChange = debounce(() => {
temporaryPluginFormMap[requestVModel.value.id] = fApi.value?.formData();
requestCompositionStore.setPluginFormMap(requestVModel.value.id, fApi.value?.formData());
handleActiveDebugChange();
}, 300);
@ -783,7 +784,7 @@
* 设置插件表单数据
*/
async function setPluginFormData() {
const tempForm = temporaryPluginFormMap[requestVModel.value.id];
const tempForm = requestCompositionStore.pluginFormMap[requestVModel.value.id];
if (tempForm || !requestVModel.value.isNew || requestVModel.value.isCopy) {
//
const formData = tempForm || requestVModel.value;

View File

@ -14,7 +14,7 @@
@open-edit-api-tab="openApiTab"
/>
</div>
<div v-if="activeApiTab.id !== 'all'" class="flex-1 overflow-hidden">
<div v-else-if="activeApiTab.id !== 'all'" class="flex-1 overflow-hidden">
<a-tabs
v-model:active-key="activeApiTab.definitionActiveKey"
animation