Commit 80567164 by 朱建香

文件目录修改

parent 0cc3fe84
/**
* newnotify-dialog.vue
* Version: 0.1
* User: wujie
* Date: 2017-12-26
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* newnotify-dialog
*
******************************************************************************
* 依赖
通知栏插件 isNotifycationOpen toNotifycationSetting
多语言 需要配置多语言
* 支持环境
App
*
*/
<template>
<div id="app" v-cloak>
<div class="header">
<p>开启通知</p>
</div>
<div class="content">
<ul class="u-android-notify">
<li class="u-android-notify-row" v-bind:class = "setp1Active">
<span class="u-android-notify-icon">&#xe6c1;</span>
<span class="u-android-notify-finish-icon" v-show="isStep1Finish"></span>
<div class="u-android-notify-title">
{{toSettingTitle}}
<v-touch tag="div" class="u-android-notify-button" v-show="isToSetting" v-on:tap="onOpenNotify">{{toSettingsub}}
<span></span></v-touch>
</div>
</li>
<li class="u-android-notify-row" v-bind:class = "setp2Active">
<span class="u-android-notify-icon">&#xe6c0;</span>
<span class="u-android-notify-finish-icon" v-show="isStep2Finish"></span>
<div class="u-android-notify-title">
{{checkSetting}}
<v-touch tag="div" class="u-android-notify-button" v-show="isKnow" v-on:tap="onIKnow">{{IKonw}}</v-touch>
</div>
<div class="u-android-notify-tip">{{checkSettingsubTitle}}</div>
<div class="u-android-notify-subtitle">{{step1Title}}</div>
<div class="u-android-notify-subcontent">{{step1content}}</div>
<div class="u-android-notify-subtitle">{{step2Title}}</div>
<div class="u-android-notify-subcontent">{{step2content}}</div>
<div class="u-android-notify-subtitle">{{step3Title}}</div>
<div class="u-android-notify-subcontent">{{step3content}}</div>
</li>
<li class="u-android-notify-row" v-bind:class = "setp3Active">
<span class="u-android-notify-icon">&#xe6c2;</span>
<span class="u-android-notify-finish-icon" v-show="isStep3Finish"></span>
<div class="u-android-notify-title">
{{endSetting}}
<v-touch tag="div" class="u-android-notify-button" v-show="isToIndex" v-on:tap="onToIndex">{{toAppIndex}}
<span></span></v-touch>
</div>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
props: ['initParam','toIndex'],
data () {
return {
toSettingTitle:Vue.t('androidNotify.toSettingTitle'),
toSettingsub:Vue.t('androidNotify.toSettingsub'),
checkSetting:Vue.t('androidNotify.checkSetting'),
IKonw:Vue.t('androidNotify.IKonw'),
checkSettingsubTitle:Vue.t('androidNotify.checkSettingsubTitle'),
step1Title:Vue.t('androidNotify.step1Title'),
step1content:Vue.t('androidNotify.step1content'),
step2Title:Vue.t('androidNotify.step2Title'),
step2content:Vue.t('androidNotify.step2content'),
step3Title:Vue.t('androidNotify.step3Title'),
step3content:Vue.t('androidNotify.step3content'),
endSetting:Vue.t('androidNotify.endSetting'),
toAppIndex:Vue.t('androidNotify.toIndex'),
//notifyState:false, // 当前是否开启了通知
//gotoIndex:this.toIndex,// 处理点击到index按钮事件
//isKnow:iot.native.isNotifycationOpen(),//是否需要显示 我已阅读
//isToIndex:false,// 是否需要显示去首页按钮
isStep1Finish:iot.native.isNotifycationOpen(),//是否需要显示步骤1的勾
isStep2Finish:false,//是否需要显示步骤2的勾
isStep3Finish:false,//是否需要显示步骤3的勾
isToSetting:!iot.native.isNotifycationOpen(),//是否需要显示去设置按钮
setp1Active:null,
setp2Active:null,// 默认为灰色 不显示active
setp3Active:null,
notifyState:false, // 当前是否开启了通知
gotoIndex:this.toIndex,// 处理点击到index按钮事件
isKnow:iot.native.isNotifycationOpen(),//是否需要显示 我已阅读
isToIndex:false,// 是否需要显示去首页按钮
}
},
mounted: function () {
this.setp1Active=this.isStep1Finish?"active changeBorder":null;
this.setp2Active=this.isStep1Finish?"active changeBorder":null;
console.log("notifyState:"+iot.native.isNotifycationOpen());
onTest(this);
// 监听程序恢复前台
document.addEventListener("resume", ()=>{
onAppReume(this);
}, false);
},
watch: {
},
methods: {
// 点击按钮关闭弹出框
onOpenNotify(){
openNotify(this);
},
onIKnow(){
IKonw(this);
},
onToIndex(){
toIndex(this);
}
}
};
function onTest(self){
console.log(self.isStep1Finish);
console.log(self.setp2Active);
}
function openNotify(self) {
console.log("去开启");
iot.native.toNotifycationSetting("notify");
self.setp1Active = 'active changeBorder';
}
function IKonw(self){
console.log("点击了我已阅读");
self.isStep2Finish = true; // 点击阅读后显示步骤2的勾
// self.setp2Active = "active changeBorder";// 点击阅读后显示步骤2的字体亮度调高
self.setp3Active = "active";// 同时步骤3的字体亮度也调高
self.isStep3Finish = true; // 步骤3的勾勾选
self.isToIndex = true;//显示去首页按钮
self.isKnow = false; // 点击我已阅读隐藏我已阅读按钮
}
function toIndex(self){
console.log("gotoIndex...");
self.gotoIndex();
}
function onAppReume(self){
let notifyState = iot.native.isNotifycationOpen();
console.log("notifyState:"+notifyState);
if (notifyState) {
self.setp2Active = "active changeBorder";
}else{// 恢复默认
self.setp2Active = null;
self.setp3Active = null;
self.isStep2Finish = false;
self.isStep3Finish = false;
self.isToIndex = false;
}
self.isStep1Finish = iot.native.isNotifycationOpen();// 再次判断当前通知是否开启
self.isToSetting = !iot.native.isNotifycationOpen(); // 再次判断是否需要显示去设置按钮
self.isKnow = iot.native.isNotifycationOpen(),// 再次判断是否需要显示 我已阅读
self.$nextTick(function () {
console.log("重新渲染");
});
}
</script>
/**
* list.vue
* Version: 0.1
* User: shz
* Date: 2017-06-20
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* list
*/
<template>
<div class="u-list" v-bind:class="initClass">
<ul class="u-list-scroll" v-show="list.length">
<v-touch tag="li" class="u-list-row" v-for="(item, index) in list" :key="index"
v-bind:class="[item.class, {disabled: item.disabled}]" v-on:tap="onTapRow(index)">
<img class="u-list-left-image" v-if="item.leftImage" v-bind:src="item.leftImage">
<p class="u-list-left-bg-image" v-bind:class="item.imgClass" v-else-if="item.imgClass"></p>
<span class="u-list-left-icon" v-else-if="item.leftIcon" v-html="item.leftIcon"></span>
<div>
<p class="u-list-title">{{ item.title }}</p>
<p class="u-list-subtitle" v-if="item.subtitle">{{ item.subtitle }}</p>
</div>
<span class="u-list-right-text" v-if="item.rightText">{{ item.rightText }}</span>
<span class="u-list-right-icon" v-if="(item.rightIcon || item.disabled !== true)"
v-html="item.rightIcon"></span>
<img class="u-list-right-image" v-else-if="(item.rightImage || item.disabled !== true)"
v-bind:src="item.rightImage">
</v-touch>
<v-touch tag="li" class="u-list-load" v-on:tap="onTapLoad" v-show="loadShowFlag">
<span class="u-list-load-animation" v-show="loadFlag"></span>
{{ loadText }}
</v-touch>
</ul>
<p class="u-list-tip" v-show="tipShowFlag && (list.length == 0)">{{ tip }}</p>
</div>
</template>
<script>
export default {
props: ['initParam'],
data() {
return {
// 组件初始化列表
list: this.initParam.list || [],
// 组件初始化样式
initClass: this.initParam.class,
// 组件初始化无数据显示文字
tip: this.initParam.tip,
pagesize: this.initParam.pagesize,
pullup: this.initParam.pullup || false,
loadText: Vue.t('scroll.clickToLoadMore'),
// loading是否显示
loadShowFlag: false,
// 是否在loading
loadFlag: false,
tipShowFlag: false
}
},
mounted() {
this.setLoadShowFlag(this.list.length);
let ulistDom = this.$el;
let self = this;
ulistDom.onscroll = function () {
//在一些特殊情况下ulistDom.scrollHeight和ulistDom.offsetHeight + ulistDom.scrollTop会相差1px,这里考虑1px的误差
if (!self.loadFlag && self.pullup && (ulistDom.scrollHeight - (ulistDom.offsetHeight + ulistDom.scrollTop)) <= 1) {
self.loadText = Vue.t('scroll.loading');
self.loadFlag = true;
self.$emit('u-list-load');
}
}
},
methods: {
setLoadShowFlag(number) {
this.loadShowFlag = (number >= this.pagesize);
},
onTapRow(index) {
tapRow(this, index);
},
onTapLoad() {
tapLoad(this);
},
changeList(list) {
changeList(this, list);
}
}
}
// 通知事件和当前点击列表选项下标
function tapRow(self, index) {
if (self.list[index].disabled !== true) {
self.$emit('u-list-tap', index);
}
}
// 通知点击加载更多事件
function tapLoad(self) {
// loading
if (!self.loadFlag && !self.pullup) {
self.$emit('u-list-load');
self.loadText = Vue.t('scroll.loading');
self.loadFlag = true;
}
}
// 修改list组件列表
function changeList(self, list) {
let array = Array.isArray(list) ? list : [];
self.tipShowFlag = (array.length === 0);
self.setLoadShowFlag(array.length - self.list.length);
self.list = array;
self.$nextTick(function () {
self.loadText = Vue.t('scroll.clickToLoadMore');
self.loadFlag = false;
});
}
</script>
\ No newline at end of file
/**
* v_alarmInfo.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 报警信息页面
*/
const PAGE_SIZE = 10;
import moment from 'moment';
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
import projectMethods from '../../public/components.js';
iot.ready(init);
function init() {
//通用 list、dialog、loading组件
uPublic.componentsInit(['u-list','u-dialog','u-loading']);
uPublic.componentsExtend(['list']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
list:[],
startId: 0,
deviceId: null,
flag: true,
noticeTipShowFlag: false
},
mounted(){
uComponents.showLoading(this);
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
resolve(this);
window.addEventListener('returnPage',() => {
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
});
},
methods:{
getList(){
return this.list;
},
setList(list){
this.list = list;
},
getStartId(){
return this.startId;
},
setStartId(id){
this.startId = id;
},
getDeviceId(){
return this.deviceId;
},
setDeviceId(id){
this.deviceId = id;
},
//tap 点击加载更多
onListLoad(){
listLoad(this);
},
onRefreshFresh(){
refreshFresh(this);
},
onNotifycationSetting(){
notifycationSetting();
},
//tap <
onBackTap(){
backTap();
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
alarmInfoList:{
initParam: {
class: 'custom-list',
list: [],
tip: Vue.t('alarmInfo.noInfoTip'),
pagesize: PAGE_SIZE,
pullup: true
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
// 获取历史记录
function resolve(self) {
self.setDeviceId(iot.navigator.getExtras().deviceId);
// uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getHistoryRecord',
{
data: {
device_id: self.getDeviceId(),
action: 2,
start_id: self.getStartId(),
page_size: PAGE_SIZE,
pullUpLoading: true
},
success: async (response) => {
console.log(response);
if(self.flag){
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
self.flag = await uPublic.upDateRead('notify', moment(record[0].time).unix());
}
}
let data = uPublic.checkResponseData(response.data);
if(data){
let list = [];
let record = data.record;
for(let i=0; i<record.length; i++){
list[i] = {
value: record[i].openId,
// leftImage: '../../resources/image/green_alarmInfo'+record[i].mode+'_icon.png',
imgClass: 'u-list-left-bg-alarm_'+record[i].mode,
subtitle: Vue.t('alarmInfo.'+config.alarmMode[record[i].mode]+''),
rightText: moment(record[i].time).format("YYYY.MM.DD HH:mm:ss")
};
}
self.setList(self.getList().concat(list));
if(record.length > 0){
self.setStartId(record[record.length-1].id);
}
//更新列表数据
projectMethods.changeList(self, self.getList());
}else{
}
uComponents.hideLoading(self);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//tap <
function backTap(){
iot.navigator.aback();
}
//重写mui.back
//mui.back = function(){
// iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
// console.log("fire");
// iot.navigator.back();
//}
//tap 点击加载更多
function listLoad(self) {
resolve(self);
}
//ios跳转到系统设置页面
//android跳转到通知页面
function notifycationSetting(){
if(plus.os.name == 'Android'){
// alert("打开通知页面");
iot.navigator.openWindow({
url: './notify.html',
id: 'notify',
styles: {
popGesture: 'none'
}
});
}else{
iot.native.toNotifycationSetting();
}
}
/**
* v_hijackRecord.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 劫持记录页面
*/
import moment from 'moment';
const PAGE_SIZE = 10;
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
import projectMethods from '../../public/components.js';
iot.ready(init);
function init() {
//通用 list、dialog、loading组件
uPublic.componentsInit(['u-list','u-dialog','u-loading']);
uPublic.componentsExtend(['list']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
list: [],
startId: 0,
deviceId: null,
userInfo: [],
flag: true,
noticeTipShowFlag: false
},
mounted(){
uComponents.showLoading(this);
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
resolve(this);
window.addEventListener('returnPage',() => {
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
});
},
methods:{
getList(){
return this.list;
},
setList(list){
this.list = list;
},
getStartId(){
return this.startId;
},
setStartId(id){
this.startId = id;
},
getDeviceId(){
return this.deviceId;
},
setDeviceId(id){
this.deviceId = id;
},
getUserInfo(){
return this.userInfo;
},
setUserInfo(info){
this.userInfo = info;
},
onListLoad(){
listLoad(this);
},
onRefreshFresh(){
refreshFresh(this);
},
onNotifycationSetting(){
notifycationSetting();
},
//tap <
onBackTap(){
backTap();
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
hijackRecordList:{
initParam: {
class: 'custom-list',
list: [],
tip: Vue.t('hijackRecord.noRecordTip'),
pagesize: PAGE_SIZE,
pullup: true
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
function resolve(self) {
self.setDeviceId(iot.navigator.getExtras().deviceId);
//
iot.business.api.sendCustom('lock/getHistoryRecord',
{
data: {
device_id: self.getDeviceId(),
action: 3,
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: async (response) => {
if(self.flag){
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
self.flag = await uPublic.upDateRead('alarm', moment(record[0].time).unix());
}
}
let data = uPublic.checkResponseData(response.data);
if(data){
console.log(data);
let list = [];
let record = data.record;
if(data.hasOwnProperty('info')){
self.setUserInfo(data.info);
}
console.log(config.hijackMode[20]);
for(let i=0; i<record.length; i++){
list[i] = {
value: record[i].openId,
title: "ID:"+record[i].openId,
// leftImage: '../../resources/image/green_hijackMode20_icon.png',
imgClass: 'u-list-left-bg-hijack',
subtitle: Vue.t('hijackRecord.'+config.hijackMode[record[i].mode]+''),
// title: ('ID:'+record[i].id),
rightText: moment(record[i].time).format("YYYY.MM.DD HH:mm:ss")
};
for(let j=0; j<self.getUserInfo().length; j++){
if(record[i].openId == self.getUserInfo()[j].openId && record[i].mode == self.getUserInfo()[j].mode){
if(self.getUserInfo()[j].nickname != null){
list[i].title = self.getUserInfo()[j].nickname;
}
}
}
}
self.setList(self.getList().concat(list));
if(record.length > 0){
self.setStartId(record[record.length-1].id);
}
//更新列表数据
projectMethods.changeList(self, self.getList());
}else{
}
uComponents.hideLoading(self);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//tap <
function backTap(){
iot.navigator.aback();
}
//重写mui.back
//mui.back = function(){
// iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
// console.log("fire");
// iot.navigator.back();
//}
//tap 点击加载更多
function listLoad(self) {
resolve(self);
}
function refreshFresh(self){
resolve(self);
}
//ios跳转到系统设置页面
//android跳转到通知页面
function notifycationSetting(){
if(plus.os.name == 'Android'){
// alert("打开通知页面");
iot.navigator.openWindow({
url: './notify.html',
id: 'notify',
styles: {
popGesture: 'none'
}
});
}else{
iot.native.toNotifycationSetting();
}
}
/**
* v_index.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 主控页面
*/
import CryptoJS from "crypto-js";
import Request from "../../public/request.js";
import moment from 'moment';
import crypto from '../../public/crypto.js';
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
import uloop from '../../public/uloop.js';
import unotify from '../../public/unotify.js';
const ON_LINE = 'on';
const OFF_LINE = 'off';
iot.ready(init);
function init() {
uPublic.closeSlideBack();
//通用 图片轮播、跑马灯、开关、按钮、dialog、loading组件
uPublic.componentsInit(['u-carousel','u-marquee','u-switch','u-button','u-dialog','u-loading','u-text','u-comm-loading']);
// uPublic.componentsExtend(['update-app']);
Request.versionRequest('device/getVersion',(info)=>{
let json = {
downloadUrl : info.url,
version: info.version,
title :Vue.t('newFeature.tip'),
content :Vue.t('newFeature.newVersion'),
ok :Vue.t('newFeature.update'),
cancel :Vue.t('newFeature.miss')
};
iot.native.checkUpdate(json);
},(err)=>{
console(err);
});
if(iot.navigator.getExtras().needClose){
iot.navigator.closeAllBesidesItself();
}
// console.log(iot.native.isNotifycationOpen());
// iot.native.toNotifycationSetting();
const app = new Vue({
data:{
//开门记录
valueOpendoorRecord: 0,
//安全报警
valueSecurityAlarm: 0,
//门锁用户
valueDoorlockUser: 0,
//劫持报警
valueHijackAlarm: 0,
//远程开门
valueRemoteOpendoor: 0,
//门锁管理
valueDoorlockManage: 0,
//开门记录
opendoorRecordDisabledFlag: false,
//安全报警
securityAlarmDisabledFlag: false,
//门锁用户
doorlockUserDisabledFlag: false,
//劫持报警
hijackAlarmDisabledFlag: false,
//远程开门
remoteOpendoorDisabledFlag: true,
//门锁管理
doorlockManageDisabledFlag: false,
//门锁最新消息是否滚动
activeFlag: true,
//配置组件
componentsConfig: initComponentsConfig(),
//
followShowFlag: false,
//电量icon
batteryState: '',
//电量百分比
batteryPercent: 100,
//消息时间
msgTime: null,
//消息文本提示
msgText: '',
//门铃是否响起
doorbellRingingFlag: false,
ringTime: null,
//点击远程开门提示
remoteOpendoorFlag: false,
//设备ID
deviceId: null,
//设备mac
mac: null,
//设备uuid
uuid: null,
//设备model
model: null,
//sds设备用户信息
userInfo: null,
//门锁id
lockId: null,
//获取用户的身份
role: null,
lockInfo: {},
//最新消息
newMsg: [],
//是否第一次获取门锁信息
// isFirstGetLockInfo: true,
opendoorRecordFlag: false,
securityAlarmFlag: false,
hijackAlarmFlag: false,
msgClass: "default_img",
warmingShowFlag: false,
normalApertureShow: false,
warmingApertureShow: false,
//是否显示远程开门页面
remoteOpendoorShowFlag: false,
//远程开门密码
textPassword: null,
//远程开门错误提示
textErrorTip: null,
//当前状态
status: 0,
flag: true,
//门铃等待计时器
time: null,
//门铃总计时器
timeout: null,
//远程开门计时器
remoteTime: null,
boolPasswordMinlength: false
},
mounted(){
//显示loading
uComponents.showLoading(this);
//监听推送
notificationListener(this);
//获取设备信息
getDevices(this);
unotify.getCid((response) => {
console.log(response);
},(error) => {
console.log(error);
});
let self = this;
window.addEventListener('returnPage',function(event){
console.log('returnPage');
//获取设备信息
getDevices(self);
//注册监听上报
// registerPushListener(self);
if(event.detail.needClose){
iot.navigator.closeAllBesidesItself();
}
});
// ringBell(self);
// setTimeout(() => {
// ringBell(self);
// setTimeout(() =>{
// ringBell(self);
// },1000);
// },1000);
},
methods:{
setValueRemoteOpendoor(value){
this.valueRemoteOpendoor = value;
},
getOpendoorRecordDisabledFlag(){
return this.opendoorRecordDisabledFlag;
},
setOpendoorRecordDisabledFlag(flag){
this.opendoorRecordDisabledFlag = flag;
},
getSecurityAlarmDisabledFlag(){
return this.securityAlarmDisabledFlag;
},
setSecurityAlarmDisabledFlag(flag){
this.securityAlarmDisabledFlag = flag;
},
getDoorlockUserDisabledFlag(){
return this.doorlockUserDisabledFlag;
},
setDoorlockUserDisabledFlag(flag){
this.doorlockUserDisabledFlag = flag;
},
getHijackAlarmDisabledFlag(){
return this.hijackAlarmDisabledFlag;
},
setHijackAlarmDisabledFlag(flag){
this.hijackAlarmDisabledFlag = flag;
},
getRemoteOpendoorDisabledFlag(){
return this.remoteOpendoorDisabledFlag;
},
setRemoteOpendoorDisabledFlag(flag){
this.remoteOpendoorDisabledFlag = flag;
},
getDoorlockManageDisabledFlag(){
return this.doorlockManageDisabledFlag;
},
setDoorlockManageDisabledFlag(flag){
this.doorlockManageDisabledFlag = flag;
},
getFollowShowFlag(){
return this.followShowFlag;
},
setFollowShowFlag(boolean){
this.followShowFlag = boolean;
},
getBatteryState(){
return this.batteryState();
},
setBatteryState(number){
this.batteryState = number
},
getBatteryPercent(){
return this.batteryPercent;
},
setBatteryPercent(percent){
this.batteryPercent = percent;
},
getMsgTime(){
return this.msgTime;
},
setMsgTime(time){
this.msgTime = time
},
getMsgText(){
return this.msgText;
},
setMsgText(text){
this.msgText = text;
},
getDoorbellRingingFlag(){
return this.doorbellRingingFlag;
},
setDoorbellRingingFlag(boolean){
this.doorbellRingingFlag = boolean;
},
getRingTime(){
return this.ringTime;
},
setRingTime(time){
this.ringTime = time;
},
getRemoteOpendoorFlag(){
return this.remoteOpendoorFlag;
},
setRemoteOpendoorFlag(flag){
this.remoteOpendoorFlag = flag;
},
getUuid(){
return this.uuid;
},
setUuid(){
this.uuid = id;
},
// getIsFirstGetLockInfo(){
// return this.isFirstGetLockInfo;
// },
// setIsFirstGetLockInfo(flag){
// this.isFirstGetLockInfo = flag
// },
getLockId(){
return this.lockId;
},
setLockId(id){
this.lockId = id;
},
getRole(){
return this.role;
},
setRole(bool){
this.role = bool;
},
getLockInfo(){
return this.lockInfo;
},
setLockInfo(info){
this.lockInfo = info;
},
getMsgClass(){
return this.msgClass;
},
setMsgClass(src){
this.msgClass = src;
},
getWarmingShowFlag(){
return this.warmingShowFlag;
},
setWarmingShowFlag(flag){
this.warmingShowFlag = flag;
},
getNormalApertureShow(){
return this.normalApertureShow;
},
setNormalApertureShow(flag){
this.normalApertureShow = flag;
},
getWarmingApertureShow(){
return this.warmingApertureShow;
},
setWarmingApertureShow(flag){
this.warmingApertureShow = flag;
},
getRemoteOpendoorShowFlag(){
return this.remoteOpendoorShowFlag;
},
setRemoteOpendoorShowFlag(flag){
this.remoteOpendoorShowFlag = flag;
},
getTextPassword(){
return this.textPassword;
},
setTextPassword(pwd){
this.textPassword = pwd;
},
setTextErrorTip(tip){
this.textErrorTip = tip;
},
getStatus(){
return this.status;
},
setStatus(status){
this.status = status;
},
//tap 个人信息
onMyInfoTap(){
myInfoTap(this);
},
//tap 绑定门锁
onBindDoorlockTap(){
bindDoorlockTap();
},
//tap 门锁管理
onDoorlockManageTap(){
doorlockManageTap(this);
},
//tap 开门记录
onOpendoorRecordTap(){
opendoorRecordTap(this);
},
//tap 安全报警
onSecurityAlarmTap(){
securityAlarmTap(this);
},
//tap 门锁用户
onDoorlockUserTap(){
doorlockUserTap(this);
},
//tap 远程开门
onRemoteOpendoorTap(){
remoteOpendoorTap(this);
},
//tap 劫持报警
onHijackAlarmTap(){
hijackAlarmTap(this);
},
//tap 保存二维码到相册
onSaveQRcodeButtonTap(){
saveQRcodeButtonTap();
},
//tap 稍后关注
onLaterFollowTap(){
laterFollowTap(this);
},
//tap <
onBackTap(){
backTap(this);
},
onPasswordChange(text){
passwordChange(this,text);
},
//tap 确定
onConfirmButtonTap(){
confirmButtonTap(this);
},
onCommLoadingButtonTap(){
commLoadingButtonTap(this);
},
//tap 停止闪铃
onStopDoorbellRing(){
stopDoorbellRing(this);
},
onPasswordMatchlength(value){
passwordMatchlength(this, value);
},
//tap 退出系统
onLogoutButtonTap(){
logoutButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
//图片轮播
carousel: {
initParam: {
class:'custom-carousel',
list: [{image: '../../resources/image/image1.png'},
{image: '../../resources/image/image2.png'},
{image: '../../resources/image/image3.png'}],
auto: true,
autoTime: 2000,
loop: true
}
},
marquee: {
initParam: {
class: "custom-marquee",
text: [Vue.t('device.defaultNewMsg')],
pauseTime: 0.8,
speed: 0,
intervalTime: 2000,
horizental: 0,
direction: 1
}
},
//开门记录switch 参数
opendoorRecordSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.opendoorRecord'),
autoChange: false
}
},
//安全报警switch 参数
securityAlarmSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.securityAlarm'),
autoChange: false
}
},
doorlockUserSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.doorlockUser'),
autoChange: false
}
},
//远程开门switch 参数
remoteOpendoorSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.remoteOpendoor'),
autoChange: false
}
},
//劫持报警switch 参数
hijackAlarmSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.hijackAlarm'),
autoChange: false
}
},
doorlockManageSwitch: {
initParam: {
class: 'custom-switch',
text: Vue.t('device.doorlockManage'),
autoChange: false
}
},
//确定 button 参数
saveQRcodeButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.saveQRcode')
}
},
confirmButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.confirm')
}
},
passwordInput: {
initParam: {
class: 'custom-text',
icon: '&#xe64d;',
placeholder: Vue.t('remoteOpendoor.passwordInputTip'),
maxlength: config.password.maxlength,
minlength: config.password.minlength
}
},
ucommloading: {
initParam: {
class: 'custom-comm-loading',
buttonText: Vue.t('btn.confirm'),
text: Vue.t('remoteOpendoor.loading'),
status: 0
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//根据用户信息获取设备
function getDevices(self){
iot.business.sds.getDevicesByUser({
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
getDevicesSuccess(self, data);
}else{
initDeviceInfo(self);
uComponents.hideLoading(self);
}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 获取设备信息'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'获取设备信息');
}
// uPublic.openRequestErrorAlert(self);
uComponents.openAlert(self, Vue.t('device.networkError'), {
text: Vue.t('btn.iSee'), callback: function () {
plus.runtime.quit();
}
});
uComponents.hideLoading(self);
},
complete: () => {}
});
}
//获取设备成功,获取设备详细信息
function getDevicesSuccess(self, data){
self.mac = data[0].mac;
self.deviceId = data[0].sn;
self.uuid = data[0].uuid;
self.model = data[0].model;
if(self.uuid){
iot.business.device.getInfo({
data: {
sds: true,
uuid: self.uuid
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
getLockInfo(self);
}
},
error: (error) => {
console.log(error);
},
complete: () => {}
});
}
}
//从云端获取该设备详细信息
function getLockInfo(self){
console.log("getLockInfo");
iot.business.api.sendCustom('lock/getLockInfo',{
data: {
device_id: self.deviceId
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
getLockInfoSuccess(self, data);
}else{
initDeviceInfo(self);
}
},
error: (error) => {
uPublic.openRequestErrorAlert(self);
initDeviceInfo(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//获取设备成功,更改页面渲染
function getLockInfoSuccess(self, data){
//判断云端是否绑定
if(data.lock_id){
//更改按钮为‘可点击’样式
setValueOfSwitch(self, false);
//设置门锁信息
self.setLockInfo(data);
self.setLockId(data.lock_id);
self.setRole(data.role);
//判断是否第一次获取门锁信息
// if(self.isFirstGetLockInfo){
loopGetLockInfo(self, 10, 999, false);
getDeviceStatus(self);
// self.setIsFirstGetLockInfo(false);
// }
//存储最后一条历史记录的ID
let historyId = null
historyId = data.info.historyId ? data.info.historyId : null;
iot.storage.setMap('historyId', historyId, (res) => {
console.log(res);
}, () => {
});
//存储历史、安全、劫持记录的时间
let historyRecord = data.info.history;
if((historyRecord.open.length != 0) || Boolean(historyRecord.alarm) || Boolean(historyRecord.notify)){
updateHistoryMap(self, historyRecord);
}else{
iot.storage.delMaps(['historyId','history'], (response) => {
console.log(response);
updateHistoryMap(self, historyRecord);
}, (error) => {
console.log(error);
});
}
//拼接首页滚动的三条记录
getTreenRecord(self, data.info.history.open);
}else{
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
}
}
//拼接首页滚动的三条记录
function getTreenRecord(self, record){
if(record && record.length){
self.newMsg = [];
console.log(self.newMsg);
for(let i = record.length - 1; i >= 0; i--){
let msg = '';
if((record[i].mode != 30) && (record[i].mode != 5)){
msg = record[i].nickname;
}
self.newMsg.push(moment(record[i].time).format("YY.MM.DD HH:mm")+ ' ' + msg + Vue.t('device.use') + Vue.t('opendoorRecord.'+config.openDoorMode[record[i].mode]+''));
}
console.log(self.newMsg);
uComponents.changeMarqueeText(self, self.newMsg);
if(self.newMsg.length >= 2){
self.activeFlag = true;
}else{
self.activeFlag = false;
}
}else{
uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
self.activeFlag = false;
}
}
//获取设备的初始状态
function getDeviceStatus(self){
iot.business.sds.getDeviceStatus({
data: {
uuid: self.uuid
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
setBatteryPercentAndIcon(self, data.BatteryPercentage.value);
iot.storage.setMap('onLineState', data.onlineState.value, (response) => {
console.log(res);
}, () => {});
registerPushListener(self);
}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 获取设备状态'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'获取设备状态');
}
uPublic.openRequestErrorAlert(self);
}
});
}
async function updateHistoryMap(self, historyRecord){
let oldHistory = {
alarm: {
time: null,
isReadFlag: true
},
notify: {
time: null,
isReadFlag: true
},
open: {
time: null,
isReadFlag: true
}
};
try{
let history = await iot.storage.getMap('history');
oldHistory = history ? history : oldHistory;
}
catch (error) {
console.log(error);
}
let openHistory = historyRecord.open;
let newHistory = oldHistory;
let now = moment(new Date()).unix();
if(openHistory.length && oldHistory.open.time < moment(openHistory[0].time).unix() && now - moment(openHistory[0].time).unix() < config.newMsg_timeout){
newHistory.open.time = moment(openHistory[0].time).unix();
newHistory.open.isReadFlag = false;
let record = openHistory;
if(record && record.length){
for(let i=0; i< record.length; i++){
let msg = '';
if((record[i].mode != 30) && (record[i].mode != 5)){
msg = record[i].nickname;
}
if(self.newMsg.length >= 3){
self.newMsg.shift();
self.newMsg.push(moment(record[i].time).format("YY.MM.DD HH:mm")+ ' ' + msg + Vue.t('device.use') + Vue.t('opendoorRecord.'+config.openDoorMode[record[i].mode]+''));
}else{
self.newMsg.push(moment(record[i].time).format("YY.MM.DD HH:mm")+ ' ' + msg + Vue.t('device.use') + Vue.t('opendoorRecord.'+config.openDoorMode[record[i].mode]+''));
}
}
uComponents.changeMarqueeText(self, self.newMsg);
if(self.newMsg.length >= 2){
self.activeFlag = true;
}else{
self.activeFlag = false;
}
}else{
uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
self.activeFlag = false;
}
}
let historyType = ['alarm','notify'];
for(let i=0 ; i < historyType.length; i++){
if(historyRecord.hasOwnProperty(historyType[i]) && oldHistory[historyType[i]].time < moment(historyRecord[historyType[i]]).unix() && now - moment(historyRecord[historyType[i]]).unix() < config.newMsg_timeout){
newHistory[historyType[i]].time = moment(historyRecord[historyType[i]]).unix();
newHistory[historyType[i]].isReadFlag = false;
console.log(moment(historyRecord[historyType[i]]).unix());
}
}
console.log(oldHistory);
console.log(newHistory);
iot.storage.setMap('history', newHistory, (response) => {
console.log(res);
}, () => {
});
iot.storage.getMap('history', (response) => {
self.securityAlarmFlag = !response.notify.isReadFlag;
self.hijackAlarmFlag = !response.alarm.isReadFlag;
self.opendoorRecordFlag = !response.open.isReadFlag;
console.log(self.securityAlarmFlag);
if(self.hijackAlarmFlag == true){
//停止响铃
stopDoorbellRing(self);
//当前数据是新获取的数据时,有historyRecord.alarm,再次获取时无historyRecord.alarm,此时使用缓存时间
if(historyRecord.alarm){
//显示劫持报警
setMsgStatus(self, true, "hijack_img", false, true, moment(historyRecord.alarm,"YYYY-MM-DD hh:mm:ss").format("HH:mm"), Vue.t('device.hijackAlarm'));
}else{
//显示劫持报警
setMsgStatus(self, true, "hijack_img", false, true, moment.unix(response.alarm.time).format("HH:mm"), Vue.t('device.hijackAlarm'));
}
}else if(self.securityAlarmFlag == true){
//停止响铃
stopDoorbellRing(self);
//当前数据是新获取的数据时,有historyRecord.notify,再次获取时无historyRecord.notify,此时使用缓存时间
if(historyRecord.notify){
//显示安全报警
setMsgStatus(self, true, "securityAlarm_img", false, true, moment(historyRecord.notify,"YYYY-MM-DD hh:mm:ss").format("HH:mm"), Vue.t('device.securityAlarm'));
}else{
//显示安全报警
setMsgStatus(self, true, "securityAlarm_img", false, true, moment.unix(response.notify.time).format("HH:mm"), Vue.t('device.securityAlarm'));
}
}else{
//停止响铃
stopDoorbellRing(self);
if((self.getMsgClass() == 'hijack_img') || (self.getMsgClass() == 'securityAlarm_img')){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
}
}, () => {
});
}
//云端获取设备信息失败
function initDeviceInfo(self){
setValueOfSwitch(self, true);
self.setLockId(null);
self.mac = null;
self.deviceId = null;
self.uuid = null;
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
self.opendoorRecordFlag = false;
self.securityAlarmFlag = false;
self.hijackAlarmFlag = false;
self.setRemoteOpendoorDisabledFlag(true);
self.setValueRemoteOpendoor(0);
setMsgStatus(self, false, "default_img", false, false, '', '');
}
//轮训获取门锁记录
async function loopGetLockInfo(self, delay, times, needStop){
let oldHistoryId = null;
try{
let historyId = await iot.storage.getMap('historyId');
if(historyId){
oldHistoryId = historyId;
}
}
catch (error){
console.log(error);
}
console.log(oldHistoryId);
new uloop({
loopContent: () => {
var urlParams = {
type: 'post',
data: {
history_id: oldHistoryId,
device_id: self.deviceId
}
};
return iot.business.api.send('lock/getNewInfo', urlParams, true, false);
// return plus.push.getClientInfo().clientid;
},
times: times,
interval:{
delay: delay*1000,
cb: {
success: (response) => {
console.log('intervalcbSuccess:'+JSON.stringify(response));
if(!needStop){
let historyRecord = response.data.history;
updateHistoryMap(self, historyRecord);
}
},
error: (error) => {
console.log('intervalcbError:'+JSON.stringify(error));
}
}
},
fincb: {
success:(response) => {
console.log(response);
let historyRecord = response.data.history;
updateHistoryMap(self, historyRecord);
},
error: (error) => {
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
},
stopcondition: async (response) => {
console.log(response);
let data = response.data;
if(data.hasOwnProperty('historyId')){
let newHistoryId = data.historyId;
if(oldHistoryId != newHistoryId){
iot.storage.setMap('historyId', newHistoryId, (res) => {
console.log(res);
oldHistoryId = newHistoryId;
}, () => {
});
return needStop;
}
}
}
}).start();
}
function setValueOfSwitch(self, flag){
self.setOpendoorRecordDisabledFlag(flag);
self.setSecurityAlarmDisabledFlag(flag);
self.setDoorlockUserDisabledFlag(flag);
self.setHijackAlarmDisabledFlag(flag);
self.setDoorlockManageDisabledFlag(flag);
self.valueOpendoorRecord = !flag;
self.valueSecurityAlarm = !flag;
self.valueDoorlockUser = !flag;
self.valueHijackAlarm = !flag;
self.valueDoorlockManage = !flag;
}
//sds监听
function registerPushListener(self){
iot.business.sds.registerPushListener({
success: (response) => {
console.log("registerPushListener");
console.log(response);
let data = uPublic.checkResponseData(response.data.params.data);
if(data){
sdsDataPorcessing(self, data);
}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 常链接失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'常链接失败');
}
uPublic.openRequestErrorAlert(self);
}
});
}
//sds消息处理方法
async function sdsDataPorcessing(self, data){
let onlineState = await iot.storage.getMap('onLineState');
console.log(data);
//设置电量百分比和icon
setBatteryPercentAndIcon(self, data.BatteryPercentage.value);
if(onlineState == data.onlineState.value){
switch(data.action.value){
case 'notify':
switch(data.notify_type.value){
case '104':
//门铃
setBellRing(self, moment(new Date(), "YYYY-MM-DD hh:mm:ss"));
break;
case '5':
//远程开门请求
setRemoteOpendoor(self, moment(new Date(), "YYYY-MM-DD hh:mm:ss"));
break;
case '1':
case '2':
case '3':
//防撬、试错、欠电报警
//轮循获取最新的历史记录
loopGetLockInfo(self, config.intervalTime, config.getHistoryTimes, true);
break;
}
break;
case 'lock_log':
switch(data.lock_action.value){
case '4':
//远程开门成功
//切换轮循loading样式
setRemoteOpenDoorLoading(self, 1, Vue.t('remoteOpendoor.openDoorSuccess'), Vue.t('btn.confirm'));
case '1':
//轮循获取最新的历史记录
loopGetLockInfo(self, config.intervalTime, config.getHistoryTimes, true);
break;
case '5':
//远程开门失败
setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
break;
case '6':
//远程开门超时
if(self.getRemoteOpendoorShowFlag()){
uComponents.openAlert(self, Vue.t('remoteOpendoor.remoteTimeout'), {
text: Vue.t('dialog.confirm'), callback: function () {
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
self.setRemoteOpendoorShowFlag(false);
if(self.getMsgClass() == 'remoteOpendoor_img'){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
window.clearTimeout(self.remoteTime);
uComponents.hideCommLoading(self);
}
});
}else{
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
if(self.getMsgClass() == 'remoteOpendoor_img'){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
}
break;
}
break;
}
}else{
iot.storage.setMap('onLineState', data.onlineState.value, (response) => {
console.log(res);
}, () => {});
}
}
//设置电量百分比、电量icon
function setBatteryPercentAndIcon(self, value){
console.log('setBatteryPercentAndIcon'+value);
self.setBatteryPercent(value);
let state = 5;
if(value >= 10){
//向上取整
state = config.powerIcon[Math.ceil(value/20)];
}else{
state = config.powerIcon[Math.round(value/20)];
}
self.setBatteryState(state);
}
//设置门铃
function setBellRing(self, time){
let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
time = moment(time, "YYYY-MM-DD hh:mm:ss");
if(now.diff(time,'seconds') < config.pushMsg_timeout && now.diff(time,'seconds') >= 0){
ringBell(self, time);
}
}
//设置远程开门
function setRemoteOpendoor(self, time){
let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
time = moment(time, "YYYY-MM-DD hh:mm:ss");
console.log(now.diff(time,'seconds'));
if(now.diff(time,'seconds') < config.pushMsg_timeout && now.diff(time,'seconds') >= 0 && (self.getRole() == 0)){
self.setValueRemoteOpendoor(true);
self.setRemoteOpendoorDisabledFlag(false);
//停止响铃
stopDoorbellRing(self);
if((self.getMsgClass() != 'hijack_img') && (self.getMsgClass() != 'securityAlarm_img')){
setMsgStatus(self, false, "remoteOpendoor_img", true, false, time.format("HH:mm"), Vue.t('device.remoteOpendoor'));
}
// //设置当前为普通状态
// self.setWarmingShowFlag(false);
// //更换icon
// self.setMsgIconSrc("../../resources/image/green_remoteOpendoor_icon.png");
// //开启普通动画效果
// self.setNormalApertureShow(true);
// self.setMsgTime(time.format("HH:mm"));
// self.setMsgText(Vue.t('device.remoteOpendoor'));
setTimeout(function(){
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
if(self.getMsgClass() == 'remoteOpendoor_img'){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
},(config.remote_timeout-now.diff(time,'seconds'))*1000);
}
}
//设置信息提示
function setMsgStatus(self, warmingShow, imgClass, normalAperture, warmingAperture, msgTime, msgText){
//设置当前为普通状态
self.setWarmingShowFlag(warmingShow);
//更换icon
self.setMsgClass(imgClass);
//开启普通动画效果
self.setNormalApertureShow(normalAperture);
self.setWarmingApertureShow(warmingAperture);
self.setMsgTime(msgTime);
self.setMsgText(msgText);
}
//设置远程开门样式
function setRemoteOpenDoorLoading(self, status, text, buttonText){
switch(status){
case 1:
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
setMsgStatus(self,false, "default_img", false, false, '', '');
case 2:
window.clearTimeout(self.remoteTime);
uComponents.changeCommButtonText(self, buttonText);
case 0:
self.setStatus(status);
uComponents.changeCommLoadingStatusAndText(self, status, text);
break;
}
}
//响铃动画和铃声设置
function ringBell(self, time){
if(self.getDoorbellRingingFlag() === false && (self.getMsgClass() != 'remoteOpendoor_img') && (self.getMsgClass() != 'hijack_img') && (self.getMsgClass() != 'securityAlarm_img')){
self.setDoorbellRingingFlag(true);
setMsgStatus(self, false, "doorbell_img", true, false, time.format("HH:mm"), Vue.t('device.doorLockRinging'));
let p = plus.audio.createPlayer(config.audioUrl);
self.timeout = setTimeout(() => {
p = plus.audio.createPlayer(config.audioUrl);
p.play( function () {
console.log( "Audio play success!" );
}, function ( e ) {
console.log( "Audio play error: " + e.message );
});
console.log(self.timeout);
self.timeout = setTimeout(() => {
console.log("in2");
p = plus.audio.createPlayer(config.audioUrl);
p.play( function () {
console.log( "Audio play success!" );
}, function ( e ) {
console.log( "Audio play error: " + e.message );
});
console.log(self.timeout);
self.timeout = setTimeout(() => {
self.setDoorbellRingingFlag(false);
self.setNormalApertureShow(false);
console.log(self.timeout);
},1500);
},2000);
},500);
}
}
function pushAction(self, msg) {
var payload = msg.payload;
if (typeof payload == 'string') {
payload = JSON.parse(msg.payload);
}
notifyDataProcessing(self, payload);
}
//推送消息处理方法
function notifyDataProcessing(self, payload){
switch(payload.type){
// case 'open':
// case 'notify':
// case 'alarm':
// //开门推送、安全报警、劫持报警
// //历史记录信息只拿一遍,不需要轮询
// getLockInfo(self);
// break;
case 'ring':
//门铃
setBellRing(self, payload.time);
break;
case 'remoteOpen':
//远程开门
setRemoteOpendoor(self, payload.time);
break;
}
}
function notificationListener(self) {
// 从系统消息中心点击消息启动应用事件
plus.push.addEventListener('click', function (msg) {
pushAction(self, msg);
}, false);
// 应用从推送服务器接收到推送消息事件
plus.push.addEventListener('receive', function (msg) {
}, false);
}
//tap 个人信息
function myInfoTap(self){
iot.navigator.openWindow({
url: '../myInfo/index.html',
id: 'myInfo',
extras: {
nickname: self.nickname
}
});
}
//tap 绑定门锁
function bindDoorlockTap(){
iot.navigator.openWindow({
url: '../addDevice/index.html',
id: 'addDevice'
});
}
//tap 开门记录
function opendoorRecordTap(self){
if(self.valueOpendoorRecord){
self.opendoorRecordFlag = false;
setMsgStatus(self, false, "default_img", false, false, '', '');
iot.navigator.openWindow({
url: './opendoorRecord.html',
id: 'opendoorRecord',
extras: {
deviceId: self.deviceId
}
});
}
}
//tap 安全报警
function securityAlarmTap(self){
if(self.valueSecurityAlarm){
self.securityAlarmFlag = false;
setMsgStatus(self, false, "default_img", false, false, '', '');
iot.navigator.openWindow({
url: './alarmInfo.html',
id: 'alarmInfo',
extras: {
deviceId: self.deviceId
}
});
}
}
//tap 劫持报警
function hijackAlarmTap(self){
if(self.valueHijackAlarm){
self.hijackAlarmFlag = false;
setMsgStatus(self, false, "default_img", false, false, '', '');
iot.navigator.openWindow({
url: './hijackRecord.html',
id: 'hijackRecord',
extras: {
deviceId: self.deviceId
}
});
}
}
//tap 门锁用户
function doorlockUserTap(self){
if(self.valueDoorlockUser){
iot.navigator.openWindow({
url: '../doorlockUsers/index.html',
id: 'doorlockUsers',
extras: {
deviceId: self.deviceId,
uuid: self.getUuid(),
lockId: self.getLockId(),
role: self.getRole(),
}
});
}
}
//tap 远程开门
function remoteOpendoorTap(self){
iot.business.sds.getDeviceStatus({
data: {
uuid: self.uuid
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
if(data.onlineState.value == ON_LINE){
if(self.valueRemoteOpendoor){
self.setTextPassword('');
self.setRemoteOpendoorShowFlag(true);
}
}else{
uComponents.openAlert(self, Vue.t('remoteOpendoor.offlineTip'), {
text: Vue.t('dialog.confirm'), callback: function () {
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
if(self.getMsgClass() == 'remoteOpendoor_img'){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
}
});
}
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
}
});
}
//tap 门锁管理
function doorlockManageTap(self){
if(self.valueDoorlockManage){
iot.navigator.openWindow({
url: '../../../../view/doorlockManage/index.html',
id: 'doorlockManage',
extras: {
deviceId: self.deviceId,
uuid: self.getUuid(),
lockInfo: self.getLockInfo()
}
});
}
}
//tap 门铃(停止响铃)
function stopDoorbellRing(self){
if(self.getMsgClass() == 'doorbell_img'){
self.setDoorbellRingingFlag(false);
self.setNormalApertureShow(false);
self.setRingTime(0);
window.clearInterval(self.time);
window.clearTimeout(self.timeout);
}
}
//tap 保存二维码到相册
function saveQRcodeButtonTap(){
alert('保存二维码到相册');
}
//tap 稍后关注
function laterFollowTap(self){
self.setFollowShowFlag(false);
}
//tap 远程开门页面返回
function backTap(self){
self.setRemoteOpendoorShowFlag(false);
}
//远程开门密码
function passwordChange(self,text){
self.setTextPassword(text);
self.setTextErrorTip('');
console.log('passwordChange: ' + self.textPassword);
}
//获取远程密码是否达到最小长度
function passwordMatchlength(self, bool) {
console.log(bool);
self.boolPasswordMinlength = bool;
}
//tap 确定(远程开门密码)
function confirmButtonTap(self){
iot.business.sds.getDeviceStatus({
data: {
uuid: self.uuid
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
if(data.onlineState.value == ON_LINE){
if(self.boolPasswordMinlength){
if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){
self.setTextErrorTip(Vue.t('remoteOpendoor.error.noPasswordTip'));
}else if(uPublic.checkString(self.getTextPassword())){
self.setTextErrorTip(Vue.t('remoteOpendoor.textlengthTip'));
}else if(self.textErrorTip == ''){
uComponents.showCommLoading(self);
setRemoteOpenDoorLoading(self, 0, Vue.t('remoteOpendoor.loading'));
let keyIv = crypto.enkey(self.mac.replace(/:/g,''));
// console.log(keyIv);
let pwd = crypto.encode(self.getTextPassword(), keyIv);
// console.log(pwd);
// let msg = crypto.decode(pwd, keyIv);
// console.log(msg);
iot.business.sds.setDeviceStatus({
data: {
uuid: self.getUuid(),
setParams: {
'action': {
'value': 'openDoor'
},
'remote_open_door': {
'value': pwd
}
}
},
success: (response) => {
//密码下发成功
console.log(response);
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 远程开门密码下发失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'远程开门密码下发失败');
}
uPublic.openRequestErrorAlert(self);
uComponents.hideCommLoading(self);
},
complete(){
}
});
}
self.remoteTime = setTimeout(function (){
if(self.getStatus() == 0){
setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.remoteTimeout'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
}
},config.remote_opendoor_timeout);
}else{
self.setTextErrorTip(Vue.t('remoteOpendoor.textlengthTip'));
// uComponents.openAlert(self, Vue.t('remoteOpendoor.textlengthTip'), {
// text: Vue.t('dialog.confirm'), callback: function () {
//
// }
// });
}
}else{
uComponents.openAlert(self, Vue.t('remoteOpendoor.offlineTip'), {
text: Vue.t('dialog.confirm'), callback: function () {
self.setRemoteOpendoorShowFlag(false);
self.setValueRemoteOpendoor(false);
self.setRemoteOpendoorDisabledFlag(true);
if(self.getMsgClass() == 'remoteOpendoor_img'){
setMsgStatus(self, false, "default_img", false, false, '', '');
}
}
});
}
}else{}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
uComponents.hideCommLoading(self);
}
});
}
//tap comm-loading ‘确认’
function commLoadingButtonTap(self){
if(self.getStatus() == 1){
//远程开门成功
self.setRemoteOpendoorShowFlag(false);
}
uComponents.hideCommLoading(self);
}
//tap 退出系统
function logoutButtonTap(self){
uComponents.openConfirm(self, Vue.t('myInfo.logoutDialogTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.confirm'), callback: function () {
iot.business.user.logout({
data: {
// sds: false
},
success: (response) => {
console.log("sdsLogout:"+response);
let sdsResponse = response;
iot.business.websql.delMaps(['utoken', 'userinfo'], (response) => {
iot.storage.delMaps(['historyId','history','isFirstAddUser','isFristAddUnlockInfo'], (response) => {
console.log("clearMap"+response);
//打开登录页面
iot.navigator.openWindow({
url: '../login/index.html',
id: 'login',
extras: {
needClose: true
}
});
}, (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
});
}, (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
});
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {}
});
}}
);
}
\ No newline at end of file
import {iot, uPublic, uComponents} from '../../public/public.js';
import config from '../../public/public.js';
iot.ready(init);
function init() {
uPublic.componentsExtend(['android-notify']);
var form = new Vue({
el: '#content',
data:{
initButtonText: "测试按钮",
componentsConfig: initComponentsConfig(),//初始化数据
dialogFlag:true,
showFlags:false,
onNotifyToIndex:notifyToIndex //改方法传入
},
mounted:function(){
},
methods: {
onTapButton(){
tapButton(this);
},
onAddDeviceButtonTap(){
console.log("onAddDeviceButtonTap......");
},
onToSetting(){
console.log("点击了toSetting");
}
}
});
function notifyToIndex(){
iot.navigator.fire(plus.webview.getWebviewById('device'),'returnPage',{
needClose: true
});
iot.navigator.openWindow({
url: './index.html',
id: 'device',
styles: {
popGesture: 'none'
},
extras: {
needClose: true
}
});
}
function tapButton(self){
console.log("tapButton.......");
}
//初始化组件参数
function initComponentsConfig() {
return {
// 设置通知弹出框参数
notifyDialog: {
// 默认参数
initParam: {
// appName:"js.通用门锁",
// time:"js.刚刚",
// title:'js.开启通知',
// content1:'js.开启通知后您将可以及时获取门锁报警',
// content2:'js.提醒、门锁开门消息通知',
// accept:'js.我知道了!',
// buttonTitle:'js.前往开启通知设置'
}
},
addDeviceButton:{
// 默认参数
initParam: {
class: 'edit-name-button',
text: "这是测试button"
}
}
};
}
}
//重写mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
iot.navigator.back();
}
/**
* v_opendoorRecord.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 开门记录页面
*/
import moment from 'moment';
const PAGE_SIZE = 10;
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
import projectMethods from '../../public/components.js';
iot.ready(init);
function init() {
//通用 list、dialog、loading组件
uPublic.componentsInit(['u-list','u-dialog','u-loading']);
uPublic.componentsExtend(['list']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
list: [],
startId: 0,
deviceId: null,
userInfo: [],
flag: true,
noticeTipShowFlag: false
},
mounted(){
uComponents.showLoading(this);
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
resolve(this);
window.addEventListener('returnPage',() => {
this.noticeTipShowFlag = !iot.native.isNotifycationOpen();
});
},
methods:{
getList(){
return this.list;
},
setList(list){
this.list = list;
},
getStartId(){
return this.startId;
},
setStartId(id){
this.startId = id;
},
getDeviceId(){
return this.deviceId;
},
getUserInfo(){
return this.userInfo;
},
setUserInfo(info){
this.userInfo = info;
},
setDeviceId(id){
this.deviceId = id;
},
onListLoad(){
listLoad(this);
},
onRefreshFresh(){
refreshFresh(this);
},
onNotifycationSetting(){
notifycationSetting();
},
//tap <
onBackTap(){
backTap();
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
opendoorRecordList:{
initParam: {
class: 'custom-list',
list: [],
tip: Vue.t('opendoorRecord.noRecordTip'),
pagesize: PAGE_SIZE,
pullup: true
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//调用接口获取开门记录
function resolve(self) {
console.log("in");
// uComponents.showLoading(self);
self.setDeviceId(iot.navigator.getExtras().deviceId);
console.log(iot.navigator.getExtras());
if(iot.navigator.getExtras().relId){
getPersonalHistory(self, iot.navigator.getExtras().relId);
}else{
getHistoryRecord(self);
}
}
//tap <
function backTap(){
iot.navigator.aback();
}
//重写mui.back
//mui.back = function(){
// iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
// console.log("fire");
// iot.navigator.back();
//}
//tap 点击加载更多
function listLoad(self) {
resolve(self);
}
//获取历史记录(整个设备)
function getHistoryRecord(self){
iot.business.api.sendCustom('lock/getHistoryRecord',
{
data: {
device_id: self.getDeviceId(),
action: 0,
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: async (response) => {
setListData(self, response);
if(self.flag){
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
self.flag = await uPublic.upDateRead('open', moment(record[0].time).unix());
}
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//获取个人历史记录
function getPersonalHistory(self, id){
iot.business.api.sendCustom('lock/getPersonalHistory',
{
data: {
device_id: self.getDeviceId(),
rel_id: id,
action: 0,
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: (response) => {
setListData(self, response);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//设置历史记录渲染列表
function setListData(self, response){
let data = uPublic.checkResponseData(response.data);
if(data){
console.log(data);
let list = [];
let record = data.record;
if(data.hasOwnProperty('info')){
self.setUserInfo(data.info);
}
for(let i=0; i<record.length; i++){
list[i] = {
value: record[i].openId,
title: ((record[i].mode == 30 ) || (record[i].mode == 5 )) ? '':"ID:"+record[i].openId,
// leftImage: '../../resources/image/green_opendoor'+record[i].mode+'_icon.png',
class: 'u-list-left-bg-image_'+record[i].mode,
subtitle: Vue.t('opendoorRecord.'+config.openDoorMode[record[i].mode]+''),
rightText: moment(record[i].time).format("YYYY.MM.DD HH:mm:ss")
};
for(let j=0; j<self.getUserInfo().length; j++){
if(record[i].openId == self.getUserInfo()[j].openId && record[i].mode == self.getUserInfo()[j].mode){
if(self.getUserInfo()[j].nickname != null){
list[i].title = self.getUserInfo()[j].nickname;
}
}
}
}
self.setList(self.getList().concat(list));
if(record.length > 0){
self.setStartId(record[record.length-1].id);
}
//更新列表数据
projectMethods.changeList(self, self.getList());
console.log("in");
}else{
}
}
//ios跳转到系统设置页面
//android跳转到通知页面
function notifycationSetting(){
if(plus.os.name == 'Android'){
iot.navigator.openWindow({
url: './notify.html',
id: 'notify',
styles: {
popGesture: 'none'
}
});
}else{
iot.native.toNotifycationSetting();
}
}
/**
* v_remoteOpendoor.js
* Version: 0.1
* User: wy
* Date: 2017-09-06
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 远程开门页面
*/
import CryptoJS from "crypto-js";
import {iot, uPublic, uComponents} from '../../public/public.js';
import crypto from '../../public/crypto.js';
iot.ready(init);
function init() {
//通用 input、按钮、dialog、loading组件
uPublic.componentsInit(['u-text','u-button','u-comm-loading','u-dialog','u-loading']);
const app = new Vue({
data:{
textPassword: null,
textErrorTip: null,
textLoading: 'loading...',
status: 0,
//配置组件
componentsConfig: initComponentsConfig(),
//设备uuid
uuid: null,
deviceId: null
},
mounted(){
resolve(this);
let a = {"mac":"B0F89310DDF2","productId":"10002","productSecret":"WABK8XXEEKKLL5MM"};
},
methods:{
getTextPassword(){
return this.textPassword;
},
setTextPassword(pwd){
this.textPassword = pwd;
},
setTextErrorTip(tip){
this.textErrorTip = tip;
},
getTextLoading(){
return this.textLoading;
},
setTextLoading(text){
this.textLoading = text;
},
getStatus(){
return this.status;
},
setStatus(value){
this.status = value;
},
onPasswordChange(text){
passwordChange(this,text);
},
onPasswordChange(text){
passwordChange(this,text);
},
getUuid(){
return this.uuid;
},
setUuid(id){
this.uuid = id;
},
getDeviceId(){
return this.deviceId;
},
setDeviceId(id){
this.deviceId = id;
},
//tap <
onBackTap(){
backTap();
},
//tap 确定
onConfirmButtonTap(){
confirmButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
passwordInput: {
initParam: {
class: 'custom-text',
icon: '&#xe64d;',
placeholder: Vue.t('remoteOpendoor.passwordInputTip')
}
},
//确定 button 参数
confirmButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.confirm')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
},
ucommstatusloading: {
initParam: {
class: 'custom-commstatus-loading',
buttonText: Vue.t('btn.confirm')
}
}
}
}
function resolve(self){
let extras = iot.navigator.getExtras();
self.setUuid(extras.uuid);
self.setDeviceId(extras.mac);
console.log(self.getUuid());
}
function passwordChange(self,text){
self.setTextPassword(text);
self.setTextErrorTip('');
console.log('passwordChange: ' + self.textPassword);
}
//tap <
function backTap(){
iot.navigator.back();
}
//tap 确定
function confirmButtonTap(self){
console.log(self.getTextPassword());
if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){
self.setTextErrorTip(Vue.t('remoteOpendoor.error.noPasswordTip'));
}else{
uComponents.showLoading(self);
console.log(self.getDeviceId());
let keyIv = crypto.enkey(self.getDeviceId().replace(/:/g,''));
console.log(keyIv);
let pwd = crypto.encode(self.getTextPassword(), keyIv);
console.log(pwd);
let msg = crypto.decode(pwd, keyIv);
console.log(msg);
iot.business.sds.setDeviceStatus({
data: {
uuid: self.getUuid(),
setParams: {
'action': {
'value': 'openDoor'
},
'remote_open_door': {
// 'value': pwd
'value': self.getTextPassword()
}
}
},
success: (response) => {
console.log(response);
uComponents.openAlert(self, Vue.t('remoteOpendoor.openDoorSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
//返回首页
// iot.navigator.back();
iot.navigator.openWindow({
url: 'index.html',
id: 'device',
});
}
});
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 远程开门失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'远程开门失败');
// }
uComponents.openAlert(self, Vue.t('remoteOpendoor.openDoorFailure'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete(){
uComponents.hideLoading(self);
}
});
}
}
/**
* v_addUnlockInfo.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 绑定开锁信息页面
*/
import moment from 'moment';
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 select、开关、按钮、dialog、loading组件
uPublic.componentsInit(['u-select','u-switch','u-button','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
recordSelectIndex: 0,
openId: null,
mode: 1,
recordSelectList: [],
waysOpenDoor: [],
selectedMode: 1,
valueSetHijack: 0,
guideShowFlag: false,
guideStep1ShowFlag: false,
guideStep2ShowFlag: false,
guideStep3ShowFlag: false,
guideStep4ShowFlag: false,
guideStep5ShowFlag: false,
guideStep6ShowFlag: false,
//配置组件
componentsConfig: initComponentsConfig(),
extras: {}
},
mounted(){
this.extras = iot.navigator.getExtras();
console.log(this.extras);
let self = this;
for( let i =1 ; config.openDoorWay.hasOwnProperty(i) ;i++){
self.waysOpenDoor.push(
{
mode: i,
text: Vue.t('unlockInfo.'+config.openDoorWay[i]+'')
}
)
}
resolve(this);
},
methods:{
getRecordSelectIndex(){
return this.recordSelectIndex;
},
setRecordSelectIndex(index){
this.recordSelectIndex = index;
},
getOpenId(){
return this.openId;
},
setOpenId(id){
this.openId = id;
},
getMode(){
return this.mode;
},
setMode(mode){
this.mode = mode;
},
getRecordSelectList(){
return this.recordSelectList;
},
setRecordSelectList(list){
this.recordSelectList = list;
},
getSelectedMode(){
return this.selectedMode;
},
setSelectedMode(mode){
this.selectedMode = mode
},
getGuideShowFlag(){
return this.guideShowFlag;
},
setGuideShowFlag(boolean){
this.guideShowFlag = boolean;
},
getGuideStep1ShowFlag(){
return this.guideStep1ShowFlag;
},
setGuideStep1ShowFlag(boolean){
this.guideStep1ShowFlag = boolean;
},
getGuideStep2ShowFlag(){
return this.guideStep2ShowFlag;
},
setGuideStep2ShowFlag(boolean){
this.guideStep2ShowFlag = boolean;
},
getGuideStep3ShowFlag(){
return this.guideStep3ShowFlag;
},
setGuideStep3ShowFlag(boolean){
this.guideStep3ShowFlag = boolean;
},
getGuideStep4ShowFlag(){
return this.guideStep4ShowFlag;
},
setGuideStep4ShowFlag(boolean){
this.guideStep4ShowFlag = boolean;
},
getGuideStep5ShowFlag(){
return this.guideStep5ShowFlag;
},
setGuideStep5ShowFlag(boolean){
this.guideStep5ShowFlag = boolean;
},
getGuideStep6ShowFlag(){
return this.guideStep6ShowFlag;
},
setGuideStep6ShowFlag(boolean){
this.guideStep6ShowFlag = boolean;
},
//tap <
onBackTap(){
backTap();
},
onRecordSelectChange(value) {
recordSelectChange(this, value);
},
//tap 添加
onAddButtonTap(){
addButtonTap(this);
},
onSelectOpenDoorModeTap(index){
selectOpenDoorModeTap(this, index);
},
//tap 下一步
onNextButtonTap(){
nextButtonTap(this);
},
onNextStepButtonTap(){
nextStepButtonTap(this);
},
//tap 我知道了
onISeeButtonTap(){
iSeeButtonTap(this);
},
onSetHijackTap(value){
setHijackTap(this, value);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
recordSelect: {
initParam: {
class: 'custom-select',
list: [],
pagesize: Number.MAX_VALUE,
tip: Vue.t('addUnlockInfo.noRecordTip')
}
},
//设为劫持指纹
setHijackSwitch: {
initParam: {
class: 'custom-setHijack-switch',
text: Vue.t('addUnlockInfo.setHijackSwitch')
}
},
//添加 button 参数
addButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.add')
}
},
//下一步 button 参数
nextButton: {
initParam: {
class: 'custom-dialog-button',
text: Vue.t('btn.next')
}
},
//我知道了 button 参数
iSeeButton: {
initParam: {
class: 'custom-dialog-button',
text: Vue.t('btn.iSee')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
function resolve(self){
getTodayReccordByMode(self,self.getSelectedMode());
iot.storage.getMap('isFristAddUnlockInfo', (res) => {
if(res){
}else{
showGuide(self);
}
}, () => {
showGuide(self);
});
}
async function showGuide(self){
self.setGuideShowFlag(true);
try{
let time = await sleep(500);
self.setGuideStep1ShowFlag(true);
time = await sleep(500);
self.setGuideStep2ShowFlag(true);
}
catch (err){
console.log(err);
}
}
//tap 下一步
function nextButtonTap(self){
self.setGuideStep1ShowFlag(false);
self.setGuideStep2ShowFlag(false);
nextGuide(self);
}
async function nextGuide(self){
try{
let time = await sleep(500);
self.setGuideStep3ShowFlag(true);
time = await sleep(500);
self.setGuideStep4ShowFlag(true);
}
catch (err){
console.log(err);
}
}
//tap 下一步
function nextStepButtonTap(self){
self.setGuideStep3ShowFlag(false);
self.setGuideStep4ShowFlag(false);
nextStepGuide(self);
}
async function nextStepGuide(self){
try{
let time = await sleep(500);
self.setGuideStep5ShowFlag(true);
time = await sleep(500);
self.setGuideStep6ShowFlag(true);
}
catch (err){
console.log(err);
}
}
//tap 我知道了
function iSeeButtonTap(self){
self.setGuideShowFlag(false);
iot.storage.setMap('isFristAddUnlockInfo', true,() => {
}, () => {});
}
function sleep(time){
return new Promise(function(resolve, reject){
setTimeout(()=>{
resolve(time);
},time);
})
}
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("returnPage");
iot.navigator.back();
}
//tap <
function backTap(){
iot.navigator.aback();
}
//
function recordSelectChange(self, value) {
console.log(value);
self.recordSelectIndex = value;
console.log('recordSelectChange:' + self.recordSelectIndex);
for(let i=0; i< self.getRecordSelectList().length; i++){
if(self.recordSelectIndex == self.getRecordSelectList()[i].id){
self.setOpenId(parseInt(self.getRecordSelectList()[i].openId));
}
}
}
//tap 添加
function addButtonTap(self){
if(self.getOpenId()){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/bindOpenLog',{
data: {
device_id: self.extras.deviceId,
mode: self.getMode(),
openId: self.getOpenId(),
rel_id: self.extras.id
},
success: (response) => {
console.log(response);
if(response.data.success){
uComponents.openAlert(self, Vue.t('addUnlockInfo.addInfoSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{ });
iot.navigator.back();
}
});
}else{}
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 绑定开门方式失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'绑定开门方式失败');
// }
uComponents.openAlert(vmObj, Vue.t('addUnlockInfo.addInfoFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
setTimeout(function(){
uComponents.openAlert(vmObj, Vue.t('addUnlockInfo.addInfoFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
uComponents.hideLoading(self);
},config.wifi_add_timeout);
}
}
function selectOpenDoorModeTap(self, index){
self.setSelectedMode(index);
self.setMode(index);
getTodayReccordByMode(self,index);
}
function getTodayReccordByMode(self, mode){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getUnbindOpen',{
data: {
mode: self.getSelectedMode(),
device_id: self.extras.deviceId
},
success: (response) => {
console.log(response);
let data = response.data;
self.setRecordSelectList(data);
let list = [];
for(let i = 0; i < data.length; i++){
list[i] = {
value: data[i].id,
title: moment(data[i].time).format("HH:mm"),
subtitle: 'ID:'+data[i].openId
}
}
if(data.length){
self.setRecordSelectIndex(data[0].id);
for(let i=0; i< self.getRecordSelectList().length; i++){
if(self.recordSelectIndex == self.getRecordSelectList()[i].id){
self.setOpenId(parseInt(self.getRecordSelectList()[i].openId));
}
}
}
uComponents.changeSelectList(self,list);
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取门锁当天的历史记录'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取门锁当天的历史记录');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
function setHijackTap(self, value){
if(value){
self.setMode(20);
}else{
self.setMode(2);
}
console.log(self.getMode());
}
/**
* v_addUser.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 添加用户页面
*/
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 input、按钮、dialog、loading组件
uPublic.componentsInit(['u-text','u-button','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
textName: null,
textErrorTip: '',
//配置组件
componentsConfig: initComponentsConfig(),
extras: {}
},
mounted(){
this.extras = iot.navigator.getExtras();
console.log(this.extras);
},
methods:{
getTextName(){
return this.textName;
},
setTextName(text){
this.textName = text;
},
getTextErrorTip(){
return this.textErrorTip;
},
setTextErrorTip(tip){
this.textErrorTip = tip
},
//tap <
onBackTap(){
backTap();
},
onNameChange(text){
nameChange(this,text);
},
//tap 确定
onConfirmButtonTap(){
confirmButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
nameInput: {
initParam: {
class: 'custom-text',
icon: '&#xe6b0;',
placeholder: Vue.t('addUser.nameInputTip'),
maxlength: config.input.maxlength
}
},
//确定 button 参数
confirmButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.confirm')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//tap <
function backTap() {
iot.navigator.aback();
}
function nameChange(self,text){
self.textName = text;
self.setTextErrorTip('');
console.log('nameChange: ' + self.textName);
}
//tap 确定
function confirmButtonTap(self){
if(self.getTextName() == null || self.getTextName().trim() == ''){
self.setTextErrorTip(Vue.t('addUser.error.nameCanNotEmpty'));
}else if(uPublic.checkString(self.getTextName())){
self.setTextErrorTip(Vue.t('textTip.textType'));
}else if(self.getTextErrorTip() == ''){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/addLockUser',{
data: {
device_id: self.extras.deviceId,
nickname: self.getTextName()
},
success: (response) => {
console.log(response);
if(response.data.id){
iot.navigator.fire(plus.webview.currentWebview().opener(), 'returnPage', {});
uComponents.openAlert(self, Vue.t('addUser.addUserSuccess'), {
text: Vue.t('btn.confirm'), callback: function () {
console.log("添加用户成功");
//跳转到门锁用户界面
iot.navigator.openWindow({
url: './doorlockUser.html',
id: 'doorlockUser',
extras: {
id: response.data.id,
lockId: self.extras.lockId,
uuid: self.extras.uuid,
role: self.extras.role
}
});
}
});
}
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 添加用户成功'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'添加用户失败');
// }
uComponents.openAlert(self, Vue.t('addUser.addUserFailure'), {
text: Vue.t('btn.confirm'), callback: function () {
console.log("添加用户失败");
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
}
/**
* v_doorlockUsers.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 门锁用户页面
*/
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 按钮、dialog、loading组件
uPublic.componentsInit(['u-button','u-dialog','u-loading']);
let opener = plus.webview.currentWebview().opener();
if(opener.id == 'addUser'){
setTimeout(function () {
plus.webview.close(opener,"none",0,{});
}, 500);
}
const app = new Vue({
data:{
userInfo: {},
bindShowFlag: true,
unbindShowFlag: false,
// stateShowFlag: false,
guideShowFlag: false,
guideStep1ShowFlag: false,
guideStep2ShowFlag: false,
guideStep3ShowFlag: false,
guideStep4ShowFlag: false,
//配置组件
componentsConfig: initComponentsConfig(),
extras: {},
imageSrc: '../../resources/image/green_unbindSuccess_icon.png',
// textBindTip: Vue.t('doorlockUser.unbindSuccess'),
role: null,
info: null,
isFirstAddUser: true
},
mounted(){
this.extras = iot.navigator.getExtras();
this.role = this.extras.role;
let self = this;
window.addEventListener('returnPage',function(event){
console.log("returnPage");
iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'),'returnPage',{});
getUserInfo(self);
});
getUserInfo(this);
let opener = plus.webview.currentWebview().opener();
if(opener.id == 'addUser'){
self.isFirstAddUser = true;
}else{
self.isFirstAddUser = false;
}
},
methods:{
getBindShowFlag(){
return this.bindShowFlag;
},
setBindShowFlag(boolean){
this.bindShowFlag = boolean;
},
getUnbindShowFlag(){
return this.unbindShowFlag;
},
setUnbindShowFlag(boolean){
this.unbindShowFlag = boolean;
},
// getStateShowFlag(){
// return this.stateShowFlag;
// },
// setStateShowFlag(boolean){
// this.stateShowFlag = boolean;
// },
getGuideShowFlag(){
return this.guideShowFlag;
},
setGuideShowFlag(boolean){
this.guideShowFlag = boolean;
},
getGuideStep1ShowFlag(){
return this.guideStep1ShowFlag;
},
setGuideStep1ShowFlag(boolean){
this.guideStep1ShowFlag = boolean;
},
getGuideStep2ShowFlag(){
return this.guideStep2ShowFlag;
},
setGuideStep2ShowFlag(boolean){
this.guideStep2ShowFlag = boolean;
},
getGuideStep3ShowFlag(){
return this.guideStep3ShowFlag;
},
setGuideStep3ShowFlag(boolean){
this.guideStep3ShowFlag = boolean;
},
getGuideStep4ShowFlag(){
return this.guideStep4ShowFlag;
},
setGuideStep4ShowFlag(boolean){
this.guideStep4ShowFlag = boolean;
},
setImageSrc(src){
this.imageSrc = src;
},
// setTextBindTip(tip){
// this.textBindTip = tip;
// },
getInfo(){
return this.info;
},
setInfo(object){
this.info = object;
},
//tap <
onBackTap(){
backTap();
},
//tap 邀请绑定
onBindButtonTap(){
bindButtonTap(this);
},
//tap 解绑
onUnbindButtonTap(){
unbindButtonTap(this);
},
//tap 绑定开锁信息
onBindUnlockInfoTap(){
bindUnlockInfoTap(this);
},
//tap 编辑用户昵称
onEditNameTap(){
editNameTap(this);
},
//tap 历史开门记录
onOpendoorRecordTap(){
opendoorRecordTap(this);
},
//tap 删除该用户
onDeleteUserButtonTap(){
deleteUserButtonTap(this);
},
// onUnbindStateDialogTap(){
// unbindStateDialogTap(this);
// },
//tap 下一步
onNextButtonTap(){
nextButtonTap(this);
},
//tap 我知道了
onISeeButtonTap(){
iSeeButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
//绑定 button 参数
bindButton: {
initParam: {
class: 'custom-unbind-button',
text: Vue.t('doorlockUser.inviteBind')
}
},
//解绑 button 参数
unbindButton: {
initParam: {
class: 'custom-unbind-button',
text: Vue.t('btn.unbind')
}
},
//解绑 button 参数
unbindButton: {
initParam: {
class: 'custom-unbind-button',
text: Vue.t('btn.unbind')
}
},
//解绑 button 参数
unbindButton: {
initParam: {
class: 'custom-unbind-button',
text: Vue.t('btn.unbind')
}
},
//删除该用户 button 参数
deleteUserButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.deleteUser')
}
},
//下一步 button 参数
nextButton: {
initParam: {
class: 'custom-dialog-button',
text: Vue.t('btn.next')
}
},
//我知道了 button 参数
iSeeButton: {
initParam: {
class: 'custom-dialog-button',
text: Vue.t('btn.iSee')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//判断是否第一次添加用户
function checkFirstAddUser(self){
iot.storage.getMap('isFirstAddUser', (res) => {
if (res) {
} else {
//显示引导动画
showGuide(self);
}
}, () => {
//显示 引导动画
showGuide(self);
});
}
//显示动画
async function showGuide(self){
self.setGuideShowFlag(true);
let time = null
console.log(self.userInfo.role);
if(self.userInfo.role == 0){
try{
time = await sleep(500);
self.setGuideStep3ShowFlag(true),
time = await sleep(500);
self.setGuideStep4ShowFlag(true);
}
catch (err){
console.log(err);
}
}else{
try{
time =await sleep(500);
self.setGuideStep1ShowFlag(true);
time = await sleep(500);
self.setGuideStep2ShowFlag(true);
}
catch (err){
console.log(err);
}
}
}
async function nextGuide(self){
try{
let time = await sleep(500);
self.setGuideStep3ShowFlag(true),
time = await sleep(500);
self.setGuideStep4ShowFlag(true);
}
catch (err){
console.log(err);
}
}
function sleep(time){
return new Promise(function(resolve, reject){
setTimeout(()=>{
resolve(time);
},time);
})
}
function getUserInfo(self){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getUserInfo',{
data: {
rel_id: self.extras.id,
device_id: self.extras.lockId
},
success: (response) => {
let data = uPublic.checkResponseData(response.data);
console.log(data);
if(data){
if(data.user_id != self.extras){
iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'),'returnPage',{});
}
self.setInfo(data);
setUserInfo(self, data);
if(self.role == 0){
checkFirstAddUser(self);
}
}else{}
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取用户信息'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取用户信息');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//设置用户信息
function setUserInfo(self, data){
self.userInfo = {
imgClass: data.role == 0 ? 'userInfo-image-admin' : data.user_id == null ? 'userInfo-image-unbind' : 'userInfo-image-bind',
role: data.role,
title: data.nickname,
subtitle: ''
}
self.setBindShowFlag(data.user_id ? false : true);
self.setUnbindShowFlag(data.user_id ? true : false);
}
//tap <
function backTap(){
iot.navigator.aback();
}
//tap 编辑用户昵称
function editNameTap(self){
if(!self.role && !self.isFirstAddUser){
iot.navigator.openWindow({
url: './editName.html',
id: 'editName',
extras: {
id: self.getInfo().id,
nickname: self.getInfo().nickname,
deviceId: self.getInfo().device_id,
role: self.extras.role
}
});
}
}
//tap 邀请绑定
function bindButtonTap(self){
checkUser(self, (data) => {
if(data.auids){
uComponents.openAlert(self, Vue.t('doorlockUser.bindedTip'), {
text: Vue.t('dialog.confirm'), callback: function () {
self.setInfo(data);
setUserInfo(self, data);
}
});
}else{
iot.navigator.openWindow({
url: './inviteBind.html',
id: 'inviteBind',
extras: {
uuid: self.extras.uuid,
id: self.extras.id,
deviceId: self.getInfo().device_id,
lockId: self.extras.lockId
}
});
}
});
}
//tap 解绑
function unbindButtonTap(self){
uComponents.openConfirm(self, Vue.t('doorlockUser.unbindDialogTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.unbind'), callback: function () {
iot.business.sds.unbindByManager({
data: {
uuid: self.extras.uuid,
destAuid: self.info.auids
},
success: (response) => {
console.log(response);
iot.business.api.sendCustom('lock/unbindUser',{
data: {
user_id: self.getInfo().user_id,
device_sn: self.getInfo().device_id,
device_id: self.extras.lockId
},
success: (response) => {
console.log(response);
iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'),'returnPage',{});
// self.setStateShowFlag(true);
uComponents.openAlert(self, Vue.t('doorlockUser.unbindSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
getUserInfo(self);
}
});
},
error: (error) => {
console.log(error);
// uPublic.openRequestErrorAlert(self);
// self.setImageSrc('../../resources/image/green_unbindFail_icon.png');
// self.setTextBindTip(Vue.t('doorlockUser.unbindFailue'));
// self.setStateShowFlag(true);
uComponents.openAlert(self, Vue.t('doorlockUser.unbindFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
// self.setImageSrc('../../resources/image/green_unbindFail_icon.png');
// self.setTextBindTip(Vue.t('doorlockUser.unbindFailue'));
// self.setStateShowFlag(true);
uComponents.openAlert(self, Vue.t('doorlockUser.unbindSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
getUserInfo(self);
}
});
},
complete: () => {
}
});
}}
);
}
//function unbindStateDialogTap(self){
// self.setStateShowFlag(false);
// self.setBindShowFlag(true);
// self.setUnbindShowFlag(false);
// self.userInfo.image = '../../resources/image/gray_unbindHead_icon.png';
//}
//tap 绑定开锁信息
function bindUnlockInfoTap(self){
iot.navigator.openWindow({
url: './unlockInfo.html',
id: 'unlockInfo',
extras: {
id: self.extras.id,
userId: self.getInfo().user_id,
deviceId: self.getInfo().device_id,
lockId: self.extras.lockId,
role: self.extras.role
}
});
}
//tap 历史开门记录
function opendoorRecordTap(self){
if(!self.isFirstAddUser){
iot.navigator.openWindow({
url: '../device/opendoorRecord.html',
id: 'opendoorRecord',
extras: {
relId: self.extras.id,
deviceId: self.getInfo().device_id
}
});
}
}
//tap 删除该用户
function deleteUserButtonTap(self){
uComponents.openConfirm(self, Vue.t('doorlockUser.deleteUserDialogTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.delete'), callback: function () {
deleteUser(self);
}}
);
}
//tap 下一步
function nextButtonTap(self){
self.setGuideStep1ShowFlag(false);
self.setGuideStep2ShowFlag(false);
nextGuide(self);
}
//tap 我知道了
function iSeeButtonTap(self){
self.setGuideShowFlag(false);
iot.storage.setMap('isFirstAddUser', true,() => {
}, (err) => {});
}
//删除用户
function deleteUser(self){
uComponents.showLoading(self);
//确认该用户是否被绑定
checkUser(self, (data) => {
self.setInfo(data);
//判断该用户是否绑定
if(self.info.auids){
iot.business.sds.unbindByManager({
data: {
uuid: self.extras.uuid,
destAuid: self.info.auids
},
success: (response) => {
deleteCloudeUser(self);
},
error: (error) => {
console.log(error);
uComponents.openAlert(self, Vue.t('doorlockUser.deleteFailure'), {
text: Vue.t('btn.confirm'), callback: function () {
}
});
},
complete: () => {
}
});
}else{
deleteCloudeUser(self);
}
})
}
function checkUser(self, callback){
iot.business.api.sendCustom('lock/getUserInfo',{
data: {
rel_id: self.extras.id,
device_id: self.extras.lockId
},
success: (response) => {
let data = uPublic.checkResponseData(response.data);
console.log(data);
if(data){
if(data.user_id != self.extras){
iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'),'returnPage',{});
}
callback(data);
}else{}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
}
});
}
function deleteCloudeUser(self){
iot.business.api.sendCustom('lock/delLockUser',{
data: {
rel_id: self.extras.id,
user_id: self.getInfo().user_id,
device_sn: self.getInfo().device_id,
device_id: self.extras.lockId
},
success: (response) => {
console.log(response);
if(response.data.success){
iot.navigator.fire(plus.webview.getWebviewById('doorlockUsers'),'returnPage',{});
uComponents.openAlert(self, Vue.t('doorlockUser.deleteSuccess'), {
text: Vue.t('btn.confirm'), callback: function () {
iot.navigator.aback();
}
});
}
},
error: (error) => {
console.log(error);
uComponents.openAlert(self, Vue.t('doorlockUser.deleteFailure'), {
text: Vue.t('btn.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
/**
* v_editName.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 修改名称页面
*/
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 input、dialog、loading组件
uPublic.componentsInit(['u-text','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
textName: iot.navigator.getExtras().nickname,
textErrorTip: '',
//配置组件
componentsConfig: initComponentsConfig(),
extras: {},
role: null
},
mounted(){
this.extras = iot.navigator.getExtras();
this.role = this.extras.role;
},
methods:{
getTextName(){
return this.textName;
},
setTextName(text){
this.textName = text;
},
getTextErrorTip(){
return this.textErrorTip;
},
setTextErrorTip(tip){
this.textErrorTip = tip;
},
//tap <
onBackTap(){
backTap();
},
//tap 保存
onSaveTap(){
saveTap(this);
},
onNameChange(text){
nameChange(this,text);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
nameInput: {
initParam: {
class: 'custom-editName-text',
placeholder: Vue.t('editName.nickNameInputTip'),
maxlength: config.input.maxlength
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//tap <
function backTap(){
iot.navigator.aback();
}
//tap 保存
function saveTap(self){
if(self.getTextName() == null || self.getTextName().trim() == ''){
self.setTextErrorTip(Vue.t('editName.error.nicknameCanNotBeBlank'));
}else if(uPublic.checkString(self.getTextName())){
self.setTextErrorTip(Vue.t('textTip.textType'));
}else if(self.getTextErrorTip() == ''){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/setLockUserName',{
data: {
rel_id: self.extras.id,
nickname: self.getTextName(),
device_id: self.extras.deviceId
},
success: (response) => {
console.log(response);
if(response.data.success){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
uComponents.openAlert(self, Vue.t('editName.editNameSuccess'), {
text: Vue.t('btn.confirm'), callback: function () {
let opener = plus.webview.currentWebview().opener();
let view = plus.webview.getWebviewById(opener.id);
console.log(view);
iot.navigator.aback();
}
});
}
// let data = uPublic.checkResponseData(response.data);
// if(data){
// uComponents.openAlert(self, Vue.t('editName.nicknameCanNotBeBlank'), {
// text: Vue.t('btn.confirm'), callback: function () {
// let opener = plus.webview.currentWebview().opener();
// let view = plus.webview.getWebviewById(opener.id);
// console.log(view);
// iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
// console.log('returnPage');
// iot.navigator.back();
// }
// });
// }
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 修改用户名称失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'修改用户名称失败');
// }
uComponents.openAlert(self, Vue.t('editName.editNameFailue'), {
text: Vue.t('btn.confirm'), callback: function () {
let opener = plus.webview.currentWebview().opener();
iot.navigator.back();
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
}
function nameChange(self,text){
self.textName = text;
self.setTextErrorTip('');
console.log('nameChange: ' + self.textName);
}
\ No newline at end of file
/**
* v_index.js
* Version: 0.1
* User: zjx
* Date: 2017-09-29
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 门锁用户
*/
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 图片轮播、跑马灯、开关、按钮、dialog、loading组件
uPublic.componentsInit(['u-swipe-list','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
//用户列表
userList: [],
userListIndex: null,
loadShowFlag: false,
loadFlag: false,
loadText: '',
pagesize: 10,
tip: '无数据',
extras: {},
userListData: [],
startId: 0,
role: null,
//当前用户id
currentId: null
},
mounted(){
this.extras = iot.navigator.getExtras();
//获取用户列表
this.role = this.extras.role;
getUserList(this);
let self = this;
window.addEventListener('returnPage',function(event){
console.log("returnPage");
self.setUserList([]);
getUserList(self);
});
},
methods:{
getUserList(){
return this.userList;
},
setUserList(list){
this.userList = list;
},
onBackTap(){
backTap();
},
onAddUserTap(){
addUserTap(this);
},
setLoadShowFlag(number){
this.loadShowFlag = (number >= this.pagesize);
},
getUserListData(){
return this.userListData;
},
setUserListData(data){
this.userListData = data;
},
getStartId(){
return this.startId;
},
setStartId(id){
this.startId = id;
},
getRole(){
return this.role;
},
setRole(role){
this.role = role;
},
onTapLoad(){
// tapLoad();
},
onTapUserList(index){
onTapUserList(this, index);
},
onTapButton(index){
tapButton(this, index);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//获取用户列表
function getUserList(self){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getLockUser',{
data: {
device_id: self.extras.deviceId
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
console.log(data);
if(data){
sortUsers(self,data);
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
function sortRule(a,b){
return a.role - b.role;
}
function getUserInfoMap() {
return new Promise(function (resolve, reject) {
iot.business.websql.getMap('userinfo', (res) => {
if (res) {
resolve(res.id);
} else {
reject(res);
}
}, (err) => {
console.log(err);
});
})
}
async function sortUsers(self, data){
try {
self.currentId = await getUserInfoMap();
}
catch (err) {
console.log(err);
}
let users = [];
let manage = [];
for(let i=0;i<data.length;i++){
if(data[i].user_id == null ||data[i].role && data[i].user_id != self.currentId){
users.push(data[i]);
}else{
manage.push(data[i]);
}
}
manage = manage.sort(sortRule);
console.log(manage);
data = manage.concat(users);
setUserData(self, data);
}
function setUserData(self, data){
let list = [];
for(let i = 0; i < data.length ; i++){
list[i] = {
value: data[i].id,
role: data[i].role,
imgClass: data[i].role == 0 ? 'user-list-image-admin' : data[i].user_id == null ? 'user-list-image-unbind' : 'user-list-image-bind',
title: data[i].nickname,
subtitle: data[i].user_id ? Vue.t('userList.binded'):Vue.t('userList.unbind')
}
}
console.log(data);
self.setUserListData(data);
self.setUserList(list);
}
//返回上一页
function backTap(){
iot.navigator.aback();
}
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
iot.navigator.back();
}
//添加用户
function addUserTap(self){
iot.navigator.openWindow({
url: '../doorlockUsers/addUser.html',
id: 'addUser',
extras: {
deviceId: self.getUserListData()[0].device_id,
uuid: self.extras.uuid,
lockId: self.extras.lockId,
role: self.extras.role
}
});
}
// 点击组件列表 通知事件和当前点击列表下标
function onTapUserList(self, listIndex) {
iot.navigator.openWindow({
url: './doorlockUser.html',
id: 'doorlockUser',
extras: {
id: self.getUserListData()[listIndex].id,
uuid: self.extras.uuid,
userId: self.getUserListData()[listIndex].user_id,
lockId: self.extras.lockId,
role: self.extras.role
}
});
if (self.userListIndex != null) {
self.userListIndex = null;
}
}
//点击按钮
function tapButton(self, index){
console.log(index);
//tap 删除该用户
uComponents.openConfirm(self, Vue.t('doorlockUser.deleteUserDialogTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.delete'), callback: function () {
deleteUser(self, index);
}}
);
}
//删除用户
function deleteUser(self, index){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/delLockUser',{
data: {
rel_id: self.getUserListData()[index].id,
user_id: self.getUserListData()[index].user_id,
device_sn: self.getUserListData()[index].device_id,
device_id: self.extras.lockId
},
success: (response) => {
console.log(response);
if(response.data.success){
uComponents.openAlert(self, Vue.t('doorlockUser.deleteSuccess'), {
text: Vue.t('btn.confirm'), callback: function () {
self.setUserList([]);
getUserList(self);
}
});
}
},
error: (error) => {
console.log(error);
uComponents.openAlert(self, Vue.t('doorlockUser.deleteFailure'), {
text: Vue.t('btn.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
\ No newline at end of file
/**
* v_inviteBind.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 邀请绑定页面
*/
let QRCode = require('qrcode');
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 按钮、dialog、loading组件
uPublic.componentsInit(['u-button','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
extras: [],
uuid: null,
qrCodeDisabled: false
},
mounted(){
this.extras = iot.navigator.getExtras();
console.log(this.extras);
this.setUuid(this.extras.uuid);
qrcodeButtonTap(this);
},
methods:{
getUuid(){
return this.uuid;
},
setUuid(id){
this.uuid = id;
},
setQrCodeDisabled(boolean){
this.qrCodeDisabled = boolean;
},
//tap <
onBackTap(){
backTap();
},
//tap 重新生成二维码
onQRcodeButtonTap(){
qrcodeButtonTap(this);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
//重新生成二维码 button 参数
qrcodeButton: {
initParam: {
class: 'custom-button',
text: Vue.t('btn.qrcodeReset')
}
},
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//tap <
function backTap(){
iot.navigator.aback();
}
//tap 重新生成二维码
function qrcodeButtonTap(self){
self.setQrCodeDisabled(false);
uComponents.showLoading(self);
iot.business.sds.saveqr({
data: {
uuid: self.getUuid()
},
success: (response) => {
let data = uPublic.checkResponseData(response.data);
if(data){
let qrKey = response.data.qrKey;
createQrcode(self, qrKey);
}else{}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 生成二维码失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'生成二维码失败');
}
//请求失败
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
setTimeout(() => {
self.setQrCodeDisabled(true);
},config.qrcode_timeout)
}
function createQrcode(self, qrKey){
let data = {
qrKey: qrKey,
lockId: self.extras.lockId,
relId: self.extras.id
}
data = JSON.stringify(data);
let qr = self.$refs.qrcode;
QRCode.toCanvas(qr, data, {
scale: 5,
margin: 2
},(error) => {
if (error) {
console.log(error);
} else {
console.log('success');
qr.style.width = "4.267rem";
qr.style.height = "4.267rem";
console.log(qr.style);
setTimeout(() => {
self.setQrCodeDisabled(true);
},config.qrcode_timeout);
}
});
}
/**
* v_unlockInfo.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c) 2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 绑定开锁信息页面
*/
import moment from 'moment';
import config from '../../public/config.js'
import {iot, uPublic, uComponents} from '../../public/public.js';
iot.ready(init);
function init() {
//通用 侧滑列表、dialog、loading组件
uPublic.componentsInit(['u-swipe-list','u-dialog','u-loading']);
uPublic.closeSlideBack();
const app = new Vue({
data:{
//配置组件
componentsConfig: initComponentsConfig(),
unlockInfoList: [],
openLockInfoList: [],
extras: {},
role: null,
lockItems: [],
selectItem: 0,
unlockInfoListTip: Vue.t('unlockInfo.unlockInfoListTip'),
noHistoryTip: Vue.t('unlockInfo.noHistoryTip'),
tipShowFlag: true,
infoList: [],
newUnlockInfo: false
// list: [],
// pullup: false,
// loadText: Vue.t('scroll.clickToLoadMore'),
// // loading是否显示
// loadShowFlag: false,
// // 是否在loading
// loadFlag: false,
// tipShowFlag: false
},
mounted(){
this.extras = iot.navigator.getExtras();
this.role = this.extras.role;
console.log(this.extras);
let self = this;
this.lockItems = [{text: Vue.t('unlockInfo.bindSoon')},{text: Vue.t('unlockInfo.bindedLockInfo')}];
itemChange(this, this.selectItem);
// this.setLoadShowFlag(this.infoList.length);
// let ulistDom = this.$refs.infoList;
// ulistDom.onscroll = function () {
// //在一些特殊情况下ulistDom.scrollHeight和ulistDom.offsetHeight + ulistDom.scrollTop会相差1px,这里考虑1px的误差
// console.log(self.loadFlag+'+'+self.pullup+'+'+ulistDom.scrollHeight+'+'+ulistDom.scrollTop);
// if (!self.loadFlag && self.pullup && (ulistDom.scrollHeight - (ulistDom.offsetHeight + ulistDom.scrollTop)) <= 1) {
// self.loadText = Vue.t('scroll.loading');
// self.loadFlag = true;
// getBindedLockInfo(self);
// }
// }
},
methods:{
getUnlockInfoList(){
return this.unlockInfoList;
},
setUnlockInfoList(list){
this.unlockInfoList = list
},
getOpenLockInfoList(){
return this.openLockInfoList;
},
setOpenLockInfoList(list){
this.openLockInfoList = list;
},
getSelectItem(){
return this.selectItem;
},
setSelectItem(index){
this.selectItem = index;
},
getInfoList(){
return this.infoList;
},
setInfoList(list){
this.infoList = list;
},
getNewUnlockInfo(){
return this.newUnlockInfo;
},
setNewUnlockInfo(info){
this.newUnlockInfo = info;
},
//tap <
onBackTap(){
backTap();
},
// onAddTap(){
// //tap 添加
// addTap(this);
// },
onItemChange(key){
itemChange(this, key);
},
onImgButtonTap(index, buttonIndex){
imgButtonTap(this, index, buttonIndex);
},
setLoadShowFlag(number) {
this.loadShowFlag = (number >= this.pagesize);
},
onTapLoad() {
tapLoad(this);
},
changeList(list) {
changeList(this, list);
}
}
}).$mount('#app');
}
//配置组件参数
function initComponentsConfig() {
return {
dialog: {
initParam: {
class: 'custom-dialog'
}
},
loading: {
initParam: {
class: 'custom-loading'
}
}
}
}
//tap <
function backTap(){
iot.navigator.back();
}
//tap 添加
function addTap(self){
iot.navigator.openWindow({
url: './addUnlockInfo.html',
id: 'addUnlockInfo',
extras: {
deviceId: self.extras.deviceId,
id: self.extras.id
}
});
}
//点击加载更多
function tapLoad(){
if (!self.loadFlag) {
self.loadText = Vue.t('scroll.loading');
self.loadFlag = true;
//再次发送获取用户列表请求
}
}
//获取已绑定的开锁信息
function getBindedLockInfo(self){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getBindOpen',{
data: {
rel_id: self.extras.id,
device_id: self.extras.deviceId
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
console.log(data);
self.setOpenLockInfoList(data);
let list = [];
let j = 1;
let lastMode = null;
for(let i=0; i<data.length; i++){
if(data[i].mode != lastMode){
j = 1;
}
list[i] = {
title: Vue.t('unlockInfo.'+config.openDoorMode[data[i].mode]+'')+j+'',
subtitle: 'ID:'+data[i].openId,
// buttons: self.extras.role ? [] : [{'text': data[i].mode == 20 ? Vue.t('unlockInfo.cancelHijack') : data[i].mode == 2 ? Vue.t('unlockInfo.setHijack') : ''},{'text': Vue.t('unlockInfo.cancelAssociated')}]
buttons: self.extras.role ? [] : (data[i].mode == 20 || data[i].mode == 2) ? [{"imgClass": data[i].mode == 20 ? "button-image-deleteHijack" : "button-image-setHijack"},{"imgClass": "button-image-deleteUnlockInfo"}] : [{"imgClass": null},{"imgClass": "button-image-deleteUnlockInfo"}]
};
j++;
lastMode = data[i].mode;
}
//更新列表
self.setInfoList(list);
// changeList(self, list);
}else{
//当已绑定信息为空时,列表渲染为空
self.setInfoList([]);
}
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
function unlockInfoListButtonTap(self, value, buttonValue) {
//设为劫持&取消劫持
if(buttonValue == '0'){
if(self.getOpenLockInfoList()[value].mode == 2){
uComponents.openConfirm(self, Vue.t('unlockInfo.setHijackTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.confirm'), callback: function () {
console.log("设为劫持");
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/updateBindLog',{
data: {
mode: 20,
id: self.getOpenLockInfoList()[value].id,
rel_id: self.extras.id
},
success: (response) => {
console.log(response);
uComponents.openAlert(self, Vue.t('unlockInfo.setHijackSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
getBindedLockInfo(self);
}
});
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 设为劫持失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'设为劫持失败');
// }
uComponents.openAlert(self, Vue.t('unlockInfo.setHijackFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}});
}else{
uComponents.openConfirm(self, Vue.t('unlockInfo.cancelHijackTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.confirm'), callback: function () {
console.log("取消劫持");
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/updateBindLog',{
data: {
mode: 2,
id: self.getOpenLockInfoList()[value].id,
rel_id: self.extras.id
},
success: (response) => {
console.log(response);
uComponents.openAlert(self, Vue.t('unlockInfo.cancelHijackSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
getBindedLockInfo(self);
}
});
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 取消劫持失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'取消劫持失败');
// }
uComponents.openAlert(self, Vue.t('unlockInfo.cancelHijackFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}});
}
}
//取消关联
else if(buttonValue == '1'){
console.log(self.getOpenLockInfoList()[value]);
uComponents.openConfirm(self, Vue.t('unlockInfo.cancelAssociatedTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.confirm'), callback: function () {
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/unbindOpenLog',{
data: {
device_id: self.extras.deviceId,
mode: self.getOpenLockInfoList()[value].mode,
openId: self.getOpenLockInfoList()[value].openId,
rel_id: self.extras.id
},
success: (response) => {
console.log(response);
uComponents.openAlert(self, Vue.t('unlockInfo.cancelAssociatedSuccess'), {
text: Vue.t('dialog.confirm'), callback: function () {
getBindedLockInfo(self);
}
});
},
error: (error) => {
console.log(error);
uComponents.openAlert(self, Vue.t('unlockInfo.cancelAssociatedFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}}
);
}
}
function itemChange(self, key){
self.setInfoList([]);
if(key == 0){
//获取未关联的开门记录
getTodayReccord(self);
}else if(key == 1){
//获取已关联的开门记录
self.setNewUnlockInfo(false);
getBindedLockInfo(self);
}
self.setSelectItem(key);
}
function imgButtonTap(self, index, buttonIndex){
if(self.getSelectItem() == 0){
addButtonTap(self, index);
}else if(self.getSelectItem() == 1){
unlockInfoListButtonTap(self, index, buttonIndex);
}
}
//获取当天未绑定的开门记录
function getTodayReccord(self){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getUnbindOpen',{
data: {
device_id: self.extras.deviceId
},
success: (response) => {
console.log(response);
let data = response.data;
self.setUnlockInfoList(data);
let list = [];
for(let i = 0; i < data.length; i++){
list[i] = {
value: data[i].id,
title: 'ID:'+data[i].openId,
subtitle: moment(data[i].time).format("HH:mm")+' '+Vue.t('opendoorRecord.'+config.openDoorMode[data[i].mode]+''),
buttons: [{"text": Vue.t('unlockInfo.bindUnlockInfo')}]
}
}
self.setInfoList(list);
},
error: (error) => {
console.log(error);
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//tap 添加
function addButtonTap(self, index){
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/bindOpenLog',{
data: {
device_id: self.extras.deviceId,
mode: parseInt(self.getUnlockInfoList()[index].mode),
openId: parseInt(self.getUnlockInfoList()[index].openId),
rel_id: self.extras.id
},
success: (response) => {
console.log(response);
if(response.data.success){
uComponents.openAlert(self, Vue.t('unlockInfo.addInfoSuccess'),
{text: Vue.t('btn.confirm'), callback: function () {
getTodayReccord(self);
self.setNewUnlockInfo(true);
}});
}else{}
},
error: (error) => {
console.log(error);
uComponents.openAlert(vmObj, Vue.t('addUnlockInfo.addInfoFailue'), {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
// // 通知点击加载更多事件
//function tapLoad(self) {
// // loading
// if (!self.loadFlag && !self.pullup) {
// getBindedLockInfo(self);
// self.loadText = Vue.t('scroll.loading');
// self.loadFlag = true;
// }
//}
//
//// 修改list组件列表
//function changeList(self, list) {
// let array = Array.isArray(list) ? list : [];
// self.tipShowFlag = (array.length === 0);
// self.setLoadShowFlag(array.length - self.list.length);
// self.list = array;
// self.$nextTick(function () {
// self.loadText = Vue.t('scroll.clickToLoadMore');
// self.loadFlag = false;
// });
//}
\ No newline at end of file
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