Commit 384493d7 by 朱建香

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

parent ac8c552c
......@@ -54,5 +54,6 @@ export default {
"newMsg_timeout": 86400,
"getHistoryTimes": 3,
"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){
}
}
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(() => {
......
......@@ -11,15 +11,18 @@ class Update{
this.downWgt();
}else{
console.log("不需要更新");
alert("不需要更新");
this.onNoNeedUpdate();
return ;
}
}
onStateChanged(download, status) {
// console.log((download.downloadedSize/download.totalSize).toFixed(2)*100)
}
downWgt(){
plus.nativeUI.showWaiting("下载wgt文件...");
this.onDownloadStart();
plus.downloader.createDownload( this.url, {filename:"_doc/update/"}, (d,status)=>{
var dtask = plus.downloader.createDownload( this.url, {}, (d,status)=>{
if ( status == 200 ) {
this.onDownloadSuccess();
console.log("下载wgt成功:"+d.filename);
......@@ -27,27 +30,21 @@ class Update{
} else {
console.log("下载wgt失败!");
this.onError(status);
plus.nativeUI.alert("下载wgt失败!");
}
plus.nativeUI.closeWaiting();
}).start();
});
dtask.addEventListener( "statechanged", this.onStateChanged, false );
dtask.start();
}
installWgt(path){
this.onInstallStart();
plus.nativeUI.showWaiting("安装wgt文件...");
plus.runtime.install(path,{force: true},()=>{ //强制安装 不进行版本校验
plus.nativeUI.closeWaiting();
console.log("安装wgt文件成功!");
this.onInstallSuccess();
plus.nativeUI.alert("应用资源更新完成!",()=>{
plus.runtime.restart();
});
},(e)=>{
plus.nativeUI.closeWaiting();
this.onError(e);
console.log("安装wgt文件失败["+e.code+"]:"+e.message);
plus.nativeUI.alert("安装wgt文件失败["+e.code+"]:"+e.message);
});
}
......@@ -71,6 +68,9 @@ class Update{
console.log(`install wgt file success`);
}
onNoNeedUpdate(){
console.log(`no need update`);
}
}
export default Update;
\ No newline at end of file
......@@ -14,6 +14,9 @@ function init() {
//通用 dialog、loading组件
uPublic.componentsInit(['u-dialog','u-loading']);
// uPublic.closeSlideBack();
if(iot.navigator.getExtras().needClose){
iot.navigator.closeAllBesidesItself();
}
const app = new Vue({
data:{
//配置组件
......@@ -56,7 +59,7 @@ function initComponentsConfig() {
//tap <
function backTap(){
iot.navigator.back();
iot.navigator.aback();
}
//tap 扫描绑定设备
......
......@@ -8,6 +8,7 @@
*/
import {iot, uPublic, uComponents} from '../../public/public.js';
import config from '../../public/config.js';
iot.ready(init);
function init() {
......@@ -128,9 +129,20 @@ function openScanCode(self){
console.log(response);
let data = uPublic.checkResponseData(response.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'));
let result = JSON.parse(data.result);
console.log(result);
......@@ -155,12 +167,6 @@ function openScanCode(self){
error: (error) => {
//绑定失败
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 绑定失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'绑定失败');
// }
scanCodeFailue(self);
}
});
......
......@@ -26,8 +26,11 @@ function init() {
noticeTipShowFlag: false,
timeout: null,
countDownText: config.add_wifi_timeout,
extras: {}
},
mounted(){
this.extras = iot.navigator.getExtras();
console.log(this.extras);
resolve(this);
let self = this;
window.addEventListener('returnPage',() => {
......
......@@ -13,13 +13,20 @@ iot.ready(init);
function init() {
//通用 按钮、dialog、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({
data:{
//配置组件
componentsConfig: initComponentsConfig()
componentsConfig: initComponentsConfig(),
extras: {}
},
mounted(){
this.extras = iot.navigator.getExtras();
window.addEventListener('returnPage',function(event){
console.log("stopFindDevice");
iot.business.sds.stopFindDevices({
......@@ -39,7 +46,7 @@ function init() {
},
//tap 开始配置Wi-Fi
onWifiAddButtonTap(){
wifiAddButtonTap();
wifiAddButtonTap(this);
}
}
}).$mount('#app');
......@@ -74,9 +81,12 @@ function backTap(){
}
//tap 开始配置Wi-Fi
function wifiAddButtonTap(){
function wifiAddButtonTap(self){
iot.navigator.openWindow({
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){
});
}
iot.navigator.openWindow({
url: '../device/index.html',
// url: '../addDevice/index.html',
// url: '../../custom/custom01/view/device/index.html',
// url: './loading.html',
id: 'device',
url: './loading.html',
id: 'loading',
styles: {
popGesture: 'none'
},
......
......@@ -10,14 +10,17 @@
import {iot, uPublic, uComponents} from '../../public/public.js';
import Update from '../../public/update.js';
iot.ready(init);
function init() {
//通用 input、按钮、dialog、loading组件
uPublic.componentsInit(['u-loading']);
uPublic.componentsInit(['u-loading','u-process']);
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig()
componentsConfig: initComponentsConfig(),
downloadPercent: null
},
mounted(){
resolve(this);
......@@ -35,19 +38,24 @@ function initComponentsConfig() {
initParam: {
class: 'custom-loading'
}
},
processLoading: {
initParam: {
class: 'custom-process',
status: 0
}
}
}
}
function resolve(self){
uComponents.showProcess(self, 0, 'loading', []);
console.log(self)
uComponents.showloading(self);
cheackSdsDevice(self);
cheackSdsDeviceExit(self);
}
//检验在sds中,该用户是否绑定设备
function cheackSdsDeviceExit(self){
uComponents.showLoading();
iot.business.sds.getDevicesByUser({
success: (response) => {
console.log(response);
......@@ -57,13 +65,12 @@ function cheackSdsDeviceExit(self){
cheackCloudDeviceExit(self, data.sn);
}else{
//sds,关系不存在
linkToAddDevice();
// linkToAddDevice();
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
uComponents.hideLoading(self);
},
complete: () => {}
});
......@@ -71,65 +78,81 @@ function cheackSdsDeviceExit(self){
//检验在云端中,该用户是否绑定设备
function cheackCloudDeviceExit(self, deviceId){
iot.business.api.send('lock/getDeviceProductId', {
data: {
device_id: deviceId
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
// iot.business.api.send('lock/getDeviceProductId', {
// data: {
// device_id: deviceId
// },
// success: (response) => {
// console.log(response);
// let data = uPublic.checkResponseData(response.data);
// if(data){
//云端,绑定关系已存在
linkToIndex(self,data);
}else{
//云端,关系不存在
linkToAddDevice();
}
},
error: (error) => {
console.log(error);
uComponents.hideLoading(self);
},
complete: () => {}
});
linkToIndex(self);
// }else{
// //云端,关系不存在
// linkToAddDevice();
// }
// },
// error: (error) => {
// console.log(error);
// },
// complete: () => {}
// });
}
//页面跳转到首页
async function linkToIndex(self, data){
async function linkToIndex(self){
let updateInfo = await iot.storage.getMap('updateInfo');
let newUpdateInfo = data.updateInfo;
console.log(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++){
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
}
}
// 这里传入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 = ()=>{
console.log("index page log onDownloadStart");
uComponents.hideLoading(self);
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("index page log onInstallSuccess");
//资源包安装成功,跳转到首页
iot.navigator.openWindow({
url: '../device/index.html',
url: '../../custom/custom'+newUpdateInfo[i].productId+'/view/device/index.html',
id: 'device',
styles: {
popGesture: 'none'
......@@ -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 = ()=>{
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();
console.log(update);
}
}else{
//无资源包需要更新,跳到默认首页
iot.navigator.openWindow({
url: '../device/index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
}
//页面跳转到添加设备页面
function linkToAddDevice(){
iot.navigator.openWindow({
url: '../addDevice/index.html',
id: 'device',
id: 'devicaddDevice',
styles: {
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