fix(项目管理): 环境参数和切换问题

This commit is contained in:
xinxin.wu 2024-03-04 19:48:44 +08:00 committed by Craftsman
parent 4c653d7eba
commit abcdecb5e2
6 changed files with 45 additions and 31 deletions

View File

@ -41,8 +41,14 @@ export interface ProcessorConfig {
export interface AssertionConfig { export interface AssertionConfig {
assertions: EnvConfigItem[]; assertions: EnvConfigItem[];
} }
export interface CommonParams {
requestTimeout: number;
responseTimeout: number;
[key: string]: any;
}
export interface EnvConfig { export interface EnvConfig {
commonParams?: EnvConfigItem; commonParams?: CommonParams;
commonVariables: EnvConfigItem[]; commonVariables: EnvConfigItem[];
httpConfig: EnvConfigItem[]; httpConfig: EnvConfigItem[];
dataSources: DataSourceItem[]; dataSources: DataSourceItem[];

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { number } from 'echarts';
import localforage from 'localforage'; import localforage from 'localforage';
import { getDetailEnv, getGlobalParamDetail } from '@/api/modules/project-management/envManagement'; import { getDetailEnv, getGlobalParamDetail } from '@/api/modules/project-management/envManagement';
@ -45,6 +46,10 @@ const envParamsDefaultConfig: EnvConfig = {
}, },
assertionConfig: { assertions: [] }, assertionConfig: { assertions: [] },
pluginConfigMap: {}, pluginConfigMap: {},
commonParams: {
requestTimeout: 60000,
responseTimeout: 60000,
},
}; };
const useProjectEnvStore = defineStore( const useProjectEnvStore = defineStore(
@ -92,7 +97,6 @@ const useProjectEnvStore = defineStore(
const appStore = useAppStore(); const appStore = useAppStore();
try { try {
if (id === NEW_ENV_PARAM) { if (id === NEW_ENV_PARAM) {
// TODO 数据参数问题
currentEnvDetailInfo.value = { currentEnvDetailInfo.value = {
projectId: appStore.currentProjectId, projectId: appStore.currentProjectId,
name: '', name: '',
@ -107,7 +111,7 @@ const useProjectEnvStore = defineStore(
allParamDetailInfo.value = await getGlobalParamDetail(appStore.currentProjectId); allParamDetailInfo.value = await getGlobalParamDetail(appStore.currentProjectId);
} else if (id !== ALL_PARAM && id) { } else if (id !== ALL_PARAM && id) {
const tmpObj = await getDetailEnv(id); const tmpObj = await getDetailEnv(id);
currentEnvDetailInfo.value = tmpObj; currentEnvDetailInfo.value = { ...tmpObj };
backupEnvDetailInfo.value = tmpObj; backupEnvDetailInfo.value = tmpObj;
} }
} catch (e) { } catch (e) {

View File

@ -60,7 +60,7 @@
<div class="footer" :style="{ width: '100%' }"> <div class="footer" :style="{ width: '100%' }">
<a-button @click="handleReset">{{ t('common.cancel') }}</a-button> <a-button @click="handleReset">{{ t('common.cancel') }}</a-button>
<a-button :disabled="!canSave" type="primary" @click="handleSave">{{ t('common.save') }}</a-button> <a-button type="primary" :loading="loading" @click="handleSave">{{ t('common.save') }}</a-button>
</div> </div>
</div> </div>
<TabSettingDrawer v-model:visible="tabSettingVisible" @init-data="initTab" /> <TabSettingDrawer v-model:visible="tabSettingVisible" @init-data="initTab" />
@ -93,7 +93,6 @@
const activeKey = ref('envParams'); const activeKey = ref('envParams');
const envForm = ref(); const envForm = ref();
const canSave = ref(false);
const { t } = useI18n(); const { t } = useI18n();
const loading = ref(false); const loading = ref(false);
const tabSettingVisible = ref(false); const tabSettingVisible = ref(false);
@ -179,15 +178,14 @@
envForm.value?.resetFields(); envForm.value?.resetFields();
store.initEnvDetail(); store.initEnvDetail();
}; };
const handleSave = async () => { const handleSave = async () => {
await envForm.value?.validate(async (valid) => { await envForm.value?.validate(async (valid) => {
if (!valid) { if (!valid) {
try { try {
loading.value = true; loading.value = true;
store.currentEnvDetailInfo.mock = true; store.currentEnvDetailInfo.mock = true;
// TODO await updateOrAddEnv({ fileList: [], request: store.currentEnvDetailInfo });
const res = await updateOrAddEnv({ fileList: [], request: store.currentEnvDetailInfo });
store.currentEnvDetailInfo = res;
Message.success(t('common.saveSuccess')); Message.success(t('common.saveSuccess'));
emit('ok'); emit('ok');
} catch (error) { } catch (error) {
@ -212,12 +210,13 @@
form.description = currentEnvDetailInfo.description as string; form.description = currentEnvDetailInfo.description as string;
} }
}); });
watchEffect(() => {
if (store.currentEnvDetailInfo) { // watchEffect(() => {
const { currentEnvDetailInfo, backupEnvDetailInfo } = store; // if (store.currentEnvDetailInfo) {
canSave.value = !isEqual(currentEnvDetailInfo, backupEnvDetailInfo); // const { currentEnvDetailInfo, backupEnvDetailInfo } = store;
} // canSave.value = !isEqual(currentEnvDetailInfo, backupEnvDetailInfo);
}); // }
// });
const initTab = async () => { const initTab = async () => {
tabSettingVisible.value = false; tabSettingVisible.value = false;

View File

@ -15,7 +15,7 @@
set: (value: any) => { set: (value: any) => {
store.currentEnvDetailInfo.config.commonVariables = value; store.currentEnvDetailInfo.config.commonVariables = value;
}, },
get: () => store.currentEnvDetailInfo.config.commonVariables || [], get: () => store.currentEnvDetailInfo.config?.commonVariables || [],
}); });
</script> </script>

View File

@ -8,12 +8,12 @@
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<a-button type="outline" @click="handleAddHttp">{{ t('project.environmental.addHttp') }}</a-button> <a-button type="outline" @click="handleAddHttp">{{ t('project.environmental.addHttp') }}</a-button>
<div class="flex flex-row gap-[8px]"> <div class="flex flex-row gap-[8px]">
<a-input-number v-model:model-value="form.linkOutTime" class="w-[180px]"> <a-input-number v-model:model-value="form.requestTimeout" class="w-[180px]">
<template #prefix> <template #prefix>
<span class="text-[var(--color-text-3)]">{{ t('project.environmental.http.linkTimeOut') }}</span> <span class="text-[var(--color-text-3)]">{{ t('project.environmental.http.linkTimeOut') }}</span>
</template> </template>
</a-input-number> </a-input-number>
<a-input-number v-model:model-value="form.timeOutTime" class="w-[180px]"> <a-input-number v-model:model-value="form.responseTimeout" class="w-[180px]">
<template #prefix> <template #prefix>
<span class="text-[var(--color-text-3)]">{{ t('project.environmental.http.linkTimeOut') }}</span> <span class="text-[var(--color-text-3)]">{{ t('project.environmental.http.linkTimeOut') }}</span>
</template> </template>
@ -58,6 +58,7 @@
import useProjectEnvStore from '@/store/modules/setting/useProjectEnvStore'; import useProjectEnvStore from '@/store/modules/setting/useProjectEnvStore';
import { BugListItem } from '@/models/bug-management'; import { BugListItem } from '@/models/bug-management';
import type { CommonParams } from '@/models/projectManagement/environmental';
import { HttpForm } from '@/models/projectManagement/environmental'; import { HttpForm } from '@/models/projectManagement/environmental';
import { TableKeyEnum } from '@/enums/tableEnum'; import { TableKeyEnum } from '@/enums/tableEnum';
@ -123,12 +124,6 @@
debug: true, debug: true,
}); });
const form = reactive({
linkOutTime: 60000,
timeOutTime: 60000,
authType: 'Basic Auth',
});
const moreActionList: ActionsItem[] = [ const moreActionList: ActionsItem[] = [
{ {
label: t('common.delete'), label: t('common.delete'),
@ -175,9 +170,17 @@
const handleNoWarning = () => { const handleNoWarning = () => {
store.setHttpNoWarning(false); store.setHttpNoWarning(false);
}; };
watch(store.currentEnvDetailInfo.config.httpConfig, () => { watch(store.currentEnvDetailInfo.config.httpConfig, () => {
propsRes.value.data = store.currentEnvDetailInfo.config.httpConfig; propsRes.value.data = store.currentEnvDetailInfo.config.httpConfig;
}); });
const form = computed({
set: (value: any) => {
store.currentEnvDetailInfo.config.commonParams = { ...value };
},
get: () => store.currentEnvDetailInfo.config.commonParams as CommonParams,
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -371,9 +371,12 @@
store.setCurrentGroupId(NEW_ENV_GROUP); store.setCurrentGroupId(NEW_ENV_GROUP);
evnGroupList.value = tmpArr; evnGroupList.value = tmpArr;
}; };
const initGroupList = async (keywordStr = '') => { const initGroupList = async (keywordStr = '', initNode = false) => {
try { try {
evnGroupList.value = await groupListEnv({ projectId: appStore.currentProjectId, keyword: keywordStr }); evnGroupList.value = await groupListEnv({ projectId: appStore.currentProjectId, keyword: keywordStr });
if (initNode && evnGroupList.value.length) {
store.setCurrentGroupId(evnGroupList.value[0].id);
}
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -386,11 +389,14 @@
store.setCurrentGroupId(id); store.setCurrentGroupId(id);
}; };
const initData = async (keywordStr = '') => { const initData = async (keywordStr = '', initNode = false) => {
try { try {
envList.value = await listEnv({ projectId: appStore.currentProjectId, keyword: keywordStr }); envList.value = await listEnv({ projectId: appStore.currentProjectId, keyword: keywordStr });
if (initNode && envList.value.length) {
store.setCurrentId(envList.value[0].id);
}
if (showType.value === 'PROJECT_GROUP') { if (showType.value === 'PROJECT_GROUP') {
initGroupList(keywordStr); initGroupList(keywordStr, initNode);
} }
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@ -418,24 +424,20 @@
if (envList.value[_newIndex + 1].id) { if (envList.value[_newIndex + 1].id) {
params.moveMode = 'BEFORE'; params.moveMode = 'BEFORE';
params.moveId = envList.value[_newIndex + 1].id; params.moveId = envList.value[_newIndex + 1].id;
return;
} }
if (envList.value[_newIndex - 1].id) { if (envList.value[_newIndex - 1].id) {
params.moveMode = 'AFTER'; params.moveMode = 'AFTER';
params.moveId = envList.value[_newIndex - 1].id; params.moveId = envList.value[_newIndex - 1].id;
return;
} }
} }
if (type === EnvAuthTypeEnum.ENVIRONMENT_GROUP) { if (type === EnvAuthTypeEnum.ENVIRONMENT_GROUP) {
if (evnGroupList.value[_newIndex + 1].id) { if (evnGroupList.value[_newIndex + 1].id) {
params.moveMode = 'AFTER'; params.moveMode = 'AFTER';
params.moveId = evnGroupList.value[_newIndex + 1].id; params.moveId = evnGroupList.value[_newIndex + 1].id;
return;
} }
if (evnGroupList.value[_newIndex - 1].id) { if (evnGroupList.value[_newIndex - 1].id) {
params.moveMode = 'BEFORE'; params.moveMode = 'BEFORE';
params.moveId = evnGroupList.value[_newIndex - 1].id; params.moveId = evnGroupList.value[_newIndex - 1].id;
return;
} }
} }
@ -545,7 +547,7 @@
} }
}; };
onMounted(() => { onMounted(() => {
initData(); initData(keyword.value, true);
}); });
</script> </script>