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="100px"
14     >
15       <el-row :gutter="20">
16         <el-col :span="12">
17           <el-form-item label="Tag名称" prop="tagName">
18             <el-input
19               v-model="dataForm.tagName"
20               placeholder="Tag名称"
21               :readonly="!!dataForm.id"
22             ></el-input>
23           </el-form-item>
24         </el-col>
25         <el-col :span="12">
26           <el-form-item label="数据类型" prop="dataType">
27             <dict-select-tag
28               v-model="dataForm.dataType"
29               placeholder="数据类型"
30               dictCode="oadp-data-type"
31             />
32           </el-form-item>
33         </el-col>
34       </el-row>
35       <el-row :gutter="20">
36         <el-col :span="12">
37           <el-form-item label="Modbus地址" prop="address">
38             <el-input
39               v-model="dataForm.address"
40               placeholder="Modbus地址"
41             ></el-input>
42           </el-form-item>
43         </el-col>
44         <el-col :span="12">
45           <el-form-item label="大小端" prop="format">
46             <el-input
47               v-model="dataForm.format"
48               placeholder="大小端"
49               dictCode="enable"
50             />
51           </el-form-item>
52         </el-col>
53       </el-row>
54       <el-row :gutter="20">
55         <el-col :span="12">
56           <el-form-item label="采集频率" prop="samplingRate">
57             <el-input-number
58               :min=0
59               :max="100000"
60               v-model="dataForm.samplingRate"
61               placeholder="采集频率,只对订阅模式有效"
62               dictCode="clock-type"
63               style="width: 100%;"
64             />
65           </el-form-item>
66         </el-col>
67         <el-col :span="12">
68           <el-form-item label="是否启用" prop="enabled">
69             <dict-select-tag
70               v-model="dataForm.enabled"
71               placeholder="是否启用"
72               dictCode="oadp-data-enabled"
73             />
74           </el-form-item>
75         </el-col>
76       </el-row>
77       <el-row :gutter="20">
78         <el-col :span="12">
79           <el-form-item label="关联设备" prop="device">
80             <el-input
81               v-model="dataForm.device"
82               placeholder="关联设备"
83               readonly
84             ></el-input>
85           </el-form-item>
86         </el-col>
87         <el-col :span="12">
88           <el-form-item label="描述" prop="tagDesc">
89             <el-input
90                 v-model="dataForm.tagDesc"
91                 placeholder="描述"
92             ></el-input>
93           </el-form-item>
94         </el-col>
95       </el-row>
96     </el-form>
97     <span slot="footer" class="dialog-footer">
98       <el-button @click="visible = false">取消</el-button>
99       <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
100     </span>
101   </el-dialog>
102 </template>
103
104 <script>
105 import DictSelectTag from "@/components/dict/dict-select-tag";
106
107 export default {
108   components: {
109     DictSelectTag,
110   },
111   data() {
112     return {
113       loading: false,
114       visible: false,
115       dataForm: {
116         id: "",
117         tagName: "",
118         dataType: "",
119         enabled: "true",
120         format: "",
121         device: "",
122         address: "",
123         samplingRate: "0",
124         tagDesc: "",
125       },
126       dataRule: {
127         tagName: [
128           { required: true, message: "Tag名不能为空", trigger: "blur" },
129         ],
130         dataType: [
131           { required: true, message: "数据类型不能为空", trigger: "blur" },
132         ],
133         enabled: [
134           { required: true, message: "是否可以tag不能为空", trigger: "blur" },
135         ],
136         address: [
137           { required: true, message: "Modbus地址不能为空", trigger: "blur" },
138         ],
139         samplingRate: [
140           { required: true, message: "采集频率不能为空", trigger: "blur" },
141         ],
142       },
143     };
144   },
145   methods: {
146     init(id, device) {
147       this.dataForm.id = id || 0;
148       this.dataForm.device = device || "";
149       this.visible = true;
150       this.$nextTick(() => {
151         this.$refs["dataForm"].resetFields();
152         if (this.dataForm.id) {
153           let id = Buffer.from(this.dataForm.id).toString("base64");
154           this.$http({
155             url: `/data/channel/modbus/tag/info/${id}`,
156             method: "get",
157             params: this.$http.adornParams(),
158           }).then(({ data }) => {
159             if (data && data.code === 0) {
160               this.dataForm.tagName = data.data.tagName;
161               this.dataForm.dataType = data.data.dataType;
162               this.dataForm.enabled = data.data.enabled;
163               this.dataForm.format = data.data.format;
164               this.dataForm.device = data.data.device;
165               this.dataForm.address = data.data.address;
166               this.dataForm.samplingRate = data.data.samplingRate;
167               this.dataForm.tagDesc = data.data.tagDesc;
168             }
169           });
170         }
171       });
172     },
173     // 表单提交
174     dataFormSubmit() {
175       this.$refs["dataForm"].validate((valid) => {
176         if (valid) {
177           this.loading = true;
178           this.$http({
179             headers: {
180               "Content-Type": "application/json",
181             },
182             url: `/data/channel/modbus/tag/${
183               !this.dataForm.id ? "add" : "update"
184             }`,
185             method: "post",
186             data: this.$http.adornData({
187               id: this.dataForm.id || undefined,
188               tagName: this.dataForm.tagName,
189               dataType: this.dataForm.dataType,
190               enabled: this.dataForm.enabled,
191               format: this.dataForm.format,
192               device: this.dataForm.device,
193               address: this.dataForm.address,
194               samplingRate: this.dataForm.samplingRate,
195               tagDesc: this.dataForm.tagDesc,
196             }),
197           }).then(({ data }) => {
198             this.loading = false;
199             if (data && data.code === 0) {
200               this.$message({
201                 message: "操作成功",
202                 type: "success",
203                 duration: 1500,
204                 onClose: () => {
205                   this.visible = false;
206                   this.$emit("refreshDataList");
207                 },
208               });
209             } else {
210               this.$message.error(data.msg);
211             }
212           });
213         }
214       });
215     },
216   },
217 };
218 </script>
219 <style>
220 .el-select {
221   width: 100%;
222 }
223
224 .el-input-group__append {
225   padding: 0 5px 0 5px;
226 }
227
228 .el-input-group__prepend {
229   padding: 0 5px 0 5px;
230 }
231 </style>