对接大兴app上传图片
parent
6cdbe2af11
commit
24ee305293
@ -0,0 +1,66 @@
|
|||||||
|
const isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1
|
||||||
|
const isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
|
||||||
|
// 这是必须要写的,用来创建一些设置
|
||||||
|
function setupWebViewJavascriptBridge(callback) {
|
||||||
|
// Android使用
|
||||||
|
if (isAndroid) {
|
||||||
|
if (window.WebViewJavascriptBridge) {
|
||||||
|
callback(window.WebViewJavascriptBridge)
|
||||||
|
} else {
|
||||||
|
document.addEventListener(
|
||||||
|
'WebViewJavascriptBridgeReady',
|
||||||
|
() => {
|
||||||
|
callback(window.WebViewJavascriptBridge)
|
||||||
|
},
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
sessionStorage.phoneType = 'android'
|
||||||
|
}
|
||||||
|
// iOS使用
|
||||||
|
if (isiOS) {
|
||||||
|
if (window.WebViewJavascriptBridge) {
|
||||||
|
return callback(window.WebViewJavascriptBridge)
|
||||||
|
}
|
||||||
|
if (window.WVJBCallbacks) {
|
||||||
|
return window.WVJBCallbacks.push(callback)
|
||||||
|
}
|
||||||
|
window.WVJBCallbacks = [callback]
|
||||||
|
var WVJBIframe = document.createElement('iframe')
|
||||||
|
WVJBIframe.style.display = 'none'
|
||||||
|
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'
|
||||||
|
document.documentElement.appendChild(WVJBIframe)
|
||||||
|
setTimeout(() => {
|
||||||
|
document.documentElement.removeChild(WVJBIframe)
|
||||||
|
}, 0)
|
||||||
|
sessionStorage.phoneType = 'ios'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 注册回调函数,第一次连接时调用 初始化函数(android需要初始化,ios不用)
|
||||||
|
setupWebViewJavascriptBridge((bridge) => {
|
||||||
|
if (isAndroid) {
|
||||||
|
// 初始化
|
||||||
|
bridge.init((message, responseCallback) => {
|
||||||
|
var data = {
|
||||||
|
'Javascript Responds': 'Wee!'
|
||||||
|
}
|
||||||
|
responseCallback(data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default {
|
||||||
|
// js调APP方法 (参数分别为:app提供的方法名 传给app的数据 回调)
|
||||||
|
callHandler(name, data, callback) {
|
||||||
|
setupWebViewJavascriptBridge((bridge) => {
|
||||||
|
bridge.callHandler(name, JSON.stringify(data), callback)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// APP调js方法 (参数分别为:js提供的方法名 回调)
|
||||||
|
registerHandler(name, callback) {
|
||||||
|
setupWebViewJavascriptBridge((bridge) => {
|
||||||
|
bridge.registerHandler(name, (data, responseCallback) => {
|
||||||
|
callback(data, responseCallback)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,216 @@
|
|||||||
|
(function(global) {
|
||||||
|
var task, img, styleTask, styleImg;
|
||||||
|
|
||||||
|
function createLoading() {
|
||||||
|
task = document.createElement('div');
|
||||||
|
task.style.cssText = 'position:fixed;background:rgba(0,0,0,0);left:0;top:0;width:100%;height:100%;z-index:9999';
|
||||||
|
document.documentElement.appendChild(task);
|
||||||
|
};
|
||||||
|
|
||||||
|
function removeLoading() {
|
||||||
|
document.documentElement.removeChild(task);
|
||||||
|
task = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function JSBridge() {
|
||||||
|
this.name = 'JSBridge';
|
||||||
|
this.reset = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
JSBridge.prototype.device = function() {
|
||||||
|
var u = navigator.userAgent;
|
||||||
|
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
|
||||||
|
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
||||||
|
return isAndroid;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @param null
|
||||||
|
* JSBridge初始化
|
||||||
|
*/
|
||||||
|
JSBridge.prototype._init = function(callback) {
|
||||||
|
if (window.WebViewJavascriptBridge) {
|
||||||
|
return callback(WebViewJavascriptBridge);
|
||||||
|
}
|
||||||
|
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
|
||||||
|
window.WVJBCallbacks = [callback];
|
||||||
|
var WVJBIframe = document.createElement('iframe');
|
||||||
|
WVJBIframe.style.display = 'none';
|
||||||
|
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
|
||||||
|
document.documentElement.appendChild(WVJBIframe);
|
||||||
|
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @param null
|
||||||
|
* JSBridge 安卓初始化回调接口
|
||||||
|
*/
|
||||||
|
JSBridge.prototype.__init__ = function(bridge) {
|
||||||
|
var isAn = this.device();
|
||||||
|
if (this.reset && isAn) {
|
||||||
|
this.reset = false;
|
||||||
|
bridge.init(function(message, responseCallback) {
|
||||||
|
console.log('JS got a message', message);
|
||||||
|
var data = {
|
||||||
|
'Javascript Responds': '测试中文!'
|
||||||
|
};
|
||||||
|
console.log('JS responding with', data);
|
||||||
|
responseCallback(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 调用原生方法
|
||||||
|
*/
|
||||||
|
JSBridge.prototype.callHandler = function(funcName, data, callback) {
|
||||||
|
var isAn = this.device();
|
||||||
|
var _this = this;
|
||||||
|
// _this._init(function (bridge) {
|
||||||
|
// _this.__init__(bridge);
|
||||||
|
// bridge.callHandler(funcName, JSON.stringify(data), function (response) {
|
||||||
|
// if (callback)
|
||||||
|
// callback(JSON.parse(response));
|
||||||
|
// })
|
||||||
|
// }.bind(this))
|
||||||
|
if(isAn){
|
||||||
|
if(window.WebViewJavascriptBridge){
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.callHandler(funcName, JSON.stringify(data), function (response) {
|
||||||
|
if (callback)
|
||||||
|
callback(JSON.parse(response));
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
}else{
|
||||||
|
document.addEventListener(
|
||||||
|
'WebViewJavascriptBridgeReady'
|
||||||
|
, function() {
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.callHandler(funcName, JSON.stringify(data), function (response) {
|
||||||
|
if (callback)
|
||||||
|
callback(JSON.parse(response));
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.callHandler(funcName, JSON.stringify(data), function (response) {
|
||||||
|
if (callback)
|
||||||
|
callback(JSON.parse(response));
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 注册方法
|
||||||
|
*/
|
||||||
|
JSBridge.prototype.registerHandler = function(funcName,initFuc, params) {
|
||||||
|
var isAn = this.device();
|
||||||
|
var _this = this;
|
||||||
|
//处理android WebViewJavascriptBridge延时问题
|
||||||
|
if(isAn) {
|
||||||
|
if(window.WebViewJavascriptBridge){
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.registerHandler(funcName, function (data, callback) {
|
||||||
|
if (initFuc) {
|
||||||
|
if (data) {
|
||||||
|
initFuc(JSON.parse(data));
|
||||||
|
} else {
|
||||||
|
initFuc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if(callback)
|
||||||
|
callback(JSON.parse(data))*/
|
||||||
|
if (params) {
|
||||||
|
callback(JSON.stringify(params));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
}else{
|
||||||
|
document.addEventListener('WebViewJavascriptBridgeReady', function() {
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.registerHandler(funcName, function (data, callback) {
|
||||||
|
if (initFuc) {
|
||||||
|
if (data) {
|
||||||
|
initFuc(JSON.parse(data));
|
||||||
|
} else {
|
||||||
|
initFuc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if(callback)
|
||||||
|
callback(JSON.parse(data))*/
|
||||||
|
if (params) {
|
||||||
|
callback(JSON.stringify(params));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
_this._init(function (bridge) {
|
||||||
|
_this.__init__(bridge);
|
||||||
|
bridge.registerHandler(funcName, function (data, callback) {
|
||||||
|
if (initFuc) {
|
||||||
|
if (data) {
|
||||||
|
initFuc(JSON.parse(data));
|
||||||
|
} else {
|
||||||
|
initFuc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if(callback)
|
||||||
|
callback(JSON.parse(data))*/
|
||||||
|
if (params) {
|
||||||
|
callback(JSON.stringify(params));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 获取经纬度
|
||||||
|
*/
|
||||||
|
JSBridge.prototype.getJwd = function(callback, params) {
|
||||||
|
this._init(function(bridge) {
|
||||||
|
this.__init__(bridge);
|
||||||
|
bridge.callHandler( 'getJwd', JSON.stringify({}), function(response) {
|
||||||
|
var res = JSON.parse(response);
|
||||||
|
jwd = res["longitude"]+","+res["latitude"];
|
||||||
|
params["userLocation"] = jwd;
|
||||||
|
if(callback)
|
||||||
|
callback(params);
|
||||||
|
})
|
||||||
|
}.bind(this))
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 全局变量设置
|
||||||
|
*/
|
||||||
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
module.exports = JSBridge;
|
||||||
|
} else if (typeof define === 'function' && (define.amd || define.cmd)) {
|
||||||
|
define(function() {
|
||||||
|
return JSBridge;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
global.JSBridge = JSBridge;
|
||||||
|
};
|
||||||
|
})(this);
|
||||||
@ -0,0 +1,462 @@
|
|||||||
|
/**各种使用的工具函数
|
||||||
|
* 目测会替换掉
|
||||||
|
* quick-view.js里面的
|
||||||
|
* QuickUrlUtils
|
||||||
|
* createOptions
|
||||||
|
*
|
||||||
|
* quick-easyuiUtils里面的
|
||||||
|
* createTreeList
|
||||||
|
* */
|
||||||
|
|
||||||
|
function QuickUtils() { }
|
||||||
|
|
||||||
|
QuickUtils.findByList = function (list, value, valueField) {
|
||||||
|
var item = null;
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
var list_item = list[i];
|
||||||
|
var v = list_item[valueField];
|
||||||
|
if (v == value) {
|
||||||
|
item = list_item;
|
||||||
|
} else {
|
||||||
|
var children = list_item["children"];
|
||||||
|
if (children && children.length > 0) {
|
||||||
|
item = QuickUtils.findByList(children, value, valueField);
|
||||||
|
if (!item) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickUtils.createTreeList = function (config) {
|
||||||
|
var finalConfig = $.extend({}, QuickUtils.convertTreeListDefaultConfig, config);
|
||||||
|
var list = finalConfig["list"];
|
||||||
|
var sjdm = finalConfig["sjdm"];
|
||||||
|
var idField = finalConfig["idField"];
|
||||||
|
var textField = finalConfig["textField"];
|
||||||
|
var reldateField = finalConfig["reldateField"];
|
||||||
|
var itemIDField = finalConfig["itemIDField"];
|
||||||
|
var itemTextField = finalConfig["itemTextField"];
|
||||||
|
return QuickUtils.innerCreateTreeList(list, sjdm, idField, textField, reldateField, itemIDField, itemTextField);
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickUtils.innerCreateTreeList = function (list, sjjgdm, idField, textField, reldateField, itemIDField, itemTextField) {
|
||||||
|
var childList = [];
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
var item = list[i];
|
||||||
|
if (item == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var sjjgdm1 = item[reldateField];
|
||||||
|
if (sjjgdm1 != sjjgdm) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
var id = item[idField];
|
||||||
|
item[itemTextField] = item[textField];
|
||||||
|
item[itemIDField] = item[idField];
|
||||||
|
var lt = QuickUtils.innerCreateTreeList(list, id, idField, textField, reldateField, itemIDField, itemTextField);
|
||||||
|
if (lt != null && lt.length != 0) {
|
||||||
|
item["children"] = lt;
|
||||||
|
}
|
||||||
|
childList.push(item);
|
||||||
|
list[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (childList.length == 0) {
|
||||||
|
childList = null;
|
||||||
|
}
|
||||||
|
return childList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickUtils.convertTreeListDefaultConfig = {
|
||||||
|
/*上级代码值*/
|
||||||
|
sjdm: ""
|
||||||
|
/*ID字段*/
|
||||||
|
, idField: "XMDM"
|
||||||
|
/*text字段*/
|
||||||
|
, textField: "XMMC"
|
||||||
|
/*关联字段*/
|
||||||
|
, reldateField: "SJDM"
|
||||||
|
/*item的id字段*/
|
||||||
|
, itemIDField: "id"
|
||||||
|
/*item的text字段*/
|
||||||
|
, itemIDField: "text"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**URL工具类*/
|
||||||
|
(function ($) {
|
||||||
|
var host = window.location.host;
|
||||||
|
var pathName = window.document.location.pathname.replace(/\/\//g, "/");
|
||||||
|
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
|
||||||
|
var currPagePath = pathName.substring(0, pathName.substr(1).lastIndexOf('/') + 1)
|
||||||
|
$.QuickUrlUtils = {
|
||||||
|
redirectUrl: function (url) {
|
||||||
|
location = currPagePath + "/" + url;
|
||||||
|
},
|
||||||
|
redirectRootUrl: function (url) {
|
||||||
|
location = projectName + "/" + url;
|
||||||
|
}
|
||||||
|
, getProjectName: function () {
|
||||||
|
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
, geCurrPagePath: function () {
|
||||||
|
return currPagePath;
|
||||||
|
}
|
||||||
|
, getHost: function () {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
, getHostProject: function () {
|
||||||
|
return host + projectName;
|
||||||
|
}
|
||||||
|
, forward: function (url, title, subTitle, isClose) {
|
||||||
|
StoreCache.setCache("title", title);
|
||||||
|
if ($.QuickVersion["isWeb"]) {
|
||||||
|
location = url;
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isWeixin"]) {
|
||||||
|
location = url;
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["android"]) {
|
||||||
|
if (!isClose) isClose = "2";
|
||||||
|
var tzurl = currPagePath + "/" + url;
|
||||||
|
if (url.indexOf("FJZLYD") != -1) {
|
||||||
|
tzurl = url;
|
||||||
|
}
|
||||||
|
android.toWebViewActivity(tzurl, title, "", isClose);
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["iPhone"]) {
|
||||||
|
window.webkit.messageHandlers.fjzlyd.postMessage({ functionName: "toWebViewActivity", parameter: { url: currPagePath + "/" + url, title: title, subTitle: "", isClose: isClose } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
, forwardRootUrl: function (url, title, subTitle, isClose) {
|
||||||
|
if ($.QuickVersion["isWeb"]) {
|
||||||
|
location = projectName + "/" + url;
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isWeixin"]) {
|
||||||
|
location = projectName + "/" + url;
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["android"]) {
|
||||||
|
if (!isClose) isClose = "2";
|
||||||
|
android.closeAllWebView(projectName + "/" + url, title, "", isClose);
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["iPhone"]) {
|
||||||
|
window.webkit.messageHandlers.fjzlyd.postMessage({ functionName: "toWebViewActivity", parameter: { url: projectName + "/" + url, title: title, subTitle: "", isClose: isClose } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
, forwardAny: function (url) {
|
||||||
|
location = url;
|
||||||
|
}
|
||||||
|
, openNewWindow: function (url, title) {
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
|
//获取URL参数
|
||||||
|
, getRequest: function (key) {
|
||||||
|
var url = decodeURI(location.search); //获取url中"?"符后的字串
|
||||||
|
var theRequest = new Object();
|
||||||
|
if (url.indexOf("?") != -1) {
|
||||||
|
var str = url.substring(url.indexOf("?") + 1, url.length);
|
||||||
|
strs = str.split("&");
|
||||||
|
for (var i = 0; i < strs.length; i++) {
|
||||||
|
if (!StringUtils.isEmpty(strs[i]))
|
||||||
|
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!key)
|
||||||
|
return theRequest;
|
||||||
|
else
|
||||||
|
return theRequest[key];
|
||||||
|
}
|
||||||
|
//获取URL参数
|
||||||
|
, getRequestByURL: function (url, key) {
|
||||||
|
var theRequest = new Object();
|
||||||
|
if (url.indexOf("?") != -1) {
|
||||||
|
var str = url.substring(url.indexOf("?") + 1, url.length);
|
||||||
|
strs = str.split("&");
|
||||||
|
for (var i = 0; i < strs.length; i++) {
|
||||||
|
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key == "")
|
||||||
|
return theRequest;
|
||||||
|
else
|
||||||
|
return theRequest[key];
|
||||||
|
}
|
||||||
|
/**退回上级页面*/
|
||||||
|
, back: function () {
|
||||||
|
history.back(-1);
|
||||||
|
}
|
||||||
|
/**预留jsbriage统一页面跳转*/
|
||||||
|
, redirectJSBridge: function (options, data) {
|
||||||
|
if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) {
|
||||||
|
//console.log('use app');
|
||||||
|
var params = {
|
||||||
|
"type": "H5",
|
||||||
|
"toPage": options["url"],
|
||||||
|
"hasNavigation": "true",
|
||||||
|
"animate": options.animate == undefined ? "push" : options.animate,
|
||||||
|
"params": data != undefined ? data : {},
|
||||||
|
"refreshUrl": options["refreshUrl"]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
JSBridge.prototype.callHandler("forward", params);
|
||||||
|
|
||||||
|
//JSBridge.prototype.callHandler("gotoWebView", options);
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isWeixin"] || $.QuickVersion["isWeb"]) {
|
||||||
|
console.log("进入判断了")
|
||||||
|
location.href = options["url"];
|
||||||
|
//当出现登录超时时,记住当前地址,登录之后跳转到当前地址。登录页和注册页以及忘记密码页 不做登录之后跳转的地址保存
|
||||||
|
// if(location.href && location.href.indexOf('login')<0){
|
||||||
|
// if(location.href.indexOf("?")>0){
|
||||||
|
// StoreCache.setCache("afterLoginUrl",location.href+"&afterLoginUrl=yes");
|
||||||
|
// }else{
|
||||||
|
// StoreCache.setCache("afterLoginUrl",location.href+"?afterLoginUrl=yes");
|
||||||
|
// }
|
||||||
|
// }else{
|
||||||
|
StoreCache.removeCache("afterLoginUrl");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
location.href = options["url"];
|
||||||
|
StoreCache.removeCache("afterLoginUrl");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**预留jsbriage统一页面返回*/
|
||||||
|
, rebackJSBridge: function (options) {
|
||||||
|
if ($.QuickVersion["isWeixin"]) {
|
||||||
|
location = options["url"];
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) {
|
||||||
|
// if(StringUtils.isEmpty(options["app_user_agent"])){
|
||||||
|
// options["url"] = currPagePath + "/" + options["url"];
|
||||||
|
// }
|
||||||
|
var params = {
|
||||||
|
"type": "H5",
|
||||||
|
"toPage": options["url"],
|
||||||
|
"hasNavigation": "true",
|
||||||
|
"animate": "pop",
|
||||||
|
};
|
||||||
|
|
||||||
|
JSBridge.prototype.callHandler("forward", params);
|
||||||
|
|
||||||
|
//JSBridge.prototype.callHandler("backtoWebView", options);
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isWeb"]) {
|
||||||
|
location = options["url"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**预留jsbriage统一页面刷新*/
|
||||||
|
, refreshJSBridge: function (options) {
|
||||||
|
if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) {
|
||||||
|
JSBridge.prototype.callHandler("refreshPage", options);
|
||||||
|
}
|
||||||
|
else if ($.QuickVersion["isWeb"] && options["url"]) {
|
||||||
|
location = options["url"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//在不提供上一页地址,返回上一页并刷新
|
||||||
|
, reBackAndRefreshJSBridge: function (url, topage) {
|
||||||
|
if ($.QuickVersion["isIOSApp"] || $.QuickVersion["isApp"]) {
|
||||||
|
var options = {
|
||||||
|
"type": "H5",
|
||||||
|
"toPage": topage ? topage : "",
|
||||||
|
"hasNavigation": "true",
|
||||||
|
"animate": "pop",
|
||||||
|
"refreshUrl": url ? url : ""
|
||||||
|
};
|
||||||
|
JSBridge.prototype.callHandler("forward", options);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(url && url!='*'){
|
||||||
|
location = url;
|
||||||
|
}else{
|
||||||
|
history.back(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(jQuery);
|
||||||
|
|
||||||
|
/**创建下拉框选项*/
|
||||||
|
(function ($) {
|
||||||
|
var defaultConfig = {
|
||||||
|
needNull: "true"
|
||||||
|
, textField: "XMMC"
|
||||||
|
, valueField: "XMDM"
|
||||||
|
};
|
||||||
|
$.fn.createOptions = function (ary, config) {
|
||||||
|
var finalConfig = $.extend({}, defaultConfig, config);
|
||||||
|
$(this).empty();
|
||||||
|
var needNull = finalConfig["needNull"];
|
||||||
|
var textField = finalConfig["textField"];
|
||||||
|
var valueField = finalConfig["valueField"];
|
||||||
|
|
||||||
|
var opts = [];
|
||||||
|
|
||||||
|
if (needNull == "true") {
|
||||||
|
var opt = $('<option>');
|
||||||
|
opt.attr("value", "");
|
||||||
|
opt.text("请选择");
|
||||||
|
//opt.css("display", "none");
|
||||||
|
opts.push(opt);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < ary.length; i++) {
|
||||||
|
var item = ary[i];
|
||||||
|
var value = item[valueField];
|
||||||
|
var text = item[textField];
|
||||||
|
var option = $('<option>');
|
||||||
|
$(option).attr('value', value);
|
||||||
|
$(option).html(text);
|
||||||
|
$(option).data(item);
|
||||||
|
var children = item['children'];
|
||||||
|
if (!StringUtils.isEmpty(children)) {
|
||||||
|
$(option).attr("children", JSON.stringify(children));
|
||||||
|
}
|
||||||
|
opts.push(option);
|
||||||
|
//options += $(option)[0].outerHTML;
|
||||||
|
}
|
||||||
|
$(this).append(opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
})(jQuery);
|
||||||
|
/**与原生交互*/
|
||||||
|
(function ($) {
|
||||||
|
$.JkcsUtils = {
|
||||||
|
getUserLocation: function (callBack, params) {
|
||||||
|
if ($.QuickVersion["isWeb"]) {
|
||||||
|
jwd = "";
|
||||||
|
params["userMapInfo"] = jwd;
|
||||||
|
if (callBack)
|
||||||
|
callBack(params);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$.JkcsUtils.jsbridgeRegister("localCallBack",function(data){
|
||||||
|
var res = data;
|
||||||
|
if(res["longitude"]=='' && res["latitude"]==''){
|
||||||
|
var jwd = ''
|
||||||
|
}else{
|
||||||
|
var jwd = res["longitude"]+","+res["latitude"];
|
||||||
|
|
||||||
|
}
|
||||||
|
params["userMapInfo"] = jwd;
|
||||||
|
if(callBack)
|
||||||
|
callBack(params);
|
||||||
|
|
||||||
|
});
|
||||||
|
$.JkcsUtils.nativePermission({
|
||||||
|
"type": "location",
|
||||||
|
"callBackMethod": "localCallBack"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
/**跳转到首页的方法*/
|
||||||
|
gotoHome: function (options) {
|
||||||
|
if ($.QuickVersion["isWeb"]) {
|
||||||
|
location = options["url"];
|
||||||
|
} else {
|
||||||
|
// alert(JSON.stringify(options));
|
||||||
|
JSBridge.prototype.callHandler("gotoHome", options);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**收藏按钮图片加载*/
|
||||||
|
loadScImg: function (sfsc) {
|
||||||
|
if ($.QuickVersion["isWeb"]) {
|
||||||
|
if (sfsc == "delete") {
|
||||||
|
$(".sc-icon").removeAttr("style");
|
||||||
|
} else {
|
||||||
|
$(".sc-icon").attr("style", "background:url('/static/images/red-star.png') no-repeat;background-size: 100% 100%;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var params = {
|
||||||
|
"title": title
|
||||||
|
};
|
||||||
|
if (sfsc == "add") {
|
||||||
|
params["scImg"] = "sc_red";
|
||||||
|
} else {
|
||||||
|
params["scImg"] = "sc_white";
|
||||||
|
}
|
||||||
|
|
||||||
|
var option = $.JkcsTile.getTitle(titleType, params);
|
||||||
|
|
||||||
|
$.JkcsUtils.setHeader(option);
|
||||||
|
|
||||||
|
//JSBridge.prototype.callHandler("loadScImg", {sfsc: sfsc});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**jsbridge注册*/
|
||||||
|
jsbridgeRegister: function (funName, initFunction, params) {
|
||||||
|
if ($.QuickVersion["isApp"] || $.QuickVersion["isIOSApp"]) {
|
||||||
|
JSBridge.prototype.registerHandler(funName, initFunction, params);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**调用原生地图*/
|
||||||
|
gotoMap: function (params) {
|
||||||
|
if ($.QuickVersion["isApp"] || $.QuickVersion["isIOSApp"]) {
|
||||||
|
JSBridge.prototype.callHandler("forward", {
|
||||||
|
"type": "Native",
|
||||||
|
"toPage": "gotoMap",
|
||||||
|
"hasNavigation": "false",
|
||||||
|
"params": params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**设置头部*/
|
||||||
|
setHeader: function (params) {
|
||||||
|
// alert("进入setHeader");
|
||||||
|
if ($.QuickVersion["isIOSApp"]) {
|
||||||
|
// alert("进入app的判断");
|
||||||
|
JSBridge.prototype.callHandler("setHeader", params);
|
||||||
|
} else if ($.QuickVersion["isApp"]) {
|
||||||
|
if (window.WebViewJavascriptBridge) {
|
||||||
|
//do your work here
|
||||||
|
// appInit();
|
||||||
|
JSBridge.prototype.callHandler("setHeader", params);
|
||||||
|
} else {
|
||||||
|
document.addEventListener(
|
||||||
|
'WebViewJavascriptBridgeReady'
|
||||||
|
, function () {
|
||||||
|
// appInit();
|
||||||
|
JSBridge.prototype.callHandler("setHeader", params);
|
||||||
|
//do your work here
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**请求数据*/
|
||||||
|
requestData: function (params) {
|
||||||
|
if ($.QuickVersion["isApp"] || $.QuickVersion["isIOSApp"]) {
|
||||||
|
JSBridge.prototype.callHandler("requestData", params);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**请求数据*/
|
||||||
|
forward: function (params) {
|
||||||
|
if ($.QuickVersion["isApp"] || $.QuickVersion["isIOSApp"]) {
|
||||||
|
JSBridge.prototype.callHandler("forward", params);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**原生权限*/
|
||||||
|
nativePermission: function (params) {
|
||||||
|
console.log(params);
|
||||||
|
JSBridge.prototype.callHandler("nativePermission", params);
|
||||||
|
// if ($.QuickVersion["isApp"] || $.QuickVersion["isIOSApp"]) {
|
||||||
|
// JSBridge.prototype.callHandler("nativePermission", params);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(jQuery);
|
||||||
Loading…
Reference in New Issue