From 09a1d1d0f675c7241f9897bc21bf2e0380c50379 Mon Sep 17 00:00:00 2001 From: leozhang2018 Date: Wed, 19 May 2021 20:53:46 +0800 Subject: [PATCH] Checking service name when add service Signed-off-by: leozhang2018 --- .../service_mgr/common/service_tree.vue | 138 ++++++++++-------- 1 file changed, 77 insertions(+), 61 deletions(-) diff --git a/zadig-portal/src/components/projects/service_mgr/common/service_tree.vue b/zadig-portal/src/components/projects/service_mgr/common/service_tree.vue index 25de65ffc2..618f64f5a2 100644 --- a/zadig-portal/src/components/projects/service_mgr/common/service_tree.vue +++ b/zadig-portal/src/components/projects/service_mgr/common/service_tree.vue @@ -300,15 +300,24 @@
- - - + + + + + + + +
{ + if (valid) { + const val = this.service.newServiceName; + const node = this.$refs.serviceTree.getNode(val); + if (!node) { + const data = { + label: val, + status: 'named', + service_name: val, + type: this.deployType ? this.deployType : 'k8s', + visibility: 'private' + }; + this.services.push(data); + this.setServiceSelected(data.service_name); + this.$router.replace({ query: { service_name: data.service_name, rightbar: 'help' } }); + this.$emit('onSelectServiceChange', data); + this.showNewServiceInput = false; + this.service.newServiceName = ''; + } + } + }); }, inputServiceNameDoneWhenEnter() { - const val = this.newServiceName; - const node = this.$refs.serviceTree.getNode(val); - let data = null; - if (val && !node) { - data = { - label: val, - status: 'named', - service_name: val, - type: this.deployType ? this.deployType : 'k8s', - visibility: 'private' - }; - } - else { - data = { - label: 'untitled', - status: 'named', - service_name: 'untitled', - type: this.deployType ? this.deployType : 'k8s', - visibility: 'private' - }; - } - if (!node) { - this.services.push(data); - } - this.setServiceSelected(data.service_name); - this.$router.replace({ query: { service_name: data.service_name, rightbar: 'help' } }); - this.$emit('onSelectServiceChange', data); - this.showNewServiceInput = false; - this.newServiceName = ''; + this.$refs['newServiceNameForm'].validate((valid) => { + if (valid) { + const val = this.service.newServiceName; + const node = this.$refs.serviceTree.getNode(val); + let data = null; + if (!node) { + data = { + label: val, + status: 'named', + service_name: val, + type: this.deployType ? this.deployType : 'k8s', + visibility: 'private' + }; + } + else { + data = { + label: 'untitled', + status: 'named', + service_name: 'untitled', + type: this.deployType ? this.deployType : 'k8s', + visibility: 'private' + }; + } + if (!node) { + this.services.push(data); + } + this.setServiceSelected(data.service_name); + this.$router.replace({ query: { service_name: data.service_name, rightbar: 'help' } }); + this.$emit('onSelectServiceChange', data); + this.showNewServiceInput = false; + this.service.newServiceName = ''; + } + }); }, reEditServiceName(node, data) { const service = this.$utils.cloneObj(data); @@ -798,7 +814,7 @@ export default { const index = this.filteredServices.findIndex(d => d.service_name === service.service_name); this.services.splice(index, 1); this.showNewServiceInput = true; - this.newServiceName = service.service_name; + this.service.newServiceName = service.service_name; this.$nextTick(() => { this.$refs.serviceNamedRef.focus(); });