Commit 384493d7 by 朱建香

资源更新,loading页面功能制作

parent ac8c552c
...@@ -54,5 +54,6 @@ export default { ...@@ -54,5 +54,6 @@ export default {
"newMsg_timeout": 86400, "newMsg_timeout": 86400,
"getHistoryTimes": 3, "getHistoryTimes": 3,
"audioUrl": "../../resources/audio/tipSound.mp3", "audioUrl": "../../resources/audio/tipSound.mp3",
// "audioUrl": "_www/resources/audio/tipSound.mp3" // "audioUrl": "_www/resources/audio/tipSound.mp3",
"downloadUrl": "http://iot.d.u-gen.net/uslock/release"
} }
\ No newline at end of file
...@@ -192,6 +192,29 @@ uPublic.upDateRead = async function(key, time){ ...@@ -192,6 +192,29 @@ uPublic.upDateRead = async function(key, time){
} }
} }
uPublic.getUrlQuery = function (url){
var search = url;
console.log(url);
var parameters = {};
if (url) {
var query = search.split('?');
console.log(query);
if(query.length > 1){
parameters.url = query[0];
var params = query[1].split('&');
console.log(params);
for (var i = 0; i < params.length; i++) {
var pair = params[i].split('=');
parameters[pair[0]] = pair[1];
console.log(pair[1]);
}
console.log(parameters);
return parameters;
}else{
return false;
}
}
}
iot.ready(() => { iot.ready(() => {
......
...@@ -11,15 +11,18 @@ class Update{ ...@@ -11,15 +11,18 @@ class Update{
this.downWgt(); this.downWgt();
}else{ }else{
console.log("不需要更新"); console.log("不需要更新");
alert("不需要更新"); this.onNoNeedUpdate();
return ; return ;
} }
} }
onStateChanged(download, status) {
// console.log((download.downloadedSize/download.totalSize).toFixed(2)*100)
}
downWgt(){ downWgt(){
plus.nativeUI.showWaiting("下载wgt文件...");
this.onDownloadStart(); this.onDownloadStart();
plus.downloader.createDownload( this.url, {filename:"_doc/update/"}, (d,status)=>{ var dtask = plus.downloader.createDownload( this.url, {}, (d,status)=>{
if ( status == 200 ) { if ( status == 200 ) {
this.onDownloadSuccess(); this.onDownloadSuccess();
console.log("下载wgt成功:"+d.filename); console.log("下载wgt成功:"+d.filename);
...@@ -27,27 +30,21 @@ class Update{ ...@@ -27,27 +30,21 @@ class Update{
} else { } else {
console.log("下载wgt失败!"); console.log("下载wgt失败!");
this.onError(status); this.onError(status);
plus.nativeUI.alert("下载wgt失败!");
} }
plus.nativeUI.closeWaiting(); });
}).start(); dtask.addEventListener( "statechanged", this.onStateChanged, false );
dtask.start();
} }
installWgt(path){ installWgt(path){
this.onInstallStart(); this.onInstallStart();
plus.nativeUI.showWaiting("安装wgt文件...");
plus.runtime.install(path,{force: true},()=>{ //强制安装 不进行版本校验 plus.runtime.install(path,{force: true},()=>{ //强制安装 不进行版本校验
plus.nativeUI.closeWaiting();
console.log("安装wgt文件成功!"); console.log("安装wgt文件成功!");
this.onInstallSuccess(); this.onInstallSuccess();
plus.nativeUI.alert("应用资源更新完成!",()=>{
plus.runtime.restart(); plus.runtime.restart();
});
},(e)=>{ },(e)=>{
plus.nativeUI.closeWaiting();
this.onError(e); this.onError(e);
console.log("安装wgt文件失败["+e.code+"]:"+e.message); console.log("安装wgt文件失败["+e.code+"]:"+e.message);
plus.nativeUI.alert("安装wgt文件失败["+e.code+"]:"+e.message);
}); });
} }
...@@ -71,6 +68,9 @@ class Update{ ...@@ -71,6 +68,9 @@ class Update{
console.log(`install wgt file success`); console.log(`install wgt file success`);
} }
onNoNeedUpdate(){
console.log(`no need update`);
}
} }
export default Update; export default Update;
\ No newline at end of file
...@@ -14,6 +14,9 @@ function init() { ...@@ -14,6 +14,9 @@ function init() {
//通用 dialog、loading组件 //通用 dialog、loading组件
uPublic.componentsInit(['u-dialog','u-loading']); uPublic.componentsInit(['u-dialog','u-loading']);
// uPublic.closeSlideBack(); // uPublic.closeSlideBack();
if(iot.navigator.getExtras().needClose){
iot.navigator.closeAllBesidesItself();
}
const app = new Vue({ const app = new Vue({
data:{ data:{
//配置组件 //配置组件
...@@ -56,7 +59,7 @@ function initComponentsConfig() { ...@@ -56,7 +59,7 @@ function initComponentsConfig() {
//tap < //tap <
function backTap(){ function backTap(){
iot.navigator.back(); iot.navigator.aback();
} }
//tap 扫描绑定设备 //tap 扫描绑定设备
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
import {iot, uPublic, uComponents} from '../../public/public.js'; import {iot, uPublic, uComponents} from '../../public/public.js';
import config from '../../public/config.js';
iot.ready(init); iot.ready(init);
function init() { function init() {
...@@ -128,9 +129,20 @@ function openScanCode(self){ ...@@ -128,9 +129,20 @@ function openScanCode(self){
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
console.log(data.result.indexOf('qrKey')); let params = uPublic.getUrlQuery(data.result);
//扫描成功 //扫描成功
if(data.result.indexOf('qrKey') != -1){ //判断扫描结果是否是下载路径
if(params.url == config.downloadUrl){
//若是下载路径,获取productId并跳转到配网绑定页面
iot.navigator.openWindow({
url: './wifiAddHelp.html',
id: 'wifiAddHelp',
extras: {
productId: params.p
}
});
}else if(data.result.indexOf('qrKey') != -1){
//若是分享路径,则获取qrKey,lockId,relId绑定
uComponents.showProcess(self, 0, Vue.t('addDevice.loading')); uComponents.showProcess(self, 0, Vue.t('addDevice.loading'));
let result = JSON.parse(data.result); let result = JSON.parse(data.result);
console.log(result); console.log(result);
...@@ -155,12 +167,6 @@ function openScanCode(self){ ...@@ -155,12 +167,6 @@ function openScanCode(self){
error: (error) => { error: (error) => {
//绑定失败 //绑定失败
console.log(error); console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 绑定失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'绑定失败');
// }
scanCodeFailue(self); scanCodeFailue(self);
} }
}); });
......
...@@ -26,8 +26,11 @@ function init() { ...@@ -26,8 +26,11 @@ function init() {
noticeTipShowFlag: false, noticeTipShowFlag: false,
timeout: null, timeout: null,
countDownText: config.add_wifi_timeout, countDownText: config.add_wifi_timeout,
extras: {}
}, },
mounted(){ mounted(){
this.extras = iot.navigator.getExtras();
console.log(this.extras);
resolve(this); resolve(this);
let self = this; let self = this;
window.addEventListener('returnPage',() => { window.addEventListener('returnPage',() => {
......
...@@ -13,13 +13,20 @@ iot.ready(init); ...@@ -13,13 +13,20 @@ iot.ready(init);
function init() { function init() {
//通用 按钮、dialog、loading组件 //通用 按钮、dialog、loading组件
uPublic.componentsInit(['u-button','u-dialog','u-loading']); uPublic.componentsInit(['u-button','u-dialog','u-loading']);
// uPublic.closeSlideBack(); let opener = plus.webview.currentWebview().opener();
if(opener.id == 'scanCodeAdd'){
setTimeout(function () {
plus.webview.close(opener,"none",0,{});
}, 500);
}
const app = new Vue({ const app = new Vue({
data:{ data:{
//配置组件 //配置组件
componentsConfig: initComponentsConfig() componentsConfig: initComponentsConfig(),
extras: {}
}, },
mounted(){ mounted(){
this.extras = iot.navigator.getExtras();
window.addEventListener('returnPage',function(event){ window.addEventListener('returnPage',function(event){
console.log("stopFindDevice"); console.log("stopFindDevice");
iot.business.sds.stopFindDevices({ iot.business.sds.stopFindDevices({
...@@ -39,7 +46,7 @@ function init() { ...@@ -39,7 +46,7 @@ function init() {
}, },
//tap 开始配置Wi-Fi //tap 开始配置Wi-Fi
onWifiAddButtonTap(){ onWifiAddButtonTap(){
wifiAddButtonTap(); wifiAddButtonTap(this);
} }
} }
}).$mount('#app'); }).$mount('#app');
...@@ -74,9 +81,12 @@ function backTap(){ ...@@ -74,9 +81,12 @@ function backTap(){
} }
//tap 开始配置Wi-Fi //tap 开始配置Wi-Fi
function wifiAddButtonTap(){ function wifiAddButtonTap(self){
iot.navigator.openWindow({ iot.navigator.openWindow({
url: './wifiAdd.html', url: './wifiAdd.html',
id: 'wifiAdd' id: 'wifiAdd',
extras: {
productId: self.extras.productId
}
}); });
} }
\ No newline at end of file
...@@ -206,10 +206,10 @@ function cloudsLogin(self, id){ ...@@ -206,10 +206,10 @@ function cloudsLogin(self, id){
}); });
} }
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/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: 'device', id: 'loading',
styles: { styles: {
popGesture: 'none' popGesture: 'none'
}, },
......
...@@ -10,14 +10,17 @@ ...@@ -10,14 +10,17 @@
import {iot, uPublic, uComponents} from '../../public/public.js'; import {iot, uPublic, uComponents} from '../../public/public.js';
import Update from '../../public/update.js'; import Update from '../../public/update.js';
iot.ready(init); iot.ready(init);
function init() { function init() {
//通用 input、按钮、dialog、loading组件 //通用 input、按钮、dialog、loading组件
uPublic.componentsInit(['u-loading']); uPublic.componentsInit(['u-loading','u-process']);
const app = new Vue({ const app = new Vue({
data:{ data:{
//配置组件 //配置组件
componentsConfig: initComponentsConfig() componentsConfig: initComponentsConfig(),
downloadPercent: null
}, },
mounted(){ mounted(){
resolve(this); resolve(this);
...@@ -35,19 +38,24 @@ function initComponentsConfig() { ...@@ -35,19 +38,24 @@ function initComponentsConfig() {
initParam: { initParam: {
class: 'custom-loading' class: 'custom-loading'
} }
},
processLoading: {
initParam: {
class: 'custom-process',
status: 0
}
} }
} }
} }
function resolve(self){ function resolve(self){
uComponents.showProcess(self, 0, 'loading', []);
console.log(self) console.log(self)
uComponents.showloading(self); cheackSdsDeviceExit(self);
cheackSdsDevice(self);
} }
//检验在sds中,该用户是否绑定设备 //检验在sds中,该用户是否绑定设备
function cheackSdsDeviceExit(self){ function cheackSdsDeviceExit(self){
uComponents.showLoading();
iot.business.sds.getDevicesByUser({ iot.business.sds.getDevicesByUser({
success: (response) => { success: (response) => {
console.log(response); console.log(response);
...@@ -57,13 +65,12 @@ function cheackSdsDeviceExit(self){ ...@@ -57,13 +65,12 @@ function cheackSdsDeviceExit(self){
cheackCloudDeviceExit(self, data.sn); cheackCloudDeviceExit(self, data.sn);
}else{ }else{
//sds,关系不存在 //sds,关系不存在
linkToAddDevice(); // linkToAddDevice();
} }
}, },
error: (error) => { error: (error) => {
console.log(error); console.log(error);
uPublic.openRequestErrorAlert(self); uPublic.openRequestErrorAlert(self);
uComponents.hideLoading(self);
}, },
complete: () => {} complete: () => {}
}); });
...@@ -71,65 +78,81 @@ function cheackSdsDeviceExit(self){ ...@@ -71,65 +78,81 @@ function cheackSdsDeviceExit(self){
//检验在云端中,该用户是否绑定设备 //检验在云端中,该用户是否绑定设备
function cheackCloudDeviceExit(self, deviceId){ function cheackCloudDeviceExit(self, deviceId){
iot.business.api.send('lock/getDeviceProductId', { // iot.business.api.send('lock/getDeviceProductId', {
data: { // data: {
device_id: deviceId // device_id: deviceId
}, // },
success: (response) => { // success: (response) => {
console.log(response); // console.log(response);
let data = uPublic.checkResponseData(response.data); // let data = uPublic.checkResponseData(response.data);
if(data){ // if(data){
//云端,绑定关系已存在 //云端,绑定关系已存在
linkToIndex(self,data); linkToIndex(self);
}else{ // }else{
//云端,关系不存在 // //云端,关系不存在
linkToAddDevice(); // linkToAddDevice();
} // }
}, // },
error: (error) => { // error: (error) => {
console.log(error); // console.log(error);
uComponents.hideLoading(self); // },
}, // complete: () => {}
complete: () => {} // });
});
} }
//页面跳转到首页 //页面跳转到首页
async function linkToIndex(self, data){ async function linkToIndex(self){
let updateInfo = await iot.storage.getMap('updateInfo'); let updateInfo = await iot.storage.getMap('updateInfo');
console.log(updateInfo);
let newUpdateInfo = data.updateInfo; // let newUpdateInfo = data.updateInfo;
let newUpdateInfo = [{
'productId': '01',
'version': '0.0.3',
'url': 'http://192.168.2.184:8010/custom01.wgtu'
}];
console.log(newUpdateInfo.length);
if(newUpdateInfo.length){
for(let i=0; i<newUpdateInfo.length; i++){ for(let i=0; i<newUpdateInfo.length; i++){
let curVersion = newUpdateInfo[i].version; let curVersion = newUpdateInfo[i].version;
let oldVersion = '0.0.0'; let oldVersion = '0.0.0';
if(updateInfo){
for(let j=0; j<updateInfo.length; j++){ for(let j=0; j<updateInfo.length; j++){
if(newUpdateInfo[i].product_id == updateInfo[j].product_id){ if(newUpdateInfo[i].product_id == updateInfo[j].product_id){
oldVersion = updateInfo[j].version oldVersion = updateInfo[j].version
} }
} }
// 这里传入Update参数 }
let update = new Update(curVersion,oldVersion,newUpdateInfo.url);
// 重写 update中的方法,在下面方法中可以对更新app的相关生命周期进行操作 console.log(curVersion+oldVersion);
// 这里传入Update参数
let update = new Update(curVersion,oldVersion,newUpdateInfo[i].url);
console.log(update);
//需要更新
//重写 update中的方法,在下面方法中可以对更新app的相关生命周期进行操作
update.onDownloadStart = ()=>{ update.onDownloadStart = ()=>{
console.log("index page log onDownloadStart"); console.log("index page log onDownloadStart");
uComponents.hideLoading(self); uComponents.showProcess(self, 0, '正在下载资源', []);
} }
update.onDownloadSuccess = ()=>{ update.onDownloadSuccess = ()=>{
uComponents.showProcess(self, 0, '下载成功', []);
console.log("index page log onDownloadSuccess"); console.log("index page log onDownloadSuccess");
} }
update.onInstallStart = ()=>{ update.onInstallStart = ()=>{
uComponents.showProcess(self, 0, '安装中...', []);
self.downloadPercent = null;
console.log("index page log onInstallStart"); console.log("index page log onInstallStart");
} }
update.onInstallSuccess = ()=>{ update.onInstallSuccess = ()=>{
uComponents.showProcess(self, 0, '安装中成功', []);
console.log("index page log onInstallSuccess"); console.log("index page log onInstallSuccess");
//资源包安装成功,跳转到首页 //资源包安装成功,跳转到首页
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/index.html', url: '../../custom/custom'+newUpdateInfo[i].productId+'/view/device/index.html',
id: 'device', id: 'device',
styles: { styles: {
popGesture: 'none' popGesture: 'none'
...@@ -144,21 +167,54 @@ async function linkToIndex(self, data){ ...@@ -144,21 +167,54 @@ async function linkToIndex(self, data){
}, () => {}); }, () => {});
} }
update.onStateChanged = (download, status) => {
let percent = (download.downloadedSize/download.totalSize).toFixed(2)*100;
console.log(parseInt(percent));
self.downloadPercent = parseInt(percent);
}
update.onError = ()=>{ update.onError = ()=>{
console.log("index page log onError"); console.log("index page log onError");
uComponents.hideLoading(self); }
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(); update.startUpdate();
console.log(update); console.log(update);
} }
}else{
//无资源包需要更新,跳到默认首页
iot.navigator.openWindow({
url: '../device/index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
} }
//页面跳转到添加设备页面 //页面跳转到添加设备页面
function linkToAddDevice(){ function linkToAddDevice(){
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../addDevice/index.html', url: '../addDevice/index.html',
id: 'device', id: 'devicaddDevice',
styles: { styles: {
popGesture: 'none' popGesture: 'none'
}, },
......
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