refactor(通用功能): 优化删除环境的提示信息

--bug=1025998 --user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001025998
This commit is contained in:
guoyuqi 2023-05-05 19:42:32 +08:00 committed by fit2-zhao
parent 306c46d22d
commit 15ba756a7c
8 changed files with 65 additions and 79 deletions

View File

@ -15,21 +15,6 @@
</environment-edit> </environment-edit>
</el-container> </el-container>
</el-dialog> </el-dialog>
<el-dialog
:visible.sync="delDialogVisible"
append-to-body
width="30%">
<span style="color: #de9d1c; font-size: 18px;padding-right: 5px">
<i class="el-icon-warning"/>
</span>
<span style="font-size: 18px">
{{ $t('commons.confirm_delete') + currentEnvironment.name }}
</span>
<span slot="footer" class="dialog-footer">
<el-button @click="delDialogVisible = false">{{ $t('commons.cancel') }}</el-button>
<el-button type="primary" @click="delEnvironment">{{ $t('commons.confirm') }}</el-button>
</span>
</el-dialog>
</div> </div>
</template> </template>
@ -78,7 +63,6 @@ export default {
], ],
selectEnvironmentId: '', selectEnvironmentId: '',
ifCreate: false, // ifCreate: false, //
delDialogVisible: false,
currentIndex: -1, currentIndex: -1,
isCopy: false isCopy: false
} }
@ -134,7 +118,7 @@ export default {
listenGoBack(this.close); listenGoBack(this.close);
}, },
deleteEnvironment(environment, index) { deleteEnvironment(environment, index) {
this.$alert(this.$t('commons.confirm_delete') + environment.name, '', { this.$alert(this.$t('commons.delete') + "(" + environment.name + ")" + this.$t('project.del_env_tip'), '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
callback: (action) => { callback: (action) => {
@ -143,11 +127,9 @@ export default {
this.result = delApiEnvironment(environment.id).then(() => { this.result = delApiEnvironment(environment.id).then(() => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.getEnvironments(); this.getEnvironments();
this.delDialogVisible = false;
}); });
} else { } else {
this.environments.splice(index, 1); this.environments.splice(index, 1);
this.delDialogVisible = false;
} }
} }
} }
@ -258,7 +240,6 @@ export default {
openDelEnv(environment, index) { openDelEnv(environment, index) {
this.currentEnvironment = environment; this.currentEnvironment = environment;
this.currentIndex = index; this.currentIndex = index;
this.delDialogVisible = true
}, },
delEnvironment() { delEnvironment() {
this.deleteEnvironment(this.currentEnvironment, this.currentIndex) this.deleteEnvironment(this.currentEnvironment, this.currentIndex)

View File

@ -930,6 +930,7 @@ const message = {
info: "Info", info: "Info",
member: "Member", member: "Member",
env: "Environment", env: "Environment",
del_env_tip: "may cause tests execution using this environment to fail",
file_manage: "File", file_manage: "File",
my_file: "My file", my_file: "My file",
all_file: "All files", all_file: "All files",

View File

@ -908,6 +908,7 @@ const message = {
info: "项目信息", info: "项目信息",
member: "项目成员", member: "项目成员",
env: "项目环境", env: "项目环境",
del_env_tip: "可能导致使用该环境的测试执行失败",
file_manage: "文件管理", file_manage: "文件管理",
my_file: "我的文件", my_file: "我的文件",
all_file: "所有文件", all_file: "所有文件",

View File

@ -907,6 +907,7 @@ const message = {
info: "項目信息", info: "項目信息",
member: "項目成員", member: "項目成員",
env: "項目環境", env: "項目環境",
del_env_tip: "可能導致使用該環境的測試執行失敗",
file_manage: "文件管理", file_manage: "文件管理",
my_file: "我的文件", my_file: "我的文件",
all_file: "所有文件", all_file: "所有文件",

View File

@ -141,7 +141,7 @@ import EnvironmentEdit from "./components/EnvironmentEdit";
import MsAsideItem from "metersphere-frontend/src/components/MsAsideItem"; import MsAsideItem from "metersphere-frontend/src/components/MsAsideItem";
import MsAsideContainer from "metersphere-frontend/src/components/MsAsideContainer"; import MsAsideContainer from "metersphere-frontend/src/components/MsAsideContainer";
import ProjectSwitch from "metersphere-frontend/src/components/head/ProjectSwitch"; import ProjectSwitch from "metersphere-frontend/src/components/head/ProjectSwitch";
import {downloadFile, operationConfirm} from "metersphere-frontend/src/utils"; import {downloadFile} from "metersphere-frontend/src/utils";
import {getCurrentProjectID} from "metersphere-frontend/src/utils/token"; import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import EnvironmentImport from "./EnvironmentImport"; import EnvironmentImport from "./EnvironmentImport";
import MsMainContainer from "metersphere-frontend/src/components/MsMainContainer"; import MsMainContainer from "metersphere-frontend/src/components/MsMainContainer";
@ -149,6 +149,7 @@ import MsContainer from "metersphere-frontend/src/components/MsContainer";
import MsDialogHeader from "metersphere-frontend/src/components/MsDialogHeader"; import MsDialogHeader from "metersphere-frontend/src/components/MsDialogHeader";
import {listAllProject} from "../../../api/project"; import {listAllProject} from "../../../api/project";
import {delEnvironmentById, getEnvironmentPages} from "../../../api/environment"; import {delEnvironmentById, getEnvironmentPages} from "../../../api/environment";
import i18n from "@/i18n";
export default { export default {
name: "EnvironmentList", name: "EnvironmentList",
@ -322,7 +323,7 @@ export default {
}, },
deleteEnv(environment) { deleteEnv(environment) {
if (environment.id) { if (environment.id) {
operationConfirm(this, this.$t('commons.confirm_delete') + environment.name, () => { this.operationConfirm(this, this.$t('commons.delete') + "(" + environment.name + ")" + this.$t('project.del_env_tip'), () => {
this.loading = delEnvironmentById(environment.id).then(() => { this.loading = delEnvironmentById(environment.id).then(() => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.list(); this.list();
@ -332,6 +333,25 @@ export default {
}) })
} }
}, },
operationConfirm(v, tip, success, cancel) {
return v
.$confirm(tip, "", {
confirmButtonText: i18n.t("commons.confirm"),
cancelButtonText: i18n.t("commons.cancel"),
type: "warning",
center: false,
})
.then(() => {
if (success) {
success();
}
})
.catch(() => {
if (cancel) {
cancel();
}
});
},
getNoRepeatName(name) { getNoRepeatName(name) {
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].name === name) { if (this.environments[i].name === name) {

View File

@ -138,7 +138,7 @@ import MsTableOperatorButton from "metersphere-frontend/src/components/MsTableOp
import MsTablePagination from "metersphere-frontend/src/components/pagination/TablePagination"; import MsTablePagination from "metersphere-frontend/src/components/pagination/TablePagination";
import {Environment, parseEnvironment} from "metersphere-frontend/src/model/EnvironmentModel"; import {Environment, parseEnvironment} from "metersphere-frontend/src/model/EnvironmentModel";
import ProjectSwitch from "metersphere-frontend/src/components/head/ProjectSwitch"; import ProjectSwitch from "metersphere-frontend/src/components/head/ProjectSwitch";
import {downloadFile, operationConfirm, strMapToObj} from "metersphere-frontend/src/utils"; import {downloadFile, strMapToObj} from "metersphere-frontend/src/utils";
import EnvironmentImport from "./EnvironmentImport"; import EnvironmentImport from "./EnvironmentImport";
import ShowMoreBtn from "metersphere-frontend/src/components/table/ShowMoreBtn"; import ShowMoreBtn from "metersphere-frontend/src/components/table/ShowMoreBtn";
import { import {
@ -152,6 +152,7 @@ import MsDialogHeader from "metersphere-frontend/src/components/MsDialogHeader";
import EnvironmentEdit from "metersphere-frontend/src/components/environment/EnvironmentEdit" import EnvironmentEdit from "metersphere-frontend/src/components/environment/EnvironmentEdit"
import {listAllProject} from "../../../api/project"; import {listAllProject} from "../../../api/project";
import {batchAddEnvGroup, delEnvironmentById, getEnvironmentPages} from "../../../api/environment"; import {batchAddEnvGroup, delEnvironmentById, getEnvironmentPages} from "../../../api/environment";
import i18n from "@/i18n";
export default { export default {
@ -350,7 +351,7 @@ export default {
}, },
deleteEnv(environment) { deleteEnv(environment) {
if (environment.id) { if (environment.id) {
operationConfirm(this, this.$t('commons.confirm_delete') + environment.name, () => { this.operationConfirm(this, this.$t('commons.delete') + "(" + environment.name + ")" + this.$t('project.del_env_tip'), () => {
this.loading = delEnvironmentById(environment.id).then(() => { this.loading = delEnvironmentById(environment.id).then(() => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.list(); this.list();
@ -360,6 +361,25 @@ export default {
}) })
} }
}, },
operationConfirm(v, tip, success, cancel) {
return v
.$confirm(tip, "", {
confirmButtonText: i18n.t("commons.confirm"),
cancelButtonText: i18n.t("commons.cancel"),
type: "warning",
center: false,
})
.then(() => {
if (success) {
success();
}
})
.catch(() => {
if (cancel) {
cancel();
}
});
},
getNoRepeatName(name) { getNoRepeatName(name) {
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].name === name) { if (this.environments[i].name === name) {

View File

@ -10,17 +10,6 @@
:delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/> :delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/>
</el-container> </el-container>
</el-dialog> </el-dialog>
<el-dialog
:visible.sync="delDialogVisible"
append-to-body
width="30%">
<span style="color: #de9d1c; font-size: 18px;padding-right: 5px"><i class="el-icon-warning"/></span><span
style="font-size: 18px">{{ $t('commons.confirm_delete') + currentEnvironment.name }}</span>
<span slot="footer" class="dialog-footer">
<el-button @click="delDialogVisible = false"> </el-button>
<el-button type="primary" @click="delEnvironment"> </el-button>
</span>
</el-dialog>
</div> </div>
</template> </template>
@ -68,8 +57,6 @@ export default {
} }
], ],
selectEnvironmentId: '', selectEnvironmentId: '',
ifCreate: false, //
delDialogVisible: false,
currentIndex: -1 currentIndex: -1
} }
}, },
@ -105,25 +92,24 @@ export default {
listenGoBack(this.close); listenGoBack(this.close);
}, },
deleteEnvironment(environment, index) { deleteEnvironment(environment, index) {
if (this.delDialogVisible === false) { this.$alert(this.$t('commons.delete') + "(" + environment.name + ")" + this.$t('project.del_env_tip'), '', {
this.delDialogVisible = true; confirmButtonText: this.$t('commons.confirm'),
return; cancelButtonText: this.$t('commons.cancel'),
} callback: (action) => {
this.ifCreate = false; if (action === 'confirm') {
if (environment.id) { if (environment.id) {
this.result = delApiEnvironment(environment.id).then(() => { this.result = delApiEnvironment(environment.id).then(() => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.getEnvironments(); this.getEnvironments();
this.delDialogVisible = false;
}); });
} else { } else {
this.environments.splice(index, 1); this.environments.splice(index, 1);
this.delDialogVisible = false;
} }
}
}
});
}, },
copyEnvironment(environment) { copyEnvironment(environment) {
this.ifCreate = false;
// //
this.environmentSelected(environment); this.environmentSelected(environment);
this.currentEnvironment = environment; this.currentEnvironment = environment;
@ -188,9 +174,6 @@ export default {
getEnvironment(environment) { getEnvironment(environment) {
parseEnvironment(environment); parseEnvironment(environment);
this.currentEnvironment = environment; this.currentEnvironment = environment;
if (this.currentEnvironment.name) {
this.ifCreate = false;
}
}, },
save() { save() {
this.$refs.environmentEdit.save(); this.$refs.environmentEdit.save();
@ -204,7 +187,6 @@ export default {
openDelEnv(environment, index) { openDelEnv(environment, index) {
this.currentEnvironment = environment; this.currentEnvironment = environment;
this.currentIndex = index; this.currentIndex = index;
this.delDialogVisible = true
}, },
delEnvironment() { delEnvironment() {
this.deleteEnvironment(this.currentEnvironment, this.currentIndex) this.deleteEnvironment(this.currentEnvironment, this.currentIndex)

View File

@ -10,17 +10,6 @@
:delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/> :delete-fuc="openDelEnv" @itemSelected="environmentSelected" ref="environmentItems"/>
</el-container> </el-container>
</el-dialog> </el-dialog>
<el-dialog
:visible.sync="delDialogVisible"
append-to-body
width="30%">
<span style="color: #de9d1c; font-size: 18px;padding-right: 5px"><i class="el-icon-warning"/></span><span
style="font-size: 18px">{{ $t('commons.confirm_delete') + currentEnvironment.name }}</span>
<span slot="footer" class="dialog-footer">
<el-button @click="delDialogVisible = false"> </el-button>
<el-button type="primary" @click="delEnvironment"> </el-button>
</span>
</el-dialog>
</div> </div>
</template> </template>
@ -64,8 +53,6 @@ export default {
} }
], ],
selectEnvironmentId: '', selectEnvironmentId: '',
ifCreate: false, //
delDialogVisible: false,
currentIndex: -1, currentIndex: -1,
isCopy: false isCopy: false
} }
@ -102,7 +89,7 @@ export default {
listenGoBack(this.close); listenGoBack(this.close);
}, },
deleteEnvironment(environment, index) { deleteEnvironment(environment, index) {
this.$alert(this.$t('commons.confirm_delete') + environment.name, '', { this.$alert(this.$t('commons.delete') + "(" + environment.name + ")" + this.$t('project.del_env_tip'), '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
callback: (action) => { callback: (action) => {
@ -111,11 +98,9 @@ export default {
this.result = delApiEnvironment(environment.id).then(() => { this.result = delApiEnvironment(environment.id).then(() => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.getEnvironments(); this.getEnvironments();
this.delDialogVisible = false;
}); });
} else { } else {
this.environments.splice(index, 1); this.environments.splice(index, 1);
this.delDialogVisible = false;
} }
} }
} }
@ -123,7 +108,6 @@ export default {
}, },
copyEnvironment(environment) { copyEnvironment(environment) {
this.ifCreate = false;
this.isCopy = true; this.isCopy = true;
// //
this.environmentSelected(environment); this.environmentSelected(environment);
@ -190,9 +174,6 @@ export default {
getEnvironment(environment) { getEnvironment(environment) {
parseEnvironment(environment); parseEnvironment(environment);
this.currentEnvironment = environment; this.currentEnvironment = environment;
if (this.currentEnvironment.name) {
this.ifCreate = false;
}
}, },
save() { save() {
this.$refs.environmentEdit.save(); this.$refs.environmentEdit.save();
@ -209,7 +190,6 @@ export default {
openDelEnv(environment, index) { openDelEnv(environment, index) {
this.currentEnvironment = environment; this.currentEnvironment = environment;
this.currentIndex = index; this.currentIndex = index;
this.delDialogVisible = true
}, },
delEnvironment() { delEnvironment() {
this.deleteEnvironment(this.currentEnvironment, this.currentIndex) this.deleteEnvironment(this.currentEnvironment, this.currentIndex)