Commit 3db8c073 by 朱建香

2

parent 80567164
class Barcode{
constructor() {
}
startQr(id,keyArrays,success,error){
console.log("开始扫描....");
this.scan = iot.navigator.barcode(id);
console.log(this.scan);
this.scan.start();
this.scan.onmarked = (type, result)=>{
if(result) {
let typeJson = this.formatUrlToJson(result);
let type = typeJson["type"];
let bool = this.isInArray(keyArrays,type);
if (bool) {
success(type);
}else{
error("当前扫描的二维码不和规范");
}
}
};
}
isInArray(arr,value){
for(var i = 0; i < arr.length; i++){
if(value === arr[i]){
return true;
}
}
return false;
}
formatUrlToJson(str){
console.log("测试字符串截取功能");
let index = str.indexOf("?");
let subStr = str.substr(index+1,str.length);
let subIndex = subStr.indexOf("=");
let keyStr = subStr.substr(0,subIndex);
console.log(keyStr);
let value = subStr.substr(subIndex+1,subStr.length);
let json = {};
json[keyStr] = value;
// alert(JSON.stringify(json));
return json;
}
}
export default new Barcode();
\ No newline at end of file
let projectMethods = {};
projectMethods.changeList = function (vmObj, list) {
vmObj.$refs.list.changeList(list);
};
export default projectMethods
\ No newline at end of file
export default {
"powerIcon":["&#xe6e5;", "&#xe62b;", "&#xe627;", "&#xe628;", "&#xe62a;", "&#xe629;"],
"openDoorMode": {
1: "passwordOpenDoor",
2: "fingerprintOpenDoor",
3: "ICcardOpenDoor",
4: "remoteOpenDoor",
5: "keyOpenDoor",
20: "hijackingAlarm",
30: "appRemoteOpenDoor"
},
"openDoorWay": {
1: "passwordOpenDoor",
2: "fingerprintOpenDoor",
3: "ICcardOpenDoor",
4: "remoteOpenDoor",
5: "keyOpenDoor"
},
"alarmMode": {
1: "tamperAlarm",
2: "trialAlarm",
3: "powerAlarm"
},
"hijackMode": {
2: "hijackingAlarm",
20: "hijackingAlarm"
},
"model": "USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",
"GET_MSG_INTERVAL": 5000,
"wifi_add_timeout": 150000,
"add_wifi_timeout": 90,
"findWifiTimeout": 60000,
// "active_device_timeout": 30,
//门铃晃动间隔时间
"await_time": 3000,
//门铃晃动次数
"shake_times": 3,
//门锁晃动总时间
"ring_time": 12000,
"remote_opendoor_timeout": 15000,
//二维码失效时间
"qrcode_timeout": 600000,
"remote_timeout": 120,
"input":{
"maxlength": 16
},
"password":{
"maxlength": 12,
"minlength": 6
},
"pushMsg_timeout": 300,
"intervalTime": 3,
//小红点超时时间,24小时之前的新消息没有小红点提示
"newMsg_timeout": 86400,
"getHistoryTimes": 3,
"audioUrl": "../../resources/audio/tipSound.mp3",
// "audioUrl": "_www/resources/audio/tipSound.mp3"
}
\ No newline at end of file
/**
* @class
* crypto
*/
import CryptoJS from "crypto-js";
import md5 from "md5";
class crypto{
static MD5(string){
console.log(string);
return md5(string);
}
static enkey(string){
let key = this.MD5(string).substr(8,16);
let iv = this.MD5(key).substr(8,16);
let keyIv = {
"key": key,
"iv": iv
}
return keyIv;
}
static encode(msg, keyIv){
let message = '';
if(typeof(msg) == 'object'){
message = JSON.stringify(msg);
}else{
message = msg;
}
console.log(message);
let key = CryptoJS.enc.Utf8.parse(keyIv.key);
let iv = CryptoJS.enc.Utf8.parse(keyIv.iv);
let code = CryptoJS.AES.encrypt(message, key, { iv: iv},{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.nopadding });
return code.toString();
}
static decode(code, keyIv){
let key = CryptoJS.enc.Utf8.parse(keyIv.key);
let iv = CryptoJS.enc.Utf8.parse(keyIv.iv);;
let decryptedData = CryptoJS.AES.decrypt(code, key, { iv: iv},{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.nopadding });
return decryptedData.toString(CryptoJS.enc.Utf8);
}
}
export default crypto;
\ No newline at end of file
var manage = 1; //1为正式地址,0为96地址
var modelManage = 0; //1为正式"USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK",0为UGEN_SECURITY_SMARTDOOR_YJ2017
//(1,1)为正式版, (1,0)为内测版, (0,1)为96版
export default {
"url": manage ? "https://cloud.iot.u-gen.net/" : "http://192.168.2.96:20000",
"model": modelManage ? "USMARTLOCK_SECURITY_SMARTDOOR_SMART_LOCK" : "UGEN_SECURITY_SMARTDOOR_YJ2017",
"appId": modelManage ? "10004" : "20004",
"appSecret": modelManage ? "10004" : "20004"
}
\ No newline at end of file
import androidNotify from '../view/c_android-notify.vue';
import list from '../view/c_list.vue';
var components = {
'android-notify': androidNotify,
'list': list
};
export default components;
\ No newline at end of file
import config from './config.js';
import VueI18n from 'vue-i18n';
import defaultConfig from './defaultConfig';
var VueTouch = require('vue-touch');
Vue.use(VueTouch);
import ugenComponents from 'ugen-components';
var uComponents = ugenComponents.uComponents;
import projectComponents from './manage';
const iot = new UIOT({
lang: ['zh', 'en'],
vue: Vue,
i18n: VueI18n,
appId: defaultConfig.appId,
appSecret: defaultConfig.appSecret,
wx: {
appId: ''
},
cloud: {
// url: 'http://wx.iotface.com'
//96环境
url: defaultConfig.url
//96外网
// url: 'http://jycinema.u-gen.net'
//正式
// url: 'https://cloud.iot.u-gen.net/'
//正式测试
// url: 'https://cloud.iot.u-gen.net/test-openapi/'
},
plugin: {
log: {
url: 'https://admin.iot.u-gen.net/admin/api/debug'
}
}
});
var uPublic = {};
uPublic.console = function (res) {
console.log(res)
};
// 设置页面字体
uPublic.recalc = function () {
var docEl = document.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = clientWidth / 10 + 'px';
};
window.addEventListener(resizeEvt, recalc, false);
recalc();
};
// 注册组件
uPublic.componentsInit = function (array) {
array.forEach(function (item, index) {
Vue.component(item, ugenComponents.manage[item]);
});
};
// 加载项目自定义组件
uPublic.componentsExtend = function (array) {
array.forEach(function (item, index) {
Vue.component(item, projectComponents[item]);
});
};
//请求发送失败弹框
uPublic.openRequestErrorAlert = function (vmObj, content = Vue.t('request.error')) {
uComponents.openAlert(vmObj, content, {
text: Vue.t('dialog.confirm'), callback: function () {
}
});
};
// 检查请求成功后data参数
uPublic.checkResponseData = function (data) {
// json
if (data != null && typeof data === 'object') {
if (Object.keys(data).length == 0 || data.hasOwnProperty('msg')) {
return false;
} else {
return data;
}
// array
} else if (Array.isArray(data)) {
if (data.length > 0) {
return data;
} else {
return false;
}
}
};
// 检查输入文字是否含有特殊字符
uPublic.checkString = function (text){
var pattern = new RegExp("[~!@#$%^&*()_+=|\?/{}<>:;'`]+");
if(!pattern.test(text)){
return false
}else{
return true;
}
}
uPublic.openWindow = function (params){
console.log("innnnn");
var wv = plus.webview.create(params.url, params.id, {styles: params.styles || {} }, { IOTData: params.extras });
console.log(wv);
wv.addEventListener('titleUpdate', function(){
wv.show('slide-in-right');
});
}
//禁用ios侧滑返回
uPublic.closeSlideBack = function (){
var wv = plus.webview.currentWebview();
wv.setStyle({
popGesture: 'none'
});
}
//logout退出
uPublic.logout = function(opts){
iot.business.user.logout({
data: opts.data,
success: (response) => {
console.log("sdsLogout:"+response);
var sdsResponse = response;
iot.business.api.send('user/logout',{
data: {
key: ['clienId']
},
success: (response) => {
console.log("logout"+response)
iot.business.websql.delMaps(['utoken', 'userinfo'], (response) => {
iot.storage.delMaps(['notifyTime','alarmTime','openTime'], (response) => {
console.log("clearMap"+response);
opts.success(sdsResponse);
}, (error) => {
opts.error(error);
});
}, (error) => {
opts.error(error);
});
},
error: (error) => {
opts.error(error);
},
complete: () => {
opts.complete();
}
}, true, false);
},
error: (error) => {
opts.error(error);
},
complete: () => {}
});
}
// 更新缓存中history存储的isReadFlag 和 time
uPublic.upDateRead = async function(key, time){
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;
console.log(oldHistory);
}
catch (error){
console.log(error);
}
let newHistory = oldHistory;
newHistory[key].isReadFlag = true;
newHistory[key].time = time;
let flag = await iot.storage.setMap('history', newHistory);
if(flag){
return false;
}
}
iot.ready(() => {
uPublic.recalc();
});
iot.navigator.getAllWebviw = function () {
return plus.webview.all();
}
iot.navigator.fire = function (webview, eventType, data) {
mui.fire(webview, eventType, data);
};
window.iot = iot;
iot.navigator.receive = function (eventType, data) {
console.log("receive。。。");
if (eventType) {
try {
if (data && typeof data === 'string') {
data = JSON.parse(data);
}
} catch (e) {
}
iot.navigator.trigger(document, eventType, data);
}
};
iot.navigator.trigger = function (element, eventType, eventData) {
console.log("trigger。。。");
console.log(element);
console.log(eventType);
element.dispatchEvent(new CustomEvent(eventType, {
detail: eventData,
bubbles: true,
cancelable: true
}));
return this;
};
iot.navigator.closeAllBesidesItself = function () {
setTimeout(function () {
var wvs = plus.webview.all();
var page = plus.webview.currentWebview();
for (var i = 0; i < wvs.length; i++) {
if (wvs[i].id != page.id && wvs[i]) {
// wvs[i].close();
plus.webview.close(wvs[i],"none",0,{});
}
}
var wvs = plus.webview.all();
}, 500);
}
iot.navigator.closeAll = function (){
var wvs = plus.webview.all();
var curWb = plus.webview.currentWebview();
for (var i = 0; i < wvs.length; i++) {
wvs[i].close();
}
}
iot.ready(function(){
// plus.key.addEventListener('backbutton',iot.navigator.aback,false);
})
iot.navigator.aback = function(){
mui.back();
}
var __back__first = null;
mui.back = function(){
var wobj = plus.webview.currentWebview();
var parent = wobj.parent();
var wbs = iot.navigator.getAllWebviw();
if (wbs.length>1) {
// console.log("不止一个webview...");
// return;
iot.navigator.back();
// console.log("有父webview...");
// return;
// parent.evalJS('iot.navigator.back()');
// parent.evalJS('mui&&mui.back();');
} else {
console.log("只有一个webView");
// return;
wobj.canBack(function(e) {
console.log("是否可以返回canback...");
console.log(window.history);
// window.history.back();
console.log(e);
//by chb 暂时注释,在碰到类似popover之类的锚点的时候,需多次点击才能返回;
if (e.canBack) { //webview history back
console.log("e.canback....");
// return;
// window.history.back();
// iot.navigator.back();
} else { //webview close or hide
console.log("不能back。。。");
if (!__back__first) {
__back__first = new Date().getTime();
console.log("给back_first设值....");
plus.nativeUI.toast( "再按一次退出应用");
// mui.toast('再按一次退出应用');
setTimeout(function() {
__back__first = null;
}, 2000);
} else {
console.log("back_first不为空....");
if (new Date().getTime() - __back__first < 2000) {
console.log("两次的间隔时间少于2秒");
plus.runtime.quit();
}else{
console.log("时间间隔大于2s");
}
}
return;
}
});
}
}
iot.navigator.getCurrentWebView = function (){
return plus.webview.currentWebview();
}
export {iot, uPublic, uComponents}
\ No newline at end of file
import {iot, uPublic, uComponents} from './public.js';
class Request{
constructor(json) {//当前版本号、最新版本号以及获取最新安装包地址
}
versionRequest(url,need,notneed){
this.getDownloadUrl(url,need,notneed);
}
getDownloadUrl(url,need,notneed){
let type = null;
if (iot.navigator.osName() == "iOS") {
type = "ios";
}else{
type = "android";
}
iot.business.api.send(url,
{
data: {
type:type
},
success: (response) => {
console.log(response);
if (response.code == 0) {
this.dealWithVersion(response,need,notneed);
}
},
error: (error) => {
console.log(error);
notneed(error);
},
complete: () => {}
},false);
}
dealWithVersion(response,need,notneed){
let type = null;
if (iot.navigator.osName() == "iOS") {
type = "ios";
}else{
type = "android";
}
let info = null;
if (type == "ios") {
info = response.data["ios"];
}else{
info = response.data["android"];
}
console.log(info);
let newVersion = info.version;// 新版本 无论是安卓还是iOS都用此变量存储
let downloadUrl = info.url;
let backinfo = {
url:downloadUrl,
version:newVersion
};
need(backinfo);
}
}
export default new Request();
\ No newline at end of file
/**
* @class
* loop
*/
//轮询通用方法:http://116.62.143.3:10080/iot-project-js/doorlock/issues/1
class Loop{
constructor(params) {
this.handle = null;
this.watcher = null;
this.time = null;
this.loopContent = params.loopContent;
this.times = params.times || 10;
this.fincb = params.fincb;
this.intervalTime = params.interval.delay;
this.intervalcb = params.interval.cb;
this.stopcondition = params.stopcondition;
this.canSend = true;
this.canDo = true;
this.i = 0;
}
clearTime(){
clearInterval(this.handle);
clearInterval(this.watcher);
clearTimeout(this.time);
}
async sendRequest(){
this.canSend = false;
try{
var response = null;
response = await this.loopContent();
console.log(response);
if(await this.stopcondition(response)){
if(this.fincb!= null){
this.fincb.success(response);
this.fincb.complete();
}
this.clearTime();
this.canSend = false;
}else{
if(this.intervalcb!= null){
this.intervalcb.success(response);
}
this.canSend = true;
}
}
catch (error){
if(this.intervalcb!= null){
if(this.intervalcb.error(error)){
this.canSend = true;
}else{
if(this.fincb!= null){
this.fincb.error(error);
this.fincb.complete();
this.clearTime();
}
}
}
}
}
start(){
console.log("开始");
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
this.sendRequest();
this.watcher = setInterval(() => {
if(this.canSend && this.canDo){
this.canDo = false;
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
this.sendRequest();
}
},1000);
let times = 1;
this.handle = setInterval(() => {
times++;
console.log('times'+times);
if(times > this.times){
this.clearTime();
this.canDo = false;
this.fincb.error('timeout');
this.fincb.complete();
this.intervalcb = null;
this.fincb = null;
}else{
this.canDo = true;
}
},this.intervalTime);
}
}
export default Loop;
/**
* @class
* unotify
*/
import uloop from './uloop';
//获取cid: http://116.62.143.3:10080/iot-project-js/doorlock/issues/4
class unotify{
//在一个周期内获取cid
static getCid(successCallback, errorCallback){
this.UpdateCid((response) => {
successCallback(response);
}, (error) => {
errorCallback(error);
});
}
//周期性获取cid,周期可调整
static getCidPeriotic(times){
var self = this;
return new Promise(function(resolve, reject){
new uloop({
loopContent: () => {
return self.getCidOnce();
},
times: times,
interval:{
delay: 1000,
cb: {
success: (response) => {
console.log('intervalcbSuccess:'+JSON.stringify(response));
},
error: (error) => {
console.log('intervalcbError:'+JSON.stringify(error));
}
}
},
fincb: {
success: (response) => {
console.log('fincbSuccess:'+JSON.stringify(response));
resolve(response);
},
error: (error) => {
console.log('fincbSuccess:'+JSON.stringify(error));
if(error == 'timeout'){
resolve(null);
}
},
complete: () => {}
},
stopcondition: async (response) => {
if(response != null && response != 'null' ){
return true;
}
}
}).start();
});
}
//单次获取cid
static getCidOnce(){
var clientInfo = plus.push.getClientInfo();
if(clientInfo && clientInfo.hasOwnProperty('clientid') && clientInfo.clientid){
return(clientInfo.clientid);
}else{
return(null);
}
}
//长期不断循环获取cid,并更新cid
static async UpdateCid(successCallback, errorCallback){
var cid = null;
var oldCid = null;
try{
cid = await this.getCidPeriotic(999);
if(cid != null && cid != oldCid){
iot.business.api.send('user/updateCid',{
data: {
clienId: cid
},
success: (response) => {
console.log(response);
if(typeof successCallback == 'function'){
successCallback('cid updateSuccess');
}
},
error: (error) => {
console.log(error);
errorCallback(error);
}
}, true, false);
}else{
successCallback('cid not updated');
}
}
catch (err){
console.log(err);
if(typeof errorCallback == 'function'){
errorCallback(err);
}
}
}
}
export default unotify;
\ 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