fix(项目管理): 修复环境管理相关bug

This commit is contained in:
xinxin.wu 2024-04-16 15:42:06 +08:00 committed by 刘瑞斌
parent b133d4a7ad
commit ff2bd397c8
11 changed files with 77 additions and 24 deletions

View File

@ -68,9 +68,10 @@ export const MEMBER = {
value: '', value: '',
options: [], options: [],
props: { props: {
multiple: false, 'multiple': false,
// 'placeholder': t('formCreate.PleaseSelect'), // 'placeholder': t('formCreate.PleaseSelect'),
modelValue: '', 'modelValue': '',
'allow-clear': true,
}, },
}; };
@ -81,10 +82,11 @@ export const MULTIPLE_MEMBER = {
value: [], value: [],
options: [], options: [],
props: { props: {
multiple: true, 'multiple': true,
// 'placeholder': t('formCreate.PleaseSelect'), // 'placeholder': t('formCreate.PleaseSelect'),
options: [], 'options': [],
modelValue: [], 'modelValue': [],
'allow-clear': true,
}, },
}; };

View File

@ -4,6 +4,7 @@
v-model:model-value="selectValue" v-model:model-value="selectValue"
:placeholder="t(props.placeholder || 'common.pleaseSelect')" :placeholder="t(props.placeholder || 'common.pleaseSelect')"
allow-search allow-search
allow-clear
:multiple="props.multiple" :multiple="props.multiple"
@search="searchHandler" @search="searchHandler"
> >

View File

@ -55,6 +55,14 @@ const envParamsDefaultConfig: EnvConfig = {
}, },
}; };
const defaultAllParams = {
projectId: '',
globalParams: {
headers: [],
commonVariables: [],
},
};
const useProjectEnvStore = defineStore( const useProjectEnvStore = defineStore(
'projectEnv', 'projectEnv',
() => { () => {
@ -75,7 +83,9 @@ const useProjectEnvStore = defineStore(
description: '', description: '',
config: cloneDeep(envParamsDefaultConfig), config: cloneDeep(envParamsDefaultConfig),
}); });
const allParamDetailInfo = ref<GlobalParams>(); // 全局参数详情 const allParamDetailInfo = ref<GlobalParams>(defaultAllParams); // 全局参数详情
const backupAllParamDetailInfo = ref<GlobalParams>(defaultAllParams);
const httpNoWarning = ref(true); const httpNoWarning = ref(true);
const getHttpNoWarning = computed(() => httpNoWarning.value); const getHttpNoWarning = computed(() => httpNoWarning.value);
@ -112,7 +122,11 @@ const useProjectEnvStore = defineStore(
config: cloneDeep(envParamsDefaultConfig), config: cloneDeep(envParamsDefaultConfig),
}; };
} else if (id === ALL_PARAM) { } else if (id === ALL_PARAM) {
allParamDetailInfo.value = await getGlobalParamDetail(appStore.currentProjectId); const res = await getGlobalParamDetail(appStore.currentProjectId);
allParamDetailInfo.value = cloneDeep(res || defaultAllParams);
nextTick(() => {
backupAllParamDetailInfo.value = cloneDeep(allParamDetailInfo.value);
});
} 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 };
@ -187,6 +201,7 @@ const useProjectEnvStore = defineStore(
setCurrentGroupId, setCurrentGroupId,
setHttpNoWarning, setHttpNoWarning,
setAllParamDetailInfo, setAllParamDetailInfo,
backupAllParamDetailInfo,
initEnvDetail, initEnvDetail,
initContentTabList, initContentTabList,
getContentTabList, getContentTabList,

View File

@ -185,7 +185,7 @@ export default {
'apiTestDebug.importByCURLTip': '支持快速导入 Chrome、Charles 或 Fiddler 等工具中的抓包数据', 'apiTestDebug.importByCURLTip': '支持快速导入 Chrome、Charles 或 Fiddler 等工具中的抓包数据',
'apiTestDebug.noPluginTip': '该插件已卸载,无法查看插件详情', 'apiTestDebug.noPluginTip': '该插件已卸载,无法查看插件详情',
'apiTestDebug.noPlugin': '插件已卸载', 'apiTestDebug.noPlugin': '插件已卸载',
'apiTestDebug.unsavedLeave': '有标签页的内容未保存,离开后未保存的内容将丢失,确定要离开吗?', 'apiTestDebug.unsavedLeave': '有标签页的内容未保存,离开后未保存的内容将丢失,确定要离开吗?',
'apiTestDebug.testSuccess': '测试成功', 'apiTestDebug.testSuccess': '测试成功',
'apiTestDebug.searchByDataBaseName': '按数据源名称搜索', 'apiTestDebug.searchByDataBaseName': '按数据源名称搜索',
'apiTestDebug.regexMatchRules': '表达式匹配规则', 'apiTestDebug.regexMatchRules': '表达式匹配规则',

View File

@ -28,7 +28,7 @@
</a-checkbox> </a-checkbox>
</a-checkbox-group> </a-checkbox-group>
</div> </div>
<div v-if="props.mode === 'remote'" class="min-h-[100px] w-[200px] p-4"> <div v-if="props.mode === 'remote'" class="w-[200px] p-4 pb-0">
<MsUserSelector <MsUserSelector
v-model="innerStatusFilters" v-model="innerStatusFilters"
:load-option-params="props.loadOptionParams" :load-option-params="props.loadOptionParams"

View File

@ -19,6 +19,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
import { cloneDeep } from 'lodash-es';
import RequestHeader from './requestHeader/index.vue'; import RequestHeader from './requestHeader/index.vue';
@ -34,7 +35,6 @@
const appStore = useAppStore(); const appStore = useAppStore();
const activeKey = ref('requestHeader'); const activeKey = ref('requestHeader');
const headerParams = ref<EnvConfigItem[]>([]);
const GlobalVariable = ref<EnvConfigItem[]>([]); const GlobalVariable = ref<EnvConfigItem[]>([]);
const { t } = useI18n(); const { t } = useI18n();
const { setIsSave } = useLeaveUnSaveTip(); const { setIsSave } = useLeaveUnSaveTip();
@ -54,25 +54,35 @@
}, },
]; ];
function initEnvDetail() { const headerParams = computed({
projectEnvStore.initEnvDetail().then(() => { get() {
headerParams.value = projectEnvStore.allParamDetailInfo?.globalParams.headers || []; return projectEnvStore.allParamDetailInfo?.globalParams.headers || [];
GlobalVariable.value = projectEnvStore.allParamDetailInfo?.globalParams.commonVariables || []; },
set(val) {
projectEnvStore.allParamDetailInfo.globalParams.headers = val;
},
}); });
function initEnvDetail() {
projectEnvStore.initEnvDetail();
headerParams.value = projectEnvStore.allParamDetailInfo.globalParams.headers || [];
} }
function change() { function change() {
canSave.value = true; canSave.value = true;
projectEnvStore.allParamDetailInfo.globalParams.headers = cloneDeep(headerParams.value);
setIsSave(false); setIsSave(false);
} }
const handleSave = async () => { const handleSave = async () => {
try { try {
loading.value = true; loading.value = true;
const headerParamsFilter = headerParams.value.filter((item) => item.key);
const params = { const params = {
id: projectEnvStore.allParamDetailInfo?.id, id: projectEnvStore.allParamDetailInfo?.id,
projectId: appStore.currentProjectId, projectId: appStore.currentProjectId,
globalParams: { globalParams: {
headers: headerParams.value, headers: headerParamsFilter,
commonVariables: GlobalVariable.value.map((item) => { commonVariables: GlobalVariable.value.map((item) => {
return { return {
key: item.key, key: item.key,

View File

@ -5,7 +5,13 @@
</a-tabs> </a-tabs>
<a-divider margin="0"></a-divider> <a-divider margin="0"></a-divider>
<div v-if="activeTab === 'scenarioProcessorConfig'" class="h-[calc(100vh - 100px)] mt-4"> <div v-if="activeTab === 'scenarioProcessorConfig'" class="h-[calc(100vh - 100px)] mt-4">
<a-alert class="mb-4" closable> {{ t('project.environmental.sceneAlertDesc') }} </a-alert> <a-alert class="mb-4" closable>
{{
props.activeType === EnvTabTypeEnum.ENVIRONMENT_PRE
? t('project.environmental.scenePreAlertDesc')
: t('project.environmental.scenePostAlertDesc')
}}
</a-alert>
<a-scrollbar <a-scrollbar
:style="{ :style="{
overflow: 'auto', overflow: 'auto',
@ -27,7 +33,13 @@
</a-scrollbar> </a-scrollbar>
</div> </div>
<div v-if="activeTab === 'requestProcessorConfig'" class="mt-4 h-full"> <div v-if="activeTab === 'requestProcessorConfig'" class="mt-4 h-full">
<a-alert class="mb-4" closable> {{ t('project.environmental.requestAlertDesc') }} </a-alert> <a-alert class="mb-4" closable>
{{
props.activeType === EnvTabTypeEnum.ENVIRONMENT_PRE
? t('project.environmental.requestPreAlertDesc')
: t('project.environmental.requestPostAlertDesc')
}}
</a-alert>
<PreTab <PreTab
v-if="props.activeType === EnvTabTypeEnum.ENVIRONMENT_PRE" v-if="props.activeType === EnvTabTypeEnum.ENVIRONMENT_PRE"
:show-associated-scene="showAssociatedScene" :show-associated-scene="showAssociatedScene"

View File

@ -646,7 +646,11 @@
store.setCurrentId(id); store.setCurrentId(id);
return; return;
} }
if (isEqual(store.currentEnvDetailInfo, store.backupEnvDetailInfo)) { const isChangeEnvValue =
store.currentId === ALL_PARAM
? isEqual(store.allParamDetailInfo, store.backupAllParamDetailInfo)
: isEqual(store.currentEnvDetailInfo, store.backupEnvDetailInfo);
if (isChangeEnvValue) {
store.setCurrentId(id); store.setCurrentId(id);
} else { } else {
// tab // tab

View File

@ -31,10 +31,14 @@ export default {
'project.environmental.TCP': 'TCP', 'project.environmental.TCP': 'TCP',
'project.environmental.pre': 'Pre', 'project.environmental.pre': 'Pre',
'project.environmental.post': 'Post', 'project.environmental.post': 'Post',
'project.environmental.sceneAlertDesc': 'project.environmental.scenePreAlertDesc':
'Perform this operation once before scenario execution, such as obtaining a token and scenario initialization', 'Perform this operation once before scenario execution, such as obtaining a token and scenario initialization',
'project.environmental.requestAlertDesc': 'project.environmental.scenePostAlertDesc':
'Perform this operation once after scenario execution, such as obtaining a token and scenario initialization',
'project.environmental.requestPreAlertDesc':
'Each API step is executed once before execution, such as request content encryption', 'Each API step is executed once before execution, such as request content encryption',
'project.environmental.requestPostAlertDesc':
'Each API step is executed once after execution, such as request content encryption',
'project.environmental.host': 'Host', 'project.environmental.host': 'Host',
'project.environmental.assert': 'Assertion', 'project.environmental.assert': 'Assertion',
'project.environmental.displaySetting': 'Display Setting', 'project.environmental.displaySetting': 'Display Setting',

View File

@ -38,8 +38,10 @@ export default {
'project.environmental.database': '数据库', 'project.environmental.database': '数据库',
'project.environmental.pre': '前置', 'project.environmental.pre': '前置',
'project.environmental.post': '后置', 'project.environmental.post': '后置',
'project.environmental.sceneAlertDesc': '场景执行前执行一次如token获取及场景初始化', 'project.environmental.scenePreAlertDesc': '场景执行前执行一次如token获取及场景初始化',
'project.environmental.requestAlertDesc': '每一个API步骤执行前均执行一次如请求内容加密', 'project.environmental.scenePostAlertDesc': '场景执行后执行一次如token获取及场景初始化',
'project.environmental.requestPreAlertDesc': '每一个API步骤执行前均执行一次如请求内容加密',
'project.environmental.requestPostAlertDesc': '每一个API步骤执行后均执行一次如请求内容加密',
'project.environmental.host': '域名', 'project.environmental.host': '域名',
'project.environmental.assert': '断言', 'project.environmental.assert': '断言',
'project.environmental.displaySetting': '显示设置', 'project.environmental.displaySetting': '显示设置',

View File

@ -375,7 +375,7 @@
} }
function changeHandler(value: string, api: any) { function changeHandler(value: string, api: any) {
api.validateField(value); api?.validateField(value);
} }
// //
@ -539,7 +539,10 @@
const confirmHandler = (dataList: DefinedFieldItem[]) => { const confirmHandler = (dataList: DefinedFieldItem[]) => {
const selectFieldIds = selectData.value.map((e) => e.id); const selectFieldIds = selectData.value.map((e) => e.id);
const newData = dataList.filter((item) => !selectFieldIds.includes(item.id)); const newData = dataList.filter((item) => !selectFieldIds.includes(item.id));
selectData.value = [...selectData.value, ...newData]; const newIds = dataList.map((item) => item.id);
// @desc value
const selectDataValue = selectData.value.filter((item) => newIds.includes(item.id));
selectData.value = [...selectDataValue, ...newData];
}; };
function changeState(value: boolean | (string | number | boolean)[], formItem) { function changeState(value: boolean | (string | number | boolean)[], formItem) {