feat(项目管理): 优化环境复制
This commit is contained in:
parent
629d402915
commit
6eb0a3ac1b
|
@ -197,26 +197,7 @@
|
|||
: isEqual(store.currentEnvDetailInfo, store.backupEnvDetailInfo);
|
||||
});
|
||||
|
||||
// 初始化插件
|
||||
const initPlugin = async () => {
|
||||
try {
|
||||
envPluginList.value = await getEnvPlugin(appStore.currentProjectId);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
await initPlugin();
|
||||
await store.initContentTabList([...sourceTabList, ...pluginTabList.value, ...settingList]);
|
||||
contentTabList.value = ((await store.getContentTabList()) || []).filter((item) => item.isShow);
|
||||
// 插件状态存储
|
||||
|
||||
const handleReset = () => {
|
||||
envForm.value?.resetFields();
|
||||
emit('resetEnv');
|
||||
};
|
||||
|
||||
function getParameters() {
|
||||
function getParameters(isNew = false) {
|
||||
const paramsConfig = cloneDeep(store.currentEnvDetailInfo.config);
|
||||
|
||||
const httpConfigList = paramsConfig.httpConfig.map((e) => {
|
||||
|
@ -225,6 +206,12 @@
|
|||
headers: filterKeyValParams(e.headers, defaultHeaderParamsItem, true).validParams,
|
||||
};
|
||||
});
|
||||
if (isNew) {
|
||||
store.currentEnvDetailInfo.name = store.currentEnvDetailInfo.name
|
||||
? store.currentEnvDetailInfo.name
|
||||
: t('project.environmental.newEnv');
|
||||
}
|
||||
|
||||
return {
|
||||
...cloneDeep(store.currentEnvDetailInfo),
|
||||
config: {
|
||||
|
@ -234,11 +221,14 @@
|
|||
};
|
||||
}
|
||||
|
||||
const saveCallBack = async () => {
|
||||
const saveCallBack = async (isNew = false) => {
|
||||
// 校验通过回调保存
|
||||
loading.value = true;
|
||||
store.currentEnvDetailInfo.mock = true;
|
||||
await updateOrAddEnv({ fileList: [], request: getParameters() });
|
||||
await updateOrAddEnv({
|
||||
fileList: [],
|
||||
request: getParameters(isNew),
|
||||
});
|
||||
setIsSave(true);
|
||||
loading.value = false;
|
||||
Message.success(store.currentEnvDetailInfo.id ? t('common.updateSuccess') : t('common.saveSuccess'));
|
||||
|
@ -265,6 +255,29 @@
|
|||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
saveCallBack,
|
||||
});
|
||||
|
||||
// 初始化插件
|
||||
const initPlugin = async () => {
|
||||
try {
|
||||
envPluginList.value = await getEnvPlugin(appStore.currentProjectId);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
await initPlugin();
|
||||
await store.initContentTabList([...sourceTabList, ...pluginTabList.value, ...settingList]);
|
||||
contentTabList.value = ((await store.getContentTabList()) || []).filter((item) => item.isShow);
|
||||
// 插件状态存储
|
||||
|
||||
const handleReset = () => {
|
||||
envForm.value?.resetFields();
|
||||
emit('resetEnv');
|
||||
};
|
||||
|
||||
watchEffect(() => {
|
||||
if (store.currentId) {
|
||||
store.initEnvDetail();
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<MsButton
|
||||
v-permission="['PROJECT_ENVIRONMENT:READ+ADD']"
|
||||
type="icon"
|
||||
:disabled="!!hasUnSaveData"
|
||||
class="!mr-0 p-[2px]"
|
||||
@click="handleCreateEnv"
|
||||
>
|
||||
|
@ -107,13 +108,16 @@
|
|||
>
|
||||
<div class="flex flex-row items-center gap-[8px]">
|
||||
<icon-drag-dot-vertical
|
||||
v-permission="['PROJECT_ENVIRONMENT:READ+UPDATE']"
|
||||
v-if="
|
||||
hasAnyPermission(['PROJECT_ENVIRONMENT:READ+UPDATE']) &&
|
||||
!excludeActionType.includes(element.id)
|
||||
"
|
||||
class="drag-handle env-item-drag-icon"
|
||||
/>
|
||||
<MsMoreAction
|
||||
v-permission="['PROJECT_ENVIRONMENT:READ+DELETE', 'PROJECT_ENVIRONMENT:READ+EXPORT']"
|
||||
trigger="click"
|
||||
:list="envMoreAction(element.mock || false)"
|
||||
:list="envMoreAction(element)"
|
||||
@select="
|
||||
(value) => handleMoreAction(value, element.id, EnvAuthTypeEnum.ENVIRONMENT_PARAM)
|
||||
"
|
||||
|
@ -219,6 +223,7 @@
|
|||
<!-- 环境变量 -->
|
||||
<EnvParamBox
|
||||
v-else-if="showType === 'PROJECT' && activeKey !== ALL_PARAM"
|
||||
ref="envParamBoxRef"
|
||||
@reset-env="resetHandler"
|
||||
@ok="successHandler"
|
||||
/>
|
||||
|
@ -331,34 +336,40 @@
|
|||
const exportOptionData = ref<MsExportDrawerMap>({
|
||||
systemColumns: {},
|
||||
});
|
||||
const excludeActionType = [NEW_ENV_PARAM_COPY, NEW_ENV_PARAM];
|
||||
|
||||
// 默认环境MoreAction
|
||||
const envMoreAction = (isMock: boolean | undefined) => {
|
||||
const envMoreAction = (item: EnvListItem) => {
|
||||
const allowAction = excludeActionType.includes(item.id)
|
||||
? []
|
||||
: [
|
||||
{
|
||||
label: t('common.rename'),
|
||||
eventTag: 'rename',
|
||||
disabled: item.mock || false,
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+UPDATE'],
|
||||
},
|
||||
{
|
||||
label: t('common.copy'),
|
||||
eventTag: 'copy',
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+ADD'],
|
||||
},
|
||||
{
|
||||
label: t('common.export'),
|
||||
eventTag: 'export',
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+EXPORT'],
|
||||
},
|
||||
{
|
||||
isDivider: true,
|
||||
},
|
||||
];
|
||||
return [
|
||||
{
|
||||
label: t('common.rename'),
|
||||
eventTag: 'rename',
|
||||
disabled: isMock,
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+UPDATE'],
|
||||
},
|
||||
{
|
||||
label: t('common.copy'),
|
||||
eventTag: 'copy',
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+ADD'],
|
||||
},
|
||||
{
|
||||
label: t('common.export'),
|
||||
eventTag: 'export',
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+EXPORT'],
|
||||
},
|
||||
{
|
||||
isDivider: true,
|
||||
},
|
||||
...allowAction,
|
||||
{
|
||||
label: t('common.delete'),
|
||||
danger: true,
|
||||
eventTag: 'delete',
|
||||
disabled: isMock,
|
||||
disabled: item.mock || false,
|
||||
permission: ['PROJECT_ENVIRONMENT:READ+DELETE'],
|
||||
},
|
||||
];
|
||||
|
@ -439,21 +450,6 @@
|
|||
importVisible.value = true;
|
||||
importAuthType.value = EnvAuthTypeEnum.ENVIRONMENT;
|
||||
};
|
||||
|
||||
// 创建环境变量
|
||||
const handleCreateEnv = () => {
|
||||
const tmpArr = envList.value;
|
||||
const unSaveEnv = envList.value.filter((item) => item.id === NEW_ENV_PARAM).length < 1;
|
||||
if (unSaveEnv) {
|
||||
tmpArr.unshift({
|
||||
id: NEW_ENV_PARAM,
|
||||
name: t('project.environmental.newEnv'),
|
||||
description: '',
|
||||
});
|
||||
store.setCurrentId(NEW_ENV_PARAM);
|
||||
envList.value = tmpArr;
|
||||
}
|
||||
};
|
||||
// 创建环境组
|
||||
const handleCreateGroup = () => {
|
||||
const tmpArr = evnGroupList.value;
|
||||
|
@ -641,7 +637,7 @@
|
|||
store.initEnvDetail();
|
||||
}
|
||||
|
||||
const envGroupBoxRef = ref();
|
||||
const envGroupBoxRef = ref<InstanceType<typeof EnvGroupBox>>();
|
||||
|
||||
const handleRenameCancelGroup = async (element: EnvListItem) => {
|
||||
groupPopVisible.value[element.id].visible = false;
|
||||
|
@ -649,10 +645,54 @@
|
|||
|
||||
const envSuccessCroupHandler = async (element: EnvListItem) => {
|
||||
await initGroupList();
|
||||
envGroupBoxRef.value.initDetail(element.id);
|
||||
envGroupBoxRef.value?.initDetail(element.id);
|
||||
};
|
||||
|
||||
const envParamBoxRef = ref<InstanceType<typeof EnvParamBox>>();
|
||||
function openModalTip(id: string, isNew = false) {
|
||||
const tipContent = isNew ? t('project.environmental.env.existNewEnvTip') : t('apiTestDebug.unsavedLeave');
|
||||
const confirmText = isNew ? t('common.save') : t('common.stay');
|
||||
openModal({
|
||||
type: 'warning',
|
||||
title: t('common.tip'),
|
||||
content: tipContent,
|
||||
hideCancel: isNew,
|
||||
okText: confirmText,
|
||||
onBeforeOk: async () => {
|
||||
if (isNew) {
|
||||
try {
|
||||
const isNewEnv = envList.value.some((item) => item.id === NEW_ENV_PARAM);
|
||||
await envParamBoxRef.value?.saveCallBack(isNewEnv);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
}
|
||||
} else {
|
||||
store.setCurrentId(id);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const hasUnSaveData = computed(() => envList.value.find((item) => excludeActionType.includes(item.id)));
|
||||
|
||||
const handleListItemClickGroup = (element: EnvListItem) => {
|
||||
const { id } = element;
|
||||
store.setCurrentGroupId(id);
|
||||
};
|
||||
|
||||
function checkHasNewEnv() {
|
||||
if (hasUnSaveData.value) {
|
||||
openModalTip(hasUnSaveData.value.id, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const handleListItemClick = (element: EnvListItem) => {
|
||||
if (checkHasNewEnv()) {
|
||||
return;
|
||||
}
|
||||
const { id } = element;
|
||||
// 校验是否切换
|
||||
if (store.currentId !== id) {
|
||||
|
@ -666,30 +706,34 @@
|
|||
: isEqual(store.currentEnvDetailInfo, store.backupEnvDetailInfo);
|
||||
if (isChangeEnvValue) {
|
||||
store.setCurrentId(id);
|
||||
} else if (hasUnSaveData.value) {
|
||||
openModalTip(id, true);
|
||||
} else {
|
||||
// 如果有未保存的tab则提示用户
|
||||
openModal({
|
||||
type: 'warning',
|
||||
title: t('common.tip'),
|
||||
content: t('apiTestDebug.unsavedLeave'),
|
||||
hideCancel: false,
|
||||
cancelText: t('common.stay'),
|
||||
okText: t('common.leave'),
|
||||
onBeforeOk: async () => {
|
||||
store.setCurrentId(id);
|
||||
},
|
||||
});
|
||||
openModalTip(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleListItemClickGroup = (element: EnvListItem) => {
|
||||
const { id } = element;
|
||||
store.setCurrentGroupId(id);
|
||||
// 创建环境变量
|
||||
const handleCreateEnv = () => {
|
||||
const tmpArr = envList.value;
|
||||
const unSaveEnv = envList.value.filter((item) => item.id === NEW_ENV_PARAM).length < 1;
|
||||
if (unSaveEnv) {
|
||||
tmpArr.unshift({
|
||||
id: NEW_ENV_PARAM,
|
||||
name: t('project.environmental.newEnv'),
|
||||
description: '',
|
||||
});
|
||||
store.setCurrentId(NEW_ENV_PARAM);
|
||||
envList.value = tmpArr;
|
||||
}
|
||||
};
|
||||
|
||||
// 复制
|
||||
function copyEnvHandler(id: string) {
|
||||
if (checkHasNewEnv()) {
|
||||
return;
|
||||
}
|
||||
const currentItem = envList.value.find((item) => item.id === id);
|
||||
const tmpArr = envList.value;
|
||||
if (currentItem) {
|
||||
|
|
|
@ -131,4 +131,5 @@ export default {
|
|||
'project.environmental.http.selectModule': 'Please select module',
|
||||
'script.delete.confirm': 'After deletion, it cannot be restored. Please exercise caution.',
|
||||
'script.delete.scenario': 'scenario',
|
||||
'project.environmental.env.existNewEnvTip': 'The new environment is not save, save?',
|
||||
};
|
||||
|
|
|
@ -131,4 +131,5 @@ export default {
|
|||
'project.environmental.http.noneDataExist': '已存在启用范围为无的域名!',
|
||||
'project.environmental.http.selectModule': '请选择模块',
|
||||
'script.delete.confirm': '删除后无法恢复, 请谨慎操作!',
|
||||
'project.environmental.env.existNewEnvTip': '当前新增环境未保存,是否保存?',
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue