发现的问题
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
这种写法了