Merge branch 'YOUFANGAPP1.1' of 192.168.0.27:dev0/youfang-app into YOUFANGAPP1.1

Conflicts:
	fangija-zsyf/config.js
	fangija-zsyf/yfindex.html
This commit is contained in:
2018-04-03 17:40:35 +08:00
15 changed files with 1376 additions and 511 deletions
+22 -4
View File
@@ -7,22 +7,40 @@ document.addEventListener('touchstart',shield,false);//取消浏览器的所有
document.oncontextmenu=shield;//屏蔽选择函数
// H5 plus事件处理
var ws=null,as='pop-in';
(function() {
var first = null;
mui.back = function() { //首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first > 1000) {
plus.runtime.quit();
}
}
};
})
function plusReady(){
ws=plus.webview.currentWebview();
/*ws=plus.webview.currentWebview();
// Android处理返回键
plus.key.addEventListener('backbutton',function(){
/*if (ws.id == 'yfindex.html') {
if (ws.id == 'yfindex.html') {
alert("aa")
plus.nativeUI.confirm("确认退出",function(e) {
alert(e.index);
if(e.index == 0) {
plus.runtime.quit();
}
});
} else {
back();
}*/
}
back();
},false);
compatibleAdjust();
compatibleAdjust();*/
}
if(w.plus){
plusReady();
+121
View File
@@ -0,0 +1,121 @@
var auths = {}
function plusReady() {
plus.oauth.getServices(function(services) {
for(var i in services){
var service=services[i];
auths[service.id]=service;
}
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
}
document.addEventListener('plusready',plusReady,false);
// 登录认证
function loginInfo(dest){
var auth=auths[dest];
console.log(JSON.stringify(auth))
if(auth){
var w=null;
if(plus.os.name=="Android"){
w=plus.nativeUI.showWaiting();
}
document.addEventListener("pause",function(){
setTimeout(function(){
w&&w.close();w=null;
},2000);
}, false );
auth.login(function(){
w&&w.close();w=null;
userinfo(auth);
},function(e){
w&&w.close();w=null;
$.toast("登录认证失败:["+e.code+"]:"+e.message);
});
}else{
$.toast("无效的登录认证通道!");
$.toast("无效的登录认证通道!",null,"登录");
}
}
//wx获取用户信息
function userinfo(a){
a.getUserInfo(function(){
console.log(JSON.stringify(a))
$.showPreloader();
if(a.id=='weixin'){
var nickname=a.userInfo.nickname||a.userInfo.name||a.userInfo.miliaoNick;
var openid = a.authResult.openid;
var accessToken = a.authResult.access_token;
var unionid = a.userInfo.unionid;
var headImg = a.userInfo.headimgurl;
wxLogin(openid,unionid,accessToken,nickname,headImg,"weixin")
}else if(a.id=='qq'){
var nickname=a.userInfo.nickname;
var openid = a.authResult.openid;
var accessToken = a.authResult.access_token;
var headImg = a.userInfo.headimgurl;
qqLogin(openid,accessToken,nickname,headImg,"qq")
}else{
//微博信息获取
var nickname=a.userInfo.name||a.userInfo.screen_name;
var openid = a.authResult.openid;
var accessToken = a.authResult.access_token;
var headImg = a.userInfo.profile_image_url;
var uid = a.authResult.uid
weiboLogin(openid,accessToken,nickname,headImg,"sinaweibo")
}
},function(e){
$.toast("获取微信用户信息失败:["+e.code+"]:"+e.message);
});
}
function wxLogin(openid, unionid, accessToken, nickname, headImg,loginFrom) {
axios.post("/rest/user/wxLogin", {loginFrom:loginFrom,openid:openid, unionid:unionid, accessToken: accessToken, nickname:nickname,headImg:headImg})
.then(function (response) {
$.hidePreloader();
if(response.data.status){
if("no"==response.data.message){
//跳转绑定手机号码页面
console.log(response.data.message)
}else{
}
}else{
//登录失败
$.toast(response.data.data)
}
})
}
function qqLogin(openid, accessToken, nickname, headImg,loginFrom) {
axios.post("/rest/user/qqLogin", {loginFrom:loginFrom,openid:openid, accessToken: accessToken, nickname:nickname,headImg:headImg})
.then(function (response) {
$.hidePreloader();
if(response.data.status){
if("no"==response.data.message){
//跳转绑定手机号码页面
}else{
}
}else{
//登录失败
$.toast(response.data.data)
}
})
}
function weiboLogin(openid, accessToken, nickname, headImg,loginFrom) {
axios.post("/rest/user/sinaweiboLogin", {loginFrom:loginFrom,openid:openid, accessToken: accessToken, nickname:nickname,headImg:headImg})
.then(function (response) {
$.hidePreloader();
if(response.data.status){
if("no"==response.data.message){
//跳转绑定手机号码页面
}else{
}
}else{
//登录失败
$.toast(response.data.data)
}
})
}
-39
View File
@@ -1,39 +0,0 @@
var auths = {}
function plusReady() {
plus.oauth.getServices(function(services) {
alert("111111111111111111111111")
auths = services;
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
}
document.addEventListener('plusready',plusReady,false);
// 登录认证
function webChatLogin(){
var auth=auths['weixin'];
if(auth){
var w=null;
if(plus.os.name=="Android"){
w=plus.nativeUI.showWaiting();
}
document.addEventListener("pause",function(){
setTimeout(function(){
w&&w.close();w=null;
},2000);
}, false );
auth.login(function(){
w&&w.close();w=null;
userinfo(auth);
},function(e){
w&&w.close();w=null;
$.toast("登录认证失败:["+e.code+"]:"+e.message);
});
}else{
$.toast("无效的登录认证通道!");
$.toast("无效的登录认证通道!",null,"登录");
}
}
function authLogin(type) {
console.log("hhhhhhhhhhhhhhhhhhh")
}
+179
View File
@@ -0,0 +1,179 @@
var xhr;
var searchDistVue = new Vue({
el: '#searchList',
data: {
searchDistricts: []
},methods: {
openDistrictDetail:function(index) {
saveHistory({district:this.searchDistricts[index].region,name:this.searchDistricts[index].name,city:this.searchDistricts[index].city})
$("#input_address").val(this.searchDistricts[index].name);
$("[name=region]").val(this.searchDistricts[index].region)
$("[name=name]").val(this.searchDistricts[index].name)
$("[name=cityAddress]").val(this.searchDistricts[index].city)
$("[name=address]").val(this.searchDistricts[index].address)
$.popup(".popup-about02")
}
}
})
$("#districtName").bind("input propertychange keyup" , function () {
var keyword = $(this).val()
if(xhr){
xhr.abort()
}
if(keyword == ""){
// $('.searchList #searchList').empty()
return
}
axios.get(BASE_PATH+"/rest/districts/search", {
params: {
keywords : keyword,
cityName:$("#input_city").val(),
max:20
}
}).then(function (response) {
var datas = response.data.data
$('.hotList').hide();
$('.historyList').hide();
if(datas == null || datas.length == 0){
$("#notFound").show()
searchDistVue.$data.searchDistricts = []
//$('.searchList #searchList').empty();
}else{
$("#notFound").hide()
var dists = [];
for(var i in datas){
var o = datas[i]
var map={city:o.city, region:o.district, name:o.name,address:o.address};
dists.push(map);
}
//searchDistVue.$set("searchDistricts") = dists;
searchDistVue.$data.searchDistricts=dists
$('.searchList').show();
}
}).catch(function (error) {
alert(error)
console.log(error);
});
})
function saveHistory(district) {
var history = recover()
var keys = []
var newHistory = []
newHistory.push(district)
keys.push(district.city + "#" + district.region + "#" + district.name)
for(var i = 0; i < history.length; i++){
var key = history[i].city + "#" +history[i].region + "#" + history[i].name
if($.inArray(key, keys) > -1){
continue
}
if(newHistory.length < 5){
keys.push(key)
newHistory.push(history[i])
}else{
break
}
}
//$.cookie('history',JSON.stringify(newHistory) ,{ expires: 7})
localStorage.setItem("history", JSON.stringify(newHistory));
}
function recover() {
//var history = $.cookie('history')
var history = localStorage.getItem('history');
if(history == undefined || history == ''){
return new Array()
}
return JSON.parse(history)
}
/* 弹出搜索小区页面 */
$("body").delegate(".open-about02", "click", function () {
$("#districtName").val("");
if($("#input_city").val()==""){
$.toast("请选择城市")
return false;
}
$('.historyList').show();
$("#notFound").hide();
$('.hotList').show();
$('.searchList').hide();
addHotDistricts($("#input_city").val());
addHistory();
$.popup(".popup-about02")
$("input").blur()
});
//添加热门小区
function addHotDistricts(cityParam){
axios.get(BASE_PATH+"/rest/districts/hotDistricts", {
params: {
city: cityParam,
top:6
}
}).then(function (response) {
var datas = response.data.data
if(datas.length>0){
var dists = [];
for(var i in datas){
var o = datas[i]
var map={city:o.city, region:o.region, name:o.name};
dists.push(map);
}
new Vue({
el: '#hotList',
data: {
hotDists: dists
}
})
}
}).catch(function (error) {
alert(error)
console.log(error);
});
}
var histories = [];
var historyVue = new Vue({
el: '#districtList',
data: {
histories: histories
},methods: {
openHistoryDetail:function(index) {
$("#input_address").val(this.histories[index].name);
$("[name=region]").val(this.histories[index].region);
$("[name=name]").val(this.histories[index].name);
$("[name=cityAddress]").val(this.histories[index].city);
$.popup(".popup-about02")
}
}
})
function addHistory(){
var history = recover()
if(history.length>0){
histories = []
$(history).each(function(){
var map={city:this.city, region:this.district, name:this.name};
histories.push(map)
})
historyVue.histories=histories;
}/*else{
$(".historyList #districtList").empty();
}*/
}
//点击清空
$("#clearSearchHistory").click(function(){
localStorage.removeItem('history')
historyVue.histories=[];
});
@@ -0,0 +1,176 @@
var xhr;
var searchDistVue = new Vue({
el: '#searchList',
data: {
searchDistricts: []
},methods: {
openDistrictDetail:function(index) {
saveHistory({district:this.searchDistricts[index].region,name:this.searchDistricts[index].name,city:this.searchDistricts[index].city})
clicked(BASE_PATH+'/district/details?city='+this.searchDistricts[index].city+'&region='+this.searchDistricts[index].region+'&name='+this.searchDistricts[index].name,true);
}
}
})
$("#districtName").bind("input propertychange keyup" , function () {
var keyword = $(this).val()
if(xhr){
xhr.abort()
}
if(keyword == ""){
// $('.searchList #searchList').empty()
return
}
axios.get(BASE_PATH+"/rest/districts/search", {
params: {
keywords : keyword,
cityName:$("#input_city").text(),
max:20
}
}).then(function (response) {
var datas = response.data.data
$('.hotList').hide();
$('.historyList').hide();
if(datas == null || datas.length == 0){
$("#notFound").show()
searchDistVue.$data.searchDistricts = []
//$('.searchList #searchList').empty();
}else{
console.log(keyword +" "+datas.length);
$("#notFound").hide()
var dists = [];
for(var i in datas){
var o = datas[i]
var map={city:o.city, region:o.district, name:o.name,address:o.address};
dists.push(map);
}
//searchDistVue.$set("searchDistricts") = dists;
searchDistVue.$data.searchDistricts=dists
$('.searchList').show();
}
}).catch(function (error) {
alert(error)
console.log(error);
});
})
function saveHistory(district) {
var history = recover()
var keys = []
var newHistory = []
newHistory.push(district)
keys.push(district.city + "#" + district.region + "#" + district.name)
for(var i = 0; i < history.length; i++){
var key = history[i].city + "#" +history[i].region + "#" + history[i].name
if($.inArray(key, keys) > -1){
continue
}
if(newHistory.length < 5){
keys.push(key)
newHistory.push(history[i])
}else{
break
}
}
//$.cookie('history',JSON.stringify(newHistory) ,{ expires: 7})
localStorage.setItem("history", JSON.stringify(newHistory));
}
function recover() {
//var history = $.cookie('history')
var history = localStorage.getItem('history');
if(history == undefined || history == ''){
return new Array()
}
return JSON.parse(history)
}
/* 弹出搜索小区页面 */
$("body").delegate(".open-about02", "click", function () {
$("#districtName").val("");
if($("#input_city").text()==""){
$.toast("请选择城市")
return false;
}
$('.historyList').show();
$("#notFound").hide();
$('.hotList').show();
$('.searchList').hide();
addHotDistricts($("#input_city").text());
addHistory();
$.popup(".popup-about02")
$("input").blur()
});
//添加热门小区
function addHotDistricts(cityParam){
axios.get(BASE_PATH+"/rest/districts/hotDistricts", {
params: {
city: cityParam,
top:6
}
}).then(function (response) {
var datas = response.data.data
if(datas.length>0){
var dists = [];
for(var i in datas){
var o = datas[i]
var map={city:o.city, region:o.region, name:o.name};
dists.push(map);
}
new Vue({
el: '#hotList',
data: {
hotDists: dists
}
})
}
}).catch(function (error) {
alert(error)
console.log(error);
});
}
var histories = [];
var historyVue = new Vue({
el: '#districtList',
data: {
histories: histories
},methods: {
openHistoryDetail:function(index) {
clicked(BASE_PATH+'/district/details?city='+this.histories[index].city+'&region='+this.histories[index].region+'&name='+this.histories[index].name,true);
}
}
})
function addHistory(){
var history = recover()
if(history.length>0){
histories = []
$(history).each(function(){
var map={city:this.city, region:this.district, name:this.name};
histories.push(map)
})
historyVue.histories=histories;
}/*else{
$(".historyList #districtList").empty();
}*/
}
//点击清空
$("#clearSearchHistory").click(function(){
//$.cookie('history',JSON.stringify([]) ,{ expires: 7});
localStorage.removeItem('history')
historyVue.histories=[];
//$("#districtList").empty();
//$.popup(".popup-about02")
});