mobileclient/YT_Client_api.js

61 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-07-23 14:57:45 +08:00
/**
* @author 何杰
* @date 2016-08-01 12:00:00
* @address www.yitong.com.cn
* @mail hj@yitong.com.cn
* @desc: 屹通客户端组件api
*/
var Fw = {};
Fw.device = {};
Fw.device.Device = function () {
var userAgent = navigator.userAgent;
//ios 事件队列
var eventQueue = [];
return {
//是否iOS设备
is_ios: userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1,
//是否Android设备
is_android: userAgent.indexOf('Android') > -1,
/**
* ios
* 注册事件
* @param code 事件编码
* @param options 参数
*/
addEvent: function (code, options) {
if (options && code) {
eventQueue.push(JSON.stringify({
code: code,
name: options
}));
}
},
/**
* ios
* 原生调用从队列中获取事件
* @returns {string}
*/
getEvent: function () {
return eventQueue.length > 0 ? eventQueue.shift() : '0';
}
};
}();
/**
* 供第三方调用API
*/
Fw.device.api = function () {
var device = Fw.device.Device;
return {
/**
* @brief app跳转微信小程序
*/
openWXMiniProgram: function (param) {
if (!device.is_ios && !device.is_android) {
alert("请在ios/android设备上使用");
return;
}
device.is_ios && device.addEvent("openWXMiniProgram", JSON.stringify(param));
device.is_android && GetInfoJs.openWXMiniProgram(JSON.stringify(param));
},
}
}();