Blame view

src/views/admin/device/index.vue 15.6 KB
77ebf04d   梁保满   个人版
1
2
3
4
5
6
7
8
9
10
11
12
  <template>
    <div ref="main" class="page-content">
      <back-box>
        <template slot="title">
          <span>设备管理</span>
        </template>
      </back-box>
      <div>
        <div class="tab-box">
          <el-radio-group v-model="type">
            <el-radio-button :label="1">基站管理</el-radio-button>
            <el-radio-button :label="2">答题器管理</el-radio-button>
77ebf04d   梁保满   个人版
13
14
15
16
17
18
19
20
21
22
23
24
25
          </el-radio-group>
        </div>
        <div class="content">
          <div v-show="type == 1">
            <div class="chart-box" v-if="count">
              <div class="device-num">
                <p class="p1">{{ count }}</p>
                <p class="p2">基站数量</p>
              </div>
              <div class="chart">
                <pie-chart
                  id="pieChart"
                  :params="chartData"
77ebf04d   梁保满   个人版
26
27
28
29
30
31
                ></pie-chart>
              </div>
            </div>
            <div class="table-box">
              <div class="answer-header">
                <div class="sel-box">
77ebf04d   梁保满   个人版
32
33
                  <el-select
                    class="sel"
21dfdeae   梁保满   平台管理员
34
35
                    v-model="query.school"
                    placeholder="选择学校"
77ebf04d   梁保满   个人版
36
37
38
                    @change="_QueryData(true)"
                  >
                    <el-option
21dfdeae   梁保满   平台管理员
39
                      v-for="item in schoolList"
77ebf04d   梁保满   个人版
40
41
42
43
44
45
46
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <el-input
21dfdeae   梁保满   平台管理员
47
                    placeholder="请输入租户"
77ebf04d   梁保满   个人版
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
                    v-model="query.sn"
                    class="input-with-select"
                    @keyup.enter.native="_QueryData(true)"
                  >
                    <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click="_QueryData(true)"
                    ></el-button>
                  </el-input>
                  <el-button class="serach-box" round @click="_QueryData(true)"
                    >筛选</el-button
                  >
                </div>
              </div>
              <el-table :data="tableData" border style="width: 100%">
                <el-table-column
                  prop="sn"
                  label="设备编码"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="frequency"
                  label="频点"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="pairingCode"
                  label="配对码"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="roomName"
                  label="所在教室"
                  align="center"
                ></el-table-column>
                <el-table-column label="关联班级" align="center">
                  <template slot-scope="scoped">
                    <p v-for="(item, index) in scoped.row.classList" :key="index">
                      {{ item.className }}
                    </p>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="otaVersionName"
                  label="固件版本号"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="onlineTime"
                  label="最近上报"
                  align="center"
                ></el-table-column>
                <el-table-column label="状态" align="center"
                  ><template slot-scope="scope">
                    {{
                      scope.row.onlineStatus == 1
                        ? "在线"
                        : scope.row.onlineStatus == 2
                        ? "异常"
                        : "离线"
                    }}
                  </template></el-table-column
                >
                <el-table-column label="操作" align="center"
                  ><template slot-scope="scoped">
                    <el-tooltip effect="dark" content="日志" placement="top">
                      <el-button
                        type="warning"
                        circle
                        size="mini"
                        icon="fa fa-eye"
                        @click="linkTo(scoped.row, 1)"
                      ></el-button>
                    </el-tooltip> </template
                ></el-table-column>
              </el-table>
            </div>
          </div>
          <div v-show="type == 2">
            <div class="chart-box" v-if="count">
              <div class="device-num">
                <p class="p1">{{ count }}</p>
                <p class="p2">答题器数量</p>
              </div>
              <div class="chart">
                <scatter-chart
                  id="scatterChart"
                  :params="chartData2"
77ebf04d   梁保满   个人版
137
138
139
140
141
142
                ></scatter-chart>
              </div>
            </div>
            <div class="table-box">
              <div class="answer-header">
                <div class="sel-box">
21dfdeae   梁保满   平台管理员
143
                 <el-select
77ebf04d   梁保满   个人版
144
                    class="sel"
21dfdeae   梁保满   平台管理员
145
146
                    v-model="query.school"
                    placeholder="选择学校"
77ebf04d   梁保满   个人版
147
148
149
                    @change="_QueryData(true)"
                  >
                    <el-option
21dfdeae   梁保满   平台管理员
150
                      v-for="item in schoolList"
77ebf04d   梁保满   个人版
151
152
153
154
155
156
157
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <el-input
21dfdeae   梁保满   平台管理员
158
                    placeholder="请输入租户"
77ebf04d   梁保满   个人版
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
                    v-model="query.sn"
                    class="input-with-select"
                    @keyup.enter.native="_QueryData(true)"
                  >
                    <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click="_QueryData(true)"
                    ></el-button>
                  </el-input>
                  <el-button class="serach-box" round @click="_QueryData(true)"
                    >筛选</el-button
                  >
                </div>
              </div>
              <el-table :data="tableData" border style="width: 100%">
                <el-table-column
                  prop="sn"
                  label="设备编码"
                  align="center"
                ></el-table-column>
                <el-table-column label="学生信息" align="center"
                  ><template slot-scope="scoped"
                    ><p
                      v-for="(item, index) in scoped.row.studentList"
                      :key="index"
                    >
                      {{ item.studentName }}
                    </p></template
                  ></el-table-column
                >
                <el-table-column
                  prop="electricity"
                  label="电量"
                  align="center"
                ></el-table-column>
                <el-table-column prop="class" label="关联班级" align="center">
                  <template slot-scope="scoped">
                    <p v-for="(item, index) in scoped.row.classList" :key="index">
                      {{ item.className }}
                    </p>
                  </template></el-table-column
                >
                <el-table-column
                  prop="pairingCode"
                  label="配对码"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="answerTimes"
                  label="答题次数"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="latestReportTime"
                  label="最后答题时间"
                  align="center"
                ></el-table-column>
                <el-table-column label="操作" align="center"
                  ><template slot-scope="scoped">
                    <el-tooltip effect="dark" content="日志" placement="top">
                      <el-button
                        type="warning"
                        circle
                        size="mini"
                        icon="fa fa-eye"
                        @click="linkTo(scoped.row, 2)"
                      ></el-button>
                    </el-tooltip> </template
                ></el-table-column>
              </el-table>
            </div>
          </div>
          <div class="pagination-box">
            <el-pagination
              small=""
              layout="total,prev, pager, next"
              :hide-on-single-page="true"
              :total="total"
              @current-change="changePage"
              :current-page="page"
              :page-size="size"
            >
            </el-pagination>
          </div>
        </div>
      </div>
     
     
    </div>
  </template>
  
  <script>
  import pieChart from "@/components/charts/pieChart";
  import scatterChart from "@/components/charts/scatterChart";
  import _ from "lodash";
  import { downloadFile, getBlob, formatGradeNameClass } from "@/utils";
  import api from "@/api/apis/apis";
  import BusEvent from "@/utils/busEvent";
  export default {
    components: { pieChart, scatterChart },
    watch: {
      type: function (val) {
        this.page = 1;
        this.total = 0;
        this.count = 0;
        this.query.classId = [];
        this.query.onlineStatus = "";
        this.query.sn = "";
        this.query.type = "";
        if (val == 1) {
          this.stationReport();
        } else if (val == 2) {
          this.keyboardReport();
        }
        this._QueryData();
      },
    },
    data() {
      return {
        code: "",
        loading: false,
21dfdeae   梁保满   平台管理员
281
        schoolList: [],
77ebf04d   梁保满   个人版
282
283
        type: 1,
        query: {
21dfdeae   梁保满   平台管理员
284
285
          school: [],
          zuhu: "",
77ebf04d   梁保满   个人版
286
        },
77ebf04d   梁保满   个人版
287
288
289
290
291
292
293
294
295
296
297
        tableData: [],
        total: 0,
        count: 0,
        chartData: [],
        chartData2: [],
        page: 1,
        size: 20,
      };
    },
    created() {
      this.code = localStorage.getItem("csCode") || "";
21dfdeae   梁保满   平台管理员
298
299
      // this.stationReport();
      // this._QueryData();
77ebf04d   梁保满   个人版
300
301
302
303
304
305
306
307
    },
    activated() {
      const that = this;
      BusEvent.$on("keepAlive", async function () {
        that.type = 1;
        that.page = 1;
        that.total = 0;
        that.count = 0;
21dfdeae   梁保满   平台管理员
308
309
310
311
        that.query.school = "";
        that.query.zuhu = "";
        // that.stationReport();
        // that._QueryData();
77ebf04d   梁保满   个人版
312
313
314
      });
    },
    methods: {
77ebf04d   梁保满   个人版
315
316
317
318
319
320
321
322
323
      linkTo(obj, type) {
        this.$router.push({
          path: "/deviceLog",
          query: {
            id: obj.id,
            type: type,
          },
        });
      },
77ebf04d   梁保满   个人版
324
325
326
327
      changePage(page) {
        this.page = page;
        this._QueryData(false);
      },
77ebf04d   梁保满   个人版
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
      // 基站统计数据
      async stationReport() {
        const { data, status, info } = await this.$request.stationReport();
        if (status === 0) {
          this.chartData =
            data.list?.map((item) => {
              return {
                name:
                  item.onlineStatus == "1"
                    ? "在线"
                    : item.onlineStatus == 0
                    ? "离线"
                    : "异常",
                value: item.total,
                rate: item.rate,
              };
            }) || [];
          this.count = data.total || 0;
        } else {
          this.$message.error(info);
        }
      },
      // 答题器统计数据
      async keyboardReport() {
        const { data, status, info } = await this.$request.keyboardReport();
        if (status === 0) {
          this.chartData2 =
            data.list?.map((item) => {
              return {
                name:
                  item.type == 1
                    ? "1日内"
                    : item.type == 2
                    ? "3日内"
                    : item.type == 3
                    ? "7日内"
                    : item.type == 4
                    ? "1月内"
                    : item.type == 5
                    ? "3月内"
                    : "3月以上",
                count: item.total,
                value: item.rate * 100,
              };
            }) || [];
          this.count = data.total || 0;
        } else {
          this.$message.error(info);
        }
      },
      setQuery() {
        //整理传参
        let query = {};
        if (this.query.sn) {
          query.sn = this.query.sn;
        } else {
          if (this.type == 1) {
            this.query.onlineStatus !== ""
              ? (query.onlineStatus = this.query.onlineStatus)
              : "";
          } else if (this.type == 2) {
            this.query.type !== "" ? (query.type = this.query.type) : "";
          }
          query.regionIds = [];
          query.schoolIds = [];
          query.gradeNames = [];
          query.classIds = [];
          this.query.classId?.map((item) => {
            if (item.length == 1) {
              if (!query.regionIds.includes(item[0])) {
                query.regionIds.push(item[0]);
              }
            } else if (item.length == 2) {
              if (!query.schoolIds.includes(item[1])) {
                query.schoolIds.push(item[1]);
              }
              query.regionIds.includes(item[0])
                ? query.regionIds.remove(item[0])
                : "";
            } else if (item.length == 3) {
              if (!query.schoolIds.includes(item[1])) {
                query.schoolIds.push(item[1]);
              }
              if (!query.gradeNames.includes(item[2])) {
                query.gradeNames.push(item[2]);
              }
              query.regionIds.includes(item[0])
                ? query.regionIds.remove(item[0])
                : "";
            } else if (item.length == 4) {
              if (!query.classIds.includes(item[3])) {
                query.classIds.push(item[3]);
              }
              query.regionIds.includes(item[0])
                ? query.regionIds.remove(item[0])
                : "";
              query.schoolIds.includes(item[1])
                ? query.schoolIds.remove(item[1])
                : "";
              query.gradeNames.includes(item[2])
                ? query.gradeNames.remove(item[2])
                : "";
            }
          });
  
          delete query.classId;
        }
        return query;
      },
      // 设备列表信息
      async _QueryData(isRef) {
        this.loading = true;
21dfdeae   梁保满   平台管理员
440
441
442
443
        let query = {...this.query};
        if(query.zuhu){
          delete query.school
        }
77ebf04d   梁保满   个人版
444
445
446
447
448
        if (isRef) {
          this.page = 1;
        }
        this.loading = true;
        this.tableData = [];
21dfdeae   梁保满   平台管理员
449
        const { data, status, info } = await this.$request.pDeviceList({
77ebf04d   梁保满   个人版
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
          ...query,
          deviceType: this.type,
          page: this.page,
          size: this.size,
        });
        this.loading = false;
        if (status == 0) {
          this.tableData =
            (data?.list &&
              data?.list.map((item) => {
                item.upgradeFlag = item.upgradeFlag == 1 ? true : false;
                return item;
              })) ||
            [];
  
          this.total = data.count;
          this.$nextTick(function () {
            this.$refs.main.scrollTop = 0;
            if (this.query.classId.length) {
              this.selectionTabIds = this.tableData.map((item) => {
                this.$refs.multipleTable.toggleRowSelection(item);
                return item.id;
              });
            }
          });
        } else {
          this.$message.error(info);
        }
      },
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .page-content {
    padding: 0 20px;
    height: 100%;
    overflow-y: auto;
  }
  .tab-box {
    padding: 20px 0 12px;
  }
  .content {
    background: #f8f8f8;
77ebf04d   梁保满   个人版
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
    border-radius: 10px;
    overflow: hidden;
    :deep(.fa-edit) {
      width: 12px;
      height: 12px;
      &::before {
        margin-left: 2px;
      }
    }
    :deep(.fa-eye) {
      width: 12px;
      height: 12px;
      &::before {
        margin-left: 1px;
      }
    }
    .chart-box {
      display: flex;
      overflow: hidden;
      height: 240px;
      border-bottom: 0.5px solid #e2e2e2;
      .device-num {
        width: 280px;
        border-right: 0.5px solid #e2e2e2;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .p1 {
          font-size: 28px;
        }
      }
      .chart {
        flex: 1;
        height: 100%;
      }
    }
    .table-box {
      padding: 20px;
      .answer-header {
        padding: 0;
        margin-bottom: 12px;
      }
    }
  }
  </style>