jesting0
2022-04-06 4a0fb138f5670809507c6483074622630e59eef3
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
<template>
  <Modal
    :value="visible"
    title="查看车辆异常"
    draggable
    sticky
    :mask="false"
    @on-visible-change="visibleChange"
    :width="456"
  >
    <Table :columns="columns" :data="list" size="small"> </Table>
    <template #footer>
      <Button type="primary" @click="close">关闭</Button>
    </template>
  </Modal>
</template>
 
<script>
import { webConfig } from "@/utils";
import HttpRequest from "@/api/request.js";
import { setLocalStorage, getLocalStorage } from "@/utils";
export default {
  name: "MonitorModalError",
  data() {
    return {
      httpRequest: new HttpRequest(webConfig.apiUrl),
      columns: [
        {
          title: "时间",
          key: "dt",
          width: 150,
        },
        {
          title: "异常",
          key: "error",
        },
      ],
      list: [],
    };
  },
  model: {
    prop: "visible",
    event: "visible-change",
  },
  props: {
    visible: Boolean,
    selectedAGVName: String,
  },
  methods: {
    visibleChange(value) {
      this.$emit("visible-change", value);
    },
    close() {
      this.$emit("visible-change", false);
    },
    loadData() {
      if (!this.selectedAGVName) return;
      const key = `abnormal.${this.selectedAGVName}`;
      this.list = getLocalStorage(key) || [];
      this.httpRequest
        .post(`vehicles/abnormal/${this.selectedAGVName}`)
        .then((res) => {
          var list = [
            {
              dt: new Date().toLocaleString(),
              error: res,
            },
            ...this.list,
          ];
          setLocalStorage(key, list);
          this.list = list;
        })
        .catch((err) => {
          this.$Message.error({ content: err, duration: 10 });
        });
    },
  },
  mounted() {
    this.loadData();
  },
  watch: {
    selectedAGVName() {
      if (this.selectedAGVName) this.loadData();
    },
  },
};
</script>
 
<style lang="less" scoped>
</style>