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