通用方法(常规一)

前言:

function setCookie(name, value) {
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function showmainH(){
	setTimeout(function(){
		$(".main").css("height","calc(100% - 75px)")
	},16);
}


function getCookie(name) {
	var arr,
		reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}

var SDHF = SDHF || {};
SDHF.showload = function() {
	layui.use('layer', function() {
		index = layer.load(2, {
			shade : [ 0.1, '#fff' ] //0.1透明度的白色背景
		});
	})
};

SDHF.hideload = function() {
	layui.use('layer', function() {
		layer.close(index);
	})
};
SDHF.norows = function(num)
{
	var norowshtml ='<tr><td colspan="'+num+'">暂无数据</td></tr>'; 
    return norowshtml;
};
SDHF.errer = function(text) {
	layui.use('layer', function() {
		layer.msg(text = undefined ? "失败了~" : text, {
			icon : 5,
			time : 2000
		});
	})
};
SDHF.getRequest = function() {
	var urls = window.location.search;
	var theRequest = new Object();
	if (urls.indexOf("?") != -1) {
		var str = urls.substr(1),
			strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
};


//		判断应该传哪个按钮的参数值
//		var btnpower={}  //2198
//		if(GAME.showtxtdata.type == 2){
//			if(ispass.examine_status==1){
//				btnpower.buttonName = 'room_cityCheckPass'
//			}else if(ispass.examine_status==2){
//				btnpower.buttonName = 'room_provinceCheckPass'
//			}
//		}else if(GAME.showtxtdata.type == 1){
//			if(ispass.examine_status==1){
//				btnpower.buttonName = 'city_cityCheckPass'
//			}else if(ispass.examine_status==2){
//				btnpower.buttonName = 'city_provinceCheckPass'
//			}
//		}else if(GAME.showtxtdata.type == 3){
//			if(ispass.examine_status==1){
//				btnpower.buttonName = 'country_cityCheckPass'
//			}else if(ispass.examine_status==2){
//				btnpower.buttonName = 'country_provinceCheckPass'
//			}
//		}
//		var btnq = SDHF.getbtnquan(btnpower);
//		if(!btnq){
//			layer.msg("权限不足",{icon:0,time:2000}); 
//			return false;
//		}

//模板
//          var btnpower={}
//			if(GAME.showtxtdata.type == 2){
//					btnpower.buttonName = 'room_planSubmit'
//			}else if(GAME.showtxtdata.type == 1){
//					btnpower.buttonName = 'city_planSubmit'
//			}else if(GAME.showtxtdata.type == 3){
//					btnpower.buttonName = 'country_planSubmit'
//			}
//			var btnq = SDHF.getbtnquan(btnpower);
//			if(!btnq){
//				layer.msg("权限不足",{icon:0,time:2000}); 
//				return false;
//			}
SDHF.getbtnquan = function(btnpower) {
	var btnquan = false;
	btnpower.userID=localStorage.id
	$.ajax({
	    type: "post",xhrFields: {withCredentials: true},
	    url: url + "permission/findRole",
	    contentType: "application/json",
	    async: false,
	    dataType:"json",
	    data: JSON.stringify(btnpower),
	    success: function(data) {
	        if(data.code==200){
	        	if(data.data=='ok'){
	        		btnquan=true;
	        	}
	        }
	    }
	});
	return btnquan;
};




SDHF.islogin = function(uid) {
//	var cookie = false;
// 	if(localStorage.username == null || localStorage.username==undefined){
// 		GAME.showtxtdata.userID = sessionStorage.getItem("id")
// 		location.href = url + "user/index?userID="+uid+'&hdurl='+hdurl;
// 	}
//	return cookie;
	GAME.showtxtdata.userID = sessionStorage.getItem("id")
	location.href = url + "user/index?userID="+uid+'&hdurl='+hdurl;
}
SDHF.isgetpage = function(totalPage, num) //总页数,当前页(返回为true的时候去执行)
{
	var a = true;
	if (GAME.currentpage == num) {
		if (num == 1) {
			layui.use('layer', function() {
				layer.msg("已经是第一页啦~", {
					icon : 5,
					time : 2000
				});
			})
		} else if (totalPage == num) {
			layui.use('layer', function() {
				layer.msg("已经是最后一页啦~", {
					icon : 5,
					time : 2000
				});
			})
		} else {
			layui.use('layer', function() {
				layer.msg("已经到当前页啦~", {
					icon : 5,
					time : 2000
				});
			})
		}
		a = false;
	}
	return a;
}

SDHF.show404 = function() {
	$(".messlistbox").html('<img src="img/zwsj.png" />')
}
SDHF.ischeckUser = function(str) {//账号
	var a = true;
	var re =  /^[a-zA-z]\w{3,15}$/;
	if(!re.test(str)) {
		layer.msg("请输入以字母或数字或下划线组成,字母开头,4-16位", {
			icon: 0,
			time: 6000
		});
		a = false;
	}
	return a;
};
SDHF.isemail = function(str) {//邮箱
	var a = true;
	var re =  /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	if(!re.test(str)) {
		layer.msg("请输入正确的邮箱格式", {
			icon: 0,
			time: 2000
		});
		a = false;
	}
	return a;
};
SDHF.isyesname = function(str) {//姓名
	var a = true;
	var re =  /^[\u0391-\uFFE5A-Za-z]+$/;
	if(!re.test(str)) {
		layer.msg("请输入中文或英文名称", {
			icon: 0,
			time: 2000
		});
		a = false;
	}
	return a;
};
SDHF.isphone = function(str) {//手机
	var a = true;
	var re = /^1\d{10}$/;
	if(!re.test(str)) {
		layer.msg("请输入以1开头的11位手机号", {
			icon: 0,
			time: 2000
		});
		a = false;
	}
	return a;
};
SDHF.showbtns = function(btnarr,tx) {//显示按钮组
	var btnhtml='';
	for(var i=0,len=btnarr.length;i<len;i++){
	    btnhtml+='<span id='+tx+i+'>'+btnarr[i]+'</span>';
	}
	$(".btns").html(btnhtml);
};
SDHF.attribute_1 = function(num) {//室内预规划属性1码表
    var tx = '';
    var lists = ['攻坚','切块'];
    num--
    tx = lists[num]
    return tx;
};
SDHF.attribute_2 = function(num) {//室内预规划属性2码表
	var tx = '';
	var lists = ['机场','高铁站','汽车站','医院','商场','酒店','娱乐场所','写字楼','综合体','住宅','校园寝室','校园图书馆','校园食堂','其他'];
	num--
	tx = lists[num]
	return tx;
};
SDHF.construc_way = function(num) {//室内预规划建设方式码表
	var tx = '';
	var lists = ['Q','L','DAS','直放站','皮站'];
	num--
	tx = lists[num]
	return tx;
};
SDHF.network_type = function(num) {//
	var tx = '';
	var lists = ['C+L','L','5G'];
	num--
	tx = lists[num]
	return tx;
};
SDHF.choosenum = function(choosenumname) {//
	var n=0;
	switch (choosenumname){
		case '预规划':
			n=0;
			break;
		case '市审核':
			n=1;
			break;
		case '省审核':
			n=1;
			break;
		case '规划库':
			n=2;
			break;
		default:
			break;
	}
	return n;
};
SDHF.scene_type = function(num) {//场景
	var tx=''
	switch (num){
		case '1':
			tx='城区'
			break;
		case '2':
			tx='农村'
			break;
		case '3':
			tx='扩容'
			break;
		case '4':
			tx='高速'
			break;
		case '5':
			tx='高铁'
			break;
		case '6':
			tx='室内'
			break;
		default:
			break;
	}
	return tx;
};
SDHF.nature = function() {//获取权限
	var qx = localStorage.nature;
	return qx;
};
SDHF.isdata = function(code) {//是否已经添加
	var isdata=false;
	$.ajax({
	    type: "post",xhrFields: {withCredentials: true},
	    url: url + "planDb/isCode",
	    contentType: "application/json",
	    async: false,
	    dataType:"json",
	    data: JSON.stringify({"code":code}),
	    success: function(data) {
	        if(data.code==0){
	        	isdata=data.data.isCode;
	        }
	    }
	});
	return isdata
};

SDHF.noundefined = function(obj) { //页面不出现undefined
				$(obj).each(function(){
					if($(this).text()=='undefined' || $(this).text()==''){
						$(this).text('--')
					}
				})
			};
SDHF.co_station = function(num) {//频点码表
	nump = Number(num)
	var tx = '';
	var lists = ['800M','1.8G','2.1G','CDMA','5G'];
	nump--
	tx = lists[nump]
	return tx;
};
SDHF.co_station2 = function(num) {//频点码表2农村领取点位
	
//	1、800M 2、1.8G 3、2.1G 4、850M 5、2.6G
	
	var tx = '';
	var lists = ['800M','1.8G','','CDMA'];
	num--
	tx = lists[num]
	return tx;
};
			SDHF.isLogin = function() { //如果登陆用户为空,则跳转页面到登陆界面
				var name = sessionStorage.getItem("username");
				if(name == null){
					window.location.href='loginuser.html';
				}
			};
var SDHF = SDHF || {};
			SDHF.showHead = function(theadarr, obj) { //显示表头
				var theadhtml = '';
				for(var i = 0, len = theadarr.length; i < len; i++) {
					theadhtml += '<p class="w' + i + '" title="' + theadarr[i] + '">' + theadarr[i] + '</p>';
				}
				$(obj).html(theadhtml);
			};
			SDHF.showW = function(warr) { //显示表格每一项宽度
				for(var i = 0, len = warr.length; i < len; i++) {
					$(".w" + i).css("width", warr[i] + '%');
				}
			};
			SDHF.GetCityOption = function(obj) { //获取城市显示下拉框

				$.ajax({
				    type: "post",xhrFields: {withCredentials: true},
				    url: url + "planDetail/getAreaList",
				    contentType: "application/json",
//				    headers:{
//				    	"userID":GAME.showtxtdata.userID,
//				    },
				    async: true,
				    dataType:"json",
				    data: JSON.stringify(GAME.showtxtdata3),
				    success: function(data) {
				        if(data.code==0){
				        	var sd=data.dataList;
				        	var cityoption='';
				        	if(sd.length==21){
				        		cityoption='<option value="510000">全省</option>'
				        	}
							var cityshowid='';
				        	for(var i=0,len=sd.length;i<len;i++){
				        		if(i==0){
				        			GAME.showtxtdata.city_code=sd[i].id
				        			GAME.showtxtdata.city_name=sd[i].name
				        			cityshowid=sd[i].id;

				        		}
				        	    cityoption+='<option value="'+sd[i].id+'">'+sd[i].name+'</option>'
				        	}
				        	$(obj).html(cityoption);
				        	$(obj).val(cityshowid);
//				        	showtableRoom1();
				        	locationByCity(cityshowid);
				        }
				    }
				});
			};
			SDHF.GetuserCityOption = function(obj,roleid) { //获取城市显示下拉框
				$.ajax({
					type: "post",xhrFields: {withCredentials: true},
					url: url + "permission/findAllRoles",
					contentType: "application/json",
					async: false,
					dataType:"json",
					data: JSON.stringify({}),
					success: function(data) {
						if(data.code==200){
							var sd=data.data;
							var cityoption='';
							var cityshowid='';
							for(var i=0,len=sd.length;i<len;i++){
								cityoption+='<option value="'+sd[i].id+'">'+sd[i].role_describe+'</option>'
							}
							$(obj).html(cityoption);
							if(roleid!=null){
                                $(obj).val(roleid);
							}
						}
					}
				});
			};
			SDHF.gaosuma = function(num) { //高速名称码表
				var namearr=[
					'',
					'S1-成绵高速复线',
					'S11-遂内高速                        ',
					'G42-沪蓉高速                        ',
					'S6-成都机场高速                       ',
					'G93-成渝环线高速                      ',
					'G5012-恩广高速                      ',
					'S66-乐自高速                        ',
					'S40-遂洪高速                        ',
					'G4201-南充绕城高速                    ',
					'S8-邛名高速                         ',
					'G65-包茂高速                        ',
					'',//12为空
					'G76-夏蓉高速                        ',
					'S2-成巴高速                         ',
					'G5-京昆高速                         ',
					'G93-成渝环线高速                      ',
					'',//17为空
					'G4201-成都绕城高速                    ',
					'G5515-南大梁高速                     ',
					'G4215-成遵高速                      ',
					'G4217-荣昌高速                      ',
					'',//22为空
					'',//23为空
					'G75-南海高速                        ',
					'G85-渝昆高速                        ',
					'成乐高速                            ',
					'',//27为空
					'G4202-成都第二绕城高速                  ',
					'',//29为空
					'',//30为空
					'',//31为空
					' S20-内威荣高速                      ',
					'S22-汉隆高速                        ',
					'S18-遂广高速                        ',
					'S17-遂西高速                        ',
					'成彭高速                            ',
					'G5013-渝蓉高速                      ',
					'S26-叙古高速                        ',
					'',//39为空
					'S40-西绵高速                        ',
					'G4216-成丽高速                      ',
					'G4203-成都第三绕城高速                  ',
					'广元绕城高速                          ',
					'宜宾绕城高速                          ',
					'G4218-雅康高速                      '
				]
				return namearr[num];
			};
			SDHF.gaotiema = function(num) { //高铁名称码表
				var namearr=[
					'',
					'达成铁路',
					'兰渝铁路广安支线',
					'成渝高铁',
					'成淮快速铁路',
					'彭州支线',
					'西城高速铁路',
					'成绵乐客运专线',
					'兰渝铁路'
				]
				return namearr[num];
			};


function formatDate(now) {
	now = new Date(now);
	var year = now.getFullYear(),
		month = now.getMonth() + 1,
		date = now.getDate(),
		hour = now.getHours(),
		minute = now.getMinutes(),
		second = now.getSeconds();
	minute = checkTime(minute);
	month = checkTime(month);
	date = checkTime(date);
	hour = checkTime(hour);
	second = checkTime(second);
//	return '<p class="timeinline">'+year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second+'</p>';
	return '<p class="timeinline">'+year + "-" + month + "-" + date + " " + hour + ":" + minute +'</p>';
}

function formatDateplan() {//返回正常人能看懂的时间
	
				now = new Date();
				now.setTime(now.getTime()-2*24*60*60*1000);
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = now.getDate(),
					day = now.getDay(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				hour = checkTime(hour);
				second = checkTime(second);
				return year + "-" + month + "-" + date;
//				return year + "-" + month + "-" + date + " 星期"+ day +" " + hour + ":" + minute + ":" + second;
//				return hour + ":" + minute + ":" + second;
			}
function formatDate2() {//返回正常人能看懂的时间
				now = new Date();
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = now.getDate(),
					day = now.getDay(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				hour = checkTime(hour);
				second = checkTime(second);
//				return year + " / " + month + " / " + date + " 星期"+ day +" " + hour + ":" + minute + ":" + second;
				return hour + ":" + minute + ":" + second;
			}
function formatDatebigscreen() {//返回正常人能看懂的时间
				now = new Date();
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = now.getDate(),
					day = now.getDay(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				hour = checkTime(hour);
				second = checkTime(second);
				return year + "-" + month + "-" + date +' <span style="margin-left:16px">'+ hour + ":" + minute+'</span>';
//				return hour + ":" + minute + ":" + second;
			}
function checkTime(i) {
	if (i < 10) {
		i = "0" + i
	}
	return i
}
function formatDate3() {//返回年月
				now = new Date();
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = now.getDate(),
					day = now.getDay(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				hour = checkTime(hour);
				second = checkTime(second);
				return year + " 年 " + month+' 月'
			}

function formatDatemap() {//返回正常人能看懂的时间
				now = new Date();
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = now.getDate(),
					day = now.getDay(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				hour = checkTime(hour);
				second = checkTime(second);
				return year + "年" + month + "月" + date + "日";
//				return hour + ":" + minute + ":" + second;
			}
function UrlSearch() {
			var name, value;
			var str = location.href; //取得整个地址栏
			var num = str.indexOf("?")
			str = str.substr(num + 1); //取得所有参数 stringvar.substr(start [, length ]
		
			var arr = str.split("&"); //各个参数放到数组里
			for(var i = 0; i < arr.length; i++) {
				num = arr[i].indexOf("=");
				if(num > 0) {
					name = arr[i].substring(0, num);
					value = arr[i].substr(num + 1);
					this[name] = decodeURI(value);
				}
			}
		}
		var Git = new UrlSearch(); //实例化
//实例化



$(".shadecon").on("click", ".off", function() {
	offfun();
})
//off-shade-fun
function offfun() {
	$(".shade").empty();
	$(".shade,.shadecon").fadeOut(150);
}
//show-shade-fun
function showfun(){
	$(".shade,.shadecon").fadeIn(150);
}

$("body").on("click", ".mapoff", function() {
	hidemapfun()
})
//map-page浮层
function hidemapfun(){
	$(".movebox").fadeOut(150);
	$(".moveling").fadeOut(150);
}
//map-page浮层
function showmapfun(){
	$(".movebox").fadeIn(150);
}

function SDHmenuinit(_this){
				var objlen=$(_this).length;
				$(_this).each(function(){
					var i=$(this).index(),w=$(this).width();
					var left=i*(w+22);
					var z=objlen--;
					$(this).css({'left':left,'z-index':z})
				})
			}
function evfun(_this,event){
        	event = event || window.event;  
        	//2.获取鼠标在整个页面的位置  
        	var pagex = event.pageX || scroll().left + event.clientX; 
            var pagey = event.pageY || scroll().top + event.clientY; 
            //3.获取盒子在整个页面的位置  
            var xx =$(_this).offset().left;  
            var yy = $(_this).offset().top;
            //4.用鼠标的位置减去盒子的位置
            var targetx = pagex - xx;  
            var targety = pagey - yy; 
            var xydata={
            	x:targetx,
            	y:targety
            }
            return xydata
        }
    	
		//封装的scrollTop
		function scroll() {  
		    if(window.pageYOffset != null) {  // ie9+ 高版本浏览器
		        // 因为 window.pageYOffset 默认的是  0  所以这里需要判断
		        return {
		            left: window.pageXOffset,
		            top: window.pageYOffset
		        }
		    }
		    else if(document.compatMode === "CSS1Compat") {    // 标准浏览器   来判断有没有声明DTD
		        return {
		            left: document.documentElement.scrollLeft,
		            top: document.documentElement.scrollTop
		        }
		    }
		    return {   // 未声明 DTD
		        left: document.body.scrollLeft,
		        top: document.body.scrollTop
		    }
		}
		
function showRT_legend(){//显示右上角图例
//	$(".rlegendsel").show();
	$(".rlegendcol").show();
//	$(".rlegendcli").show();
}
function hideRT_legend(){//显示右上角图例
//	$(".rlegendsel").hide();
	$(".rlegendcol").hide();
//	$(".rlegendcli").hide();
}

function getpageSize(){
	var pageSize=Math.ceil(($(".tbox").height()-80)/25);
	return pageSize
}
function distance(num){
	var num = parseInt(num);
	if(isNaN(num)){
		num='--'
	}
	return num
}


//显示各种随机数   室外高速高铁
function getrandom(num){
		var onenum = num/100;
		var nnum=Math.floor(Math.random()*4*onenum+98*onenum);
		return nnum;
	}
	function getrandommin(){
		var nnum=(Math.random()*0.04+0.01).toFixed(2);
		return nnum;
	}
function shownumtext(num,id){
		var numsr = getrandom(num);   
		$(id).text(numsr)
	}
	function shownumtext2(id){
		var numsr = getrandommin();   
		$(id).text(numsr)
	}
	
function getformdata(obj){
	var data={};
	$(obj).serializeArray().map(function(x){data[x.name]=x.value});
	return data;
}

//后评估下钻之后码表
function gettyts(id){
	var tx='';
	if(id==1){
		tx='领取'
	}else if(id==2){
		tx='开通'
	}else if(id==3){
		tx='终止'
	}
	return tx;
}
//返回城市
function getcitynametwo(name){
	var namesth = name.length;
	switch (namesth){
		case 3:
		    name = name.substr(0,2);
			break;
		case 4:
		    name = '攀枝花';
			break;
		case 7:
			if(name == '甘孜藏族自治州'){
				name = '甘孜'
			}else if(name == '凉山彝族自治州'){
				name = '凉山'
			}
			break;
		case 9:
			if(name == '阿坝藏族羌族自治州'){
				name = '阿坝'
			}
			break;
		default:
			break;
	}
	return name
}
//个人模块导出
function windowOpen(url, data) {
        var htmlContent = '<form id="windowOpenForm" action="' + url + '" method="post" target="_blank">';
        for (var key in data) {
            htmlContent += '<input type="hidden" name="' + key + '" value="' + data[key] + '"/>';
        }
        htmlContent += '</form>'
        $('body').append(htmlContent);
        $('#windowOpenForm').submit();
        $('#windowOpenForm').remove();
    }



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值