// 路由的配置
|
var routers = [
|
{
|
path: '/',
|
componentUrl: "./pages/main/index.html"
|
},
|
{ // 登陆
|
path: '/login/',
|
componentUrl: "./pages/main/login.html"
|
},
|
{ // 首页
|
path:'/home/',
|
componentUrl: "./pages/main/home.html",
|
},
|
{ // 数据分析
|
path: '/data/main/',
|
componentUrl: "./pages/main/data.html",
|
},
|
{ // 数据分析
|
path: '/chat/',
|
componentUrl: "./pages/main/chat.html",
|
},
|
{
|
path: '/monitor/',
|
routes:[
|
{ // 数据监控
|
path: 'main/',
|
componentUrl: "./pages/main/monitor.html",
|
},
|
{ // 电池组列表
|
path: 'batt/:province/:city/:county/:home/:homeid/',
|
componentUrl: "./pages/monitor/batt.html"
|
},
|
{ // 电池组功能
|
path: 'index/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
|
componentUrl: "./pages/monitor/index.html",
|
},
|
{ // 实时监测
|
path: 'control/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
|
componentUrl: "./pages/monitor/control.html"
|
},
|
{ // 核容参数设置
|
path: 'nuclear/param/set/:home/:fbsid/:stationid/:groupid/',
|
componentUrl: './pages/monitor/nuclear-param-set.html'
|
},
|
{ // 电池参数设置
|
path: 'batt/param/set/:home/:fbsid/:stationid/:groupid/',
|
componentUrl: './pages/monitor/batt-param-set.html'
|
},
|
{ // 系统参数设置
|
path: 'sys/param/set/:home/:fbsid/:stationid/:groupid/',
|
componentUrl: './pages/monitor/sys-param-set.html'
|
},
|
{ // 电池参数
|
path: 'batt/param/:fbsid/:stationid/',
|
componentUrl: './pages/monitor/batt-param.html'
|
},
|
{ // 系统参数
|
path: 'sys/param/:fbsid/:stationid/',
|
componentUrl: './pages/monitor/sys-param.html'
|
},
|
{
|
// 单体电压
|
path: 'batt/mon/vol/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
|
componentUrl: './pages/monitor/batt-mon-vol.html'
|
},
|
{
|
// 单体温度
|
path: 'batt/mon/tmp/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
|
componentUrl: './pages/monitor/batt-mon-tmp.html'
|
},
|
{
|
// 单体内阻
|
path: 'batt/mon/res/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
|
componentUrl: './pages/monitor/batt-mon-res.html'
|
},
|
{
|
// 单体电导
|
path: 'batt/mon/cond/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
|
componentUrl: './pages/monitor/batt-mon-cond.html'
|
},
|
{ // 历史监测
|
path: 'history/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
|
componentUrl: "./pages/monitor/history.html"
|
},
|
{ // 历史放电测试数据
|
path: 'history/data/:groupid/:groupname/:count/:capstd/:volstd/',
|
componentUrl: "./pages/monitor/history-data.html",
|
tabs:[
|
{
|
path: '/',
|
id: 'monVol'
|
},
|
{
|
path: '/common-bar/',
|
id: 'commonBar'
|
},
|
|
{
|
path: '/common-line/',
|
id: 'commonLine'
|
}
|
]
|
},
|
{ // 电池信息
|
path: 'batt/group/info/:groupid/',
|
componentUrl: './pages/monitor/batt-group-info.html'
|
},
|
{
|
// 添加机房
|
path: 'add/home/:battnum/',
|
componentUrl: "./pages/monitor/add-home.html"
|
},
|
{ // 基站信息
|
path: 'home/:stationid/'
|
}
|
]
|
},
|
{
|
path: '/data/:province/:city/:county/:home/:fbsid/:stationid/',
|
componentUrl: './pages/data/index.html',
|
routes: [
|
{ // 电池信息统计查询
|
path: 'batt-info/',
|
componentUrl: './pages/data/batt-info.html'
|
},
|
{ // 电池组信息统计查询
|
path: 'group-info/',
|
componentUrl: './pages/data/group-info.html'
|
},
|
{ // 电池单体统计分析查询
|
path: 'mon-info/',
|
componentUrl: './pages/data/batt-mon-info.html'
|
},
|
]
|
},
|
{ // 基站信息(style标记的是页面返回类型back或者popup-close)
|
path: '/data/home/info/:stationid/:style',
|
componentUrl: "./pages/data/home-info.html"
|
},
|
{
|
path: '/warn/:province/:city/:county/:home/:fbsid/:stationid/',
|
componentUrl: './pages/warn/index.html',
|
routes: [
|
{
|
path: 'control/',
|
componentUrl: './pages/warn/control.html'
|
}
|
]
|
},
|
{
|
path: '/panel/left/',
|
componentUrl: "./pages/panel/panel-left-page.html"
|
},
|
{
|
path: '/panel/right/',
|
componentUrl: "./pages/panel/panel-right-page.html"
|
},
|
{
|
path:'/data/popup/',
|
popup: {
|
id: 'popupData',
|
}
|
},
|
{
|
path: '(.*)',
|
url: './pages/404.html',
|
},
|
];
|
|
var monthNames = monthNamesShort = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月' , '9月' , '10月', '11月', '12月'];
|
var dayNames = dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
|
|
// 定义Dom7
|
var $$ = Dom7;
|
|
// 根据id和数据获取模板生成的html
|
function getTplHtml(id, data) {
|
var tpl = $$(id).html();
|
var compiledTpl = Template7.compile(tpl);
|
var tplHtml = compiledTpl(data);
|
return tplHtml;
|
}
|
|
// 根据数据生成列表
|
function createList(container, data) {
|
container.text("");
|
for(var i=0; i<data.length;i++) {
|
var _data = data[i];
|
var li = $$('<li></li>');
|
var a = $$('<a href="#" class="home-item"></a>');
|
a.text(_data.text);
|
a.data('data', _data);
|
li.append(a);
|
container.append(li);
|
}
|
}
|
|
// 在tab中view检测是否被显示
|
function viewCheckStatus(view) {
|
var status = false;
|
if($$(view).hasClass("tab-active")) {
|
status = true;
|
}
|
return status;
|
}
|
|
//开启页面是否在运行
|
function setIsRun(page, id) {
|
page.isRun = viewCheckStatus(id);
|
// 定义计时器查看当前page所在的view是否显示
|
var interval = setInterval(function(){
|
page.isRun = viewCheckStatus(id);
|
}, 100);
|
}
|
|
function PieEcharts(id) {
|
this.$el = $("#"+id);
|
this.chart="";
|
this._init();
|
};
|
PieEcharts.prototype._init = function() {
|
var graph = this.$el.find('.graph').get(0);
|
this.chart = echarts.init(graph);
|
this.chart.showLoading();
|
};
|
PieEcharts.prototype.resize = function() {
|
this.chart.resize();
|
};
|
PieEcharts.prototype.setOption = function(props) {
|
var defaultPorps = {
|
title: "",
|
subtitle: "",
|
x: "center",
|
name: "未知",
|
legendData: [],
|
seriesData: [],
|
color:[]
|
};
|
|
var data = $.extend({}, defaultPorps, props);
|
|
this.chart.hideLoading(); // 关闭等待框
|
|
var option = {
|
// #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
|
color: function() {
|
var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
|
for(var i = data.color.length; i>0; i--) {
|
var _color = data.color[i-1];
|
color.unshift(_color);
|
}
|
return color;
|
}(),
|
title : {
|
text: data.title,
|
subtext: data.subtitle,
|
x: data.x
|
},
|
toolbox: {
|
show: true,
|
feature : {
|
mark : {show: true},
|
dataView : {show: true, readOnly: true},
|
magicType : {
|
show: true,
|
type: ['pie', 'funnel']
|
}
|
}
|
},
|
tooltip : {
|
trigger: 'item',
|
formatter: "{a} <br/>{b} : {c} ({d}%)"
|
},
|
legend: {
|
orient: 'vertical',
|
right: 10,
|
top: 20,
|
bottom: 20,
|
//data: data.legendData,
|
},
|
series : [
|
{
|
name: data.name,
|
type: 'pie',
|
radius : '55%',
|
center: ['50%', '50%'],
|
data: data.seriesData,
|
itemStyle: {
|
emphasis: {
|
shadowBlur: 10,
|
shadowOffsetX: 0,
|
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
}
|
}
|
}
|
]
|
};
|
|
// 生成echarts
|
this.chart.setOption(option);
|
};
|
|
function BarEcharts(id) {
|
this.$el = $("#"+id);
|
this.chart="";
|
this.props = "";
|
this._init();
|
};
|
BarEcharts.prototype._init = function() {
|
var graph = this.$el.find('.graph').get(0);
|
this.chart = echarts.init(graph);
|
this.chart.showLoading();
|
};
|
BarEcharts.prototype.resize = function() {
|
this.chart.resize();
|
this.setOption(this.props);
|
};
|
BarEcharts.prototype.setOption = function(props) {
|
var defaultPorps = {
|
title: "",
|
subtitle: "",
|
x: "center",
|
name: "未知",
|
legendData: [],
|
seriesData: [],
|
yData: [],
|
color:[]
|
};
|
|
var data = $.extend({}, defaultPorps, props);
|
this.chart.hideLoading(); // 关闭等待框
|
this.props = data;
|
|
var max = Math.max.apply(null, props.seriesData);
|
var min = Math.min.apply(null, props.seriesData);
|
var maxflag = true;
|
var minflag = true;
|
var option = {
|
// #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
|
color: function() {
|
var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
|
for(var i = data.color.length; i>0; i--) {
|
var _color = data.color[i-1];
|
color.unshift(_color);
|
}
|
return color;
|
}(),
|
title : {
|
text: data.title,
|
subtext: data.subtitle,
|
x: data.x
|
},
|
tooltip : {
|
trigger: 'axis',
|
axisPointer: {
|
type: 'shadow'
|
}
|
},
|
legend: {
|
left: '3%',
|
right: '4%',
|
bottom: '3%',
|
containLabel: true
|
},
|
xAxis: {
|
type: 'value',
|
max: (max*1.05).toFixed(2),
|
min: (min*0.8).toFixed(2),
|
boundaryGap: [0, 0.01]
|
},
|
yAxis: {
|
type: 'category',
|
inverse: true,
|
data: data.yData
|
},
|
series : [
|
{
|
name: data.name,
|
type: 'bar',
|
data: data.seriesData,
|
itemStyle: {
|
normal: {
|
label:{
|
show: false,
|
position: 'top',
|
fontSize:11
|
},
|
color: function setcolor(value) {
|
if(maxflag==true && value.value==max)
|
{
|
maxflag=false;
|
return 'green';
|
}
|
else if(minflag==true && value.value==min)
|
{
|
minflag=false;
|
return 'red';
|
}else
|
{
|
return '#b4d3fa'; //设置为普通的颜色
|
}
|
}
|
}
|
|
}
|
}
|
]
|
};
|
this.chart.resize();
|
// 生成echarts
|
this.chart.setOption(option);
|
};
|
|
// 折线图
|
function LineEcharts(id) {
|
this.$el = $("#"+id);
|
this.chart="";
|
this.props = "";
|
this._init();
|
};
|
LineEcharts.prototype._init = function() {
|
var graph = this.$el.find('.graph').get(0);
|
this.chart = echarts.init(graph);
|
this.chart.showLoading();
|
};
|
LineEcharts.prototype.resize = function() {
|
this.chart.resize();
|
this.setOption(this.props);
|
};
|
LineEcharts.prototype.setOption = function(props, container) {
|
// 默认配置项
|
var defaultPorps = {
|
title: "",
|
subtitle: "",
|
x: "center",
|
name: [],
|
legendData: [],
|
seriesData: [],
|
xData: [],
|
color:[]
|
};
|
|
var data = $.extend({}, defaultPorps, props);
|
this.props = data;
|
//console.log(data);
|
var max = getMaxFromArr(data.seriesData);
|
var min = getMinFromArr(data.seriesData);
|
|
var option = {
|
// #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
|
color: function() {
|
var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
|
for(var i = data.color.length; i>0; i--) {
|
var _color = data.color[i-1];
|
color.unshift(_color);
|
}
|
return color;
|
}(),
|
tooltip:{
|
trigger: 'axis'
|
},
|
title : {
|
text: data.title,
|
subtext: data.subtitle,
|
x: data.x
|
},
|
calculable :true,
|
grid: {
|
left: '1%',
|
right: '5%',
|
bottom: '2%',
|
containLabel: true
|
},
|
xAxis: {
|
data: data.xData
|
},
|
yAxis: [{
|
type: 'value',
|
min: Math.floor(min-1),
|
max: Math.ceil(max+1),
|
precision:2,
|
axisLabel:{
|
formatter:function(value){
|
//解决原点处带符号问题
|
if(value==0)
|
{
|
return value;
|
}else{
|
return value ;
|
}
|
}
|
}
|
}],
|
series: function() {
|
var series = [];
|
for(var i=0; i<data.name.length; i++) {
|
var _name = data.name[i];
|
var _data = data.seriesData[i];
|
var tmp = {
|
name: _name,
|
type: 'line',
|
symbol:'none',
|
data: _data,
|
itemStyle:{
|
normal:{
|
lineStyle:{
|
width:2
|
}
|
}
|
}
|
};
|
series.push(tmp);
|
}
|
return series;
|
}()
|
};
|
//console.log(option);
|
this.chart.hideLoading(); // 关闭等待框
|
this.chart.resize();
|
// 生成echarts
|
this.chart.setOption(option);
|
};
|
|
// 生成特殊的折线图
|
function LineEcharts2(id, container) {
|
this.$el = $("#"+id);
|
this.$cont = '';
|
this.chart="";
|
this.props = "";
|
// 设置外层容器
|
if(container) {
|
this.$cont = $('#'+container);
|
this.$el.height(this.$cont.height());
|
}
|
this._init();
|
};
|
LineEcharts2.prototype._init = function() {
|
var graph = this.$el.find('.graph').get(0);
|
this.chart = echarts.init(graph);
|
this.chart.showLoading();
|
};
|
LineEcharts2.prototype.resize = function() {
|
this.chart.resize();
|
this.setOption(this.props);
|
};
|
LineEcharts2.prototype.setOption = function(props, container) {
|
// 默认配置项
|
var defaultPorps = {
|
title: "",
|
subtitle: "",
|
x: "center",
|
name: [],
|
legendData: [],
|
seriesData: [],
|
xData: [],
|
lname: [],
|
color:[]
|
};
|
|
var data = $.extend({}, defaultPorps, props);
|
this.props = data;
|
// 声明临时变量
|
var sdata = data.seriesData;
|
var xdata = data.xData;
|
var lname = data.lname;
|
var battname = data.name;
|
|
// echarts配置项
|
var option={
|
tooltip:{
|
show:true,
|
trigger:'axis',
|
formatter:function(params){
|
//console.info(params);
|
var str = '';
|
for(var i=0;i<params.length;i++){
|
str+=params[i].seriesName+'</br>';
|
str+=params[i].marker+params[i].seriesId+':'+params[i].data[0]+','+params[i].data[1]+'AH</br>';
|
}
|
return str;
|
}
|
},
|
title : {
|
//text: tname,
|
x: "center", //标题水平方向位置
|
textStyle: {
|
fontSize:13
|
}
|
},
|
toolbox:{
|
show : true
|
},
|
calculable : true,
|
xAxis:{
|
data:xdata
|
},
|
grid: {
|
top:'10%',
|
left: '1%',
|
right: '5%',
|
bottom: '2%',
|
containLabel: true
|
},
|
yAxis:[{
|
name:"y(AH)",
|
type:'value',
|
min:function(){
|
var min = Number.POSITIVE_INFINITY; //正无穷大的数
|
var arr = new Array();
|
if(sdata.length>0){
|
for(var i=0;i<sdata.length;i++){
|
for(var j=0;j<sdata[i].length;j++){
|
arr.push(sdata[i][j][1]);
|
}
|
}
|
min = Math.min.apply(null,arr);
|
}
|
return (Math.floor(min*0.8));
|
}(),
|
max:function(){
|
var max = Number.NEGATIVE_INFINITY; //负无穷大的数
|
var arr = new Array();
|
if(sdata.length>0){
|
for(var i=0;i<sdata.length;i++){
|
for(var j=0;j<sdata[i].length;j++){
|
arr.push(sdata[i][j][1]);
|
}
|
}
|
max = Math.max.apply(null,arr);
|
}else{
|
max = 1;
|
}
|
|
return (Math.ceil(max*1.24));
|
}(),
|
axisLabel:{
|
formatter:function(value){
|
//解决原点处带符号问题
|
if(value==0)
|
{
|
return value;
|
}else{
|
return value ;
|
}
|
}
|
}
|
}],
|
series:function(){
|
var serie=[];
|
for( var i=0;i<sdata.length;i++){
|
var item={
|
type:'line',
|
//symbol:'none',
|
id:lname[i],
|
data:sdata[i],
|
name:battname[i]
|
}
|
serie.push(item);
|
}
|
return serie;
|
}()
|
};
|
|
// 设置容器的高度
|
if(container) {
|
var ht = container.height();
|
this.$el.height(ht);
|
}
|
|
this.chart.hideLoading(); // 关闭等待框
|
this.chart.resize();
|
// 生成echarts
|
this.chart.setOption(option);
|
}
|
// 自定义查询后台
|
function ajaxMain(props) {
|
|
}
|
|
// 自定义查询后台
|
function myAjax(props) {
|
// 请求后台
|
$.ajax({
|
type: "post",
|
async: true,
|
url: props.url,
|
data: "json="+JSON.stringify(props.data),
|
dataType: "json",
|
beforeSend: function(xhr) {
|
if(typeof props.beforeSend == "function") {
|
props.beforeSend(xhr);
|
}
|
},
|
success: function(res) {
|
var rs = JSON.parse(res.result);
|
if(typeof props.success == "function") {
|
props.success(rs);
|
}
|
},
|
complete: function() {
|
if(typeof props.complete == "function") {
|
props.complete();
|
}
|
}
|
});
|
}
|
|
//Cookie
|
function getCookie(c_name)
|
{
|
if (document.cookie.length>0)
|
{
|
c_start=document.cookie.indexOf(c_name + "=")
|
if (c_start!=-1)
|
{
|
c_start=c_start + c_name.length+1
|
c_end=document.cookie.indexOf(";",c_start)
|
if (c_end==-1) c_end=document.cookie.length
|
return unescape(document.cookie.substring(c_start,c_end))
|
}
|
}
|
return ""
|
}
|
|
/**
|
* 自定义日期
|
* @author hdw
|
*/
|
var HdwDate = function() {};
|
|
/**
|
* 设置MyDate的原型函数
|
*/
|
HdwDate.prototype = {
|
/**
|
* 获取输入的年份是闰年还是普通年份
|
* @return 返回是否为闰年
|
*/
|
isLeapYear: function(year) {
|
var isLeap = false;
|
// 输入的年份能够被4整除
|
if(year%4==0) {
|
// 输入的年份不能被100整除
|
if(year%100 != 0) {
|
isLeap = true;
|
}else if(year%400 == 0){
|
isLeap = true;
|
}
|
}
|
|
return isLeap;
|
},
|
/**
|
* 根据字符串yyyy-MM获取当前月有几天
|
* @return 返回当前月有多少天
|
*/
|
getMonthDay: function(date) {
|
var dates = date.split("-");
|
var year = Number(dates[0]);
|
var month = Number(dates[1]);
|
var day = 30;
|
// 判断是否为2月
|
switch(month) {
|
case 2:
|
var isLead = this.isLeapYear(year);
|
day = isLead?29:28;
|
break;
|
case 1:
|
case 3:
|
case 5:
|
case 7:
|
case 8:
|
case 10:
|
case 12:
|
day = 31;
|
break;
|
default:
|
day = 30;
|
break;
|
}
|
return day;
|
}
|
|
};
|
// 实例化对象
|
var hdwDate = new HdwDate();
|
|
// 根据对象获取url
|
function getUrlStr(props) {
|
var str = "";
|
Object.keys(props).forEach(function(key) {
|
str+=props[key]+"/";
|
});
|
return str;
|
}
|
|
|
//格式化时间
|
Date.prototype.format =function(format)
|
{
|
var o = {
|
"M+" : this.getMonth()+1, //month
|
"d+" : this.getDate(), //day
|
"h+" : this.getHours(), //hour
|
"m+" : this.getMinutes(), //minute
|
"s+" : this.getSeconds(), //second
|
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
|
"S" : this.getMilliseconds() //millisecond
|
};
|
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
|
(this.getFullYear()+"").substr(4- RegExp.$1.length));
|
for(var k in o)if(new RegExp("("+ k +")").test(format))
|
format = format.replace(RegExp.$1,
|
RegExp.$1.length==1? o[k] :
|
("00"+ o[k]).substr((""+ o[k]).length));
|
return format;
|
};
|
|
//将秒转化成时:分:秒
|
function formatSeconds(value) {
|
if(value > 0){
|
|
}else{
|
value = 0;
|
}
|
var theTime = parseInt(value); // 秒
|
var theTime1 = 0; // 分
|
var theTime2 = 0; // 小时
|
//alert(theTime);
|
if(theTime >= 60) {
|
theTime1 = parseInt(theTime/60);
|
theTime = parseInt(theTime%60);
|
//alert(theTime1+"-"+theTime);
|
if(theTime1 >= 60) {
|
theTime2 = parseInt(theTime1/60);
|
theTime1 = parseInt(theTime1%60);
|
}
|
}
|
var result = (theTime<10?"0":"")+parseInt(theTime);
|
if(theTime1 >= 0) {
|
result =(theTime1<10?"0":"")+parseInt(theTime1)+":"+result;
|
}
|
if(theTime2 >= 0) {
|
result =(theTime2<10?"0":"")+parseInt(theTime2)+":"+result;
|
}
|
return result;
|
}
|
|
// 定义面包屑导航条的点击事件
|
function breadItemClick(num) {
|
var cView = app.views.current;
|
var history = cView.router.history;
|
var url = history[num];
|
cView.router.back(url, {
|
force: true
|
});
|
}
|
|
// 生成表格内容
|
function createTblBody(tbody, tds, options) {
|
tbody.text("");
|
var colors = ['green', 'red'];
|
// 设置数据的最值
|
var errorVal = -999999;
|
var max = errorVal; // 设置默认最大值
|
var min = errorVal; // 设置默认最小值
|
var maxinum = false; // 设置是否开启最值(不开启)
|
// 根据options的值复写最值
|
if(options) {
|
maxinum = (options.maxinum != undefined)?options.maxinum: false;
|
max = (options.max !=undefined)?options.max: errorVal;
|
min = (options.min !=undefined)?options.min: errorVal;
|
colors = (options.colors != undefined)?options.colors: colors;
|
}
|
var maxColor = colors[0];
|
var minColor = colors[1];
|
// 遍历tds的值
|
for(var i=0; i<tds.length; i++) {
|
var $tr = $("<tr></tr>");
|
var td = tds[i];
|
for(var k=0; k<td.length; k++) {
|
var _td = td[k];
|
var $td = $('<td></td>');
|
$td.text(_td);
|
|
// 判断是否设置最值
|
if(maxinum) {
|
// 当前数据是否为最大值
|
if(_td == max) {
|
$td.addClass('tbl-max-val');
|
$td.css('background-color', maxColor);
|
}
|
if(_td == min) {
|
$td.addClass('tbl-min-val');
|
$td.css('background-color', minColor);
|
}
|
}
|
|
$tr.append($td);
|
}
|
tbody.append($tr);
|
}
|
}
|
|
// 自定义面板
|
function MyModal(id) {
|
this.id = id;
|
this.elem = $(id);
|
this._init();
|
}
|
MyModal.prototype._init = function() {
|
var showElems = $('.show-my-modal');
|
var self = this;
|
var id = this.id;
|
// 设置显示按钮
|
showElems.each(function() {
|
var href = $(this).data('href');
|
if(href && href==id) {
|
$(this).click(function() {
|
self.show();
|
});
|
}
|
});
|
|
|
var toggleElems = $('.toggle-my-modal');
|
// toggle显示按钮
|
toggleElems.each(function() {
|
var href = $(this).data('href');
|
if(href && href==id) {
|
$(this).click(function() {
|
self.toggle();
|
});
|
}
|
});
|
|
// 设置关闭按钮
|
var closeElems = this.elem.find('.my-modal-close');
|
closeElems.click(function() {
|
self.hide();
|
});
|
|
|
};
|
MyModal.prototype.show = function() {
|
if(!this.elem.hasClass('my-modal-show')) {
|
this.elem.addClass('my-modal-show');
|
setTimeout(function() {
|
// 设置内容的高度
|
var container = this.elem.find('.my-modal-container');
|
var header = this.elem.find('.my-modal-header');
|
var content = this.elem.find('.my-modal-content');
|
var footer = this.elem.find('.my-modal-footer');
|
|
content.height(container.height()-header.height()-footer.height());
|
}.bind(this), 400);
|
}
|
};
|
MyModal.prototype.hide = function() {
|
this.elem.removeClass('my-modal-show');
|
var modalContent = this.elem.find('.my-modal-content');
|
};
|
MyModal.prototype.toggle = function() {
|
if(this.elem.hasClass('my-modal-show')) {
|
this.hide();
|
}else {
|
this.show();
|
}
|
}
|
|
// 加载popup页面的首屏
|
function loadPopupByRoute(elem) {
|
console.log(elem);
|
console.log($(elem));
|
}
|
|
//定义计时器
|
function Interval() {
|
this.timer = null;
|
this.time = '';
|
this.callback = '';
|
}
|
// 开启计时器并添加
|
Interval.prototype.start = function(callback, time) {
|
// 先关闭计时器
|
this.stop();
|
// 配置执行函数
|
if(typeof callback == 'function' && typeof time == 'number') {
|
this.callback = callback;
|
this.time = time;
|
callback();
|
this.timer = setInterval(callback, time);
|
}else {
|
console.warn('未完整配置参数!');
|
}
|
};
|
// 开启计时器
|
Interval.prototype.open = function() {
|
var callback = this.callback;
|
var time = this.time;
|
this.start(callback, time);
|
};
|
|
// 关闭计时器
|
Interval.prototype.stop = function() {
|
clearInterval(this.timer);
|
};
|
|
// 延时计时器
|
function Timeout() {
|
this.timer = null;
|
this.time = '';
|
this.callback = '';
|
}
|
// 开启计时器并添加
|
Timeout.prototype.start = function(callback, time, exe) {
|
// 先关闭计时器
|
this.stop();
|
// 配置执行函数
|
if(typeof callback == 'function' && typeof time == 'number') {
|
this.callback = callback;
|
this.time = time;
|
if(exe != 'exe') {
|
callback();
|
}
|
this.timer = setTimeout(callback, time);
|
}else {
|
console.warn('未完整配置参数!');
|
}
|
};
|
// 开启计时器
|
Timeout.prototype.open = function() {
|
var callback = this.callback;
|
var time = this.time;
|
this.start(callback, time, 'exe');
|
};
|
|
// 关闭计时器
|
Timeout.prototype.stop = function() {
|
clearTimeout(this.timer);
|
};
|
|
// 封装toast
|
function Toast() {
|
this.toast = '';
|
}
|
// 显示
|
Toast.prototype.open = function(opts) {
|
var defaults = {
|
text: '',
|
};
|
|
var options = $.extend({}, defaults, opts);
|
// Create center toast
|
this.toast = app.toast.create(options);
|
this.toast.open();
|
};
|
var toast = new Toast();
|
|
// 根据验证规则校验对象的属性值
|
function checkObjIsGood(obj, verify, callback) {
|
var result = {
|
code: 1,
|
name: '',
|
msg: '',
|
data: obj
|
};
|
Object.keys(verify).forEach(function(key) {
|
// 上一笔数据是否有效
|
if(result.code && obj[key] != undefined) {
|
var valueStatus = checkValueIsGood(obj[key], verify[key]);
|
result.code = valueStatus.code;
|
result.name = valueStatus.name;
|
result.msg = valueStatus.msg;
|
}
|
});
|
|
// 如果code=1设置msg的值
|
if(result.code) {
|
result.name = '';
|
result.msg = '数据匹配成功';
|
}
|
|
// 执行callback函数
|
if(typeof callback == 'function') {
|
callback(result);
|
}
|
}
|
|
// 检测当前数据是否符合要求
|
function checkValueIsGood(val, option) {
|
var result = {
|
code: 0,
|
name: option.name,
|
msg: option.msg
|
};
|
// 校验数据是否符合匹配规则
|
if(option.pattern.test(val)) {
|
// 数据存在取值范围的校验
|
if(option.regVal) {
|
if(val>=option.min && val<=option.max) {
|
result.code =1;
|
}
|
}else {
|
result.code =1;
|
}
|
}
|
// 返回结果集
|
return result;
|
}
|
|