Commit 03b7b6ad by 朱建香

绑定设备(自定义)

parent bb1e8673
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
}, },
"btn": { "btn": {
"confirm": "确定", "confirm": "确定",
"guideLogin": "账号/密码登录",
"login": "登录", "login": "登录",
"getCode": "获取验证码", "getCode": "获取验证码",
"register": "注册", "register": "注册",
......
...@@ -81,6 +81,14 @@ uPublic.checkResponseData = function (data) { ...@@ -81,6 +81,14 @@ uPublic.checkResponseData = function (data) {
} }
}; };
iot.ready(() => {
uPublic.recalc();
});
iot.navigator.getAllWebviw = function () {
return plus.webview.all();
}
iot.navigator.fire = function (webview, eventType, data) { iot.navigator.fire = function (webview, eventType, data) {
if (webview) { if (webview) {
if (typeof data === 'undefined') { if (typeof data === 'undefined') {
...@@ -121,7 +129,80 @@ iot.navigator.trigger = function (element, eventType, eventData) { ...@@ -121,7 +129,80 @@ iot.navigator.trigger = function (element, eventType, eventData) {
return this; return this;
}; };
iot.ready(() => { iot.navigator.closeAllBesidesItself = function () {
uPublic.recalc(); var wvs = plus.webview.all();
}); // var curWb = plus.webview.currentWebview();
for (var i = 0; i < wvs.length-1; i++) {
// if (wvs[i].id != curWb.id) {
wvs[i].close();
// }
}
}
iot.navigator.closeAll = function (){
var wvs = plus.webview.all();
var curWb = plus.webview.currentWebview();
for (var i = 0; i < wvs.length; i++) {
wvs[i].close();
}
}
iot.ready(function(){
plus.key.addEventListener('backbutton',iot.navigator.aback,false);
// plus.key.addEventListener('backbutton',iot.navigator.aback,false);
})
iot.navigator.aback =function(){
var wobj = plus.webview.currentWebview();
var parent = wobj.parent();
var wbs = iot.navigator.getAllWebviw();
if (wbs.length>1) {
// console.log("不止一个webview...");
// return;
iot.navigator.back();
// console.log("有父webview...");
// return;
// parent.evalJS('iot.navigator.back()');
// parent.evalJS('mui&&mui.back();');
} else {
console.log("只有一个webView");
// return;
wobj.canBack(function(e) {
console.log("是否可以返回canback...");
console.log(window.history);
window.history.back();
console.log(e);
//by chb 暂时注释,在碰到类似popover之类的锚点的时候,需多次点击才能返回;
if (e.canBack) { //webview history back
console.log("e.canback....");
// return;
window.history.back();
// iot.navigator.back();
} else { //webview close or hide
console.log("不能back。。。");
if (!__back__first) {
__back__first = new Date().getTime();
console.log("给back_first设值....");
plus.nativeUI.toast( "再按一次退出应用");
// mui.toast('再按一次退出应用');
setTimeout(function() {
__back__first = null;
}, 2000);
} else {
console.log("back_first不为空....");
if (new Date().getTime() - __back__first < 2000) {
console.log("两次的间隔时间少于2秒");
plus.runtime.quit();
}else{
console.log("时间间隔大于2s");
}
}
return;
}
});
}
}
export {iot, uPublic, uComponents} export {iot, uPublic, uComponents}
\ No newline at end of file
...@@ -12,51 +12,37 @@ import {iot, uPublic, uComponents} from '../../public/public.js'; ...@@ -12,51 +12,37 @@ import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init); iot.ready(init);
function init() { function init() {
//通用 input、按钮、dialog、loading组件 //通用 input、按钮、dialog、loading组件
uPublic.componentsInit(['u-text','u-button','u-commstatus-loading','u-dialog','u-loading']); uPublic.componentsInit(['u-text','u-button','u-comm-loading','u-dialog','u-loading']);
const app = new Vue({ const app = new Vue({
data:{ data:{
textWiFiName: null, textWiFiName: null,
textPassword: null, textPassword: null,
textErrorTip: null, textErrorTip: null,
textLoading: 'loading...',
status: 0,
//配置组件 //配置组件
componentsConfig: initComponentsConfig() componentsConfig: initComponentsConfig(),
status: 0
}, },
mounted(){ mounted(){
iot.business.sds.findWifi({ resolve(this);
data: {
// model: 'model',
// ssid: 'ssid',
wifiPwd: 'wifiPwd',
timeout: 20000
}, },
success: (response) => { methods:{
console.log(response); getTextWiFiName(){
return this.textWiFiName;
}, },
error: (error) => { setTextWiFiName(text){
console.log(error); this.textWiFiName = text;
}
});
}, },
methods:{
getTextPassword(){ getTextPassword(){
return this.textPassword; return this.textPassword;
}, },
setTextPassword(pwd){ setTextPassword(pwd){
this.textPassword = pwd; this.textPassword = pwd;
}, },
getTextLoading(){
return this.textLoading;
},
setTextLoading(text){
this.textLoading = text;
},
getStatus(){ getStatus(){
return this.status; return this.status;
}, },
setStatus(value){ setStatus(status){
this.status = value; this.status = status;
}, },
onPasswordChange(text){ onPasswordChange(text){
passwordChange(this,text); passwordChange(this,text);
...@@ -70,8 +56,8 @@ function init() { ...@@ -70,8 +56,8 @@ function init() {
connectButtonTap(this); connectButtonTap(this);
}, },
//tap loading button //tap loading button
onCommstatusLoadingButtonTap(){ onCommLoadingButtonTap(){
commstatusLoadingButtonTap(this); commLoadingButtonTap(this);
} }
} }
}).$mount('#app'); }).$mount('#app');
...@@ -105,15 +91,32 @@ function initComponentsConfig() { ...@@ -105,15 +91,32 @@ function initComponentsConfig() {
class: 'custom-loading' class: 'custom-loading'
} }
}, },
ucommstatusloading: { ucommloading: {
initParam: { initParam: {
class: 'custom-commstatus-loading', class: 'custom-comm-loading',
buttonText: Vue.t('btn.confirm') buttonText: Vue.t('btn.confirm'),
text: 'loading',
status: 0
} }
} }
} }
} }
function resolve(self){
iot.business.sds.getSSId({
success: (response) => {
console.log(response);
let data = JSON.parse(response);
self.textWiFiName = data.ssid;
console.log(self.textWiFiName);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
}
});
}
function passwordChange(self,text){ function passwordChange(self,text){
self.textPassword = text; self.textPassword = text;
console.log('passwordChange: ' + self.textPassword); console.log('passwordChange: ' + self.textPassword);
...@@ -126,29 +129,91 @@ function backTap(){ ...@@ -126,29 +129,91 @@ function backTap(){
//tap 连接 //tap 连接
function connectButtonTap(self){ function connectButtonTap(self){
uComponents.showCommstatusloading(self); // uComponents.showCommstatusloading(self);
setTimeout(function(){ // setTimeout(function(){
self.setTextLoading(Vue.t('commstatusLoading.connectSuccess')); // self.setTextLoading(Vue.t('commstatusLoading.connectSuccess'));
setTimeout(function(){ // setTimeout(function(){
//绑定成功 // //绑定成功
// self.setStatus(1);
// self.setTextLoading(Vue.t('commstatusLoading.bindSuccess'));
// //绑定失败
// //self.setStatus(2);
// //self.setTextLoading(Vue.t('commstatusLoading.bindFailed'));
// //uComponents.changeCommstatusButtonText(self,Vue.t('btn.reBound'));
// },3000);
// },3000);
console.log(self.getTextWiFiName());
self.setTextPassword('macro_scope00');
console.log(self.getTextPassword());
iot.business.sds.findWifi({
data: {
model: 'THM_LIVING_ELECTRICALBLANKET_TH_1507',
ssid: "ugen-f",
wifiPwd: 'macro_scope00',
timeout: 20000
},
success: (response) => {
console.log("findWifi");
console.log(response);
if(response.data == 'onProvisioning'){
//wifi链接中
uComponents.showCommLoading(self);
}else if(response.data == 'provisioned success'){
//wifi连接成功,停止连接wifi
// iot.business.sds.stopFindWifi({
// success: (response) => {},
// error: (error) => {}
// });
}
},
error: (error) => {
console.log(error);
}
});
iot.business.sds.findDevices({
success: (response) => {
console.log("findDevices");
console.log(response);
if(response.data == "joined success"){
//连接成功
uComponents.changeCommLoadingStatusAndText(self, 1, '绑定成功');
self.setStatus(1); self.setStatus(1);
self.setTextLoading(Vue.t('commstatusLoading.bindSuccess')); // //停止查找设备
//绑定失败 iot.business.sds.stopFindDevices({
//self.setStatus(2); success: (response) => {},
//self.setTextLoading(Vue.t('commstatusLoading.bindFailed')); error: (error) => {}
//uComponents.changeCommstatusButtonText(self,Vue.t('btn.reBound')); });
},3000); }else if(response.data == "fail"){
},3000); //连接失败
uComponents.changeCommLoadingStatusAndText(self, 2, '绑定失败');
self.setStatus(2);
uComponents.changeCommButtonText('请重新绑定');
//停止查找设备
iot.business.sds.stopFindDevices({
success: (response) => {},
error: (error) => {}
});
}
},
error: (error) => {
console.log(error);
}
});
} }
//tap loading button //tap loading button
function commstatusLoadingButtonTap(self) { function commLoadingButtonTap(self) {
if(self.getStatus() == 1){
//绑定成功 //绑定成功
uComponents.hideCommstatusloading(self); uComponents.hideCommLoading(self);
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/', url: '../device/',
id: 'device' id: 'device'
}); });
}else if(self.getStatus() == 2){
//绑定失败 //绑定失败
//uComponents.hideCommstatusloading(self); uComponents.hideCommLoading(self);
}
} }
\ No newline at end of file
...@@ -63,18 +63,18 @@ function backTap(){ ...@@ -63,18 +63,18 @@ function backTap(){
//tap 开始配置Wi-Fi //tap 开始配置Wi-Fi
function wifiAddButtonTap(){ function wifiAddButtonTap(){
// iot.navigator.openWindow({ iot.navigator.openWindow({
// url: './wifiAdd.html', url: './wifiAdd.html',
// id: 'wifiAdd' id: 'wifiAdd'
// });
iot.business.sds.wifiDeviceConfig({
success: function (response) {
console.log('wifiDeviceConfig success');
console.log(response);
},
error: function (error) {
console.log('wifiDeviceConfig error');
console.log(error);
}
}); });
// iot.business.sds.wifiDeviceConfig({
// success: function (response) {
// console.log('wifiDeviceConfig success');
// console.log(response);
// },
// error: function (error) {
// console.log('wifiDeviceConfig error');
// console.log(error);
// }
// });
} }
\ No newline at end of file
...@@ -29,6 +29,7 @@ function init() { ...@@ -29,6 +29,7 @@ function init() {
componentsConfig: initComponentsConfig() componentsConfig: initComponentsConfig()
}, },
mounted(){ mounted(){
iot.navigator.closeAllBesidesItself();
}, },
methods:{ methods:{
getValueOpendoorRecord(){ getValueOpendoorRecord(){
......
...@@ -106,9 +106,11 @@ function saveButtonTap(self){ ...@@ -106,9 +106,11 @@ function saveButtonTap(self){
text: Vue.t('btn.confirm'), callback: function () { text: Vue.t('btn.confirm'), callback: function () {
let opener = plus.webview.currentWebview().opener(); let opener = plus.webview.currentWebview().opener();
let view = plus.webview.getWebviewById(opener.id); let view = plus.webview.getWebviewById(opener.id);
iot.navigator.fire(view,'returnPage',{ console.log(view);
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{
name: 'zhu' name: 'zhu'
}); });
console.log('returnPage');
iot.navigator.back(); iot.navigator.back();
} }
}); });
......
...@@ -25,42 +25,13 @@ function init() { ...@@ -25,42 +25,13 @@ function init() {
showDeviceList: [] showDeviceList: []
}, },
mounted(){ mounted(){
//显示loading
uComponents.showLoading(this);
iot.business.user.login({
data: {
// sds: true,
//17621209360
//yyl111
username: '18679022601',
pwd: '123'
// userinfo: {
// username: '"18679022601"',
//// pwd: '123'
// nickname: 'zhu',
// head: 'head',
// utoken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEwMCwiaWF0IjoxNTA1ODE4NDI5LCJleHAiOjE1MDY2ODI0Mjl9.Bhl9TTcT1PUZZdmcPobE3f4OA2IgSURmtHyT2yluBFA'
// }
},
success: (response) => {
console.log(response);
//获取设备列表
getDeviceList(this);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {}
});
console.log("in");
// getDeviceList(this);
let self = this; let self = this;
window.addEventListener('returnPage',function(event){ window.addEventListener('returnPage',function(event){
console.log("innn");
self.showDeviceList = []; self.showDeviceList = [];
getDeviceList(self); getDeviceList(self);
}); });
//获取设备列表
getDeviceList(self);
}, },
methods:{ methods:{
getDeviceList(){ getDeviceList(){
...@@ -132,6 +103,8 @@ function initComponentsConfig() { ...@@ -132,6 +103,8 @@ function initComponentsConfig() {
//获取所有的设备 //获取所有的设备
function getDeviceList(self){ function getDeviceList(self){
//显示loading
uComponents.showLoading(self);
iot.business.device.getList({ iot.business.device.getList({
data: { data: {
sds: true, sds: true,
...@@ -284,13 +257,16 @@ function deleteDoorlook(self, index){ ...@@ -284,13 +257,16 @@ function deleteDoorlook(self, index){
rojectMethods.changeGridList(self, self.getDeviceList()); rojectMethods.changeGridList(self, self.getDeviceList());
uComponents.openAlert(self, Vue.t('doorlockManage.deleteSuccess'), { uComponents.openAlert(self, Vue.t('doorlockManage.deleteSuccess'), {
text: Vue.t('btn.confirm'), callback: function () { text: Vue.t('btn.confirm'), callback: function () {
console.log("删除成功");
projectMethods.changeGridList(self, self.getShowDeviceList()); projectMethods.changeGridList(self, self.getShowDeviceList());
uComponents.hideLoading(self);
} }
}); });
}else{ }else{
//删除失败 //删除失败
uComponents.openAlert(self, Vue.t('doorlockManage.editNameFailue'), { uComponents.openAlert(self, Vue.t('doorlockManage.editNameFailue'), {
text: Vue.t('btn.confirm'), callback: function () { text: Vue.t('btn.confirm'), callback: function () {
console.log("删除失败");
uComponents.hideLoading(self); uComponents.hideLoading(self);
} }
}); });
......
...@@ -99,8 +99,8 @@ function qrcodeButtonTap(self){ ...@@ -99,8 +99,8 @@ function qrcodeButtonTap(self){
} else { } else {
console.log('success'); console.log('success');
uComponents.hideLoading(self); uComponents.hideLoading(self);
qr.style.width = "5.333rem"; qr.style.width = "5.280rem";
qr.style.height = "5.333rem"; qr.style.height = "5.280rem";
console.log(qr.style); console.log(qr.style);
setTimeout(() => { setTimeout(() => {
self.setQrCodeDisabled(true); self.setQrCodeDisabled(true);
......
...@@ -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']); uPublic.componentsInit(['u-dialog','u-loading','u-button']);
const app = new Vue({ const app = new Vue({
data:{ data:{
//配置组件 //配置组件
...@@ -26,6 +26,40 @@ function init() { ...@@ -26,6 +26,40 @@ function init() {
// }); // });
// },2000) // },2000)
let self = this; let self = this;
},
methods:{
onLoginButtonTap(){
loginButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
//登录 button 参数
loginButton: {
initParam: {
class: 'custom-guide-button',
text: Vue.t('btn.guideLogin')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
function loginButtonTap(self){
uComponents.showLoading(self);
iot.business.sds.init({ iot.business.sds.init({
data: { data: {
oa: true oa: true
...@@ -59,26 +93,6 @@ function init() { ...@@ -59,26 +93,6 @@ function init() {
uPublic.openRequestErrorAlert(self); uPublic.openRequestErrorAlert(self);
} }
}); });
},
methods:{
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
} }
//云端登陆 //云端登陆
...@@ -88,6 +102,7 @@ function cloudsLogin(self, id){ ...@@ -88,6 +102,7 @@ function cloudsLogin(self, id){
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/', url: '../device/',
id: 'device' id: 'device'
...@@ -107,6 +122,7 @@ function cloudsLogin(self, id){ ...@@ -107,6 +122,7 @@ function cloudsLogin(self, id){
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/', url: '../device/',
id: 'device' id: 'device'
...@@ -131,6 +147,7 @@ function cloudsLogin(self, id){ ...@@ -131,6 +147,7 @@ function cloudsLogin(self, id){
//注册成功 //注册成功
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/', url: '../device/',
id: 'device' id: 'device'
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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