houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3       :title="!dataForm.id ? '新增' : '修改'"
4       :close-on-click-modal="false"
5       :visible.sync="visible"
6       append-to-body
7   >
8     <el-form
9         :model="dataForm"
10         :rules="dataRule"
11         ref="dataForm"
12         @keyup.enter.native="dataFormSubmit()"
13         label-width="120px"
14     >
15       <el-row :gutter="20">
16         <el-col :span="12">
17           <el-form-item label="接口名称" prop="name">
18             <el-input v-model="dataForm.name" placeholder="接口名称"></el-input>
19           </el-form-item>
20         </el-col>
21         <el-col :span="12">
22           <el-form-item label="接口代码" prop="code">
23             <el-input
24                 v-model="dataForm.code"
25                 placeholder="接口代码"
26             ></el-input>
27           </el-form-item>
28         </el-col>
29       </el-row>
30       <el-row :gutter="20">
31         <el-col :span="24">
32           <el-form-item label="接口地址" prop="url">
33             <el-input v-model="dataForm.url" placeholder="应用接口名称"></el-input>
34           </el-form-item>
35         </el-col>
36       </el-row>
37       <el-row :gutter="20">
38         <el-col :span="12">
39           <el-form-item label="方法类型" prop="method">
40             <dict-select-tag v-model="dataForm.method" placeholder="方法类型" dictCode="http-method" />
41           </el-form-item>
42         </el-col>
43         <el-col :span="12">
44           <el-form-item label="采集器类型" prop="collectType">
45             <dict-select-tag v-model="dataForm.collectType" placeholder="采集器类型" dictCode="collect-type" />
46           </el-form-item>
47         </el-col>
48       </el-row>
49       <el-row>
50         <el-col :span="24">
51           <el-form-item label="参数" prop="param">
52             <el-input v-model="dataForm.param" placeholder="参数"></el-input>
53           </el-form-item>
54         </el-col>
55       </el-row>
56       <el-row :gutter="20">
57         <el-col :span="24">
58           <el-form-item label="描述" prop="descp">
59             <el-input
60                 v-model="dataForm.descp"
61                 placeholder="描述"
62                 type="textarea"
63                 :autosize="{ minRows: 2, maxRows: 2}"
64             ></el-input>
65           </el-form-item>
66         </el-col>
67       </el-row>
68     </el-form>
69     <span slot="footer" class="dialog-footer">
70       <el-button @click="visible = false">取消</el-button>
71       <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
72     </span>
73   </el-dialog>
74 </template>
75
76 <script>
77   import DictSelectTag from "@/components/dict/dict-select-tag";
78
79   export default {
80     components: {
81       DictSelectTag,
82     },
83     data() {
84       return {
85         loading: false,
86         visible: false,
87         dataForm: {
88           id: '',
89           name: '',
90           code: '',
91           url: '',
92           method: '',
93           collectType: '',
94           param: '',
95           descp: '',
96         },
97         dataRule: {
98           name: [
99             {required: true, message: "名称不能为空", trigger: "blur"},
100           ],
101           code: [
102             {required: true, message: "接口代码不能为空", trigger: "blur"},
103           ],
104           url: [
105             {required: true, message: "接口地址不能为空", trigger: "blur"},
106           ],
107           method: [
108             {required: true, message: "方法类型不能为空", trigger: "blur"},
109           ],
110           collectType: [
111             {required: true, message: "采集器类型不能为空", trigger: "blur"},
112           ]
113         },
114       };
115     },
116     methods: {
117       init(id) {
118         this.dataForm.id = id || 0;
119         this.visible = true;
120         this.$nextTick(() => {
121           this.$refs["dataForm"].resetFields();
122           if (this.dataForm.id) {
123             this.getInfo()
124           }
125         });
126       },
127
128       // 获取信息
129       getInfo() {
130         this.$http.get(`/data/http/api/info/${this.dataForm.id}`).then(({data: res}) => {
131           if (res.code !== 0) {
132             return this.$message.error(res.msg)
133           }
134           this.dataForm = {
135             ...this.dataForm,
136             ...res.data
137           }
138         }).catch(() => {
139         })
140       },
141
142       // 表单提交
143       dataFormSubmit () {
144         this.$refs['dataForm'].validate((valid) => {
145           if (!valid) {
146             return false
147           }
148           this.loading = true
149           this.$http['post'](`/data/http/api/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => {
150             this.loading = false
151             if (res.code !== 0) {
152               return this.$message.error(res.msg)
153             }
154             this.$message({
155               message: this.$t('prompt.success'),
156               type: 'success',
157               duration: 500,
158               onClose: () => {
159                 this.visible = false
160                 this.$emit('refreshDataList')
161               }
162             })
163           }).catch(() => {
164           })
165         })
166       }
167     },
168   };
169 </script>
170 <style>
171   .el-select {
172     width: 100%;
173   }
174
175   .el-input-group__append {
176     padding: 0 5px 0 5px;
177   }
178
179   .el-input-group__prepend {
180     padding: 0 5px 0 5px;
181   }
182 </style>