123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- /*+++++通用函数脚本++++++++*/
- 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 += "<div class='cr-menu-panel'>";
- liHtml += "<img src='" + options.path + "'>";
- liHtml += "<span>" + options.label + "</span>";
- liHtml += "</div>";
- 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 += "<div class='cr-menu-smart-panel'>";
- liHtml += "<img src='" + options.path + "'>";
- liHtml += "<span>" + options.label + "</span>";
- liHtml += "</div>";
- 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 = "<li class='mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3'";
- if(options.idx != undefined){
- menuHtml += " idx='" + options.idx + "'";
- }
- menuHtml += " onclick='" + options.click + "()'>";
- menuHtml += "<div class='cr-menu-smart-panel'>";
- menuHtml += "<img src='" + options.path + "'>";
- menuHtml += "<span>" + options.label + "</span>";
- menuHtml += "</div>";
- menuHtml += "</li>";
- return menuHtml;
- }
- /**
- * 创建并打开页面
- * @param {JSON} options 配置项
- * htmlPath{string}:页面路径
- * top{number/undefined 可选项}:窗口距离顶端高度
- * bottom{number/undefined 可选项}:窗口距离底部高度
- * backgroundColor{color 可选项}:导航栏背景色
- * lineColor{color 可选项}:导航栏底框颜色
- * title{string}:导航栏标题
- * statusbar:{boolean 可选项}:状态栏是否透明
- * extras{JSON 可选项}:传递参数
- * showSlide{string 可选项}:动画方式 slide-in-bottom
- * isShow{boolean}:是否默认显示
- */
- function createAndOpenPage(options) {
- var viewId = options.id == undefined ? options.htmlPath : options.id;
- UIView_DidLoad(function() {
- var pageConfig = {
- "titleNView": {
- backgroundColor: options.backgroundColor == undefined ? colorBackground : options
- .backgroundColor,
- titleColor: options.titleColor == undefined ? colorTitle : options.titleColor,
- autoBackButton: options.autoback == undefined ? false : options.autoback,
- titleText: options.title,
- splitLine: {
- color: options.lineColor == undefined ? colorLine : options.lineColor,
- }
- },
- top: options.top == undefined ? '0' : options.top,
- bottom: options.bottom == undefined ? '0' : options.bottom,
- contentAdjust: false
- }
- /* 判断是否增加了按钮配置 */
- if (options.buttons != undefined) {
- pageConfig.titleNView.buttons = options.buttons;
- }
- /* 配置sttusbar 主要是为了配置任务栏的背景色 */
- if (options.statusbar != undefined && !options.statusbar) {
- pageConfig.statusbar = {
- background: colorBackground,
- }
- }
- /* 判断是否设置了高度 */
- if (options.height != undefined) {
- pageConfig.height = options.height;
- }
- /* 根据是否传参决定采用何种方式加载 */
- var subPage = undefined;
- if (options.extras != undefined) {
- subPage = plus.webview.create(options.htmlPath, viewId, pageConfig, options.extras);
- } else {
- subPage = plus.webview.create(options.htmlPath, viewId, pageConfig);
- }
- subPage.onloaded = function(e) {
- if (options.onloaded != undefined) options.onloaded(subPage);
- }
- /* 是否显示 */
- if (options.isShow == undefined || options.isShow == true) {
- /* 显示动画 */
- if (options.showSlide == undefined) {
- subPage.show('slide-in-right', 300);
- } else {
- subPage.show(options.showSlide, 300);
- }
- } else {
- subPage.hide();
- }
- });
- }
- /**
- * 获取值 对0值进行特殊处理
- * @param {string} strValue 字符串或其他
- */
- function getEChartsValue(strValue) {
- var value = parseFloat(strValue)
- if (value == 0) {
- return 0.1;
- } else {
- return value;
- }
- }
- /**
- * 验证Ip地址
- * @param {string} ip 输入的ip地址
- */
- function isValidIP(ip) {
- var reg =
- /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
- return reg.test(ip);
- }
- /**
- * 验证Com端口号
- * @param {string} com 输入的com端口号
- */
- function isValidCom(com) {
- var reg =
- /^(\d{4,4})$/
- return reg.test(com);
- }
- /**
- * 验证电话号码
- * @param {string} phoneNumber 输入的电话号码
- */
- function isValidPhone(phoneNumber) {
- var reg =
- /^(\d{11,11})$/
- return reg.test(phoneNumber);
- }
|