/*+++++通用函数脚本++++++++*/ var colorBackground = "#3255ee"; var colorTitle = "#FFFFFF"; var colorLine = "#323af1"; /** * APP 获取GPS位置 * @param {Object} callback 成功获取后回调 */ function plusGetLocation(callback) { mui.plusReady(function() { //获取位置信息 plus.geolocation.getCurrentPosition(function(position) { var lng = position.coords.longitude; var lat = position.coords.latitude; callback(lat, lng); }, function(e) { mui.alert(e.message); }, { provider: 'system', coordsType: 'wgs84', geocode: false, enableHighAccuracy: true, //这个布尔值用来表明应用是否使用其最高精度来表示结果。如果值为 true ,同时设备能够提供一个更精确的位置,那么设备就会使用这个位置 maximumAge: 0, //它表明可以返回多长时间(即最长年龄,单位毫秒)内的可获取的缓存位置。如果设置为 0, 说明设备不能使用一个缓存位置 }); }); } /** * 加载顶部导航栏 * @param {Object} title 导航栏标题 * @param {Object} showBackButton 导航栏是否具备返回按钮 */ function plusSetNavbar(title, showBackButton) { var ws = plus.webview.currentWebview(); //设置导航条 ws.setStyle({ "titleNView": { backgroundColor: colorBackground, titleText: title, titleColor: colorTitle, autoBackButton: showBackButton, splitLine: { color: colorLine } } }); } /** * 加载顶部导航栏 * @param {Object} title 导航栏标题 * @param {Object} showBackButton 导航栏是否具备返回按钮 */ function plusSetNavbarRef(title, showBackButton, callback) { var ws = plus.webview.currentWebview(); //设置导航条 ws.setStyle({ "titleNView": { backgroundColor: colorBackground, titleText: title, titleColor: colorTitle, autoBackButton: showBackButton, splitLine: { color: colorLine }, buttons: [{ 'float': 'right', fontSrc: '../fonts/iconfont.ttf', text: '\ueb73', onclick: callback, }] } }); } /** * UIWebView加载完成 大多数方法建议放到此处运行 * @param {Object} callback */ function UIView_DidLoad(callback) { mui.plusReady(function() { // var self = plus.webview.currentWebview(); // //添加显示监听 // self.addEventListener('show', function() { callback(); // }); }); } /** * 输出控制台消息 * @param {Object} msg 消息内容 */ function printToConsole(msg) { console.log(msg); } /** * 日期格式化 * @param {Object} fmt 格式化字符串 */ Date.prototype.Format = function(fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "H+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (( "00" + o[ k]).substr(("" + o[k]).length))); return fmt; } /** * @param {JSON} options 图片路径 * path{string}:图片路径 * lable{string}:文字描述 * click{function}:回调函数 */ function createBigMenu(options) { var li = document.createElement("li"); li.className = 'mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3'; var liHtml = ""; liHtml += "
"; li.innerHTML = liHtml; if (options.click != undefined) li.onclick = function() { options.click(); }; return li; } /** * @param {JSON} options 图片路径 * path{string}:图片路径 * lable{string}:文字描述 * click{function}:回调函数 */ function createSmartMenu(options) { var li = document.createElement("li"); li.className = 'mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3'; var liHtml = ""; liHtml += " "; li.innerHTML = liHtml; if (options.click != undefined) { li.onclick = function() { options.click('options'); }; } return li; } /** * 创建菜单Html * @param {JSON} options 图片路径 * path{string}:图片路径 * lable{string}:文字描述 * click{function}:回调函数 */ function createSmartMenuHtml(options) { var menuHtml = "