Browse Source

修改地图查询添加参数到URL中

elis 2 years ago
parent
commit
04f6ef8c21
1 changed files with 65 additions and 0 deletions
  1. 65 0
      nngkxxdp/src/main/resources/static/district/js/sy.js

+ 65 - 0
nngkxxdp/src/main/resources/static/district/js/sy.js

@@ -436,6 +436,26 @@ $(function() {
 		error: function(err) {},
 	});
 
+	var str=window.location.search;
+	console.log(str)
+	str = decodeURI(str)
+	let name = "se"
+	if (str.indexOf(name)!=-1){
+		var pos_start=str.indexOf(name)+name.length+1;
+		var pos_end=str.indexOf("&",pos_start);
+		if (pos_end==-1){
+			let searchVal = str.substring(pos_start);
+			if (searchVal!==null&&searchVal!==''){
+				console.log(searchVal)
+				$('.inp').val(searchVal)
+				localStorage.setItem("gjIndex","1");
+				localStorage.setItem("gjImg","0");
+				localStorage.setItem("zjImg","0");
+				localStorage.setItem("zjIndex","0");
+				xrSearchResultList(searchVal);
+			}
+		}
+	}
 	// 点击显示弹窗
 	$('.flex_li').click(function() {
 		var tabtext = $(this).text().replace(/\s+/g, '');
@@ -854,6 +874,47 @@ $(function() {
 		}
 		$('.title-first1:nth-child(2)').css('padding-top',60);
 	});
+	// $('input.inp').on('input',function(e){
+	// 	console.log(e)
+	// 	console.log($('.inp').val())
+	// 	let sev = $('.inp').val();
+	// 	if (sev !== null && sev !== ''){
+	// 		replaceParamVal("se",$('.inp').val())
+	// 	}else {
+	//
+	// 	}
+	// })
+	function replaceParamVal(paramName,replaceWith) {
+		var oUrl = this.location.href.toString();
+		// console.log(oUrl)
+		var re=eval('/('+ paramName+'=)([^&]*)/gi');
+		// console.log(re)
+		var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
+		// console.log(nUrl)
+		this.location = nUrl;
+		window.location.hash=nUrl
+	}
+	function replaceParamVal2(paramName,replaceWith) {
+		debugger
+		let search = window.location.search;
+		var oUrl = this.location.href.toString();
+		if (search.indexOf("se")!=-1){
+			// console.log(oUrl)
+			var re=eval('/('+ paramName+'=)([^&]*)/gi');
+			// console.log(re)
+			var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
+			// console.log(nUrl)
+			this.location = nUrl;
+			window.location.href=nUrl
+		}else {
+			var nUrl = oUrl+"?se="+replaceWith;
+			this.location = nUrl;
+			window.location.href=nUrl
+		}
+
+
+
+	}
 
 	// 点击列表中的一条,重置地图中心点
 	$(document).on('click', '.title-first li', function() {
@@ -2912,6 +2973,7 @@ $(function() {
 			localStorage.setItem("zjImg","0");
 			localStorage.setItem("zjIndex","0");
 			xrSearchResultList(searchInp);
+			replaceParamVal2("se",searchInp)
 		}
 	});
 	$('.inp').bind('keyup',function(event){
@@ -2931,6 +2993,7 @@ $(function() {
 				localStorage.setItem("zjImg","0");
 				localStorage.setItem("zjIndex","0");
 				xrSearchResultList(searchInp);
+				replaceParamVal2("se",searchInp)
 			}
 		}
 	});
@@ -3023,6 +3086,7 @@ $(function() {
 		gjIndex = localStorage.getItem("gjIndex");
 		gjImg = localStorage.getItem("gjImg");
 		var gjLine = JSON.parse(localStorage.getItem("gjLine"));
+		// replaceParamVal('se','')
 		if(gjIndex == 1) {
 			$('.show-first').show().siblings().hide();
 			$('.text-second').empty();
@@ -3137,5 +3201,6 @@ $(function() {
 			resultDrivingLine(zjLine[0],zjLine[1]);
 			localStorage.setItem("zjImg","2");
 		}
+		replaceParamVal2('se','')
 	});
 })