lgq
3 天以前 081f12a52906abe6c2d139fdc144135978681009
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
import dxui from '../../dxmodules/dxUi.js'
import std from '../../dxmodules/dxStd.js'
import viewUtils from './viewUtils.js'
import screen from '../screen.js'
import logger from '../../dxmodules/dxLogger.js'
import newPwdView from './config/newPwdView.js'
 
// 主要显示系统时间和状态图标
const topView = {}
topView.init = function () {
    const screenMain = dxui.View.build('topView', dxui.Utils.LAYER.TOP)
    topView.screenMain = screenMain
    viewUtils._clearStyle(screenMain)
    screenMain.scroll(false)
    screenMain.width(screen.screenSize.width)
    screenMain.height(screen.screenSize.height)
    screenMain.bgOpa(0)
    screenMain.clickable(false)
 
    const topBox = dxui.View.build('topBox', screenMain)
    topView.topBox = topBox
    viewUtils._clearStyle(topBox)
    topBox.width(screen.screenSize.width)
    topBox.height(screen.screenSize.height * (70 / 1024))
    topBox.bgOpa(0)
    topBox.clickable(false)
 
    topBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW)
    topBox.flexAlign(dxui.Utils.FLEX_ALIGN.SPACE_BETWEEN, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER)
 
    const topBoxLeft = dxui.View.build('topBoxLeft', topBox)
    viewUtils._clearStyle(topBoxLeft)
    topBoxLeft.width(400)
    topBoxLeft.height(70)
    topBoxLeft.padLeft(38)
    topBoxLeft.bgOpa(0)
    topBoxLeft.clickable(false)
 
    const topBoxRight = dxui.View.build('topBoxRight', topBox)
    viewUtils._clearStyle(topBoxRight)
    topBoxRight.width(400)
    topBoxRight.height(70)
    topBoxRight.padRight(38)
    topBoxRight.bgOpa(0)
    topBoxRight.clickable(false)
    topBoxRight.flexFlow(dxui.Utils.FLEX_FLOW.ROW)
    topBoxRight.flexAlign(dxui.Utils.FLEX_ALIGN.END, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER)
    
    const ethShow = dxui.Image.build('ethShow', topBoxRight)
    topView.ethShow = ethShow
    ethShow.source(screen.resourcePath.imagePath + '/ethernet.png')
    ethShow.clickable(false)
    ethShow.hide()
 
    const wifiShow = dxui.Image.build('wifiShow', topBoxRight)
    topView.wifiShow = wifiShow
    wifiShow.source(screen.resourcePath.imagePath + '/wifi.png')
    wifiShow.clickable(false)
    wifiShow.hide()
 
    const _4gShow = dxui.Image.build('4gShow', topBoxRight)
    topView._4gShow = _4gShow
    _4gShow.source(screen.resourcePath.imagePath + '/4g.png')
    _4gShow.clickable(false)
    _4gShow.hide()
 
    const mqttShow = dxui.Image.build('mqttShow', topBoxRight)
    topView.mqttShow = mqttShow
    mqttShow.source(screen.resourcePath.imagePath + '/mqtt.png')
    mqttShow.clickable(false)
    mqttShow.hide()
 
    // 添加长按进入管理页面的区域
    const adminArea = dxui.View.build('adminArea', screenMain)
    viewUtils._clearStyle(adminArea)
    adminArea.setSize(120, 120)
    adminArea.align(dxui.Utils.ALIGN.TOP_RIGHT, 0, 0)
    adminArea.bgOpa(0)
    adminArea.clickable(true)
    
    logger.info('[topView]: 长按区域已创建,位置:右上角')
    
    let pressStartTime = 0
    let isPressing = false
    let longPressTimer = null
    
    // 使用PRESSING事件检测按住状态
    adminArea.on(dxui.Utils.EVENT.PRESSING, () => {
        if (!isPressing) {
            // 第一次检测到按住
            isPressing = true
            pressStartTime = Date.now()
            logger.info('[topView]: 开始按住')
            
            // 启动长按计时器
            longPressTimer = std.setTimeout(() => {
                const pressDuration = Date.now() - pressStartTime
                logger.info(`[topView]: 按住不放${pressDuration}ms成功,进入管理页面`)
                dxui.loadMain(newPwdView.screenMain)
                longPressTimer = null
            }, 3000)
        }
    })
    
    // 使用CLICK事件检测释放(当用户释放时,PRESSING事件会停止)
    adminArea.on(dxui.Utils.EVENT.CLICK, () => {
        if (isPressing) {
            const pressDuration = Date.now() - pressStartTime
            logger.info(`[topView]: 按住时间${pressDuration}ms,释放`)
            
            // 清除计时器
            if (longPressTimer) {
                std.clearTimeout(longPressTimer)
                longPressTimer = null
            }
            
            isPressing = false
        } else {
            logger.info('[topView]: 长按区域检测到点击事件')
        }
    })
 
}
 
// 切换主题,两套图标,一套白色,一套黑色
topView.changeTheme = function (dark) {
    if (dark) {
        // topView.dateLbl.textColor(0x767676)
        topView.ethShow.source(screen.resourcePath.imagePath + '/ethernet_dark.png')
        topView.mqttShow.source(screen.resourcePath.imagePath + '/mqtt_dark.png')
        topView.wifiShow.source(screen.resourcePath.imagePath + '/wifi_dark.png')
        topView._4gShow.source(screen.resourcePath.imagePath + '/4g_dark.png')
    } else {
        // topView.dateLbl.textColor(0x2e2e2e)
        topView.ethShow.source(screen.resourcePath.imagePath + '/ethernet.png')
        topView.mqttShow.source(screen.resourcePath.imagePath + '/mqtt.png')
        topView.wifiShow.source(screen.resourcePath.imagePath + '/wifi.png')
        topView._4gShow.source(screen.resourcePath.imagePath + '/4g.png')
    }
}
 
// mqtt连接状态
topView.mqttConnectState = function (connected) {
    if (connected) {
        topView.mqttShow.show()
    } else {
        topView.mqttShow.hide()
    }
}
 
// eth连接状态
topView.ethConnectState = function (connected, type) {
    if (connected) {
        if (type == 1) {
            topView.ethShow.show()
            topView.wifiShow.hide()
            topView._4gShow.hide()
        } else if (type == 2) {
            topView.ethShow.hide()
            topView.wifiShow.show()
            topView._4gShow.hide()
        } else if (type == 4) {
            topView.ethShow.hide()
            topView.wifiShow.hide()
            topView._4gShow.show()
        }
    } else {
        topView.ethShow.hide()
        topView.wifiShow.hide()
        topView._4gShow.hide()
    }
}
export default topView