ZZJ
2022-06-28 2cb264ec2b7c7dd9798d1821927104fad35bd063
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
<template>
  <div class="mqtt-gateway">
    <el-form :model="mqttForm" ref="mqttForm">
      <div class="title form-item">网络设置</div>
 
      <el-form-item class="form-item">
        <switchBar
          :barName="`MOTT网关`"
          :value="mqttForm.enable"
          @switchChange="switchChange('enable', arguments)"
        ></switchBar>
      </el-form-item>
 
      <div class="block">
        <el-form-item class="form-item">
          <div class="item-title">IP地址</div>
          <div class="inputContain">
            <ipInput
              :ip="mqttForm.ip"
              @on-blur="mqttForm.ip = arguments[0]"
            ></ipInput>
          </div>
        </el-form-item>
 
        <el-form-item class="form-item">
          <div class="item-title">端口号</div>
          <div class="inputContain">
            <el-input
              v-model="mqttForm.port"
              placeholder="请输入用户名"
              size="small"
            ></el-input>
          </div>
        </el-form-item>
      </div>
 
      <div class="block">
        <el-form-item class="form-item">
          <div class="item-title">名称</div>
          <div class="inputContain">
            <el-input
              v-model="mqttForm.username"
              placeholder="请输入用户名"
              size="small"
            ></el-input>
          </div>
        </el-form-item>
 
        <el-form-item class="form-item">
          <div class="item-title">密码</div>
          <div class="inputContain">
            <el-input
              v-model="mqttForm.password"
              placeholder="请输入密码"
              size="small"
              show-password
              auto-complete="new-password"
            ></el-input>
          </div>
        </el-form-item>
      </div>
 
      <div class="block">
        <el-form-item class="form-item">
          <switchBar
            :barName="`匿名用户`"
            :value="mqttForm.anonymousEnable"
            @switchChange="switchChange('anonymousEnable', arguments)"
          ></switchBar>
        </el-form-item>
      </div>
    </el-form>
 
    <div class="ok" @click="saveList">保存</div>
  </div>
</template>
 
<script>
import ipInput from "../components/IPInput";
import switchBar from "../components/switchBar";
import { getMqtt, saveMqtt } from "@/api/system";
export default {
  name: "mqttGateway",
  created() {
    this.getList();
  },
  data() {
    return {
      accessible: false,
      mqttForm: {
        enable: "",
        anonymousEnable: "",
      },
    };
  },
  components: {
    switchBar,
    ipInput,
  },
  methods: {
    async getList() {
      const res = await getMqtt();
      this.mqttForm = { ...res.data };
    },
    async saveList() {
      const res = await saveMqtt(this.mqttForm);
      console.log(res);
    },
    switchChange(tar, arr) {
      this.mqttForm[tar] = arr[0];
    },
  },
};
</script>
 
<style scoped lang="scss">
@import "../asset/common.scss";
.mqtt-gateway {
  display: flex;
  flex-direction: column;
  .block {
    margin-top: 16px;
  }
}
</style>