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
<template>
  <div style="padding: 20px">
    <el-card>
      <div style="display: flex">
        <div class="timee">
          {{ time }}
        </div>
        <div style="margin-left: 1.5rem; margin-top:-1.1rem">
          <span>设备和站点:</span>
          <el-cascader
           v-model="newMac"
            :options="options"
            :props="props"
            collapse-tags
            clearable
            @change="changeYz"
            placeholder="选择设备"
            style="width: 25rem"
          ></el-cascader>
        </div>
        <div style="margin-left: 1.5rem; margin-top: -12px">
          <span>选择因子:</span>
          <el-cascader
            :options="newSensor"
            :props="props"
            collapse-tags
            clearable
            @change="res"
          ></el-cascader>
        </div>
        <div style="margin-left: 1.5rem; margin-top: -12px">
          <el-button type="primary">查询</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>        
 
<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import《组件名称》from'《组件路径》';
 
export default {
  //import 引入的组件需要注入到对象中才能使用
  components: {},
  props: {},
  data() {
    //这里存放数据
    return {
      time: '',
      props: { multiple: true },
      defaultData: [],
      options: [],
      newSensor:[],
      newMac:'',
      newMac1:[]
    }
  },
  // 计算属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {
     newMac(newVal, oldval) {
      this.newMac1 = []
      for (let i = 0; i < newVal.length; i++) {
        // console.log(newVal[i], 111)
        this.newMac1.push(newVal[i][1][1])
      }
      // 设备更新后,重新获取因子数据
      this.getSensor()
      console.log(this.newMac1)
    },
  },
  //方法集合
  methods: {
    res(res){
      console.log(res.toString());
    },
    getData() {
      this.$request({
        url: '/monitorPoint/queryMonitorPoints',
        method: 'get',
        params: {
          organizationId: this.$store.state.orgId,
        },
      })
        .then((res) => {
          this.defaultData = res.data.monitorPoints
          for (let i = 0; i < this.defaultData.length; i++) {
            this.options.push({
              value: this.defaultData[i].name,
              label: this.defaultData[i].name,
            })
            this.options[i].children = []
            for (let j = 0; j < this.defaultData[i].devices.length; j++) {
              this.options[i].children.push({
                value: [
                  this.defaultData[i].devices[j].name,
                  this.defaultData[i].devices[j].mac,
                ],
                label: this.defaultData[i].devices[j].name,
              })
            }
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    changeYz(){
      console.log(11111);
      this.getSensor();
    },
     getSensor() {
      this.$request({
        url: '/deviceInfo/getMacSensors',
        method: 'post',
        data: {
          macs: this.newMac1,
        },
      })
        .then((result) => {
          console.log(result);
          var sensor = result.data
          for (var i in sensor) {
            this.newSensor.push({ value: i, label: sensor[i] })
            
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
  },
  //生命周期 - 创建完成(可以访问当前 this 实例)
  created() {
    var timer = this.dateTypeFormat('YYYY-mm-dd HH:MM:SS', new Date())
    this.time = timer
    this.getData();
  },
  //生命周期 - 挂载完成(可以访问 DOM 元素)
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
}
</script>
<style scoped>
 
</style>