Commit 03b7b6ad by 朱建香

绑定设备(自定义)

parent bb1e8673
......@@ -6,6 +6,7 @@
},
"btn": {
"confirm": "确定",
"guideLogin": "账号/密码登录",
"login": "登录",
"getCode": "获取验证码",
"register": "注册",
......
......@@ -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) {
if (webview) {
if (typeof data === 'undefined') {
......@@ -121,7 +129,80 @@ iot.navigator.trigger = function (element, eventType, eventData) {
return this;
};
iot.ready(() => {
uPublic.recalc();
});
iot.navigator.closeAllBesidesItself = function () {
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}
\ No newline at end of file
......@@ -12,51 +12,37 @@ import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 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({
data:{
textWiFiName: null,
textPassword: null,
textErrorTip: null,
textLoading: 'loading...',
status: 0,
//配置组件
componentsConfig: initComponentsConfig()
componentsConfig: initComponentsConfig(),
status: 0
},
mounted(){
iot.business.sds.findWifi({
data: {
// model: 'model',
// ssid: 'ssid',
wifiPwd: 'wifiPwd',
timeout: 20000
resolve(this);
},
success: (response) => {
console.log(response);
methods:{
getTextWiFiName(){
return this.textWiFiName;
},
error: (error) => {
console.log(error);
}
});
setTextWiFiName(text){
this.textWiFiName = text;
},
methods:{
getTextPassword(){
return this.textPassword;
},
setTextPassword(pwd){
this.textPassword = pwd;
},
getTextLoading(){
return this.textLoading;
},
setTextLoading(text){
this.textLoading = text;
},
getStatus(){
return this.status;
},
setStatus(value){
this.status = value;
setStatus(status){
this.status = status;
},
onPasswordChange(text){
passwordChange(this,text);
......@@ -70,8 +56,8 @@ function init() {
connectButtonTap(this);
},
//tap loading button
onCommstatusLoadingButtonTap(){
commstatusLoadingButtonTap(this);
onCommLoadingButtonTap(){
commLoadingButtonTap(this);
}
}
}).$mount('#app');
......@@ -105,15 +91,32 @@ function initComponentsConfig() {
class: 'custom-loading'
}
},
ucommstatusloading: {
ucommloading: {
initParam: {
class: 'custom-commstatus-loading',
buttonText: Vue.t('btn.confirm')
class: 'custom-comm-loading',
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){
self.textPassword = text;
console.log('passwordChange: ' + self.textPassword);
......@@ -126,29 +129,91 @@ function backTap(){
//tap 连接
function connectButtonTap(self){
uComponents.showCommstatusloading(self);
setTimeout(function(){
self.setTextLoading(Vue.t('commstatusLoading.connectSuccess'));
setTimeout(function(){
//绑定成功
// uComponents.showCommstatusloading(self);
// setTimeout(function(){
// self.setTextLoading(Vue.t('commstatusLoading.connectSuccess'));
// 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.setTextLoading(Vue.t('commstatusLoading.bindSuccess'));
//绑定失败
//self.setStatus(2);
//self.setTextLoading(Vue.t('commstatusLoading.bindFailed'));
//uComponents.changeCommstatusButtonText(self,Vue.t('btn.reBound'));
},3000);
},3000);
// //停止查找设备
iot.business.sds.stopFindDevices({
success: (response) => {},
error: (error) => {}
});
}else if(response.data == "fail"){
//连接失败
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
function commstatusLoadingButtonTap(self) {
function commLoadingButtonTap(self) {
if(self.getStatus() == 1){
//绑定成功
uComponents.hideCommstatusloading(self);
uComponents.hideCommLoading(self);
iot.navigator.openWindow({
url: '../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(){
//tap 开始配置Wi-Fi
function wifiAddButtonTap(){
// iot.navigator.openWindow({
// url: './wifiAdd.html',
// 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.navigator.openWindow({
url: './wifiAdd.html',
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);
// }
// });
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ function init() {
componentsConfig: initComponentsConfig()
},
mounted(){
iot.navigator.closeAllBesidesItself();
},
methods:{
getValueOpendoorRecord(){
......
......@@ -106,9 +106,11 @@ function saveButtonTap(self){
text: Vue.t('btn.confirm'), callback: function () {
let opener = plus.webview.currentWebview().opener();
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'
});
console.log('returnPage');
iot.navigator.back();
}
});
......
......@@ -25,42 +25,13 @@ function init() {
showDeviceList: []
},
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;
window.addEventListener('returnPage',function(event){
console.log("innn");
self.showDeviceList = [];
getDeviceList(self);
});
//获取设备列表
getDeviceList(self);
},
methods:{
getDeviceList(){
......@@ -132,6 +103,8 @@ function initComponentsConfig() {
//获取所有的设备
function getDeviceList(self){
//显示loading
uComponents.showLoading(self);
iot.business.device.getList({
data: {
sds: true,
......@@ -284,13 +257,16 @@ function deleteDoorlook(self, index){
rojectMethods.changeGridList(self, self.getDeviceList());
uComponents.openAlert(self, Vue.t('doorlockManage.deleteSuccess'), {
text: Vue.t('btn.confirm'), callback: function () {
console.log("删除成功");
projectMethods.changeGridList(self, self.getShowDeviceList());
uComponents.hideLoading(self);
}
});
}else{
//删除失败
uComponents.openAlert(self, Vue.t('doorlockManage.editNameFailue'), {
text: Vue.t('btn.confirm'), callback: function () {
console.log("删除失败");
uComponents.hideLoading(self);
}
});
......
......@@ -99,8 +99,8 @@ function qrcodeButtonTap(self){
} else {
console.log('success');
uComponents.hideLoading(self);
qr.style.width = "5.333rem";
qr.style.height = "5.333rem";
qr.style.width = "5.280rem";
qr.style.height = "5.280rem";
console.log(qr.style);
setTimeout(() => {
self.setQrCodeDisabled(true);
......
......@@ -12,7 +12,7 @@ import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 dialog、loading组件
uPublic.componentsInit(['u-dialog','u-loading']);
uPublic.componentsInit(['u-dialog','u-loading','u-button']);
const app = new Vue({
data:{
//配置组件
......@@ -26,6 +26,40 @@ function init() {
// });
// },2000)
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({
data: {
oa: true
......@@ -59,26 +93,6 @@ function init() {
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){
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({
url: '../device/',
id: 'device'
......@@ -107,6 +122,7 @@ function cloudsLogin(self, id){
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({
url: '../device/',
id: 'device'
......@@ -131,6 +147,7 @@ function cloudsLogin(self, id){
//注册成功
let data = uPublic.checkResponseData(response.data);
if(data){
uComponents.hideLoading(self);
iot.navigator.openWindow({
url: '../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