组内框架web4.2发现的问题

发现的问题

1.仅看deviceInfo.js里,一个Promise居然有四种写法

  //获取在线升级能力
    getOnlineUpgradeCap() {
        let self = this;
        return new Promise(resolve => {
            _oWebSdk.WSDK_GetDeviceConfig("onlineUpgradeCapa").then(
                xmlDoc => {
                    self._oSettingBasicInfo.bSupportOnlineUpgrade = true;
                    if ($(xmlDoc).find("notSupportAutoUpgrade") && $(xmlDoc).find("notSupportAutoUpgrade").text() === "true") {
                        self._oSettingBasicInfo.bSupportOnlineUpgrade = false;
                    }
                    resolve();
                }
            );
        });
    }

需要注意的是await已经相当于promise.then()了,所以后面不能再加then

  async getOnlineUp() {
        let self = this;
        await self.getOnlineUpgradeCap().then(() => {
            if (self._oSettingBasicInfo.bSupportOnlineUpgrade) {
                self.getOnlineUpgradeVersion(false);
            }
        });
    }
 // 获取报警输入
    getDeviceInfo() {
        let self = this;
        self._oSettingBasicInfo.iChannelNum = 0;
        self._oSettingBasicInfo.iAlarmInNum = 0;
        self._oSettingBasicInfo.iAlarmOutNum = 0;
        return _oWebSdk.WSDK_GetDeviceConfig("deviceInfo").then(
            xmlDoc => {
                self.oXmlDoc = xmlDoc;

                self._oSettingBasicInfo.szDeviceName = _oUtils.nodeValue(xmlDoc, "deviceName");
                self._oSettingBasicInfo.szDeviceNo = _oUtils.nodeValue(xmlDoc, "telecontrolID");
                self._oSettingBasicInfo.szDeviceModel = _oUtils.nodeValue(xmlDoc, "model").replace("/", " / ");
                self._oSettingBasicInfo.szSerialNo = _oUtils.nodeValue(xmlDoc, "serialNumber").replace("/", " / ");
                self._oSettingBasicInfo.szFirmwareVersion = _oUtils.nodeValue(xmlDoc, "firmwareVersion") + " " + _oUtils.nodeValue(xmlDoc, "firmwareReleasedDate");
                self._oSettingBasicInfo.szEncoderVersion = _oUtils.nodeValue(xmlDoc, "encoderVersion") + " " + _oUtils.nodeValue(xmlDoc, "encoderReleasedDate");
                //硬件版本
                if ($(xmlDoc).find("hardwareVersion").length > 0) {
                    self._oSettingBasicInfo.bSptHardwareVersion = true;
                    self._oSettingBasicInfo.szHardwareVersion = _oUtils.nodeValue(xmlDoc, "hardwareVersion");
                }
                //主控版本属性
                if ($(xmlDoc).find("firmwareVersionInfo").length > 0) {
                    self._oSettingBasicInfo.szFirmwareVersionInfo = _oUtils.nodeValue(xmlDoc, "firmwareVersionInfo");
                }
            }
        );
    }
     _oWebSdk.WSDK_SetDeviceConfig("onlineUpgrade", null, {
                success: () => {
                    self._oSettingBasicInfo.iUpgradeProcess = 0;// 重置进度条为0
                    let szHtml = '<div id="upgrade-slider" class="upgrade-slider"><div slider type="process" show-box="true" current-value="oSettingBasicInfo.iUpgradeProcess" step="1" min="0" max="100"></div></div>';
                    //self._oUpgradeDlg = _oDialog.htmlNoButton(_oTranslator.getValue("upgrading"), szHtml);
                    self._oUpgradeDlg = _oDialog.html({
                        szTitle: _oTranslator.getValue("upgrading"),
                        szContent: szHtml,
                        oButtons: {
                            bOK: false,
                            bCancel: false,
                            bClose: false
                        }
                    });
                    compile(angular.element("#upgrade-slider"))(scope);

                    self._tUpgradeStatus = setInterval(function () {
                        scope.$apply(function () {
                            self.getUpgradeStatus();
                        });
                    }, 2000);
                },
                error: () => {
                    self._oSettingBasicInfo.szUpgradeStatus = _oTranslator.getValue("upgradeFailed");
                    setTimeout(function () {
                        self._oSettingBasicInfo.szUpgradeStatus = "";
                    }, 5 * 1000);
                }
            });

2.既然已经用了es6语法,并且对map/foreach做了兼容处理,那么不应当再使用$.each进行遍历

                    $.each($(xmlDoc).find("AlgorithmsVersionInfo"), function () {
                        let szVersion = "V" + _oUtils.nodeValue(this, "majorVersion") + "." + _oUtils.nodeValue(this, "minorVersion") + "." + _oUtils.nodeValue(this, "revisionNumber");
                        if (_oUtils.nodeValue(this, "name") === "faceProperties") { //人脸识别库版本
                            self._oSettingBasicInfo.bSupportHumanVer = true;
                            self._oSettingBasicInfo.szFaceProperties = szVersion;
                        } else if (_oUtils.nodeValue(this, "name") === "humanAttribute") { //智能HMS平台版本
                            self._oSettingBasicInfo.bSupportHMSVersion = true;
                            self._oSettingBasicInfo.szHumanAttribute = szVersion;
                        } else if (_oUtils.nodeValue(this, "name") === "faceSnap") { //人脸抓拍算法库版本
                            self._oSettingBasicInfo.bSupportHumanCaptureVersion = true;
                            self._oSettingBasicInfo.szHumanCaptureVersion = szVersion;
                        }
                    });

3.关于es6里class里的this指向,构造函数里的this始终指向实例对象,记住一点即可,this是由使用时的作用域决定的,(箭头函数没有自己的this)

class Pa{
    constructor(){
        this.str='233'
        this.test={
            str:'788',
            op:{
                str:'555',
                str2:this.str,
                str3:'444'
            }

        }
    }
    init(){
        console.log(this.test);
    }
   
}
const t=new Pa()
t.init()
//{ str: '788', op: { str: '555', str2: '233', str3: '444' } }

故可以抛弃形如let that=this这种写法了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值