2aaabffe by fuenxin

clear ls.user

1 parent 73aafca1
angular.module('myApp')
.controller('mainController',['$scope','$rootScope','dingdaService','$state','globalService',function($scope,$rootScope,dingdaService,$state,globalService){
.controller('mainController', ['$scope', '$rootScope', 'dingdaService', '$state', 'globalService', function ($scope, $rootScope, dingdaService, $state, globalService) {
$rootScope.isRendBike = false;
$rootScope.isLoadFinish = false;
$scope.unfinishOrder = {};
var init = function() {
// globalService.init();
function getUrl(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var init = function () {
// globalService.init();
function getUrl(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
if (r != null) return unescape(r[2]); return null;
}
var code = getUrl('code')
var loginUrlCode = function (code) {
if(code){
if (code) {
dingdaService.verifyThirdCode(code).success(function (res) {
globalService.saveData('loginCode', code)
if(res.meta.code == 200) {
if (res.meta.code == 200) {
dingdaService.verifyPhoneCode(res.data.mobile, res.data.code).success(function (data) {
if (data.meta.code == 200) {
data.data.userName = res.data.mobile;
globalService.saveData('user',data.data);
globalService.saveData('user', data.data);
layer.open({
content: '登录成功',
time:1
time: 1
});
setTimeout(function() {
setTimeout(function () {
window.location.href = window.location.origin + window.location.pathname
// location.reload();
} , 300);
}, 300);
} else if (data.meta.code == 401) {
layer.open({
content: data.meta.message,
time:1
time: 1
});
// alert(data.meta.message);
// layer.msg(data.data.error);
......@@ -41,55 +41,54 @@ angular.module('myApp')
}
})
}
if(res.meta.code == 500){
$state.go('login', {}, {reload: true});
if (res.meta.code == 500) {
$state.go('login', {}, { reload: true });
}
})} else {
})
} else {
$scope.userinfo = {};
$scope.userinfo.userName = "未登录";
$scope.userinfo.loginState = false;
}
}
$scope.userinfo = globalService.getData("user");
if(!$scope.userinfo ) {
if (!$scope.userinfo) {
loginUrlCode()
} else {
var loginCode = globalService.getData("loginCode");
if(code && (loginCode !== code)){
if (code && (loginCode !== code)) {
localStorage.removeItem('ls.user')
loginUrlCode()
return
}
// alert("getUnfinishedOrder")
dingdaService.getUnfinishedOrder().success(function(data , status){
// alert(JSON.stringify(data))
if(data.meta.code === 303){
} else {
dingdaService.getUnfinishedOrder().success(function (data, status) {
if (data.meta.code === 303) {
layer.open({
content: data.meta.message,
time:2
time: 2
})
localStorage.removeItem('ls.user')
}
if(data.meta.code === 401) {
if (data.meta.code === 401) {
layer.open({
content:'登录token失效,请重新登录',
time:2
content: '登录token失效,请重新登录',
time: 2
})
localStorage.removeItem('ls.user')
return
}
if(data.meta.code === 200) {
if(data.data.unfinishedOrder.id) {
if (data.meta.code === 200) {
if (data.data.unfinishedOrder.id) {
$rootScope.isRendBike = true;
$scope.unfinishOrder = data.data.unfinishedOrder;
layer.open({
content: '您有未支付的订单,是否前往支付?',
btn: ['确认', '取消'],
shadeClose: false,
yes: function(index){
yes: function (index) {
layer.close(index);
$state.go('tripDetail' , { orderId : $scope.unfinishOrder.id});
$state.go('tripDetail', { orderId: $scope.unfinishOrder.id });
return;
},no: function(index){
}, no: function (index) {
layer.close(index);
}
});
......@@ -97,31 +96,33 @@ angular.module('myApp')
}
}).error(function(data , status) {
}).error(function (data, status) {
console.log(JSON.stringify(data))
})
}
}
$scope.moduleList = [];
$scope.moduleList.push({
name : "行程记录",
icon : "images/trip.png",
state : "trip"
name: "行程记录",
icon: "images/trip.png",
state: "trip"
});
$scope.moduleList.push({
name : "钱包",
icon : "images/wallet.png",
state : "wallet"
name: "钱包",
icon: "images/wallet.png",
state: "wallet"
});
$scope.moduleList.push({
name : "保证金",
icon : "images/bond.png",
state : "bond"
name: "保证金",
icon: "images/bond.png",
state: "bond"
});
$scope.moduleList.push({
name : "联系我们",
icon : "images/contact.png",
state : "contact"
name: "联系我们",
icon: "images/contact.png",
state: "contact"
});
// $scope.moduleList.push({
// name : "意见反馈",
......@@ -130,13 +131,13 @@ angular.module('myApp')
// });
}
$scope.doAction = function(index) {
if($scope.checkLogin()) {
$scope.doAction = function (index) {
if ($scope.checkLogin()) {
var arg = {};
if(index == 2 || index == 4) {
arg = {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude };
if (index == 2 || index == 4) {
arg = { longitude: $rootScope.currentPoint.longitude, latitude: $rootScope.currentPoint.latitude };
}
if(index == 3) {
if (index == 3) {
location.href = "http://wx.dy.dingdatech.com/contactUs.html";
} else {
$state.go($scope.moduleList[index].state, arg);
......@@ -144,15 +145,15 @@ angular.module('myApp')
}
}
$scope.checkLogin = function() {
if(!globalService.getData("user")) {
$state.go('login', {}, {reload: true});
$scope.checkLogin = function () {
if (!globalService.getData("user")) {
$state.go('login', {}, { reload: true });
return false;
}
return true;
}
$scope.logout = function() {
$scope.logout = function () {
$scope.userinfo = {};
$scope.userinfo.userName = "未登录";
$scope.userinfo.loginState = false;
......@@ -160,13 +161,13 @@ angular.module('myApp')
location.reload()
}
var initScan = function() {
var initScan = function () {
$rootScope.openScan = false;
$rootScope.openDetail = false;
$rootScope.openMenu = false;
$rootScope.openRing = false;
$rootScope.$watch("openScan",function(newVal, oldVal){
if(newVal !== oldVal && newVal) {
$rootScope.$watch("openScan", function (newVal, oldVal) {
if (newVal !== oldVal && newVal) {
// if(!$scope.checkLogin()) {
// return;
// }
......@@ -178,45 +179,45 @@ angular.module('myApp')
$rootScope.openScan = false;
if(!appClient){
if (!appClient) {
layer.open({
content: '调起摄像头失败',
time:2
time: 2
});
} else {
appClient.getERCode('', function (str, cb) {
dingdaService.verifyScanCode(str).success(function(data , status){
// alert(JSON.stringify(data))
if(data.meta.code == 200) {
if(data.data.orderDetail.id) {
dingdaService.verifyScanCode(str).success(function (data, status) {
// alert(JSON.stringify(data))
if (data.meta.code == 200) {
if (data.data.orderDetail.id) {
layer.open({
content: "租车成功,订单号为:" + data.data.orderDetail.id,
time:2
time: 2
});
// alert("租车成功,订单号为:" + data.data.orderDetail.id);
// alert("租车成功,订单号为:" + data.data.orderDetail.id);
$rootScope.isRendBike = true;
$state.go('rentDetail', {}, {reload: true});
$state.go('rentDetail', {}, { reload: true });
}
} else if(data.meta.code == 202) {
} else if (data.meta.code == 202) {
layer.open({
content: data.meta.message,
time:2
time: 2
});
$state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude });
$state.go('bond', { longitude: $rootScope.currentPoint.longitude, latitude: $rootScope.currentPoint.latitude });
} else {
layer.open({
content: data.meta.message,
time:2
time: 2
});
}
}).error(function(data , status){
}).error(function (data, status) {
layer.open({
content: "租车失败" + JSON.stringify(data),
time:2
time: 2
});
});
})
......@@ -243,96 +244,96 @@ angular.module('myApp')
// }, '')
}
// wx.scanQRCode({
// needResult: 1, // 默认为1,扫描结果由微信处理,1则直接返回扫描结果,
// scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
// success: function (res) {
// var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
// // alert(result);
// dingdaService.verifyScanCode(result).success(function(data , status){
// // alert(JSON.stringify(data))
// if(data.meta.code == 200) {
// if(data.data.orderDetail.id) {
//
// layer.open({
// content: "租车成功,订单号为:" + data.data.orderDetail.id,
// time:2
// });
// // alert("租车成功,订单号为:" + data.data.orderDetail.id);
// $rootScope.isRendBike = true;
//
// $state.go('rentDetail', {}, {reload: true});
//
// }
// } else if(data.meta.code == 202) {
// layer.open({
// content: data.meta.message,
// time:2
// });
// $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude });
// } else {
// layer.open({
// content: data.meta.message,
// time:2
// });
// }
// }).error(function(data , status){
// layer.open({
// content: "租车失败" + JSON.stringify(data),
// time:2
// });
// });
// }
// });
// wx.scanQRCode({
// needResult: 1, // 默认为1,扫描结果由微信处理,1则直接返回扫描结果,
// scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
// success: function (res) {
// var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
// // alert(result);
// dingdaService.verifyScanCode(result).success(function(data , status){
// // alert(JSON.stringify(data))
// if(data.meta.code == 200) {
// if(data.data.orderDetail.id) {
//
// layer.open({
// content: "租车成功,订单号为:" + data.data.orderDetail.id,
// time:2
// });
// // alert("租车成功,订单号为:" + data.data.orderDetail.id);
// $rootScope.isRendBike = true;
//
// $state.go('rentDetail', {}, {reload: true});
//
// }
// } else if(data.meta.code == 202) {
// layer.open({
// content: data.meta.message,
// time:2
// });
// $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude });
// } else {
// layer.open({
// content: data.meta.message,
// time:2
// });
// }
// }).error(function(data , status){
// layer.open({
// content: "租车失败" + JSON.stringify(data),
// time:2
// });
// });
// }
// });
}
})
$rootScope.$watch("openDetail",function(newVal, oldVal){
if(newVal === oldVal) return;
$rootScope.$watch("openDetail", function (newVal, oldVal) {
if (newVal === oldVal) return;
if(newVal) {
dingdaService.getUnfinishedOrder().success(function(data , status){
if(data.meta.code == 200) {
if(!data.data.unfinishedOrder.id) {
if (newVal) {
dingdaService.getUnfinishedOrder().success(function (data, status) {
if (data.meta.code == 200) {
if (!data.data.unfinishedOrder.id) {
layer.open({
content: '租车完成',
time:2
time: 2
});
// alert("租车完成")
// alert("租车完成")
$state.go('main');
}
}
if(data.data.unfinishedOrder.status == 200) {
$state.go('tripDetail' , { orderId : data.data.unfinishedOrder.id});
if (data.data.unfinishedOrder.status == 200) {
$state.go('tripDetail', { orderId: data.data.unfinishedOrder.id });
} else {
$state.go('rentDetail', {}, {reload: true});
$state.go('rentDetail', {}, { reload: true });
}
}).error(function(data , status) {
}).error(function (data, status) {
console.log(JSON.stringify(data))
})
}
})
$rootScope.$watch("openRing",function(newVal, oldVal){
$rootScope.$watch("openRing", function (newVal, oldVal) {
// TODO open new message
})
$rootScope.$watch("isLoadFinish" , function(newVal , oldVal){
if(newVal === oldVal) return;
if(newVal) {
if(document.getElementById("sliderMenu")){
$rootScope.$watch("isLoadFinish", function (newVal, oldVal) {
if (newVal === oldVal) return;
if (newVal) {
if (document.getElementById("sliderMenu")) {
document.getElementById("sliderMenu").style.display = "block";
}
}
})
document.getElementById("sliderMenu").addEventListener("touchmove", function(){
document.getElementById("sliderMenu").addEventListener("touchmove", function () {
return;
} , false);
}, false);
}
// mui.init();
// mui.init();
initScan();
init();
}]);
}]);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!