/*+++++通用函数脚本++++++++*/ var colorBackground = "#243f6d"; // 3255ee var colorBackground01 = "#243f6dDD"; // 3255ee var colorTitle = "#FFFFFF"; var colorLine = "#00323af1"; var eChartsResetTime = 50000; //统计图表重制时间周期 /* +++++++++++屏幕适配++++++++++ */ var PageSize = { smartSize: 600, middleSize: 1400, } /** * 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); callback(35.159, 118.203) }, function(e) { mui.alert(e.message); }, { provider: 'system', coordsType: 'wgs84', geocode: false, enableHighAccuracy: true, //这个布尔值用来表明应用是否使用其最高精度来表示结果。如果值为 true ,同时设备能够提供一个更精确的位置,那么设备就会使用这个位置 maximumAge: 0, //它表明可以返回多长时间(即最长年龄,单位毫秒)内的可获取的缓存位置。如果设置为 0, 说明设备不能使用一个缓存位置 }); }); } /* 方向监听标识Id */ let watchOrientationId = undefined; /** * 开启方向变化监听 * @param {Function} callChange 变化回调callChange(角度) */ function plusOrientationListenerOn(callChange) { mui.plusReady(function() { watchOrientationId = plus.orientation.watchOrientation(function(o) { // console.log("精度指标 = " + o.headingAccuracy); if (callChange) callChange(o.trueHeading); }, function(err) { console.log("方向错误 = " + e.message); }, { frequency: 100, }); }) } /** * 关闭方向监听 * @param {Function} callCompletion 完成回到callCompletion() */ function plusOrientationListenerOff(callCompletion) { if (watchOrientationId) { plus.orientation.clearWatch(watchOrientationId); watchOrientationId = undefined; if (callCompletion) callCompletion(); } } /* GPS位置监听 */ let watchGpsId = undefined; /** * 开启GPS位置变化监听 * @param {Function} callChange GPS位置变化回调callChange(纬度,经度); */ function plusGPSListenerOn(callChange, callError) { mui.plusReady(function() { watchGpsId = plus.geolocation.watchPosition(function(p) { if (callChange) callChange(p.coords.latitude, p.coords.longitude); }, function(err) { if (callError) callError('GPS定位失败,请确保开启定位服务及权限!'); console.log('定位错误 = ' + err.message); }, { provider: 'system', coordsType: 'wgs84', geocode: false, enableHighAccuracy: true, //这个布尔值用来表明应用是否使用其最高精度来表示结果。如果值为 true ,同时设备能够提供一个更精确的位置,那么设备就会使用这个位置 maximumAge: 0, //它表明可以返回多长时间(即最长年龄,单位毫秒)内的可获取的缓存位置。如果设置为 0, 说明设备不能使用一个缓存位置 }); }) } /** * 关闭GPS位置监听 * @param {Function} callCompletion 完成回到callCompletion() */ function plusGPSListenerOff(callCompletion) { if (watchGpsId) { plus.geolocation.clearWatch(watchGpsId); watchGpsId = undefined; if (callCompletion) callCompletion(); } } /** * 加载顶部导航栏 * @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 += "
"; liHtml += ""; liHtml += "" + options.label + ""; 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 += "
"; liHtml += ""; liHtml += "" + options.label + ""; 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 = "
  • "; menuHtml += "
    "; menuHtml += ""; menuHtml += "" + options.label + ""; menuHtml += "
    "; menuHtml += "
  • "; 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.addEventListener('show', function() { // subPage.evalJS('pageFirstShow()'); // }, false); 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(); } if (options.success != undefined) options.success(subPage); }); } /** * 获取值 对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); } /** * 获取配置信息 * @param {function} callback 回调函数 */ function getConfigInfo(callback) { mui.plusReady(function() { plus.runtime.getProperty(plus.runtime.appid, function(info) { plus.io.resolveLocalFileSystemURL('_www/manifest.json', function(entry) { entry.file(function(file) { var fileReader = new plus.io.FileReader(); fileReader.readAsText(file, 'utf-8'); fileReader.onloadend = function(evt) { var data = JSON.parse(evt.target.result); if (callback != undefined) { callback({ appid: info.appid, version: info.version, versionCode: info.versionCode, name: info.name, devName: data.developer.name, devUrl: data.developer.url, devEmail: data.developer.email, devPhone: data.developer.phone, devTel: data.developer.tel, devCopyright: data.developer.copyright, }) } } }, function(err) { printToConsole("读取文件错误:" + JSON.stringify(err)); }); }, function(err) { printToConsole("获取文件错误:" + JSON.stringify(err)); }); }); }); } /** * 生成随机颜色 * @param {Array} red [0~255,0~255] * @param {Array} green [0~255,0~255] * @param {Array} blue [0~255,0~255] * return rgb(r,g,b) */ function randomRgbColor(red, green, blue) { //随机生成RGB颜色 var rStart = red[1] - red[0]; var gStart = green[1] - green[0]; var bStart = blue[1] - blue[0]; var r = Math.floor(Math.random() * rStart + red[0]); //随机生成256以内r值 var g = Math.floor(Math.random() * gStart + green[0]); //随机生成256以内g值 var b = Math.floor(Math.random() * bStart + blue[0]); //随机生成256以内b值 var color = 'rgb(' + r + ',' + g + ',' + b + ')'; return color; //返回rgb(r,g,b)格式颜色 } /** * 显示顶部日期+时间 */ var strDate = ''; /** * 内部函数 * 显示当前日期和时间 */ function _showTopTime() { /* 修改展示方式 */ var strDay = new Date().Format('dd'); var strYearAndMonth = new Date().Format('yyyy.MM') var strYear = new Date().Format('yyyy') var strMonth = new Date().Format('MM') var strDay = new Date().Format('dd') var china = calendar.solar2lunar(strYear, strMonth, strDay); var chinaDay = " 农历" + china.Animal + "年" + china.IMonthCn + china.IDayCn + " " + china.ncWeek; var time = new Date().Format('HH:mm:ss'); var timeHtml = ""; timeHtml += "" + strDay + ""; timeHtml += "" + strYearAndMonth + ""; timeHtml += "" + chinaDay + ""; timeHtml += "" + time + ""; $('.topTime').html(timeHtml); } /** * 开始显示日期 */ function beginShowTime() { _showTopTime(); window.setInterval(_showTopTime, 1000); } /** * 创建轮播项 * @param {string} imgPath 图片路径 * @param {boolean} isFistOrLast 是否是第一项或最后一项 */ function _createSliderItemHtml(imgPath, isFistOrLast) { var divHtml = ""; if (isFistOrLast) { divHtml += "
    "; } else { divHtml += "
    "; } divHtml += ""; divHtml += ""; divHtml += ""; divHtml += "
    "; return divHtml; } /** * 根据图片路径数组初始化轮播内容 * @param {string} sliderId 轮播容器Id * @param {Array} sliderImages 轮播图片路径数组 */ function _initSliderContent(sliderId, sliderImages) { var sliderHtml = ""; //轮播内容 var indicatorHtml = ""; //轮播指示器内容 /* 额外增加的一个节点(循环轮播:第一个节点是最后一张轮播) */ sliderHtml += _createSliderItemHtml(sliderImages[sliderImages.length - 1], true); for (var i = 0; i < sliderImages.length; i++) { sliderHtml += _createSliderItemHtml(sliderImages[i], false); if (i === 0) indicatorHtml += "
    "; else indicatorHtml += "
    "; } /* 额外增加的一个节点(循环轮播:最后一个节点是第一张轮播) */ sliderHtml += _createSliderItemHtml(sliderImages[0], false); /* 组合展示 */ var strHtml = "
    "; strHtml += sliderHtml; strHtml += "
    "; strHtml += "
    "; strHtml += indicatorHtml; strHtml += "
    "; $("#" + sliderId).html(strHtml); } /** * 启动图片轮播 * @param {string} sliderId 轮播容器Id * @param {Array} imagePaths 图片路径数组 * @param {int} sliderTimespan 轮播时间间隔 0 代表不轮播 */ function beginSliderContent(sliderId, imagePaths, sliderTimespan) { _initSliderContent(sliderId, imagePaths); /* 自动轮播 */ var slider = mui('#' + sliderId); if (sliderTimespan > 0) { slider.slider({ interval: sliderTimespan, }); } } /** * 设置样式中变量的值 * @param {string} variable 变量 * @param {string} value 值 */ function setPropertyFromStyle(variable, value) { document.documentElement.style.setProperty(variable, value); } /* 给选择类型按钮添加监听 */ function addListenerToSelectButton(btnDomId, config) { var btn = $("#" + btnDomId)[0]; btn.addEventListener('tap', function() { var _self = this; if (_self.picker) { _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); $(_self).attr('data-code', selectItems[0].value); }); } else { _self.picker = new mui.PopPicker({ buttons: ['清除', '使用'] }); _self.picker.setData(config); _self.picker.cancel.addEventListener('tap', function() { $(_self).html($(_self).attr('value')); $(_self).attr('data-value', ""); $(_self).attr('data-code', ""); }) _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); $(_self).attr('data-code', selectItems[0].value); }); } }) } /** * * @param {string} btnDomId 需要绑定的选择器Id * @param {string} tabName 选择器关联的表名 * @param {string} fldName 选择器关联的字段名 * @param {function} callback 选择回调函数 */ function bindListenerToSelectButton(btnDomId, tabName, fldName, callback) { var btn = $("#" + btnDomId)[0]; btn.addEventListener('tap', function() { var _self = this; /* 首先进行查询 */ querySimpleFieldInfo(tabName, fldName, function(config) { if (_self.picker) { _self.picker.setData(config); _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); $(_self).attr('data-code', selectItems[0].value); if (callback) callback(selectItems[0].text, selectItems[0].value); }); } else { _self.picker = new mui.PopPicker({ buttons: ['清除', '使用'] }); _self.picker.setData(config); _self.picker.cancel.addEventListener('tap', function() { $(_self).html($(_self).attr('value')); $(_self).attr('data-value', ""); $(_self).attr('data-code', ""); }) _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); $(_self).attr('data-code', selectItems[0].value); if (callback) callback(selectItems[0].text, selectItems[0].value); }); } }); }) } /** * 绑定日期控件 * @param {string} btnDomId 需要绑定的选择器Id * @param {function} callback 选择回调函数 */ function bindListenerToDateButton(btnDomId, callback) { var btn = $("#" + btnDomId)[0]; btn.addEventListener('tap', function() { var _self = this; if (_self.picker) { _self.picker.show(function(selectItems) { $(_self).html(selectItems.text); $(_self).attr('data-value', selectItems.text); $(_self).attr('data-code', selectItems.value); _self.picker.dispose(); _self.picker = null; if (callback) callback(selectItems.text, selectItems.value); }); } else { /* 获取存储的值 */ let value = $(_self).attr("data-value") || ''; // console.log("存储 = " + value); _self.picker = new mui.DtPicker({ buttons: ['清除', '使用'], type: 'date', beginDate: new Date('1990', '1', '1'), endDate: new Date('2050', '12', '31'), value: value, }); _self.picker.ui.cancel.addEventListener('tap', function() { $(_self).html($(_self).attr('value')); $(_self).attr('data-value', ""); $(_self).attr('data-code', ""); }); _self.picker.show(function(selectItems) { $(_self).html(selectItems.text); $(_self).attr('data-value', selectItems.text); $(_self).attr('data-code', selectItems.value); _self.picker.dispose(); _self.picker = null; if (callback) callback(selectItems.text, selectItems.value); }); } }) } /** * 查询单字段信息 * @param {string} tabName 表名称 * @param {string} fldName 字段名称 * @param {function} callSuccess 成功回调函数 */ function querySimpleFieldInfo(tabName, fldName, callSuccess) { var iData = { tabName: tabName, fldName: fldName, } /* 查询结果 */ var result = []; /* 开始联网查询 */ sendAjax({ waitMessate: '同步数据...', url: 'appQuerySimpleFiled', data: iData, success: function(resData) { for (var i in resData) { result.push({ value: resData[i].selCode, text: resData[i].selName, }) } if (callSuccess != undefined) callSuccess(result); }, error: function(err) { muiAlertError(err); } }) } /** * 清除选择器 * @param {string} btnDomId 选择控件Id */ function clearSelectButton(btnDomId) { console.log("调用清除!"); var _self = document.getElementById(btnDomId); if (_self.picker) { _self.picker.setData([]); } $(_self).html($(_self).attr('value')); $(_self).attr('data-value', ""); $(_self).attr('data-code', ""); } /** * 联网获取并设置单项选择器 * @param {JSON} options * tabName{string}:表名称 * fldName{string}:字段名称 * btnDomId{string}:挂接容器 */ function setSimpleConfig(options) { var iData = { tabName: options.tabName, fldName: options.fldName, } var btn = $("#" + options.btnDomId)[0]; var dataConfig = []; sendAjax({ waitMessate: '同步数据...', url: 'appQuerySimpleFiled', data: iData, success: function(resData) { for (var i in resData) { dataConfig.push({ value: resData[i].selCode, text: resData[i].selName, }) } btn.addEventListener('tap', function() { var _self = this; if (_self.picker) { _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); }); } else { _self.picker = new mui.PopPicker({ buttons: ['清除', '使用'] }); _self.picker.setData(dataConfig); _self.picker.cancel.addEventListener('tap', function() { $(_self).html($(_self).attr('value')); $(_self).attr('data-value', ""); }) _self.picker.show(function(selectItems) { $(_self).html(selectItems[0].text); $(_self).attr('data-value', selectItems[0].text); }); } }) if (options.success != undefined) options.success(); }, error: function(err) { if (options.error != undefined) options.error(err); } }) } /** * 定位图斑 * @param {string} longitude 经度 * @param {string} latitude 纬度 * @param {string} title 标题 */ function toMapLocation(longitude, latitude, title) { var lMapId = 'FeatureLocationByMap'; /* 启动定位之前判断是否存在 */ mui.plusReady(function() { var mapPageView = plus.webview.getWebviewById(lMapId); if (mapPageView != null) { plus.webview.show(mapPageView, 'slide-in-right', 300, function() { mapPageView.evalJS("jsLocation('" + longitude + "','" + latitude + "','" + title + "')") }); } else { muiAlert("地图页面尚未加载,请稍后重试!"); } }); } /** * 通过表名和要素Id定位图斑要素 * @param {string} tabName 经度 * @param {string} feaId 纬度 * @param {string} title 标题 */ function toMapLocation_tabName_feaId(tabName, feaId, title) { var lMapId = 'FeatureLocationByMap'; /* 启动定位之前判断是否存在 */ mui.plusReady(function() { var mapPageView = plus.webview.getWebviewById(lMapId); if (mapPageView != null) { plus.webview.show(mapPageView, 'slide-in-right', 300, function() { mapPageView.evalJS("jsLocation_tabName_feaId('" + tabName + "','" + feaId + "','" + title + "')"); }); } else { muiAlert("地图定位页面异常,请稍后重试!"); } }); } /** * 启动App * @param {string} appId App的Id * @param {string} appName App的名称 */ function beginApp(appId, appName) { mui.plusReady(function() { if (plus.runtime.isApplicationExist({ pname: appId })) { plus.runtime.launchApplication({ pname: appId, }, function(e) { muiAlertError("启动失败:" + e.message); }); } else { muiAlert('您尚未安装' + appName + ',请安装后重试!', "警告") } }); } /** * 获取页面的宽、高 */ function getPageSize() { return { width: document.body.clientWidth, height: document.body.clientHeight } } /** * 显示完整内容 * @param {string} content */ function showContent(content) { muiAlert(content, "提示"); } /** * 文本循环移动动画 适用于容器内展示span且span宽度超过div宽度 * @param {string} domId 容器Id * @param {int} time 动画时间,单位ms */ function textMoveAnimateById(domId, time) { var obj = $("#" + domId); var widthSpan = $("#" + domId + ">span").width(); var widthMove = widthSpan - obj.width(); obj.scrollLeft(0); obj.animate({ scrollLeft: widthMove, }, time, 'linear', function() { textMoveAnimateById(domId, time); }); } /** * 文本循环移动动画 适用于容器内展示span且span宽度超过div宽度 * @param {string} selector 容器选择器 * @param {int} time 动画时间,单位ms */ function textMoveAnimateBySelector(selector, time) { var obj = $("." + selector); var widthSpan = $('.' + selector + ">span").width(); console.log(widthSpan); var widthMove = widthSpan - obj.width(); obj.scrollLeft(0); obj.animate({ scrollLeft: widthMove, }, time, 'linear', function() { textMoveAnimateBySelector(selector, time); }); } /** * 获取通过URL传递的参数 * main.html?key=124 * @param {string} name 关键字 * @return {string} 未获取到返回null 否则返回值 */ function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } /** * 绑定搜索框 通过绑定监听 获取查询内容 * @param {string} controlID 搜索框ID * @param {function} callback 返回监听 */ function bindSearchControlEvent(controlID, callback) { var self = this; /** * 搜索框追加事件 */ document.getElementById(controlID).addEventListener('keypress', function(e) { //判断点击的是否是 搜索 按钮 if (e.keyCode == 13) { var value = this.value; document.activeElement.blur(); if (callback != undefined) callback(value); } }); } /** * 获取dom的属性值 * @param {Object} domId * @param {Object} attrName */ function getAttributeValue(domId, attrName) { var value = $("#" + domId).attr(attrName); if (value == undefined) return ""; else return value; } /** * 打开侧滑菜单 */ function openMainMenu() { mui('.mui-off-canvas-wrap').offCanvas('show'); } /** * 关闭侧滑菜单 */ function closeMainMenu() { mui('.mui-off-canvas-wrap').offCanvas('close'); } /** * 给类添加点击事件 * @param {string} className 类名称 */ function appendClickEventByClassName(className) { $("." + className).each(function(index, element) { $("." + className)[index].addEventListener('tap', function() { muiAlert($(this).text(), '详细内容'); }) }) } /** * 显示内容 * @param {Object} obj 显示内容的容器 */ function showDetails(obj) { muiAlert($(obj).text(), '详细内容'); } /** * 重置图表的尺寸 */ function echartsSizeInit() { $(".jt-count-echarts-panel .jt-content").each(function(index, element) { var echartsDom = $(".jt-count-echarts-panel .jt-content")[index]; var width = $(echartsDom).width(); var height = $(echartsDom).height(); if (height < 10) { $(echartsDom).height(width * 3 / 4); } }); } /* +++++++++++++++++地块公用+++++++++++++++++++++ */ /** * 查询地块数据 * @param {string} title 标题 * @param {string} tabName 数据表名称 * @param {string} fldName 字段名称 * @param {string} fldValue 字段值 * @param {string} showFldName 展示字段名称 */ function queryFeatures(title, tabName, fldName, fldValue, showFldName) { var iData = { tabName: tabName, fldName: fldName, fldValue: fldValue, queryType: 'equal', showFldName: showFldName === undefined ? '' : showFldName, start: '1', count: '100', } sendAjax({ url: 'appQueryFeatureData', data: iData, waitMessage: '查询中...', success: function(resData) { var data = resData[0]; if (data.dataCount == 0) { muiAlert('未查询到任何数据!', '警告'); } else { showFeaturesResult(title, data); } }, error: function(err) { muiAlertError(err); } }) } /** * 地块数据展示 * @param {string} title 标题 * @param {JSON} jsonData 数据集 */ function showFeaturesResult(title, jsonData) { /* 判断容器是否存在 */ var rootPanel = document.getElementById('queryResultPopover'); if (rootPanel) { $(rootPanel).html(''); } else { rootPanel = document.createElement('div'); rootPanel.id = 'queryResultPopover'; rootPanel.className = 'mui-popover mui-popover-action mui-popover-bottom jt-query-result-popover'; document.body.append(rootPanel); } /* 创建标题头 */ var header = document.createElement('header'); header.className = 'mui-bar'; header.innerHTML = "
    " + title + '
    查询结果'; rootPanel.append(header); /* 创建内容容器 */ var divScroll = document.createElement('div'); divScroll.className = 'mui-scroll-wrapper'; rootPanel.append(divScroll); /* 创建滚动子容器 */ var divScrollChild = document.createElement('div'); divScrollChild.className = 'mui-scroll'; divScroll.append(divScrollChild); /* 创建查询结果根容器 */ var divRoot = document.createElement('div'); divRoot.className = 'mui-card'; divScrollChild.append(divRoot); /* 加入数据 */ for (var i in jsonData.dataList) { var item = jsonData.dataList[i]; var divItem = document.createElement('div'); if (i % 2 == 0) { divItem.className = 'jt-feature-data-row jt-row-even-number'; } else { divItem.className = 'jt-feature-data-row jt-row-odd-number'; } divRoot.append(divItem); var html = ""; html += "" + item.feaNumber + ""; html += "" + item.feaName + ""; html += "" + item.feaArea + "亩"; html += "