he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<template>
  <el-form
    ref="ruleForm"
    size="mini"
    label-position="top"
    :model="params"
    :rules="rules"
    class="params-dialog"
  >
    <el-row :gutter="layout.gutter">
      <el-col :span="layout.span">
        <el-form-item label="交流过压告警值(V)" prop="acOvervolCoeAc">
          <el-input v-model="params.acOvervolCoeAc"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="layout.span">
        <el-form-item label="交流欠压告警值(V)" prop="acUndervolCoeAc">
          <el-input v-model="params.acUndervolCoeAc"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="layout.span">
        <el-form-item label="缺相告警点(V)" prop="acLessvolCoeAc">
          <el-input v-model="params.acLessvolCoeAc"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="layout.span">
        <el-form-item label="交流过流告警值(A)" prop="acOvercurrCoeAc">
          <el-input v-model="params.acOvercurrCoeAc"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="layout.span">
        <el-form-item label="频率高告警值(Hz)" prop="freqHighCoeAc">
          <el-input v-model="params.freqHighCoeAc"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="layout.span">
        <el-form-item label="频率低告警值(Hz)" prop="freqLowCoeAc">
          <el-input v-model="params.freqLowCoeAc"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <div class="form-footer">
      <template v-if="!pReadOnly">
        <three-btn @click="getParams()">读取</three-btn>
        <three-btn :disabled="!setTestFlag" @click="submitFrom">设定</three-btn>
      </template>
      <three-btn v-else @click="$emit('close')">关闭</three-btn>
    </div>
    <el-dialog
      title="人脸校验"
      width="480px"
      :visible.sync="setFaceShow"
      :close-on-click-modal="false"
      top="0"
      :modal="false"
      class="dialog-center"
      :modal-append-to-body="false"
      :destroy-on-close="true"
    >
      <check-face
        v-if="setFaceShow"
        @checkSuccess="setFaceSuccess"
      ></check-face>
    </el-dialog>
  </el-form>
</template>
 
<script>
import const_61590 from "@/assets/js/const/const_61590";
 
import { testVal } from "@/assets/js/tools";
import CheckFace from "@/components/checkFace";
 
import config from "@/assets/js/config";
import {
  setDev6159ACParam,
  getDev6159ACParam,
} from "../js/realTime";
 
import { checkUserPwd } from "@/views/login/js/api";
 
export default {
  components: { CheckFace },
  props: {
    devId: {
      type: [String, Number],
      required: true,
    },
    // 只读模式 显示参数用
    pReadOnly: {
      type: Boolean,
      default: false,
    },
    paramData: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    let rules = const_61590.acParamsRules;
    function getRule(prop) {
      return [
        {
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules[prop]);
          },
          trigger: "change",
        },
      ];
    }
    let rulesObj = {};
    [
      "acOvervolCoeAc",
      "acUndervolCoeAc",
      "acLessvolCoeAc",
      "acOvercurrCoeAc",
      "freqHighCoeAc",
      "freqLowCoeAc",
    ].forEach((v) => {
      rulesObj[v] = getRule(v);
    });
 
    return {
      // 组号
      groupIdx: "",
      layout: {
        gutter: 16,
        span: 12,
      },
      reason: "",
      setFaceShow: false,
      startFaceShow: false,
      setTestFlag: false, // 设置参数的状态
      readOnly: false,
 
      params: {
        acOvervolCoeAc: 0,
        acUndervolCoeAc: 0,
        acLessvolCoeAc: 0,
        acOvercurrCoeAc: 0,
        freqHighCoeAc: 0,
        freqLowCoeAc: 0,
        devId: this.devId,
      },
      rules: rulesObj,
    };
  },
  watch: {
  },
  methods: {
    initParams() {
      // 初始化参数
      this.params = {
        acOvervolCoeAc: 0,
        acUndervolCoeAc: 0,
        acLessvolCoeAc: 0,
        acOvercurrCoeAc: 0,
        freqHighCoeAc: 0,
        freqLowCoeAc: 0,
        devId: this.devId,
      };
    },
    // 获取参数
    getParams() {
      // 定义等待框
      let loading = this.$layer.loading(1);
      // 启动按钮不可点击
      this.startTestFlag = false;
 
      // 查询后台
      getDev6159ACParam(this.devId)
        .then((res) => {
          res = res.data;
          if (res.code && res.data) {
            let fsparam = res.data2;
            // 遍历参数属性并赋值
            for (let key in this.params) {
              this.params[key] = fsparam[key];
            }
            if (res.data2) {
              this.$layer.msg("读取成功!");
              // 设置按钮可点击
              this.setTestFlag = true;
            }
          } else {
            // 初始化参数
            this.initParams();
            // 设置按钮不可点击
            this.setTestFlag = false;
            this.$layer.msg("读取失败!");
          }
          // 关闭等待框
          this.$layer.close(loading);
        })
        .catch((error) => {
          console.log(error);
          // 初始化参数
          this.initParams();
          // 设置按钮不可点击
          this.setTestFlag = false;
          // 关闭等待框
          this.$layer.close(loading);
          this.$layer.msg("读取失败,读取请求异常!");
        });
    },
    // 提交表单设置参数
    submitFrom() {
      this.$refs.ruleForm.validate((valid) => {
        // 校验通过
        if (valid) {
          // 设置参数
          this.setParamsCheck();
        } else {
          this.$layer.msg("存在校验未通过的数据!");
          return false;
        }
      });
    },
    setParamsCheck() {
      if (config.setParamsByFace.value) {
        this.setFaceShow = true;
      } else {
        this.setParams(true);
      }
    },
    // 设置参数
    setParams() {
      // 等待框
      let loading = this.$layer.loading(1);
      // 请求后台
      setDev6159ACParam(this.params)
        .then((res) => {
          res = res.data;
          if (res.code && res.data) {
            // 启动按钮可点击
            this.startTestFlag = true;
            // 提示信息
            this.$layer.msg("设置成功");
          } else {
            // 启动按钮不可点击
            this.startTestFlag = false;
            // 提示信息
            this.$layer.msg("设置失败!");
          }
          // 关闭等待框
          this.$layer.close(loading);
        })
        .catch((error) => {
          console.log(error);
          // 关闭等待框
          this.$layer.close(loading);
          // 启动按钮不可点击
          this.startTestFlag = false;
          // 提示信息
          this.$layer.msg("设置失败,设置请求异常!");
        });
    },
    setFaceSuccess() {
      this.setFaceShow = false;
      this.setParams();
    },
  },
  computed: {
  },
  mounted() {
    // 获取数据
    if (this.pReadOnly) {
      this.initParams();
      this.params = {
        ...this.params,
        ...this.paramData,
      };
    } else {
      this.getParams();
    }
  },
};
</script>
 
<style scoped>
.params-dialog {
  background: #f0f0f0;
  padding: 20px 20px 1px;
  width: 600px;
}
.form-footer {
  margin-top: 16px;
  margin-bottom: 16px;
  text-align: right;
}
 
.form-footer .three-btn {
  margin-left: 12px;
}
</style>