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