houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog :title="!dataForm.id ? '新增' : '修改'"
3              :close-on-click-modal="false"
4              :visible.sync="visible"
5              append-to-body>
6     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
7       <el-row :gutter="20">
8         <el-col :span="12">
9           <el-form-item label="实例名称" prop="instanceName">
10             <el-input v-model="dataForm.instanceName" placeholder="实例名称"></el-input>
11           </el-form-item>
12         </el-col>
13         <el-col :span="12">
14           <el-form-item label="IP地址" prop="address">
15             <el-input v-model="dataForm.address" placeholder="IP地址"></el-input>
16           </el-form-item>
17         </el-col>
18       </el-row>
19       <el-row :gutter="20">
20         <el-col :span="12">
21           <el-form-item label="端口" prop="port">
22             <el-input v-model="dataForm.port" placeholder="端口"/>
23           </el-form-item>
24         </el-col>
25         <el-col :span="12">
26           <el-form-item label="用户名" prop="username">
27             <el-input v-model="dataForm.username" placeholder="用户名"/>
28           </el-form-item>
29         </el-col>
30       </el-row>
31       <el-row :gutter="20">
32         <el-col :span="12">
33           <el-form-item label="密码" prop="password">
34             <el-input v-model="dataForm.password" placeholder="密码"/>
35           </el-form-item>
36         </el-col>
37       </el-row>
38     </el-form>
39     <span slot="footer" class="dialog-footer">
40       <el-button @click="visible = false">取消</el-button>
41       <el-button :loading="loading" type="primary" @click="dataFormSubmitHandle()">确定</el-button>
42     </span>
43   </el-dialog>
44 </template>
45
46 <script>
47   import DictSelectTag from "@/components/dict/dict-select-tag";
48   import debounce from "lodash/debounce";
49
50   export default {
51     components: {
52       DictSelectTag,
53     },
54     data() {
55       return {
56         loading: false,
57         visible: false,
58         dataForm: {
59           id: '',
60           instanceName: '',
61           address: '',
62           port: '',
63           username: '',
64           password: ''
65         },
66         dataRule: {
67           instanceName: [
68             {required: true, message: "服务名不能为空", trigger: "blur"},
69           ],
70           address: [
71             {required: true, message: "端点URL不能为空", trigger: "blur"},
72           ],
73           port: [
74             {required: true, message: "安全策略不能为空", trigger: "blur"},
75           ],
76           username: [
77             {required: true, message: "安全模式不能为空", trigger: "blur"},
78           ],
79           password: [
80             {required: true, message: "连接方式不能为空", trigger: "blur"},
81           ]
82         },
83       };
84     },
85     methods: {
86       init() {
87         this.visible = true
88         this.$nextTick(() => {
89             this.$refs['dataForm'].resetFields()
90             if (this.dataForm.id) {
91               this.getInfo()
92             }
93           }
94         )
95       },
96       getInfo() {
97         this.$http.get(`/data/channel/kio/device/${this.dataForm.id}`).then(({code, data, msg}) => {
98           if (code !== 0) {
99             return this.$message.error(msg)
100           }
101           this.dataForm = {
102             ...this.dataForm,
103             ...data
104           }
105         }).catch(() => {
106         })
107       },
108       // 表单提交
109       dataFormSubmitHandle: debounce(function () {
110         this.$refs['dataForm'].validate((valid) => {
111           if (!valid) {
112             return false
113           }
114           this.loading = true
115           this.$http[!this.dataForm.id ? 'post' : 'put']('/data/channel/kio/device', {
116             ...this.dataForm
117           }).then(({code, msg}) => {
118             this.loading = false
119             if (code !== 0) {
120               return this.$message.error(msg)
121             }
122             this.$message({
123               message: this.$t('prompt.success'),
124               type: 'success',
125               duration: 500,
126               onClose: () => {
127                 this.visible = false
128                 this.$emit('refreshDataList')
129               }
130             })
131           }).catch(() => {
132           })
133         })
134       }, 1000, {'leading': true, 'trailing': false}),
135     },
136   };
137 </script>