yangyin
2024-07-04 4352f162401ac7fe7d1bfa517039e6c61c909a3d
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
155
156
157
158
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
//app.js
import Request from "./utils/api"
var Constant = require('./utils/constant');
App({
  onLaunch: function () {
    //获取当前系统信息
    this.globalData.sysInfo = wx.getSystemInfoSync();
    // console.log(this.globalData.sysInfo);
    //获取当前设备信息
    this.getDeviceInfo();
    this.globalData.timer = null
    //获取当前用户信息
    var getUserInfoFromCache = wx.getStorageSync('LoginUserInfo');
    // console.log(getUserInfoFromCache);
    if (getUserInfoFromCache) {
      //
      this.globalData.userInfo = getUserInfoFromCache;
    } else {
      this.globalData.userInfo = null;
    }
  },
 
  //获取报警记录
  getAllAlarmList() {
    var that = this
    // that.cancelTimer()
    Request({
      url: Constant.BASE_SERVER_URL + 'Monitor/Value/Alarm/Record/Std/GetFluzzyPageList@V1.0',
      method: 'GET',
      data: {
        AlarmStatus: 0,
        PageIndex: that.globalData.PageIndex,
        PageSize: that.globalData.PageSize,
      },
      fail: function (err) {
        wx.showModal({
          title: '',
          content: '通讯失败',
        })
      }, //请求失败
      success: (res) => {
        var result = res.data
        if (res.statusCode == 404) {
          wx.showModal({
            title: '',
            content: '通讯失败',
          })
          that.globalData.alarmTotal = 0
          return
        }
        if (result.Code != 0) {
          wx.showModal({
            title: '提示',
            content: result.Message,
            showCancel: false,
          })
          return;
        }
        // result.Data.Total=1
        if (result.Data.Total == 0) {
          that.globalData.monitorDataTimeOut = false
          that.startTimer()
          return;
        }
        that.getMonitorDialog()
        that.startTimer()
 
      }
    })
  },
  //初始化时打开报警消息通知弹窗
  getMonitorDialog() {
    var that = this
    if (that.globalData.monitorModalName) return
    wx.showModal({
      title: '消息报警',
      content: '您有新的报警消息需要处理,点击前往报警处理查看',
      success: function (res) {
        if (res.confirm) {
          that.workMonitorSure()
          that.globalData.monitorModalName = true
          that.globalData.monitorDataTimeOut = true
        } else {
          that.globalData.monitorModalName = false
          that.globalData.monitorDataTimeOut = false
          that.startTimer()
        }
      }
    })
    that.globalData.monitorModalName = true
    that.globalData.monitorDataTimeOut = true
    that.cancelTimer()
  },
  onStartAlarm(){
    this.globalData.monitorDataTimeOut = false
    this.globalData.monitorModalName = false
    this.startTimer()
  },
  onReset() {
    this.globalData.monitorDataTimeOut = true
    this.cancelTimer()
  },
  startTimer() {
    var that = this
    that.cancelTimer()
    if (that.globalData.monitorDataTimeOut) return
    that.globalData.timer = setInterval(() => {
      that.getAllAlarmList()
    }, 300000)
  },
  cancelTimer() {
    var that = this;
    // 取消定时器
    if (that.globalData.timer) {
      clearTimeout(that.globalData.timer);
      that.globalData.timer = null;
    }
  },
  //报警消息通知跳转到报警处理
  workMonitorSure() {
    wx.navigateTo({
      url: '/other/alarm/index',
    })
    this.cancelTimer()
  },
  // 获取当前设备信息
  getDeviceInfo: function (callback) {
    var that = this;
    //
    if (this.globalData.deviceInfo) {
      typeof callback == "function" && callback(this.globalData.deviceInfo)
    } else {
      wx.getSystemInfo({
        success: function (res) {
          that.globalData.deviceInfo = res;
          var e = res
          //获取屏幕尺寸,放到全局结构中
          that.globalData.screenSize = {
            height: res.windowHeight,
            width: res.windowWidth
          };
          typeof callback == "function" && callback(that.globalData.deviceInfo)
          //自定义顶部custom组件的属性
          that.globalData.StatusBar = e.statusBarHeight;
          let capsule = wx.getMenuButtonBoundingClientRect();
          if (capsule) {
            that.globalData.Custom = capsule;
            that.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
          } else {
            that.globalData.CustomBar = e.statusBarHeight + 50;
          }
        }
      })
    }
  },
  getSystemInfo: function () {
    wx.getSystemInfo({ //获取系统信息
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let capsule = wx.getMenuButtonBoundingClientRect();
        if (capsule) {
          this.globalData.Custom = capsule;
          this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
        } else {
          this.globalData.CustomBar = e.statusBarHeight + 50;
        }
      }
    })
  },
  getModel: function () {
    return this.globalData.sysInfo["model"]
  },
  getVersion: function () {
    return this.globalData.sysInfo["version"]
  },
  getSystem: function () {
    return this.globalData.sysInfo["system"]
  },
  getPlatform: function () {
    return this.globalData.sysInfo["platform"]
  },
  getSDKVersion: function () {
    return this.globalData.sysInfo["SDKVersion"]
  },
  getWindowWidth: function () {
    return this.globalData.sysInfo["windowWidth"]
  },
  getWindowHeight: function () {
    return this.globalData.sysInfo["windowHeight"]
  },
 
 
 
  //检测用户是否登陆
  onCheckLogin: function (cbSuccess, cbFail) {
    var that = this;
    var userInfo = that.globalData.userInfo;
    //console.log(userInfo)
    if (!userInfo) {
      wx.navigateTo({
        url: '/login/login/index',
      });
    }
    return;
    wx.getStorage({ //如果没有缓存内容直接 跳转 登录页授权
      key: 'LoginUserInfo',
      success: function (res) {
        //console.log("用户信息来源缓存",res)
        that.globalData.userInfo = res.data;
        //wx.redirectTo({ url: '/Start/author/index', })
        //if (res.data) {
        //return;
        //} else { 
        //return;
        //}
      },
      fail: function (res) {
        console.log(res)
        //if (res.errMsg == "getStorage:fail data not found") {
        //wx.redirectTo({ url: '/Start/author/index', })
        //}
        return;
      },
    })
  },
  globalData: {
    // 设备信息,主要用于获取屏幕尺寸而做适配
    deviceInfo: null,
    //系统信息
    sysInfo: null,
    // 用户信息
    userInfo: null, //null/!null
    screenSize: null, //全局的屏幕尺寸,已经去掉了上边的标题栏  
    timer: null,
    PageIndex: 1,
    PageSize: 9,
    alarmList: [],
    alarmTotal: 0,
    monitorModalName: false, //是否显示报警提示
    monitorDataTimeOut: false,
    mockData: []
  }
})