virsical-jssdk
Advanced tools
Comparing version 0.1.11 to 0.1.12
225
index.js
@@ -1,9 +0,13 @@ | ||
;(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
global.Virsical = factory() | ||
; | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' | ||
? module.exports = factory() | ||
: typeof define === 'function' && define.amd | ||
? define(factory) | ||
: global.Virsical = factory() | ||
}(this, (function () { | ||
// document.write(" <script language=\"javascript\" src=\"qwebchannel.js\" > </script>"); | ||
// document.write(" <script language=\"javascript\" src=\"qwebchannel.js\" > | ||
// </script>"); | ||
'use strict'; | ||
@@ -18,34 +22,42 @@ var Virsical; | ||
var _platform_mac = 3; | ||
var _platform_Windows = 4; | ||
var _platform_Windows = 4; | ||
function setHadConfig(){ | ||
sessionStorage.setItem("configStatus",true); | ||
function setHadConfig() { | ||
sessionStorage.setItem("configStatus", true); | ||
} | ||
//做为是否config成功的标志,此处仅demo,实际需要考虑加密 | ||
function hadConfig(){ | ||
// return sessionStorage.getItem("configStatus"); | ||
function hadConfig() { | ||
// return sessionStorage.getItem("configStatus"); | ||
return true; | ||
} | ||
//Windows终端接口 | ||
function clickConfig(id, secret) { | ||
//Windows终端接口 | ||
function clickConfig(id, secret) { | ||
try { | ||
new QWebChannel(qt.webChannelTransport, function (channel) { | ||
var content = channel.objects.content; | ||
content.clickConfig(id,secret); | ||
content.clickConfig(id, secret); | ||
}); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
} | ||
function getPlatform(){ | ||
function getPlatform() { | ||
var u = navigator.userAgent; | ||
if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1){ //android终端 | ||
if (isDebugger) { | ||
window | ||
.console | ||
.log('Virsical: ', u); | ||
} | ||
if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) { //android终端 | ||
return _platform_android; | ||
}else if(!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) { | ||
} else if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) { | ||
return _platform_ios; | ||
}else if(!!u.match(/Mac OS X/)) { | ||
} else if (!!u.match(/Mac OS X/)) { | ||
return _platform_mac; | ||
}else if(u.indexOf('QtWebEngine')> -1){//Windows终端 | ||
return _platform_Windows; | ||
}else{// 其他设备 | ||
} else if (u.indexOf('QtWebEngine') > -1) { //Windows终端 | ||
return _platform_Windows; | ||
} else { // 其他设备 | ||
return _platform_other; | ||
@@ -55,25 +67,27 @@ } | ||
//绑定第三方应用分配的client_id和client_secret | ||
Virsical.config = function(info){ | ||
Virsical.config = function (info) { | ||
isDebugger = info.debug; | ||
var platform = getPlatform(); | ||
if(platform == _platform_android){ | ||
if (platform == _platform_android) { | ||
try { | ||
window.control.config(info.debug, info.client_id, info.client_secret); | ||
} catch(e) { | ||
window | ||
.control | ||
.config(info.debug, info.client_id, info.client_secret); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
isDebugger = info.debug; | ||
}else if(platform==_platform_ios || platform == _platform_mac ){ | ||
} else if (platform == _platform_ios || platform == _platform_mac) { | ||
//TODO ios | ||
window.location.href = 'vsk3browser://config?'+'debug='+info.debug+'&'+'clientid='+info.client_id+'&'+'clientsecret='+info.client_secret; | ||
}else if(platform==_platform_Windows){ | ||
window.location.href = 'vsk3browser://config?debug=' + info.debug + '&clientid=' + info.client_id + '&clientsecret=' + info.client_secret; | ||
} else if (platform == _platform_Windows) { | ||
//TODO Windows | ||
clickConfig(info.client_id, info.client_secret); | ||
clickConfig(info.client_id, info.client_secret); | ||
} else { | ||
throw new Error("Device validation failed, only support for mobile devices"); | ||
} | ||
throw new Error("Device validation failed, only support for mobile devices"); | ||
} | ||
var configReadyCallback; | ||
Virsical.ready = function(callbackFunction){ | ||
Virsical.ready = function (callbackFunction) { | ||
configReadyCallback = callbackFunction; | ||
@@ -83,3 +97,3 @@ } | ||
//webview调用,config成功 | ||
function configReady(){ | ||
function configReady() { | ||
setHadConfig(); | ||
@@ -90,3 +104,3 @@ configReadyCallback && configReadyCallback(); | ||
var configErrorCallback; | ||
Virsical.error = function(callbackFunction){ | ||
Virsical.error = function (callbackFunction) { | ||
configErrorCallback = callbackFunction; | ||
@@ -96,11 +110,8 @@ }; | ||
//webview调用,config失败 | ||
function configError(){ | ||
configReadyCallback && configReadyCallback({ | ||
msg: mg, | ||
code: cd | ||
}); | ||
function configError() { | ||
configReadyCallback && configReadyCallback({msg: mg, code: cd}); | ||
} | ||
var loginTimer; | ||
var login_timeout_during = 60*1000; | ||
var login_timeout_during = 60 * 1000; | ||
var login_timeout_code = 200; | ||
@@ -111,4 +122,7 @@ | ||
//设置登录超时回调方法 | ||
Virsical.login = function(callbackFunction){ | ||
if(!hadConfig()){ | ||
Virsical.login = function (callbackFunction) { | ||
if (!hadConfig()) { | ||
window | ||
.console | ||
.error('no config, please using Virsical.config(...) to config your app.') | ||
alert("Please config app first"); | ||
@@ -123,10 +137,12 @@ return; | ||
var platform = getPlatform(); | ||
if(platform==_platform_android){ | ||
if (platform == _platform_android) { | ||
try { | ||
window.control.login(); | ||
} catch(e) { | ||
window | ||
.control | ||
.login(); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
}else if(platform==_platform_ios || platform == _platform_mac){ | ||
} else if (platform == _platform_ios || platform == _platform_mac) { | ||
//TODO ios | ||
@@ -138,3 +154,3 @@ window.location.href = 'vsk3browser://login'; | ||
//登录超时处理 | ||
function loginTimeout(){ | ||
function loginTimeout() { | ||
loginResult("1", "", login_timeout_code, "Engineer no response"); | ||
@@ -144,21 +160,15 @@ } | ||
//webview调用,返回登录结果信息 | ||
function loginResult(result, json, cd, mg){ | ||
function loginResult(result, json, cd, mg) { | ||
clearTimeout(loginTimer); | ||
if (result == 0){ | ||
loginSuccessCallback && loginSuccessCallback({ | ||
info: json | ||
}); | ||
if (result == 0) { | ||
loginSuccessCallback && loginSuccessCallback({info: json}); | ||
} else { | ||
loginFailCallback && loginFailCallback({ | ||
msg: mg, | ||
code: cd | ||
}); | ||
loginFailCallback && loginFailCallback({msg: mg, code: cd}); | ||
} | ||
} | ||
var selectImageSuccessCallback; | ||
//选择图片 | ||
Virsical.selectImage = function(info){ | ||
if(!hadConfig()){ | ||
Virsical.selectImage = function (info) { | ||
if (!hadConfig()) { | ||
alert("Please config app first"); | ||
@@ -168,5 +178,7 @@ return; | ||
selectImageSuccessCallback = info.successCallback; | ||
if(getPlatform()==_platform_android){ | ||
window.image.selectOne(); | ||
}else if(getPlatform()==_platform_ios){ | ||
if (getPlatform() == _platform_android) { | ||
window | ||
.image | ||
.selectOne(); | ||
} else if (getPlatform() == _platform_ios) { | ||
//TODO ios | ||
@@ -177,18 +189,17 @@ } | ||
//webview调用,返回选择的图片信息 | ||
function imageResult(ids){ | ||
selectImageSuccessCallback({ | ||
localIds: ids | ||
}); | ||
function imageResult(ids) { | ||
selectImageSuccessCallback({localIds: ids}); | ||
} | ||
//预览图片 | ||
Virsical.previewImage = function(info){ | ||
if(!hadConfig()){ | ||
Virsical.previewImage = function (info) { | ||
if (!hadConfig()) { | ||
alert("Please config app first"); | ||
return; | ||
} | ||
if(getPlatform()==_platform_android){ | ||
window.image.show(info.ids); | ||
}else if(getPlatform()==_platform_ios){ | ||
if (getPlatform() == _platform_android) { | ||
window | ||
.image | ||
.show(info.ids); | ||
} else if (getPlatform() == _platform_ios) { | ||
//TODO ios | ||
@@ -199,3 +210,3 @@ } | ||
var locationTimer; | ||
var location_timeout_during = 60*1000; | ||
var location_timeout_during = 60 * 1000; | ||
var location_timeout_code = 200; | ||
@@ -206,4 +217,4 @@ | ||
//设置定位超时回调方法 | ||
Virsical.location = function(callbackFunction){ | ||
if(!hadConfig()){ | ||
Virsical.location = function (callbackFunction) { | ||
if (!hadConfig()) { | ||
alert("Please config app first"); | ||
@@ -215,5 +226,7 @@ return; | ||
locationFailCallback = callbackFunction.fail; | ||
if(getPlatform()==_platform_android){ | ||
window.map.location(); | ||
}else if(getPlatform()==_platform_ios){ | ||
if (getPlatform() == _platform_android) { | ||
window | ||
.map | ||
.location(); | ||
} else if (getPlatform() == _platform_ios) { | ||
//TODO ios | ||
@@ -224,3 +237,3 @@ } | ||
//定位超时处理 | ||
function locationTimeout(){ | ||
function locationTimeout() { | ||
locationResult("1", "", "", login_timeout_code, "Engineer no response"); | ||
@@ -230,15 +243,8 @@ } | ||
//webview调用,返回登录结果信息 | ||
function locationResult(result, addr, lat, lng, cd, mg){ | ||
function locationResult(result, addr, lat, lng, cd, mg) { | ||
clearTimeout(locationTimer); | ||
if (result == 0){ | ||
locationSuccessCallback({ | ||
addr: addr, | ||
lat: lat, | ||
lng: lng | ||
}); | ||
}else{ | ||
locationFailCallback({ | ||
msg: mg, | ||
code: cd | ||
}); | ||
if (result == 0) { | ||
locationSuccessCallback({addr: addr, lat: lat, lng: lng}); | ||
} else { | ||
locationFailCallback({msg: mg, code: cd}); | ||
} | ||
@@ -250,4 +256,4 @@ } | ||
//扫描二维码 | ||
Virsical.captureQR = function(callbackFunction){ | ||
if(!hadConfig()){ | ||
Virsical.captureQR = function (callbackFunction) { | ||
if (!hadConfig()) { | ||
alert("Please config app first"); | ||
@@ -259,5 +265,7 @@ return; | ||
var platform = getPlatform(); | ||
if(platform==_platform_android){ | ||
window.captureqr.scan(); | ||
}else if(platform==_platform_ios || platform == _platform_mac){ | ||
if (platform == _platform_android) { | ||
window | ||
.captureqr | ||
.scan(); | ||
} else if (platform == _platform_ios || platform == _platform_mac) { | ||
//TODO ios | ||
@@ -269,12 +277,7 @@ window.location.href = 'vsk3browser://captureqr'; | ||
//webview调用,返回扫描结果信息 | ||
function captureQRResult(result, url, cd, mg){ | ||
if (result == 0){ | ||
workspaceSuccessCallback({ | ||
url: url | ||
}); | ||
}else{ | ||
workspaceFailCallback({ | ||
msg: mg, | ||
code: cd | ||
}); | ||
function captureQRResult(result, url, cd, mg) { | ||
if (result == 0) { | ||
workspaceSuccessCallback({url: url}); | ||
} else { | ||
workspaceFailCallback({msg: mg, code: cd}); | ||
} | ||
@@ -281,0 +284,0 @@ } |
{ | ||
"name": "virsical-jssdk", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "Virsical 3.0 JS SDK", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10863
253