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
import dxui from '../../dxmodules/dxUi.js'
import std from '../../dxmodules/dxStd.js'
import viewUtils from "./viewUtils.js"
import topView from "./topView.js"
import screen from '../screen.js'
import mainView from './mainView.js'
import dxCommonUtils from '../../dxmodules/dxCommonUtils.js'
import driver from '../driver.js'
import i18n from "./i18n.js"
const wechatFaceView = {}
 
let option = {}
 
wechatFaceView.init = function () {
    /**************************************************创建屏幕*****************************************************/
    const screenMain = dxui.View.build('wechatFaceView', dxui.Utils.LAYER.MAIN)
    wechatFaceView.screenMain = screenMain
    screenMain.scroll(false)
    screenMain.bgOpa(0)
 
    screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => {
        topView.changeTheme(true)
 
        faceTackLbl.show()
        wechatFaceView.ccount = 4
        faceTackLbl.text(i18n.t('wechatFaceView.countdown').replace('{n}', wechatFaceView.ccount - 1))
        wechatFaceView.ctimer = std.setInterval(() => {
            wechatFaceView.ccount--
            faceTackLbl.text(i18n.t('wechatFaceView.countdown').replace('{n}', wechatFaceView.ccount - 1))
            if (wechatFaceView.ccount == 1) {
                faceTackLbl.hide()
            } else if (wechatFaceView.ccount == 0) {
                std.clearInterval(wechatFaceView.ctimer)
                wechatFaceView.ctimer = null
 
                let faceData = null, featureBase64 = null, faceBase64 = null, code = screen.MQTT_CODE.E_100
                try {
                    // 人脸抓拍,超时时间是10秒,10秒内没有抓拍到人脸,则mqtt返回失败
                    faceData = screen.tackFace()
                    faceBase64 = dxCommonUtils.fs.fileToBase64(faceData.picPath)
                    featureBase64 = faceData.feature
 
                    // let fea=driver.face.getFeaByFile(faceData.picPath)
                    // console.log('--后---');
                    // console.log('----fea--',JSON.stringify(fea));
                    // featureBase64 = fea.feature
                    wechatFaceView.statusPanel.success("wechatFaceView.tackSuccess")
                } catch (error) {
                    wechatFaceView.statusPanel.fail("wechatFaceView.tackError")
                }
                if (faceBase64 && featureBase64) {
                    code = screen.MQTT_CODE.S_000
                }
                let payload
                console.log('----option.type----', option.type);
 
                if (option.type == 1) {
                    payload = screen.mqttReply(option.serialNo, { keyId: option.keyId, faceBase64: faceBase64, type: option.type }, code)
                } else if (option.type == 2) {
                    payload = screen.mqttReply(option.serialNo, { keyId: option.keyId, featureBase64: featureBase64, type: option.type }, code)
                } else {
                    payload = screen.mqttReply(option.serialNo, { keyId: option.keyId, featureBase64: featureBase64, faceBase64: faceBase64, type: option.type }, code)
                }
 
 
                option = {}
                payload.uuid = payload.uuid.toUpperCase()
                screen.driver.mqtt.send("access_device/v2/cmd/control_reply", JSON.stringify(payload))
                std.setTimeout(() => {
                    dxui.loadMain(mainView.screenMain)
                }, 1000);
            }
        }, 1000);
    })
 
    screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => {
        if (wechatFaceView.ctimer) {
            std.clearInterval(wechatFaceView.ctimer)
            wechatFaceView.ctimer = null
        }
    })
 
    const titleBoxBg = dxui.View.build(screenMain.id + 'titleBoxBg', screenMain)
    viewUtils._clearStyle(titleBoxBg)
    titleBoxBg.setSize(screen.screenSize.width * (600 / 600), screen.screenSize.height * (70 / 1024))
    titleBoxBg.align(dxui.Utils.ALIGN.TOP_MID, 0, 0)
    titleBoxBg.bgColor(0xffffff)
 
    // 远程抓拍标题
    const titleBox = dxui.View.build("wechatFaceViewTitle", screenMain)
    viewUtils._clearStyle(titleBox)
    titleBox.setSize(screen.screenSize.width * (600 / 600), screen.screenSize.height * (70 / 1024))
    titleBox.bgColor(0xffffff)
 
    // 远程抓拍标题文字
    const titleLbl = dxui.Label.build('wechatFaceViewTitle' + 'title', titleBox)
    titleLbl.textFont(viewUtils.font(32))
    titleLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0)
    titleLbl.dataI18n = 'wechatFaceView.title'
    titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (70 / 1024))
 
    const faceTack = dxui.Image.build('faceTack', screenMain)
    faceTack.align(dxui.Utils.ALIGN.TOP_MID, 0, screen.screenSize.height * (140 / 1024))
    faceTack.source(screen.resourcePath.imagePath + '/faceRec2.png')
 
    const faceTackLbl = dxui.Label.build('faceTackLbl', screenMain)
    faceTackLbl.align(dxui.Utils.ALIGN.CENTER, 0, 0)
    faceTackLbl.dataI18n = 'wechatFaceView.countdown'
    faceTackLbl.text(i18n.t('wechatFaceView.countdown').replace('{n}', wechatFaceView.ccount || 3))
    faceTackLbl.textFont(viewUtils.font(28))
    faceTackLbl.textColor(0xffffff)
 
    wechatFaceView.statusPanel = viewUtils.statusPanel(screenMain)
}
 
// 抓拍人脸
wechatFaceView.weComTackFace = function (data) {
    option.keyId = data.data.extra.keyId
    option.serialNo = data.serialNo
    option.type = data.data.extra.type
 
}
 
 
export default wechatFaceView