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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
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
440
441
442
443
444
445
446
447
448
449
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
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
import dxui from '../../../../dxmodules/dxUi.js'
import std from '../../../../dxmodules/dxStd.js'
import viewUtils from "../../viewUtils.js"
import topView from "../../topView.js"
import configView from '../configView.js'
import i18n from "../../i18n.js"
import screen from '../../../screen.js'
import map from '../../../../dxmodules/dxMap.js'
const net_map = map.get("NET")
const networkSettingView = {}
 
networkSettingView.init = function () {
    /**************************************************创建屏幕*****************************************************/
    const screenMain = dxui.View.build('networkSettingView', dxui.Utils.LAYER.MAIN)
    // 默认返回的上级界面是配置页面,在企业微信模式下,返回的上级界面是企业微信网络配置页面
   
    screenMain.backScreen = configView.screenMain
    networkSettingView.screenMain = screenMain
    screenMain.scroll(false)
    screenMain.bgColor(0xffffff)
    screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => {
        topView.changeTheme(true)
        const configAll = screen.getConfig()
 
        // Store initial state for comparison on save
        networkSettingView.initialConfig = {
            type: configAll["net.type"],
            dhcp: configAll["net.dhcp"],
            ip: configAll["net.ip"],
            mask: configAll["net.mask"],
            gateway: configAll["net.gateway"],
            dns: configAll["net.dns"].split(",")[0] ? configAll["net.dns"].split(",")[0] : "",
            ssid: configAll["net.ssid"],
            psk: configAll["net.psk"]
        }
 
        networkSettingView.changeNetType(configAll["net.type"])
        let netList = []
        switch (screen.dxDriver.DRIVER.MODEL) {
            case "vf105":
                netList = [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView.wifi')]
                break;
            case "vf114":
                netList = [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView.wifi')]
                break;
            case "vf202":
                netList = [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView._4G')]
                break;
            case "vf203":
                netList = [i18n.t('networkSettingView.ethernet'), i18n.t('networkSettingView.wifi'), i18n.t('networkSettingView._4G')]
                break;
            default:
                break;
        }
        networkSettingView.netInfo[0].value = netList
        networkSettingView.netInfo[0].dropdown.setOptions(networkSettingView.netInfo[0].value)
        networkSettingView.refresh()
    })
 
    screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => {
        wifiListBoxClose.send(dxui.Utils.EVENT.CLICK)
    })
 
    const titleBox = viewUtils.title(screenMain, configView.screenMain, 'networkSettingViewTitle', 'networkSettingView.title')
    titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (50 / 1280))
    screenMain.titleBox = titleBox
    screenMain.titleBox.backScreen = screenMain.backScreen
 
 
    const networkSettingBox = dxui.View.build('networkSettingBox', screenMain)
    viewUtils._clearStyle(networkSettingBox)
    networkSettingBox.setSize(screen.screenSize.width * (600 / 600), screen.screenSize.height * (700 / 1280))
    networkSettingBox.bgColor(0xeeeeee)
    networkSettingBox.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (142 / 1280))
    networkSettingBox.borderWidth(1)
    networkSettingBox.setBorderColor(0xDEDEDE)
    networkSettingBox.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_TOP, 0)
    networkSettingBox.bgOpa(0)
    networkSettingBox.flexFlow(dxui.Utils.FLEX_FLOW.ROW_WRAP)
    networkSettingBox.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.START, dxui.Utils.FLEX_ALIGN.START)
    networkSettingBox.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
 
    networkSettingView.netInfo = [
        {
            title: 'networkSettingView.type',
            value: [],
            type: 'dropdown',
            obj: null,
            dropdown: null
        },
        {
            title: 'networkSettingView.wifiName',
            value: null,
            type: 'input',
            obj: null,
        },
        {
            title: 'networkSettingView.wifiPwd',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.dhcp',
            value: null,
            type: 'switch',
            obj: null
        },
        {
            title: 'networkSettingView.ip',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.mask',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.gateway',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.dns',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.dns2',
            value: null,
            type: 'input',
            obj: null
        },
        {
            title: 'networkSettingView.mac',
            value: " ",
            type: 'label',
            obj: null,
            label: null
        },
        {
            title: 'networkSettingView.status',
            value: i18n.t('networkSettingView.networkUnconnected'),
            type: 'label',
            obj: null,
            label: null
        }
    ]
 
    networkSettingView.netInfo.forEach((item, index) => {
        const networkSettingItem = dxui.View.build(networkSettingBox.id + item.title, networkSettingBox)
        if (item.title === 'networkSettingView.dns2') {
            networkSettingItem.hide()
        }
        viewUtils._clearStyle(networkSettingItem)
        item.obj = networkSettingItem
        networkSettingItem.setSize(screen.screenSize.width * (560 / 600), screen.screenSize.height * (76 / 1280))
        networkSettingItem.bgColor(0xffffff)
        networkSettingItem.borderWidth(1)
        networkSettingItem.setBorderColor(0xDEDEDE)
        networkSettingItem.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0)
 
        const title = dxui.Label.build(item.title, networkSettingItem)
        title.textFont(viewUtils.font(26))
        title.align(dxui.Utils.ALIGN.LEFT_MID, 0, 0)
        title.dataI18n = item.title
 
 
        if (item.type === 'input') {
            const input = viewUtils.input(networkSettingItem, item.title + 'input', undefined, undefined, 'networkSettingView.input')
            input.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0)
            input.setSize(screen.screenSize.width * (310 / 600), screen.screenSize.height * (45 / 1280))
            item.input = input
 
            if (item.title === 'networkSettingView.wifiName') {
                input.setSize(screen.screenSize.width * (200 / 600), screen.screenSize.height * (45 / 1280))
                input.align(dxui.Utils.ALIGN.RIGHT_MID, -screen.screenSize.width * (110 / 600), 0)
 
                const searchBtn = dxui.Button.build('wifiSearchBtn', networkSettingItem)
                searchBtn.setSize(screen.screenSize.width * (100 / 600), screen.screenSize.height * (45 / 1280))
                searchBtn.radius(screen.screenSize.width * (10 / 600))
                searchBtn.bgColor(0xEAEAEA)
                searchBtn.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0)
 
                const searchBtnLabel = dxui.Label.build('wifiSearchBtnLabel', searchBtn)
                searchBtnLabel.dataI18n = 'networkSettingView.search'
                searchBtnLabel.align(dxui.Utils.ALIGN.CENTER, 0, 0)
                searchBtnLabel.textFont(viewUtils.font(24))
                searchBtnLabel.textColor(0x000000)
 
                searchBtn.on(dxui.Utils.EVENT.CLICK, () => {
                    if (networkSettingView.wifiScanTimer) {
                        std.clearInterval(networkSettingView.wifiScanTimer);
                        networkSettingView.wifiScanTimer = null;
                    }
                    // Initial scan
                    screen.netGetWifiSsidList()
                    wifiList.refresh()
                    wifiListBoxbg.moveForeground()
                    wifiListBoxbg.show()
                    // Start new polling
                    networkSettingView.wifiScanTimer = std.setInterval(() => {
                        screen.netGetWifiSsidList()
                    }, 3000)
                })
            }
        }
 
        if (item.type === 'switch') {
            const __switch = dxui.Switch.build(item.title + 'switch', networkSettingItem)
            __switch.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0)
            __switch.setSize(screen.screenSize.width * (70 / 600), screen.screenSize.height * (35 / 1280))
            __switch.bgColor(0x000000, NativeObject.APP.NativeComponents.NativeEnum.LV_PART_INDICATOR | NativeObject.APP.NativeComponents.NativeEnum.LV_STATE_CHECKED)
            item.switch = __switch
        }
 
        if (item.type === 'dropdown') {
            const dropdown = dxui.Dropdown.build(item.title + 'dropdown', networkSettingItem)
            dropdown.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0)
            dropdown.setSize(screen.screenSize.width * (200 / 600), screen.screenSize.height * (45 / 1280))
            dropdown.padTop((screen.screenSize.height * (45 / 1280) - viewUtils.font(26).obj.lvFontGetLineHeight()) / 2)
            dropdown.padBottom(0)
            dropdown.textFont(viewUtils.font(26))
            dropdown.getList().textFont(viewUtils.font(26))
            dropdown.setSymbol(screen.dropdownSymbol)
            dropdown.setOptions(item.value)
            item.dropdown = dropdown
 
            if (item.title === 'networkSettingView.type') {
                dropdown.on(dxui.Utils.EVENT.VALUE_CHANGED, () => {
                    switch (dropdown.getSelected()) {
                        case 0:
                            networkSettingView.changeNetType(1)
                            // 以太网
                            break;
                        case 1:
                            networkSettingView.changeNetType(screen.dxDriver.DRIVER.MODEL == "vf202" ? 4 : 2)
                            // 切换为WiFi(vf202是切换为4g)
                            break;
                        case 2:
                            networkSettingView.changeNetType(4)
                            // 切换为4g
                            break;
                        default:
                            break;
                    }
                })
            }
        }
 
        if (item.type === 'label') {
            const label = dxui.Label.build(item.title + 'label', networkSettingItem)
            label.textFont(viewUtils.font(26))
            label.align(dxui.Utils.ALIGN.RIGHT_MID, 0, 0)
            label.text(item.value)
            label.textColor(0x333333)
            item.label = label
        }
 
    })
 
    // wifi列表
    const wifiListBoxbg = dxui.View.build('wifiListBoxbg', screenMain)
    viewUtils._clearStyle(wifiListBoxbg)
    wifiListBoxbg.setSize(screen.screenSize.width, screen.screenSize.height)
    wifiListBoxbg.bgColor(0x000000)
    wifiListBoxbg.bgOpa(50)
    wifiListBoxbg.hide()
    wifiListBoxbg.on(dxui.Utils.EVENT.CLICK, () => {
        wifiListBoxClose.send(dxui.Utils.EVENT.CLICK)
    })
 
    const wifiListBox = dxui.View.build('wifiListBox', wifiListBoxbg)
    viewUtils._clearStyle(wifiListBox)
    wifiListBox.setSize(screen.screenSize.width * (520 / 600), screen.screenSize.height * (800 / 1280))
    wifiListBox.bgColor(0xffffff)
    wifiListBox.radius(screen.screenSize.width * (20 / 600))
    wifiListBox.align(dxui.Utils.ALIGN.CENTER, 0, 0)
 
    const wifiListBoxTitle = dxui.Label.build('wifiListBoxTitle', wifiListBox)
    wifiListBoxTitle.textFont(viewUtils.font(28))
    wifiListBoxTitle.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (32 / 1280))
    wifiListBoxTitle.dataI18n = 'networkSettingView.wifiList'
 
    const wifiListBoxClose = viewUtils.imageBtn(wifiListBox, 'wifiListBoxClose', screen.resourcePath.imagePath + '/close_small.png')
    wifiListBoxClose.align(dxui.Utils.ALIGN.TOP_RIGHT, -screen.screenSize.width * (36 / 600), screen.screenSize.height * (30 / 1280))
    wifiListBoxClose.on(dxui.Utils.EVENT.CLICK, () => {
        wifiListBoxbg.hide()
        if (networkSettingView.wifiScanTimer) {
            std.clearInterval(networkSettingView.wifiScanTimer)
            networkSettingView.wifiScanTimer = null
        }
        networkSettingView.wifiListData = []
    })
 
    const closeBtn = dxui.Button.build('closeBtn', wifiListBox)
    closeBtn.setSize(screen.screenSize.width * (172 / 600), screen.screenSize.height * (50 / 1280))
    closeBtn.radius(screen.screenSize.width * (10 / 600))
    closeBtn.bgColor(0xEAEAEA)
    closeBtn.align(dxui.Utils.ALIGN.BOTTOM_LEFT, screen.screenSize.width * (69 / 600), -screen.screenSize.height * (53 / 1280))
    closeBtn.on(dxui.Utils.EVENT.CLICK, () => {
        wifiListBoxClose.send(dxui.Utils.EVENT.CLICK)
    })
 
    const closeBtnText = dxui.Label.build('closeBtnText', closeBtn)
    closeBtnText.textFont(viewUtils.font(24))
    closeBtnText.dataI18n = 'networkSettingView.close'
    closeBtnText.align(dxui.Utils.ALIGN.CENTER, 0, 0)
    closeBtnText.textColor(0x000000)
 
    const confirmBtn = dxui.Button.build('confirmBtn', wifiListBox)
    confirmBtn.setSize(screen.screenSize.width * (172 / 600), screen.screenSize.height * (50 / 1280))
    confirmBtn.radius(screen.screenSize.width * (10 / 600))
    confirmBtn.bgColor(0x000000)
    confirmBtn.align(dxui.Utils.ALIGN.BOTTOM_RIGHT, -screen.screenSize.width * (69 / 600), -screen.screenSize.height * (53 / 1280))
    confirmBtn.on(dxui.Utils.EVENT.CLICK, () => {
        wifiListBoxClose.send(dxui.Utils.EVENT.CLICK)
        networkSettingView.netInfo[1].input.text(networkSettingView.selectedValue)
    })
 
    const confirmBtnText = dxui.Label.build('confirmBtnText', confirmBtn)
    confirmBtnText.textFont(viewUtils.font(24))
    confirmBtnText.dataI18n = 'networkSettingView.confirm'
    confirmBtnText.align(dxui.Utils.ALIGN.CENTER, 0, 0)
    confirmBtnText.textColor(0xffffff)
 
    // const wifiListData = ['办公区无线网络']
    // const wifiListData = ['办公区无线网络', '生产区无线网络', '测试区无线网络', '访客区无线网络', '开发区无线网络']
    networkSettingView.wifiListData = []
 
    networkSettingView.selectedValue = screen.getConfig()["net.ssid"]
    networkSettingView.selectedItem = null
 
    const wifiList = dxui.View.build('wifiList', wifiListBox)
    viewUtils._clearStyle(wifiList)
    const itemCount = 10
    const itemHeight = screen.screenSize.height * (60 / 1280)
    wifiList.setSize(screen.screenSize.width * (440 / 600), itemHeight * itemCount)
    wifiList.flexFlow(dxui.Utils.FLEX_FLOW.COLUMN)
    wifiList.obj.lvObjSetStylePadAll(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
    wifiList.obj.lvObjSetStylePadGap(0, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
 
    const listItems = []
 
    for (let i = 0; i < itemCount; i++) {
        const item = dxui.View.build(`wifiListItem${i}`, wifiList)
        viewUtils._clearStyle(item)
        item.setSize(screen.screenSize.width * (440 / 600), itemHeight)
        item.bgOpa(0)
        item.borderWidth(1)
        item.setBorderColor(0xDEDEDE)
        item.obj.setStyleBorderSide(dxui.Utils.ENUM.LV_BORDER_SIDE_BOTTOM, 0)
 
        const wifiItemLbl = dxui.Label.build(item.id + 'wifiItemLbl', item)
        wifiItemLbl.align(dxui.Utils.ALIGN.LEFT_MID, screen.screenSize.width * (25 / 600), 0)
        wifiItemLbl.textFont(viewUtils.font(24))
        wifiItemLbl.textColor(0x888888)
        wifiItemLbl.width(screen.screenSize.width * (300 / 600))
        wifiItemLbl.longMode(dxui.Utils.LABEL_LONG_MODE.SCROLL_CIRCULAR)
 
        item.radius(10)
        item.on(dxui.Utils.EVENT.CLICK, () => {
            if (networkSettingView.selectedItem) {
                networkSettingView.selectedItem.bgOpa(0)
            }
            networkSettingView.selectedItem = item
            networkSettingView.selectedValue = wifiItemLbl.text()
            item.bgColor(0xEAEAEA)
            item.bgOpa(100)
        })
 
        const wifiItemImg = dxui.Image.build(item.id + 'wifi', item)
        wifiItemImg.align(dxui.Utils.ALIGN.RIGHT_MID, -screen.screenSize.width * (24 / 600), 0)
        wifiItemImg.source(screen.resourcePath.imagePath + '/wifi.png')
 
        const lockItemImg = dxui.Image.build(item.id + 'lock', item)
        lockItemImg.align(dxui.Utils.ALIGN.RIGHT_MID, -screen.screenSize.width * (55 / 600), 0)
        lockItemImg.source(screen.resourcePath.imagePath + '/lock.png')
 
        listItems.push({ container: item, label: wifiItemLbl, wifiImg: wifiItemImg, lockImg: lockItemImg })
        item.hide()
    }
 
    wifiList.refresh = () => {
        const data = networkSettingView.wifiListData.slice(0, itemCount)
        listItems.forEach((item, index) => {
            if (data[index]) {
                item.label.text(data[index])
                item.wifiImg.show()
                item.lockImg.show()
                item.container.show()
            } else {
                item.container.hide()
            }
        })
    }
    wifiList.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (80 / 1280))
    wifiList.bgOpa(0)
    networkSettingView.wifiList = wifiList
 
    const saveBtn = viewUtils.bottomBtn(screenMain, screenMain.id + 'saveBtn', 'networkSettingView.save', () => {
        if (!networkSettingView._isConfigChanged()) {
            // No changes, just go back
            dxui.loadMain(screenMain.backScreen)
            return
        }
 
        let netType = 1
        switch (networkSettingView.netInfo[0].dropdown.getSelected()) {
            case 0:
                netType = 1
                break;
            case 1:
                netType = screen.dxDriver.DRIVER.MODEL == "vf202" ? 4 : 2
                break;
            case 2:
                netType = 4
                break;
            default:
                break;
        }
 
        let saveConfigData = {
            "net": {
                "type": netType,
                "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
                "ip": networkSettingView.netInfo[4].input.text(),
                "mask": networkSettingView.netInfo[5].input.text(),
                "gateway": networkSettingView.netInfo[6].input.text(),
                "dns": networkSettingView.netInfo[7].input.text(),
                "psk": networkSettingView.netInfo[2].input.text(),
                "ssid": networkSettingView.netInfo[1].input.text()
            }
        }
        if (!networkSettingView.netInfo[3].switch.isSelect()) {
            switch (networkSettingView.netInfo[0].dropdown.getSelected()) {
                case 0:
                    // 以太网
                    saveConfigData = {
                        "net": {
                            "type": netType,
                            "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
                            "ip": networkSettingView.netInfo[4].input.text(),
                            "mask": networkSettingView.netInfo[5].input.text(),
                            "gateway": networkSettingView.netInfo[6].input.text(),
                            "dns": networkSettingView.netInfo[7].input.text(),
                        }
                    }
                    break;
                case 1:
                    // WIFI/4G
                    saveConfigData = screen.dxDriver.DRIVER.MODEL == "vf202" ? {
                        "net": {
                            "type": netType,
                        }
                    } : {
                        "net": {
                            "type": netType,
                            "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
                            "psk": networkSettingView.netInfo[2].input.text(),
                            "ssid": networkSettingView.netInfo[1].input.text(),
                            "ip": networkSettingView.netInfo[4].input.text(),
                            "mask": networkSettingView.netInfo[5].input.text(),
                            "gateway": networkSettingView.netInfo[6].input.text(),
                        }
                    }
                    break;
                case 2:
                    // 4G
                    saveConfigData = {
                        "net": {
                            "type": netType,
                        }
                    }
                    break;
                default:
                    break;
            }
        } else {
            switch (networkSettingView.netInfo[0].dropdown.getSelected()) {
                case 0:
                    // 以太网
                    saveConfigData = {
                        "net": {
                            "type": netType,
                            "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
                        }
                    }
                    break;
                case 1:
                    // WIFI/4G
                    saveConfigData = screen.dxDriver.DRIVER.MODEL == "vf202" ?  {
                        "net": {
                            "type": netType,
                        }
                    } : {
                        "net": {
                            "type": netType,
                            "dhcp": networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
                            "psk": networkSettingView.netInfo[2].input.text(),
                            "ssid": networkSettingView.netInfo[1].input.text()
                        }
                    } 
                    break;
                case 2:
                    //4G
                    saveConfigData = {
                        "net": {
                            "type": netType,
                        }
                    }
                    break;
                default:
                    break;
            }
        }
 
        const res = screen.saveConfig(saveConfigData)
 
        if (res === true) {
            // 保存成功
            networkSettingView.statusPanel.success()
            std.setTimeout(() => {
                // 成功返回上一层界面
                dxui.loadMain(screenMain.backScreen)
            }, 500)
            screen.updateNetStatus("disconnect")
            screen.fireNetStatus()
            screen.netReconnect()
        } else {
            networkSettingView.statusPanel.fail()
        }
    })
    saveBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -screen.screenSize.height * (40 / 1280))
 
    networkSettingView.changeNetType(1)
 
    networkSettingView.statusPanel = viewUtils.statusPanel(screenMain, 'networkSettingView.success', 'networkSettingView.fail')
 
    screen.updateNetStatus(net_map.get("NET_STATUS"))//有可能执行到这里的时候网络已经连接完成
}
 
networkSettingView._isConfigChanged = function () {
    //如果打开界面时的数据和点击保存按钮时的数据前后没有发生变化,就不触发重连和数据保存
    if (net_map.get("NET_STATUS") != "connected") {
        return true //但是假如网络没连上,就一定要触发重连和数据保存
    }
    const selectedTypeIndex = networkSettingView.netInfo[0].dropdown.getSelected()
    let currentType
    switch (selectedTypeIndex) {
        case 0:
            currentType = 1 // Ethernet
            break;
        case 1:
            currentType = screen.dxDriver.DRIVER.MODEL == "vf202" ? 4 : 2 // WiFi/4G
            break;
        case 2:
            currentType = 4 // 4G
            break;
        default:
            break;
    }
 
    const currentConfig = {
        type: currentType,
        dhcp: networkSettingView.netInfo[3].switch.isSelect() ? 2 : 1,
        ip: networkSettingView.netInfo[4].input.text(),
        mask: networkSettingView.netInfo[5].input.text(),
        gateway: networkSettingView.netInfo[6].input.text(),
        dns: networkSettingView.netInfo[7].input.text(),
        psk: networkSettingView.netInfo[2].input.text(),
        ssid: networkSettingView.netInfo[1].input.text()
    }
 
    const initial = networkSettingView.initialConfig
    if (initial.type !== currentConfig.type ||
        initial.dhcp !== currentConfig.dhcp ||
        initial.ssid !== currentConfig.ssid ||
        initial.psk !== currentConfig.psk) {
        return true
    }
 
    if (currentConfig.dhcp === 1) { // Static IP checks only if DHCP is off
        if (initial.ip !== currentConfig.ip ||
            initial.mask !== currentConfig.mask ||
            initial.gateway !== currentConfig.gateway ||
            (currentConfig.type === 1 && initial.dns !== currentConfig.dns)) {
            return true
        }
    }
 
    return false
}
 
// 1:以太网 2:wifi 4:4G
networkSettingView.changeNetType = function (type) {
    if (type === 1) {
        // 以太网
        networkSettingView.netInfo[1].obj.hide()
        networkSettingView.netInfo[2].obj.hide()
        networkSettingView.netInfo[3].obj.show()
        networkSettingView.netInfo[4].obj.show()
        networkSettingView.netInfo[5].obj.show()
        networkSettingView.netInfo[6].obj.show()
        networkSettingView.netInfo[7].obj.show()
        // networkSettingView.netInfo[8].obj.show()
    } else if (type === 2) {
        // wifi
        networkSettingView.netInfo[1].obj.show()
        networkSettingView.netInfo[2].obj.show()
        networkSettingView.netInfo[3].obj.show()
        networkSettingView.netInfo[4].obj.show()
        networkSettingView.netInfo[5].obj.show()
        networkSettingView.netInfo[6].obj.show()
        networkSettingView.netInfo[7].obj.hide()
        // networkSettingView.netInfo[8].obj.show()
    } else if (type === 4) {
        networkSettingView.netInfo[1].obj.hide()
        networkSettingView.netInfo[2].obj.hide()
        networkSettingView.netInfo[3].obj.hide()
        networkSettingView.netInfo[4].obj.hide()
        networkSettingView.netInfo[5].obj.hide()
        networkSettingView.netInfo[6].obj.hide()
        networkSettingView.netInfo[7].obj.hide()
        // networkSettingView.netInfo[8].obj.hide()
    }
    // networkSettingView.netInfo[9].obj.hide()
}
 
networkSettingView.refresh = function () {
    const configAll = screen.getConfig()
 
    let selectNum = 0
    switch (configAll["net.type"]) {
        case 1:
            selectNum = 0
            break;
        case 2:
            selectNum = 1
            break;
        case 4:
            selectNum = screen.dxDriver.DRIVER.MODEL == "vf203" ? 2 : 1
            break;
        default:
            break;
    }
    networkSettingView.netInfo[0].dropdown.setSelected(selectNum)
    networkSettingView.netInfo[1].input.text(configAll["net.ssid"])
    networkSettingView.netInfo[2].input.text(configAll["net.psk"])
    networkSettingView.netInfo[3].switch.select(configAll["net.dhcp"] == 2)
    networkSettingView.netInfo[4].input.text(configAll["net.ip"])
    networkSettingView.netInfo[5].input.text(configAll["net.mask"])
    networkSettingView.netInfo[6].input.text(configAll["net.gateway"])
    networkSettingView.netInfo[7].input.text(configAll["net.dns"].split(",")[0] ? configAll["net.dns"].split(",")[0] : "")
    // networkSettingView.netInfo[8].input.text(configAll["net.dns"].split(",")[1] ? configAll["net.dns"].split(",")[1] : "")
    networkSettingView.netInfo[9].label.text(configAll["net.mac"] ? configAll["net.mac"] : " ")
}
 
export default networkSettingView