Novecane
2025-02-15 d13e470cf0256e3ffbc3b0ad34df27ce0b0b5e5f
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
"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_assets = require("../../../common/assets.js");
const api_index = require("../../../api/index.js");
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const state = common_vendor.ref({});
    const controlValue = common_vendor.ref(100);
    const logEntry = common_vendor.ref([]);
    const temp = common_vendor.ref({});
    const controInfo = common_vendor.ref({});
    const flag = common_vendor.ref(false);
    let positionInterval;
    common_vendor.onMounted(async () => {
      const option = getCurrentPages()[getCurrentPages().length - 1].options;
      const deviceInfo = JSON.parse(decodeURIComponent(option.device));
      state.value = deviceInfo;
      getOpeHistory();
      getControlData();
      try {
        const res = await api_index.getDeviceInfoByDeviceId(deviceInfo.facilityCode);
        state.value = {
          ...res.data,
          ...deviceInfo
        };
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/router/deviceInfo/index.vue:92", "Failed to fetch device info:", error);
      }
    });
    const startGetPosition = () => {
      if (positionInterval) {
        clearInterval(positionInterval);
      }
      common_vendor.index.showToast({
        title: "操作设备中",
        icon: "loading",
        mask: true,
        duration: 3500
      });
      positionInterval = setInterval(() => {
        api_index.getControlInfo(state.value.facilityCode).then((res) => {
          if (res.data.position >= 100) {
            flag.value = false;
            clearInterval(positionInterval);
          }
        }).catch((error) => {
          common_vendor.index.__f__("error", "at pages/router/deviceInfo/index.vue:115", "Error fetching control info:", error);
          clearInterval(positionInterval);
        });
      }, 2e3);
    };
    const removeSharedDevice = async () => {
      temp.value = {
        facilityCode: state.value.facilityCode
      };
      try {
        const res = await api_index.deleteDevice(temp.value);
        if (res.code === 200) {
          common_vendor.index.redirectTo({
            url: "/pages/layout/index"
          });
        } else {
          common_vendor.index.showToast({
            title: "设备删除失败",
            icon: "fail"
          });
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/router/deviceInfo/index.vue:144", "Failed to delete device:", error);
      }
    };
    const handleControlChange = (e) => {
      controInfo.value = {
        sn: state.value.facilityCode,
        destinationPosition: e.detail.value
      };
      api_index.deviceControlInfo(controInfo.value).then((res) => {
        if (res.code === 200) {
          flag.value = true;
          startGetPosition();
        }
      }).catch((error) => {
        common_vendor.index.__f__("error", "at pages/router/deviceInfo/index.vue:161", "Failed to control device:", error);
      });
    };
    const getOpeHistory = () => {
      api_index.getOpeInfo(state.value.facilityCode).then((res) => {
        if (res.code === 200) {
          logEntry.value = res.data;
        }
      }).catch((e) => {
        common_vendor.index.__f__("log", "at pages/router/deviceInfo/index.vue:175", "fail info", e);
      });
    };
    const getControlData = () => {
      api_index.getControlInfo(state.value.facilityCode).then((res) => {
        controlValue.value = res.data.position;
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_assets._imports_0$1,
        b: common_vendor.t(state.value.facilityName),
        c: common_vendor.t(state.value.facilityCode),
        d: state.value.isOnLine == 1
      }, state.value.isOnLine == 1 ? {} : {}, {
        e: common_vendor.t(state.value.dcInputVolt),
        f: common_vendor.t(state.value.rssi),
        g: common_vendor.o(handleControlChange),
        h: controlValue.value,
        i: flag.value,
        j: common_vendor.f(logEntry.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.operateName),
            b: common_vendor.t(item.operateStatus),
            c: common_vendor.t(item.createTimeView),
            d: index
          };
        }),
        k: common_vendor.o(removeSharedDevice)
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-68c572bb"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/router/deviceInfo/index.js.map