Эх сурвалжийг харах

保存前增加链接校验

zhangliang2 2 жил өмнө
parent
commit
f58480b45a

+ 44 - 2
src/views/algorithmsLibrary/gitAlgorithms.vue

@@ -155,8 +155,29 @@ export default {
             return
         },
         save(){
-            this.$refs.form.validate((valid) => {
+            this.$refs.form.validate(async (valid) => {
                 if (valid) {
+                    let testConnection = await this.$axios({
+                        method: "POST",
+                        url: this.$api.algorithmsLibrary.testConnection,
+                        data:{
+                            gitUrl: this.form.gitUrl,
+                            gitUserName: this.form.gitUserName,
+                            gitPassword: this.form.gitPassword,
+                        }
+                    }).then(res=>{
+                        if(res.code == 200) {
+                            return true
+                        } else {
+                            this.$message.error(res.message || "测试失败");
+                            return false
+                        }
+                    }).catch(e=>{
+                        return false
+                    })
+                    
+                    if(!testConnection) return
+
                     this.$axios({
                         method: "post",
                         url: this.$api.algorithmsLibrary.addOrUpdate,
@@ -175,8 +196,29 @@ export default {
             });
         },
         saveOther(){
-            this.$refs.form.validate((valid) => {
+            this.$refs.form.validate(async (valid) => {
                 if (valid) {
+                    let testConnection = await this.$axios({
+                        method: "POST",
+                        url: this.$api.algorithmsLibrary.testConnection,
+                        data:{
+                            gitUrl: this.form.gitUrl,
+                            gitUserName: this.form.gitUserName,
+                            gitPassword: this.form.gitPassword,
+                        }
+                    }).then(res=>{
+                        if(res.code == 200) {
+                            return true
+                        } else {
+                            this.$message.error(res.message || "测试失败");
+                            return false
+                        }
+                    }).catch(e=>{
+                        return false
+                    })
+                    
+                    if(!testConnection) return
+                    
                     let data = {...this.form}
                     data.id = ''
                     this.$axios({