Commit 03cbd2ff by 朱建香

资源更新

parent 1369239b
const NEED_UPDATE = 2;
const CHOOSE_UPDATE = 1;
const NO_UPDATE = 0;
class CheckUpdate{
constructor() {
}
checkWgtuVersion(min, max){
console.log(min);
console.log(max);
let wgtu = this.checkVersion(min.ver, max.ver);
console.log(wgtu);
let support = false;
let type = "";
if(plus.os.name == 'Android'){
type = 'android';
}else if(plus.os.name == 'iOS'){
type = 'ios';
}
if(wgtu){
if(max.support[type] < plus.runtime.version){
support = true;
}
}
let wgtuSupport = {
"wgtu": wgtu,
"support": support
}
console.log(wgtuSupport);
return wgtuSupport;
}
checkVersion(min, max){
let minVer = this.transformVersion(min);
let maxVer = this.transformVersion(max);
console.log(minVer+maxVer);
console.log(plus.runtime.version);
let nowVer = this.transformVersion(plus.runtime.version);
console.log(minVer);
console.log(maxVer);
console.log(nowVer);
if(nowVer < minVer){
//当前版本小于最低版本,必须更新app
console.log("必须更新app");
return NEED_UPDATE;
}else if(nowVer < maxVer){
//当前版本介于最低版本和最高版本之间,可选择更新app
console.log("可选择更新app");
return CHOOSE_UPDATE;
}else{
//等于当前版本不用更新
console.log("不用更新");
return NO_UPDATE;
}
}
//将版本号转化成
transformVersion(v) {
var array = v.split(".");
var floatVersion = "";
console.log("下面是获取系统版本");
console.log(array);
if(array.length>2){
for (var i = 0; i < array.length; i++) {
if(i == 1){
floatVersion = floatVersion + '.'+ array[i]
}else{
floatVersion = floatVersion + array[i];
}
}
}else{
floatVersion = v;
}
if(isNaN(floatVersion)){
return null;
}
return floatVersion;
}
}
export default CheckUpdate;
\ No newline at end of file
var manage = 1; //1为正式地址,0为96地址 var manage = 0; //1为正式地址,0为96地址
var modelManage = 0; //1为正式"USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",0为UGEN_SECURITY_SMARTDOOR_YJ2017 var modelManage = 0; //1为正式"USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",0为UGEN_SECURITY_SMARTDOOR_YJ2017
//(1,1)为正式版, (1,0)为内测版, (0,1)为96版 //(1,1)为正式版, (1,0)为内测版, (0,1)为96版
...@@ -6,6 +6,6 @@ var modelManage = 0; //1为正式"USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",0 ...@@ -6,6 +6,6 @@ var modelManage = 0; //1为正式"USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",0
export default { export default {
"url": manage ? "https://cloud.iot.u-gen.net/" : "http://192.168.2.96:20000", "url": manage ? "https://cloud.iot.u-gen.net/" : "http://192.168.2.96:20000",
"model": modelManage ? "USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK" : "UGEN_SECURITY_SMARTDOOR_YJ2017", "model": modelManage ? "USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK" : "UGEN_SECURITY_SMARTDOOR_YJ2017",
"appId": modelManage ? "10004" : "20004", "appId": modelManage ? "10004" : "10004",
"appSecret": modelManage ? "10004" : "20004" "appSecret": modelManage ? "10004" : "10004"
} }
\ No newline at end of file
...@@ -7,6 +7,8 @@ Vue.use(VueTouch); ...@@ -7,6 +7,8 @@ Vue.use(VueTouch);
import ugenComponents from 'ugen-components'; import ugenComponents from 'ugen-components';
var uComponents = ugenComponents.uComponents; var uComponents = ugenComponents.uComponents;
import projectComponents from './manage'; import projectComponents from './manage';
import Update from './update.js';
import CheckUpdate from './checkUpdate.js';
const iot = new UIOT({ const iot = new UIOT({
lang: ['zh', 'en'], lang: ['zh', 'en'],
...@@ -216,6 +218,229 @@ uPublic.getUrlQuery = function (url){ ...@@ -216,6 +218,229 @@ uPublic.getUrlQuery = function (url){
} }
} }
//检验在sds中,该用户是否绑定设备
uPublic.cheackSdsDeviceExit = function(self){
iot.business.sds.getDevicesByUser({
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
//sds,绑定关系已存在
uPublic.cheackCloudDeviceExit(self, data.sn);
}else{
//sds,关系不存在
uPublic.linkToAddDevice();
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {}
});
}
//检验在云端中,该用户是否绑定设备
uPublic.cheackCloudDeviceExit = function(self, deviceId){
// console.log(iot.business.product.getInfoById({
// data:{
// pid:1
// },
// success:function(res){
// console.log(res);
// }
// }));
try{
iot.business.product.getInfoById({
data:{
pid:1
},
success:function(response){
console.log(response);
console.log("innnn");
let data = response.data;
console.log(data);
let wgut = new CheckUpdate().checkWgtuVersion(data.min,data.now);
console.log(wgut);
}
});
console.log(plus.os.name);
let os = "";
if(plus.os.name == 'Android'){
os = "android";
}else if(plus.os.name == 'iOS'){
os = "ios";
}
iot.business.app.getVersion({
data:{
os:os
},
success:function(response){
console.log(response);
let data = response.checkResponseData(data);
if(data){
let update = new CheckUpdate().checkVersion(data.min,data.now);
console.log(update);
}
}
});
}
catch(e) {
console.log(e);
}
// iot.business.api.send('lock/getDeviceProductId', {
// data: {
// device_id: deviceId
// },
// success: (response) => {
// console.log(response);
// let data = uPublic.checkResponseData(response.data);
// if(data){
//云端,绑定关系已存在
// uPublic.linkToIndex(self);
// }else{
// //云端,关系不存在
// uPublic.linkToAddDevice();
// }
// },
// error: (error) => {
// console.log(error);
// },
// complete: () => {}
// });
}
//页面跳转到首页
uPublic.linkToIndex = async function (self){
var updateInfo = await iot.storage.getMap('updateInfo');
console.log(updateInfo);
// var newUpdateInfo = data.updateInfo;
var newUpdateInfo = [{
'productId': '01',
'version': '0.0.4',
'url': 'http://192.168.2.184:8010/custom01.wgtu'
}];
console.log(newUpdateInfo.length);
if(newUpdateInfo.length){
for(let i=0; i<newUpdateInfo.length; i++){
let curVersion = newUpdateInfo[i].version;
let oldVersion = '0.0.0';
if(updateInfo){
for(let j=0; j<updateInfo.length; j++){
if(newUpdateInfo[i].product_id == updateInfo[j].product_id){
oldVersion = updateInfo[j].version
}
}
}
console.log(curVersion+oldVersion);
// 这里传入Update参数
let update = new Update(curVersion,oldVersion,newUpdateInfo[i].url);
console.log(update);
//需要更新
//重写 update中的方法,在下面方法中可以对更新app的相关生命周期进行操作
update.onDownloadStart = ()=>{
console.log("index page log onDownloadStart");
uComponents.showProcess(self, 0, '正在下载资源', []);
}
update.onDownloadSuccess = ()=>{
uComponents.showProcess(self, 0, '下载成功', []);
console.log("index page log onDownloadSuccess");
}
update.onInstallStart = ()=>{
uComponents.showProcess(self, 0, '安装中...', []);
// self.downloadPercent = null;
console.log("index page log onInstallStart");
}
update.onInstallSuccess = ()=>{
uComponents.showProcess(self, 0, '安装成功', []);
console.log(newUpdateInfo[i]);
try{
console.log("index page log onInstallSuccess");
//资源包安装成功,跳转到首页
iot.navigator.openWindow({
url: '../../custom/custom'+newUpdateInfo[i].productId+'/view/device/index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
//更新app缓存的productId和对应版本
iot.storage.setMap('updateInfo', newUpdateInfo, (response) => {
console.log(res);
}, () => {});
}
catch(e){
console.log(e);
}
}
update.onStateChanged = (download, status) => {
var percent = (download.downloadedSize/download.totalSize).toFixed(2)*100;
console.log(parseInt(percent));
// self.downloadPercent = parseInt(percent);
}
update.onError = ()=>{
console.log("index page log onError");
}
update.onNoNeedUpdate = () => {
console.log(".....不需要更新");
//不需要更新
iot.navigator.openWindow({
url: '../../custom/custom'+newUpdateInfo[i].productId+'/view/device/index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
update.startUpdate();
console.log(update);
}
}else{
//无资源包需要更新,跳到默认首页
iot.navigator.openWindow({
url: '../device/index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
}
//页面跳转到添加设备页面
uPublic.linkToAddDevice = function(){
iot.navigator.openWindow({
url: '../addDevice/index.html',
id: 'devicaddDevice',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
iot.ready(() => { iot.ready(() => {
uPublic.recalc(); uPublic.recalc();
......
class Update{ class Update{
constructor(curV,newV,url) {//当前版本号、最新版本号以及获取最新安装包地址 constructor(curV,newV,url,needRestart) {//当前版本号、最新版本号以及获取最新安装包地址
this.curV = curV; this.curV = curV;
this.newV = newV; this.newV = newV;
this.url = url; this.url = url;
this.needRestart = false || needRestart;
} }
startUpdate(){ startUpdate(){
...@@ -41,7 +42,11 @@ class Update{ ...@@ -41,7 +42,11 @@ class Update{
plus.runtime.install(path,{force: true},()=>{ //强制安装 不进行版本校验 plus.runtime.install(path,{force: true},()=>{ //强制安装 不进行版本校验
console.log("安装wgt文件成功!"); console.log("安装wgt文件成功!");
this.onInstallSuccess(); this.onInstallSuccess();
//判断是否需要重启
console.log(this.needRestart);
if(this.needRestart){
plus.runtime.restart(); plus.runtime.restart();
}
},(e)=>{ },(e)=>{
this.onError(e); this.onError(e);
console.log("安装wgt文件失败["+e.code+"]:"+e.message); console.log("安装wgt文件失败["+e.code+"]:"+e.message);
......
...@@ -292,15 +292,23 @@ function unbind(self){ ...@@ -292,15 +292,23 @@ function unbind(self){
// self.setStateShowFlag(true); // self.setStateShowFlag(true);
// self.setShowMsg(Vue.t('doorlockManage.unbindSuccess')); // self.setShowMsg(Vue.t('doorlockManage.unbindSuccess'));
// self.setUnbindSucceess(true); // self.setUnbindSucceess(true);
uComponents.openAlert(self, Vue.t('doorlockManage.unbindSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/index.html', url: '../login/loading.html',
id: 'device' id: 'loading',
}); extras: {
lockId: self.extras.lockInfo.lock_id,
nickname: self.getTextNickname()
} }
}); });
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{}); // uComponents.openAlert(self, Vue.t('doorlockManage.unbindSuccess'), {
// text: Vue.t('dialog.confirm'), callback: function () {
// iot.navigator.openWindow({
// url: '../device/index.html',
// id: 'device'
// });
// }
// });
// iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
}, },
error: (error) => { error: (error) => {
console.log(error); console.log(error);
......
...@@ -12,7 +12,7 @@ import {iot, uPublic, uComponents} from '../../public/public.js'; ...@@ -12,7 +12,7 @@ import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init); iot.ready(init);
function init() { function init() {
//通用 dialog、loading组件 //通用 dialog、loading组件
uPublic.componentsInit(['u-dialog','u-loading','u-button']); uPublic.componentsInit(['u-dialog','u-loading','u-button','u-process']);
uPublic.closeSlideBack(); uPublic.closeSlideBack();
//是否需要关闭其他页面 //是否需要关闭其他页面
if(iot.navigator.getExtras().needClose){ if(iot.navigator.getExtras().needClose){
...@@ -23,7 +23,8 @@ function init() { ...@@ -23,7 +23,8 @@ function init() {
//配置组件 //配置组件
componentsConfig: initComponentsConfig(), componentsConfig: initComponentsConfig(),
clientId: null, clientId: null,
showLoginButtonFlag: false showLoginButtonFlag: false,
downloadPercent: null
}, },
mounted(){ mounted(){
if(window.iotDebug){ if(window.iotDebug){
...@@ -49,7 +50,6 @@ function init() { ...@@ -49,7 +50,6 @@ function init() {
this.showLoginButtonFlag = flag; this.showLoginButtonFlag = flag;
}, },
onLoginButtonTap(){ onLoginButtonTap(){
uComponents.showLoading(this);
loginButtonTap(this); loginButtonTap(this);
}, },
getClientId(){ getClientId(){
...@@ -81,12 +81,19 @@ function initComponentsConfig() { ...@@ -81,12 +81,19 @@ function initComponentsConfig() {
initParam: { initParam: {
class: 'custom-loading' class: 'custom-loading'
} }
},
processLoading: {
initParam: {
class: 'custom-process',
status: 0
}
} }
} }
} }
//sds登陆 //sds登陆
function loginButtonTap(self){ function loginButtonTap(self){
uComponents.showProcess(self, 0, '数据加载中...', []);
if (plus.os.name == 'Android') { if (plus.os.name == 'Android') {
iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) { iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) {
console.log('success', res); console.log('success', res);
...@@ -117,7 +124,7 @@ function openSdsLogin(self){ ...@@ -117,7 +124,7 @@ function openSdsLogin(self){
var data = uPublic.checkResponseData(response.data); var data = uPublic.checkResponseData(response.data);
if(data){ if(data){
if(data.hasOwnProperty('UserID')){ if(data.hasOwnProperty('UserID')){
uComponents.hideLoading(self); // uComponents.hideLoading(self);
cloudsLogin(self, data.UserID); cloudsLogin(self, data.UserID);
} }
}else{ }else{
...@@ -133,7 +140,7 @@ function openSdsLogin(self){ ...@@ -133,7 +140,7 @@ function openSdsLogin(self){
if (window.iotDebug) { if (window.iotDebug) {
iotDebug.upload(iot,'sds登陆失败'); iotDebug.upload(iot,'sds登陆失败');
} }
uComponents.hideLoading(self); // uComponents.hideLoading(self);
}, },
complete: () => {} complete: () => {}
}); });
...@@ -156,7 +163,7 @@ function openSdsLogin(self){ ...@@ -156,7 +163,7 @@ function openSdsLogin(self){
}, },
complete: () => { complete: () => {
console.log("complete"); console.log("complete");
uComponents.hideLoading(self); // uComponents.hideLoading(self);
} }
}); });
} }
...@@ -164,7 +171,7 @@ function openSdsLogin(self){ ...@@ -164,7 +171,7 @@ function openSdsLogin(self){
//云端登陆 //云端登陆
function cloudsLogin(self, id){ function cloudsLogin(self, id){
console.log("showLoading"); console.log("showLoading");
uComponents.showLoading(self); // uComponents.showLoading(self);
if(window.iotDebug){ if(window.iotDebug){
iotDebug.push('start: cloudsLogin'); iotDebug.push('start: cloudsLogin');
} }
...@@ -198,25 +205,26 @@ function cloudsLogin(self, id){ ...@@ -198,25 +205,26 @@ function cloudsLogin(self, id){
error: (error) => { error: (error) => {
console.log(error); console.log(error);
uPublic.openRequestErrorAlert(self); uPublic.openRequestErrorAlert(self);
uComponents.hideLoading(self); // uComponents.hideLoading(self);
}, },
complete: () => { complete: () => {
// uComponents.hideLoading(self); // uComponents.hideLoading(self);
} }
}); });
} }
iot.navigator.openWindow({ // iot.navigator.openWindow({
// url: '../addDevice/index.html', //// url: '../addDevice/index.html',
// url: '../../custom/custom01/view/device/index.html', //// url: '../../custom/custom01/view/device/index.html',
url: './loading.html', // url: './loading.html',
id: 'loading', // id: 'loading',
styles: { // styles: {
popGesture: 'none' // popGesture: 'none'
}, // },
extras: { // extras: {
needClose: true // needClose: true
} // }
}); // });
uPublic.cheackSdsDeviceExit(self);
plus.navigator.closeSplashscreen(); plus.navigator.closeSplashscreen();
}, },
error: (error) => { error: (error) => {
......
...@@ -49,9 +49,9 @@ function initComponentsConfig() { ...@@ -49,9 +49,9 @@ function initComponentsConfig() {
} }
function resolve(self){ function resolve(self){
uComponents.showProcess(self, 0, 'loading', []); // uComponents.showProcess(self, 0, 'loading', []);
console.log(self) // console.log(self)
cheackSdsDeviceExit(self); // cheackSdsDeviceExit(self);
} }
//检验在sds中,该用户是否绑定设备 //检验在sds中,该用户是否绑定设备
...@@ -65,7 +65,7 @@ function cheackSdsDeviceExit(self){ ...@@ -65,7 +65,7 @@ function cheackSdsDeviceExit(self){
cheackCloudDeviceExit(self, data.sn); cheackCloudDeviceExit(self, data.sn);
}else{ }else{
//sds,关系不存在 //sds,关系不存在
// linkToAddDevice(); linkToAddDevice();
} }
}, },
error: (error) => { error: (error) => {
...@@ -107,7 +107,7 @@ async function linkToIndex(self){ ...@@ -107,7 +107,7 @@ async function linkToIndex(self){
// let newUpdateInfo = data.updateInfo; // let newUpdateInfo = data.updateInfo;
let newUpdateInfo = [{ let newUpdateInfo = [{
'productId': '01', 'productId': '01',
'version': '0.0.3', 'version': '0.0.4',
'url': 'http://192.168.2.184:8010/custom01.wgtu' 'url': 'http://192.168.2.184:8010/custom01.wgtu'
}]; }];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment