diff --git a/frontend/src/components/business/ms-assertion/comp/ScriptTab.vue b/frontend/src/components/business/ms-assertion/comp/ScriptTab.vue index dad1f389ef..78318be989 100644 --- a/frontend/src/components/business/ms-assertion/comp/ScriptTab.vue +++ b/frontend/src/components/business/ms-assertion/comp/ScriptTab.vue @@ -7,10 +7,6 @@ import conditionContent from '@/views/api-test/components/condition/content.vue'; - import { getEnvironment } from '@/api/modules/api-test/common'; - import useProjectEnvStore from '@/store/modules/setting/useProjectEnvStore'; - - const store = useProjectEnvStore(); interface ScriptItem { [key: string]: any; } @@ -31,26 +27,12 @@ const condition = useVModel(props, 'data', emit); - const currentEnvConfig = ref({}); - - async function initEnvironment() { - if (store.currentId) { - currentEnvConfig.value = await getEnvironment(store.currentId); - } - } - /** 向孙组件提供属性 */ - provide('currentEnvConfig', readonly(currentEnvConfig)); - /** * 删除列表项 */ function deleteItem(id: string | number) { emit('deleteScriptItem', id); } - - onBeforeMount(() => { - initEnvironment(); - }); diff --git a/frontend/src/components/business/ms-environment-select/index.vue b/frontend/src/components/business/ms-environment-select/index.vue new file mode 100644 index 0000000000..603bd99f7f --- /dev/null +++ b/frontend/src/components/business/ms-environment-select/index.vue @@ -0,0 +1,91 @@ + + + + + diff --git a/frontend/src/components/pure/ms-jsonpath-picker/index.vue b/frontend/src/components/pure/ms-jsonpath-picker/index.vue index bb5c63772f..7f38aab591 100644 --- a/frontend/src/components/pure/ms-jsonpath-picker/index.vue +++ b/frontend/src/components/pure/ms-jsonpath-picker/index.vue @@ -75,9 +75,7 @@ 'pick', jsonPath.value, json.value, - JSONPath({ json: json.value, path: jsonPath.value }).map((e) => - e.toString().replace(/Number\(([^)]+)\)/g, '$1') - ) + JSONPath({ json: json.value, path: jsonPath.value }).map((e) => `${e}`.replace(/Number\(([^)]+)\)/g, '$1')) ); } }, 0); diff --git a/frontend/src/components/pure/ms-table/base-table.vue b/frontend/src/components/pure/ms-table/base-table.vue index 8ad78dd55b..0f04a2687c 100644 --- a/frontend/src/components/pure/ms-table/base-table.vue +++ b/frontend/src/components/pure/ms-table/base-table.vue @@ -665,7 +665,6 @@ } } .setting-icon { - margin-left: 16px; color: var(--color-text-4); background-color: var(--color-text-10); cursor: pointer; diff --git a/frontend/src/store/modules/app/index.ts b/frontend/src/store/modules/app/index.ts index 75fb576310..9e6272c389 100644 --- a/frontend/src/store/modules/app/index.ts +++ b/frontend/src/store/modules/app/index.ts @@ -5,10 +5,11 @@ import { cloneDeep } from 'lodash-es'; import type { BreadcrumbItem } from '@/components/business/ms-breadcrumb/types'; +import { getEnvironment, getEnvList } from '@/api/modules/api-test/common'; import { getProjectInfo } from '@/api/modules/project-management/basicInfo'; import { getProjectList } from '@/api/modules/project-management/project'; import { getPageConfig } from '@/api/modules/setting/config'; -import { getPackageType, getSystemVersion, getUserHasProjectPermission } from '@/api/modules/system'; +import { getPackageType, getSystemVersion } from '@/api/modules/system'; import { getMenuList } from '@/api/modules/user'; import defaultSettings from '@/config/settings.json'; import { useI18n } from '@/hooks/useI18n'; @@ -65,6 +66,8 @@ const useAppStore = defineStore('app', { packageType: '', projectList: [] as ProjectListItem[], ordList: [], + envList: [], + currentEnvConfig: undefined, }), getters: { @@ -352,6 +355,30 @@ const useAppStore = defineStore('app', { console.log(error); } }, + async setEnvConfig(env: string) { + try { + const res = await getEnvironment(env); + this.currentEnvConfig = { + ...res, + id: env, + name: this.envList.find((item) => item.id === env)?.name || '', + }; + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } + }, + async initEnvList(env?: string) { + try { + this.envList = await getEnvList(this.currentProjectId); + if (this.envList.findIndex((item) => item.id === this.currentEnvConfig?.id) === -1) { + this.setEnvConfig(env || this.envList[0]?.id); + } + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } + }, }, persist: { paths: ['currentOrgId', 'currentProjectId', 'pageConfig'], diff --git a/frontend/src/store/modules/app/types.ts b/frontend/src/store/modules/app/types.ts index 3b52036d0d..6817e1282e 100644 --- a/frontend/src/store/modules/app/types.ts +++ b/frontend/src/store/modules/app/types.ts @@ -1,6 +1,7 @@ import type { MsFileItem } from '@/components/pure/ms-upload/types'; import type { BreadcrumbItem } from '@/components/business/ms-breadcrumb/types'; +import { EnvConfig, EnvironmentItem } from '@/models/projectManagement/environmental'; import type { LoginConfig, PageConfig, PlatformConfig, ThemeConfig } from '@/models/setting/config'; import { ProjectListItem } from '@/models/setting/project'; @@ -40,6 +41,8 @@ export interface AppState { packageType: string; projectList: ProjectListItem[]; ordList: { id: string; name: string }[]; + envList: EnvironmentItem[]; + currentEnvConfig?: EnvConfig; // 当前环境配置信息 } export interface UploadFileTaskState { diff --git a/frontend/src/store/modules/setting/useProjectEnvStore.ts b/frontend/src/store/modules/setting/useProjectEnvStore.ts index 39dd469b22..8b020fb74b 100644 --- a/frontend/src/store/modules/setting/useProjectEnvStore.ts +++ b/frontend/src/store/modules/setting/useProjectEnvStore.ts @@ -1,6 +1,5 @@ import { defineStore } from 'pinia'; import { cloneDeep } from 'lodash-es'; -import localforage from 'localforage'; import { getDetailEnv, getGlobalParamDetail } from '@/api/modules/project-management/envManagement'; import useLocalForage from '@/hooks/useLocalForage'; diff --git a/frontend/src/views/api-test/components/condition/content.vue b/frontend/src/views/api-test/components/condition/content.vue index 6d1b0782f5..2701c9fc56 100644 --- a/frontend/src/views/api-test/components/condition/content.vue +++ b/frontend/src/views/api-test/components/condition/content.vue @@ -549,7 +549,6 @@ const { t } = useI18n(); - const currentEnvConfig = inject>('currentEnvConfig'); const condition = defineModel('data', { required: true, }); @@ -557,10 +556,10 @@ function filterDataSource() { if (condition.value.processorType === RequestConditionProcessor.SQL && condition.value.dataSourceId) { // 如果是SQL类型的条件且已选数据源,需要根据环境切换数据源 - const dataSourceItem = currentEnvConfig?.value.dataSources.find( + const dataSourceItem = appStore.currentEnvConfig?.dataSources.find( (item) => item.dataSource === condition.value.dataSourceName ); - if (currentEnvConfig?.value.dataSources.length === 0) { + if (appStore.currentEnvConfig?.dataSources.length === 0) { // 如果没有数据源,就清除已选的数据源 condition.value.dataSourceName = ''; condition.value.dataSourceId = ''; @@ -568,16 +567,16 @@ // 每次初始化都去查找一下最新的数据源,因为切换环境的时候数据源也需要切换 condition.value.dataSourceName = dataSourceItem.dataSource; condition.value.dataSourceId = dataSourceItem.id; - } else if (currentEnvConfig && currentEnvConfig.value.dataSources.length > 0) { + } else if (appStore.currentEnvConfig && appStore.currentEnvConfig?.dataSources.length > 0) { // 如果没有找到,就默认取第一个数据源 - condition.value.dataSourceName = currentEnvConfig.value.dataSources[0].dataSource; - condition.value.dataSourceId = currentEnvConfig.value.dataSources[0].id; + condition.value.dataSourceName = appStore.currentEnvConfig?.dataSources[0].dataSource; + condition.value.dataSourceId = appStore.currentEnvConfig?.dataSources[0].id; } } } watch( - () => currentEnvConfig?.value, + () => appStore.currentEnvConfig?.id, () => { filterDataSource(); }, diff --git a/frontend/src/views/api-test/components/environmentSelect.vue b/frontend/src/views/api-test/components/environmentSelect.vue deleted file mode 100644 index 839da8693f..0000000000 --- a/frontend/src/views/api-test/components/environmentSelect.vue +++ /dev/null @@ -1,136 +0,0 @@ - - - - - diff --git a/frontend/src/views/api-test/components/fastExtraction/index.vue b/frontend/src/views/api-test/components/fastExtraction/index.vue index 4d2464a7fe..b36dd45310 100644 --- a/frontend/src/views/api-test/components/fastExtraction/index.vue +++ b/frontend/src/views/api-test/components/fastExtraction/index.vue @@ -248,7 +248,7 @@ JSONPath({ json: parseJson.value, path: expressionForm.value.expression, - })?.map((e) => e.toString().replace(/Number\(([^)]+)\)/g, '$1')) || []; + })?.map((e) => `${e}`.replace(/Number\(([^)]+)\)/g, '$1')) || []; } catch (error) { matchResult.value = JSONPath({ json: props.response || '', path: expressionForm.value.expression }) || []; } diff --git a/frontend/src/views/api-test/components/quoteSqlSourceDrawer.vue b/frontend/src/views/api-test/components/quoteSqlSourceDrawer.vue index 9ea8532a56..53e73c7383 100644 --- a/frontend/src/views/api-test/components/quoteSqlSourceDrawer.vue +++ b/frontend/src/views/api-test/components/quoteSqlSourceDrawer.vue @@ -40,8 +40,7 @@ import { getEnvironment } from '@/api/modules/api-test/common'; import { useI18n } from '@/hooks/useI18n'; - - import { EnvConfig } from '@/models/projectManagement/environmental'; + import useAppStore from '@/store/modules/app'; const props = defineProps<{ visible: boolean; @@ -52,10 +51,10 @@ (e: 'apply', value: any): void; }>(); + const appStore = useAppStore(); const { t } = useI18n(); /** 接收祖先组件提供的属性 */ - const currentEnvConfig = inject>('currentEnvConfig'); const innerVisible = useVModel(props, 'visible', emit); const keyword = ref(''); const selectedKey = ref(props.selectedKey || ''); @@ -112,12 +111,13 @@ const res = await getEnvironment(envId); propsRes.value.data = cloneDeep(res.dataSources) as any[]; } catch (error) { + // eslint-disable-next-line no-console console.log(error); } } watch( - () => currentEnvConfig?.value, + () => appStore.currentEnvConfig, (config) => { if (config && config.id) { initEnvironment(config.id); @@ -131,20 +131,20 @@ watch( () => innerVisible.value, (val) => { - if (val && currentEnvConfig?.value.id) { - initEnvironment(currentEnvConfig.value.id); + if (val && appStore.currentEnvConfig?.id) { + initEnvironment(appStore.currentEnvConfig?.id); } } ); function searchDataSource() { - propsRes.value.data = cloneDeep(currentEnvConfig?.value.dataSources) as any[]; + propsRes.value.data = cloneDeep(appStore.currentEnvConfig?.dataSources) as any[]; if (keyword.value.trim() !== '') { - propsRes.value.data = currentEnvConfig?.value.dataSources.filter((e) => + propsRes.value.data = appStore.currentEnvConfig?.dataSources.filter((e) => e.dataSource.includes(keyword.value) ) as any[]; } else { - propsRes.value.data = cloneDeep(currentEnvConfig?.value.dataSources) as any[]; + propsRes.value.data = cloneDeep(appStore.currentEnvConfig?.dataSources) as any[]; } } diff --git a/frontend/src/views/api-test/components/requestComposition/index.vue b/frontend/src/views/api-test/components/requestComposition/index.vue index f79f3a25b0..cd1eefcf0b 100644 --- a/frontend/src/views/api-test/components/requestComposition/index.vue +++ b/frontend/src/views/api-test/components/requestComposition/index.vue @@ -530,7 +530,6 @@ isDefinition?: boolean; // 是否是接口定义模式 hideResponseLayoutSwitch?: boolean; // 是否隐藏响应体的布局切换 otherParams?: Record; // 保存请求时的其他参数 - currentEnvConfig?: EnvConfig; executeApi?: (params: ExecuteRequestParams) => Promise; // 执行接口 localExecuteApi?: (url: string, params: ExecuteRequestParams) => Promise; // 本地执行接口 createApi?: (...args) => Promise; // 创建接口 @@ -1147,7 +1146,7 @@ return { id: requestVModel.value.id.toString(), reportId: reportId.value, - environmentId: props.currentEnvConfig?.id || '', + environmentId: appStore.currentEnvConfig?.id || '', name: requestName, moduleId: requestModuleId, ...apiDefinitionParams, @@ -1517,7 +1516,7 @@ ...definitionParams, ...saveCaseModalForm.value, projectId: appStore.currentProjectId, - environmentId: props.currentEnvConfig?.id || '', + environmentId: appStore.currentEnvConfig?.id || '', apiDefinitionId: requestVModel.value.id, }; await addCase(params); diff --git a/frontend/src/views/api-test/management/components/management/api/apiTable.vue b/frontend/src/views/api-test/management/components/management/api/apiTable.vue index ad1365e734..0068cb534c 100644 --- a/frontend/src/views/api-test/management/components/management/api/apiTable.vue +++ b/frontend/src/views/api-test/management/components/management/api/apiTable.vue @@ -482,7 +482,7 @@ slotName: 'action', dataIndex: 'operation', fixed: 'right', - width: hasOperationPermission.value ? 220 : 50, + width: hasOperationPermission.value ? 200 : 50, }, ]; diff --git a/frontend/src/views/api-test/management/components/management/api/index.vue b/frontend/src/views/api-test/management/components/management/api/index.vue index 4128129c6c..f1be52ebd7 100644 --- a/frontend/src/views/api-test/management/components/management/api/index.vue +++ b/frontend/src/views/api-test/management/components/management/api/index.vue @@ -92,7 +92,6 @@ :file-save-as-source-id="activeApiTab.id" :file-module-options-api="getTransferOptions" :file-save-as-api="transferFile" - :current-env-config="currentEnvConfig" is-definition @add-done="handleAddDone" /> @@ -184,7 +183,6 @@ const { openModal } = useModal(); const refreshModuleTree: (() => Promise) | undefined = inject('refreshModuleTree'); - const currentEnvConfig = inject>('currentEnvConfig'); const apiTabs = defineModel('apiTabs', { required: true, }); diff --git a/frontend/src/views/api-test/management/components/management/case/caseDetail.vue b/frontend/src/views/api-test/management/components/management/case/caseDetail.vue index 1cdf406010..95aa85db93 100644 --- a/frontend/src/views/api-test/management/components/management/case/caseDetail.vue +++ b/frontend/src/views/api-test/management/components/management/case/caseDetail.vue @@ -3,7 +3,7 @@ - >(); - const currentEnvConfig = computed(() => environmentSelectRef.value?.currentEnvConfig); - onBeforeMount(() => { initMemberOptions(); initProtocolList(); @@ -322,7 +317,6 @@ ]); /** 向孙组件提供属性 */ - provide('currentEnvConfig', readonly(currentEnvConfig)); provide('defaultCaseParams', readonly(defaultCaseParams)); provide('protocols', readonly(protocols)); diff --git a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue index 611a35bd23..d107a75c2a 100644 --- a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue +++ b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue @@ -53,9 +53,9 @@ v-if="!props.step || props.step?.stepType === ScenarioStepType.CUSTOM_REQUEST" class="customApiDrawer-title-right flex items-center gap-[16px]" > - +
- {{ t('apiScenario.env', { name: currentEnvConfig?.name }) }} + {{ t('apiScenario.env', { name: appStore.currentEnvConfig?.name }) }}
@@ -397,7 +397,6 @@ RequestTaskResult, } from '@/models/apiTest/common'; import { ScenarioStepFileParams, ScenarioStepItem } from '@/models/apiTest/scenario'; - import { EnvConfig } from '@/models/projectManagement/environmental'; import { RequestAuthType, RequestBodyFormat, @@ -483,7 +482,6 @@ // 注入祖先组件提供的属性 const scenarioId = inject('scenarioId'); - const currentEnvConfig = inject>('currentEnvConfig'); const hasLocalExec = inject>('hasLocalExec'); const isPriorityLocalExec = inject>('isPriorityLocalExec'); @@ -578,7 +576,7 @@ const showEnvPrefix = computed( () => requestVModel.value.customizeRequestEnvEnable && - currentEnvConfig?.value.httpConfig.find((e) => e.type === 'NONE')?.url + appStore.currentEnvConfig?.httpConfig.find((e) => e.type === 'NONE')?.url ); const currentLoop = ref(1); const currentResponse = computed(() => { diff --git a/frontend/src/views/api-test/scenario/components/scenarioTable.vue b/frontend/src/views/api-test/scenario/components/scenarioTable.vue index a504ff39a5..05a533188d 100644 --- a/frontend/src/views/api-test/scenario/components/scenarioTable.vue +++ b/frontend/src/views/api-test/scenario/components/scenarioTable.vue @@ -876,7 +876,7 @@ slotName: 'operation', dataIndex: 'operation', fixed: 'right', - width: 220, + width: 200, }, ]; const { propsRes, propsEvent, loadList, setLoadListParams, resetSelector } = useTable( diff --git a/frontend/src/views/api-test/scenario/components/step/stepTree.vue b/frontend/src/views/api-test/scenario/components/step/stepTree.vue index 3be96ca697..2c84101ba3 100644 --- a/frontend/src/views/api-test/scenario/components/step/stepTree.vue +++ b/frontend/src/views/api-test/scenario/components/step/stepTree.vue @@ -615,7 +615,6 @@ }); // 没啥用,目前用来展示选中样式 const isPriorityLocalExec = inject>('isPriorityLocalExec'); const localExecuteUrl = inject>('localExecuteUrl'); - const currentEnvConfig = inject>('currentEnvConfig'); const permissionMap = { execute: 'PROJECT_API_SCENARIO:READ+EXECUTE', @@ -947,7 +946,7 @@ const params: AddApiCaseParams = { name: saveModalForm.value.name, projectId: appStore.currentProjectId, - environmentId: currentEnvConfig?.value.id || '', + environmentId: appStore.currentEnvConfig?.id || '', apiDefinitionId: id, request: { ...detail, @@ -992,7 +991,7 @@ status: RequestDefinitionStatus.PROCESSING, customFields: [], versionId: '', - environmentId: currentEnvConfig?.value.id || '', + environmentId: appStore.currentEnvConfig?.id || '', request: { ...detail, url: path, @@ -1085,7 +1084,7 @@ const fileParams = scenario.value.stepFileParam[activeStep.value.id]; const params: AddApiCaseParams = { projectId: appStore.currentProjectId, - environmentId: currentEnvConfig?.value.id || '', + environmentId: appStore.currentEnvConfig?.id || '', apiDefinitionId: activeStep.value.resourceId || '', request: detail, ...saveCaseModalForm.value, @@ -1432,7 +1431,7 @@ const res = await debugScenario({ id: scenario.value.id || '', grouped: false, - environmentId: currentEnvConfig?.value?.id || '', + environmentId: appStore.currentEnvConfig?.id || '', projectId: appStore.currentProjectId, scenarioConfig: scenario.value.scenarioConfig, frontendDebug: scenario.value.executeType === 'localExec', diff --git a/frontend/src/views/api-test/scenario/index.vue b/frontend/src/views/api-test/scenario/index.vue index 4b6f2fd3b8..22c77c17a3 100644 --- a/frontend/src/views/api-test/scenario/index.vue +++ b/frontend/src/views/api-test/scenario/index.vue @@ -17,10 +17,7 @@
- + (scenarioTabs.value[0] as ScenarioParams); - const currentEnvConfig = ref(); const executeButtonRef = ref>(); const websocketMap: Record = {}; @@ -441,7 +437,7 @@ scenarioTabs.value.push({ ...cloneDeep(defaultScenario), id: getGenerateId(), - environmentId: currentEnvConfig.value?.id || '', + environmentId: appStore.currentEnvConfig?.id || '', label: `${t('apiScenario.createScenario')}${scenarioTabs.value.length}`, moduleId: activeModule.value === 'all' ? 'root' : activeModule.value, projectId: appStore.currentProjectId, @@ -616,7 +612,6 @@ provide('isPriorityLocalExec', readonly(isPriorityLocalExec)); provide('hasLocalExec', readonly(hasLocalExec)); provide('localExecuteUrl', readonly(localExecuteUrl)); - provide('currentEnvConfig', readonly(currentEnvConfig)); provide('scenarioId', scenarioId); provide('scenarioExecuteLoading', scenarioExecuteLoading); provide('moduleTree', readonly(moduleTree)); diff --git a/frontend/src/views/case-management/caseManagementFeature/components/caseTable.vue b/frontend/src/views/case-management/caseManagementFeature/components/caseTable.vue index 0f2a4ff183..97624d9e31 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/caseTable.vue +++ b/frontend/src/views/case-management/caseManagementFeature/components/caseTable.vue @@ -699,7 +699,7 @@ fixed: 'right', showInTable: true, showDrag: false, - width: hasOperationPermission.value ? 200 : 50, + width: hasOperationPermission.value ? 130 : 50, }, ]; const platformInfo = ref>({}); diff --git a/frontend/src/views/project-management/environmental/components/envParams/preAndPost.vue b/frontend/src/views/project-management/environmental/components/envParams/preAndPost.vue index 6ed768e42b..a062ed7d9e 100644 --- a/frontend/src/views/project-management/environmental/components/envParams/preAndPost.vue +++ b/frontend/src/views/project-management/environmental/components/envParams/preAndPost.vue @@ -65,12 +65,9 @@ import PreTab from './PreTab.vue'; import { useI18n } from '@/hooks/useI18n'; - import useProjectEnvStore from '@/store/modules/setting/useProjectEnvStore'; import { EnvTabTypeEnum } from '@/enums/envEnum'; - const store = useProjectEnvStore(); - const { t } = useI18n(); const props = defineProps<{ @@ -109,14 +106,6 @@ }; } }); - - const currentEnvConfig = ref({}); - /** 向孙组件提供属性 */ - provide('currentEnvConfig', readonly(currentEnvConfig)); - - onBeforeMount(() => { - currentEnvConfig.value = store.currentEnvDetailInfo; - });