shiyu 3 vuotta sitten
vanhempi
commit
6fddb7f956
1 muutettua tiedostoa jossa 81 lisäystä ja 21 poistoa
  1. 81 21
      src/views/algorithmsLibrary/gitAlgorithms.vue

+ 81 - 21
src/views/algorithmsLibrary/gitAlgorithms.vue

@@ -53,16 +53,26 @@
                             v-autoTrim="{ obj: form, key: 'gitPassword' }"
                             v-model="form.gitPassword"
                         >
+                        <el-button slot="suffix" type="primary" @click="testConnection">测试链接</el-button>
                         </el-input>
                     </el-form-item>
-                    <div class="testLinkPanel">
-                        <el-button type="primary" @click="testConnection">测试链接</el-button>
-                    </div>
                 </el-form>
 
                 <div class="btns">
-                    <el-button type="primary" @click="save">保存</el-button>
-                    <el-button type="primary" @click="cancel">取消</el-button>
+                    <el-button
+                        type="primary"
+                        @click="save"
+                        >保存</el-button
+                    >
+                    <el-button
+                        v-if="form.share === '0' || form.share === '1'"
+                        type="primary"
+                        @click="saveOther"
+                        >另存为</el-button
+                    >
+                    <el-button type="primary" plain @click="cancel"
+                        >取消</el-button
+                    >
                 </div>
             </el-col>
         </el-row>
@@ -96,24 +106,53 @@ export default {
             },
         };
     },
-
-    methods: {
-        testConnection(){
+    mounted(){
+        let id = this.$route.query.id;
+        if (id) {
+            this.form.share = this.$route.query.share;
             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) {
-                    this.$message.success("测试成功");
+                method: "post",
+                url: this.$api.algorithmsLibrary.selectDetailsById,
+                data: {
+                    id,
+                },
+            }).then((res) => {
+                if (res.code == 200 && res.info) {
+                    this.form = res.info;
                 } else {
-                    this.$message.error(res.message || "测试失败");
+                    this.$message.error(res.message || "获取信息失败");
                 }
+            });
+        }
+    },
+    methods: {
+        testConnection(){
+            let validateFieldList = []
+            this.$refs.form.validateField(['gitUserName','gitPassword','gitUrl'],async errorMsg=>{
+                if(!errorMsg){
+                    validateFieldList.push(errorMsg)
+                    if(validateFieldList.length == 3 && validateFieldList.every(item=>item ==='')){
+                        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) {
+                                this.$message.success("测试成功");
+                            } else {
+                                this.$message.error(res.message || "测试失败");
+                            }
+                        })    
+                    }
+                }else{
+                    return false
+                } 
             })
+            return
         },
         save(){
             this.$refs.form.validate((valid) => {
@@ -135,6 +174,26 @@ export default {
                 }
             });
         },
+        saveOther(){
+            this.$refs.form.validate((valid) => {
+                if (valid) {
+                    let data = {...this.form}
+                    data.id = ''
+                    this.$axios({
+                        method: "post",
+                        url: this.$api.algorithmsLibrary.addOrUpdate,
+                        data: data,
+                    }).then((res) => {
+                        if (res.code == 200) {
+                            this.$message.success("保存成功");
+                            this.cancel();
+                        } else {
+                            this.$message.error(res.message || "保存失败");
+                        }
+                    });
+                }
+            });
+        },
         cancel(){
             this.$router.replace({ path: "/algorithmsLibraryList" });
         }
@@ -188,8 +247,6 @@ export default {
             this.type = val;
         }, */
     },
-
-    // mounted: {},
 };
 </script>
 
@@ -203,6 +260,9 @@ export default {
         .el-select {
             width: 100%;
         }
+        /deep/ .el-input__suffix{
+            right: 0;
+        }
     }
 
     .testLinkPanel {