2aaabffe by fuenxin

clear ls.user

1 parent 73aafca1
1 angular.module('myApp') 1 angular.module('myApp')
2 .controller('mainController',['$scope','$rootScope','dingdaService','$state','globalService',function($scope,$rootScope,dingdaService,$state,globalService){ 2 .controller('mainController', ['$scope', '$rootScope', 'dingdaService', '$state', 'globalService', function ($scope, $rootScope, dingdaService, $state, globalService) {
3 3
4 $rootScope.isRendBike = false; 4 $rootScope.isRendBike = false;
5 $rootScope.isLoadFinish = false; 5 $rootScope.isLoadFinish = false;
6 $scope.unfinishOrder = {}; 6 $scope.unfinishOrder = {};
7 7
8 var init = function() { 8 var init = function () {
9 // globalService.init(); 9 // globalService.init();
10 function getUrl(name){ 10 function getUrl(name) {
11 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 11 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
12 var r = window.location.search.substr(1).match(reg); 12 var r = window.location.search.substr(1).match(reg);
13 if(r!=null)return unescape(r[2]); return null; 13 if (r != null) return unescape(r[2]); return null;
14 } 14 }
15 var code = getUrl('code') 15 var code = getUrl('code')
16 var loginUrlCode = function (code) { 16 var loginUrlCode = function (code) {
17 if(code){ 17 if (code) {
18 dingdaService.verifyThirdCode(code).success(function (res) { 18 dingdaService.verifyThirdCode(code).success(function (res) {
19 globalService.saveData('loginCode', code) 19 globalService.saveData('loginCode', code)
20 if(res.meta.code == 200) { 20 if (res.meta.code == 200) {
21 dingdaService.verifyPhoneCode(res.data.mobile, res.data.code).success(function (data) { 21 dingdaService.verifyPhoneCode(res.data.mobile, res.data.code).success(function (data) {
22 if (data.meta.code == 200) { 22 if (data.meta.code == 200) {
23 data.data.userName = res.data.mobile; 23 data.data.userName = res.data.mobile;
24 globalService.saveData('user',data.data); 24 globalService.saveData('user', data.data);
25 layer.open({ 25 layer.open({
26 content: '登录成功', 26 content: '登录成功',
27 time:1 27 time: 1
28 }); 28 });
29 setTimeout(function() { 29 setTimeout(function () {
30 window.location.href = window.location.origin + window.location.pathname 30 window.location.href = window.location.origin + window.location.pathname
31 // location.reload(); 31 // location.reload();
32 } , 300); 32 }, 300);
33 } else if (data.meta.code == 401) { 33 } else if (data.meta.code == 401) {
34 layer.open({ 34 layer.open({
35 content: data.meta.message, 35 content: data.meta.message,
36 time:1 36 time: 1
37 }); 37 });
38 // alert(data.meta.message); 38 // alert(data.meta.message);
39 // layer.msg(data.data.error); 39 // layer.msg(data.data.error);
...@@ -41,55 +41,54 @@ angular.module('myApp') ...@@ -41,55 +41,54 @@ angular.module('myApp')
41 } 41 }
42 }) 42 })
43 } 43 }
44 if(res.meta.code == 500){ 44 if (res.meta.code == 500) {
45 $state.go('login', {}, {reload: true}); 45 $state.go('login', {}, { reload: true });
46 } 46 }
47 })} else { 47 })
48 } else {
48 $scope.userinfo = {}; 49 $scope.userinfo = {};
49 $scope.userinfo.userName = "未登录"; 50 $scope.userinfo.userName = "未登录";
50 $scope.userinfo.loginState = false; 51 $scope.userinfo.loginState = false;
51 } 52 }
52 } 53 }
53 $scope.userinfo = globalService.getData("user"); 54 $scope.userinfo = globalService.getData("user");
54 if(!$scope.userinfo ) { 55 if (!$scope.userinfo) {
55 loginUrlCode() 56 loginUrlCode()
56 } else { 57 } else {
57 var loginCode = globalService.getData("loginCode"); 58 var loginCode = globalService.getData("loginCode");
58 if(code && (loginCode !== code)){ 59 if (code && (loginCode !== code)) {
60 localStorage.removeItem('ls.user')
59 loginUrlCode() 61 loginUrlCode()
60 return 62 } else {
61 } 63 dingdaService.getUnfinishedOrder().success(function (data, status) {
62 // alert("getUnfinishedOrder") 64 if (data.meta.code === 303) {
63 dingdaService.getUnfinishedOrder().success(function(data , status){
64 // alert(JSON.stringify(data))
65 if(data.meta.code === 303){
66 layer.open({ 65 layer.open({
67 content: data.meta.message, 66 content: data.meta.message,
68 time:2 67 time: 2
69 }) 68 })
70 localStorage.removeItem('ls.user') 69 localStorage.removeItem('ls.user')
71 } 70 }
72 if(data.meta.code === 401) { 71 if (data.meta.code === 401) {
73 layer.open({ 72 layer.open({
74 content:'登录token失效,请重新登录', 73 content: '登录token失效,请重新登录',
75 time:2 74 time: 2
76 }) 75 })
77 localStorage.removeItem('ls.user') 76 localStorage.removeItem('ls.user')
78 return 77 return
79 } 78 }
80 if(data.meta.code === 200) { 79 if (data.meta.code === 200) {
81 if(data.data.unfinishedOrder.id) { 80 if (data.data.unfinishedOrder.id) {
82 $rootScope.isRendBike = true; 81 $rootScope.isRendBike = true;
83 $scope.unfinishOrder = data.data.unfinishedOrder; 82 $scope.unfinishOrder = data.data.unfinishedOrder;
84 layer.open({ 83 layer.open({
85 content: '您有未支付的订单,是否前往支付?', 84 content: '您有未支付的订单,是否前往支付?',
86 btn: ['确认', '取消'], 85 btn: ['确认', '取消'],
87 shadeClose: false, 86 shadeClose: false,
88 yes: function(index){ 87 yes: function (index) {
89 layer.close(index); 88 layer.close(index);
90 $state.go('tripDetail' , { orderId : $scope.unfinishOrder.id}); 89 $state.go('tripDetail', { orderId: $scope.unfinishOrder.id });
91 return; 90 return;
92 },no: function(index){ 91 }, no: function (index) {
93 layer.close(index); 92 layer.close(index);
94 } 93 }
95 }); 94 });
...@@ -97,31 +96,33 @@ angular.module('myApp') ...@@ -97,31 +96,33 @@ angular.module('myApp')
97 96
98 } 97 }
99 98
100 }).error(function(data , status) { 99 }).error(function (data, status) {
101 console.log(JSON.stringify(data)) 100 console.log(JSON.stringify(data))
102 }) 101 })
103 } 102 }
104 103
104 }
105
105 $scope.moduleList = []; 106 $scope.moduleList = [];
106 $scope.moduleList.push({ 107 $scope.moduleList.push({
107 name : "行程记录", 108 name: "行程记录",
108 icon : "images/trip.png", 109 icon: "images/trip.png",
109 state : "trip" 110 state: "trip"
110 }); 111 });
111 $scope.moduleList.push({ 112 $scope.moduleList.push({
112 name : "钱包", 113 name: "钱包",
113 icon : "images/wallet.png", 114 icon: "images/wallet.png",
114 state : "wallet" 115 state: "wallet"
115 }); 116 });
116 $scope.moduleList.push({ 117 $scope.moduleList.push({
117 name : "保证金", 118 name: "保证金",
118 icon : "images/bond.png", 119 icon: "images/bond.png",
119 state : "bond" 120 state: "bond"
120 }); 121 });
121 $scope.moduleList.push({ 122 $scope.moduleList.push({
122 name : "联系我们", 123 name: "联系我们",
123 icon : "images/contact.png", 124 icon: "images/contact.png",
124 state : "contact" 125 state: "contact"
125 }); 126 });
126 // $scope.moduleList.push({ 127 // $scope.moduleList.push({
127 // name : "意见反馈", 128 // name : "意见反馈",
...@@ -130,13 +131,13 @@ angular.module('myApp') ...@@ -130,13 +131,13 @@ angular.module('myApp')
130 // }); 131 // });
131 } 132 }
132 133
133 $scope.doAction = function(index) { 134 $scope.doAction = function (index) {
134 if($scope.checkLogin()) { 135 if ($scope.checkLogin()) {
135 var arg = {}; 136 var arg = {};
136 if(index == 2 || index == 4) { 137 if (index == 2 || index == 4) {
137 arg = {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude }; 138 arg = { longitude: $rootScope.currentPoint.longitude, latitude: $rootScope.currentPoint.latitude };
138 } 139 }
139 if(index == 3) { 140 if (index == 3) {
140 location.href = "http://wx.dy.dingdatech.com/contactUs.html"; 141 location.href = "http://wx.dy.dingdatech.com/contactUs.html";
141 } else { 142 } else {
142 $state.go($scope.moduleList[index].state, arg); 143 $state.go($scope.moduleList[index].state, arg);
...@@ -144,15 +145,15 @@ angular.module('myApp') ...@@ -144,15 +145,15 @@ angular.module('myApp')
144 } 145 }
145 } 146 }
146 147
147 $scope.checkLogin = function() { 148 $scope.checkLogin = function () {
148 if(!globalService.getData("user")) { 149 if (!globalService.getData("user")) {
149 $state.go('login', {}, {reload: true}); 150 $state.go('login', {}, { reload: true });
150 return false; 151 return false;
151 } 152 }
152 return true; 153 return true;
153 } 154 }
154 155
155 $scope.logout = function() { 156 $scope.logout = function () {
156 $scope.userinfo = {}; 157 $scope.userinfo = {};
157 $scope.userinfo.userName = "未登录"; 158 $scope.userinfo.userName = "未登录";
158 $scope.userinfo.loginState = false; 159 $scope.userinfo.loginState = false;
...@@ -160,13 +161,13 @@ angular.module('myApp') ...@@ -160,13 +161,13 @@ angular.module('myApp')
160 location.reload() 161 location.reload()
161 } 162 }
162 163
163 var initScan = function() { 164 var initScan = function () {
164 $rootScope.openScan = false; 165 $rootScope.openScan = false;
165 $rootScope.openDetail = false; 166 $rootScope.openDetail = false;
166 $rootScope.openMenu = false; 167 $rootScope.openMenu = false;
167 $rootScope.openRing = false; 168 $rootScope.openRing = false;
168 $rootScope.$watch("openScan",function(newVal, oldVal){ 169 $rootScope.$watch("openScan", function (newVal, oldVal) {
169 if(newVal !== oldVal && newVal) { 170 if (newVal !== oldVal && newVal) {
170 // if(!$scope.checkLogin()) { 171 // if(!$scope.checkLogin()) {
171 // return; 172 // return;
172 // } 173 // }
...@@ -178,45 +179,45 @@ angular.module('myApp') ...@@ -178,45 +179,45 @@ angular.module('myApp')
178 $rootScope.openScan = false; 179 $rootScope.openScan = false;
179 180
180 181
181 if(!appClient){ 182 if (!appClient) {
182 layer.open({ 183 layer.open({
183 content: '调起摄像头失败', 184 content: '调起摄像头失败',
184 time:2 185 time: 2
185 }); 186 });
186 187
187 } else { 188 } else {
188 appClient.getERCode('', function (str, cb) { 189 appClient.getERCode('', function (str, cb) {
189 dingdaService.verifyScanCode(str).success(function(data , status){ 190 dingdaService.verifyScanCode(str).success(function (data, status) {
190 // alert(JSON.stringify(data)) 191 // alert(JSON.stringify(data))
191 if(data.meta.code == 200) { 192 if (data.meta.code == 200) {
192 if(data.data.orderDetail.id) { 193 if (data.data.orderDetail.id) {
193 194
194 layer.open({ 195 layer.open({
195 content: "租车成功,订单号为:" + data.data.orderDetail.id, 196 content: "租车成功,订单号为:" + data.data.orderDetail.id,
196 time:2 197 time: 2
197 }); 198 });
198 // alert("租车成功,订单号为:" + data.data.orderDetail.id); 199 // alert("租车成功,订单号为:" + data.data.orderDetail.id);
199 $rootScope.isRendBike = true; 200 $rootScope.isRendBike = true;
200 201
201 $state.go('rentDetail', {}, {reload: true}); 202 $state.go('rentDetail', {}, { reload: true });
202 203
203 } 204 }
204 } else if(data.meta.code == 202) { 205 } else if (data.meta.code == 202) {
205 layer.open({ 206 layer.open({
206 content: data.meta.message, 207 content: data.meta.message,
207 time:2 208 time: 2
208 }); 209 });
209 $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude }); 210 $state.go('bond', { longitude: $rootScope.currentPoint.longitude, latitude: $rootScope.currentPoint.latitude });
210 } else { 211 } else {
211 layer.open({ 212 layer.open({
212 content: data.meta.message, 213 content: data.meta.message,
213 time:2 214 time: 2
214 }); 215 });
215 } 216 }
216 }).error(function(data , status){ 217 }).error(function (data, status) {
217 layer.open({ 218 layer.open({
218 content: "租车失败" + JSON.stringify(data), 219 content: "租车失败" + JSON.stringify(data),
219 time:2 220 time: 2
220 }); 221 });
221 }); 222 });
222 }) 223 })
...@@ -243,96 +244,96 @@ angular.module('myApp') ...@@ -243,96 +244,96 @@ angular.module('myApp')
243 // }, '') 244 // }, '')
244 } 245 }
245 246
246 // wx.scanQRCode({ 247 // wx.scanQRCode({
247 // needResult: 1, // 默认为1,扫描结果由微信处理,1则直接返回扫描结果, 248 // needResult: 1, // 默认为1,扫描结果由微信处理,1则直接返回扫描结果,
248 // scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 249 // scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
249 // success: function (res) { 250 // success: function (res) {
250 // var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 251 // var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
251 // // alert(result); 252 // // alert(result);
252 // dingdaService.verifyScanCode(result).success(function(data , status){ 253 // dingdaService.verifyScanCode(result).success(function(data , status){
253 // // alert(JSON.stringify(data)) 254 // // alert(JSON.stringify(data))
254 // if(data.meta.code == 200) { 255 // if(data.meta.code == 200) {
255 // if(data.data.orderDetail.id) { 256 // if(data.data.orderDetail.id) {
256 // 257 //
257 // layer.open({ 258 // layer.open({
258 // content: "租车成功,订单号为:" + data.data.orderDetail.id, 259 // content: "租车成功,订单号为:" + data.data.orderDetail.id,
259 // time:2 260 // time:2
260 // }); 261 // });
261 // // alert("租车成功,订单号为:" + data.data.orderDetail.id); 262 // // alert("租车成功,订单号为:" + data.data.orderDetail.id);
262 // $rootScope.isRendBike = true; 263 // $rootScope.isRendBike = true;
263 // 264 //
264 // $state.go('rentDetail', {}, {reload: true}); 265 // $state.go('rentDetail', {}, {reload: true});
265 // 266 //
266 // } 267 // }
267 // } else if(data.meta.code == 202) { 268 // } else if(data.meta.code == 202) {
268 // layer.open({ 269 // layer.open({
269 // content: data.meta.message, 270 // content: data.meta.message,
270 // time:2 271 // time:2
271 // }); 272 // });
272 // $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude }); 273 // $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude });
273 // } else { 274 // } else {
274 // layer.open({ 275 // layer.open({
275 // content: data.meta.message, 276 // content: data.meta.message,
276 // time:2 277 // time:2
277 // }); 278 // });
278 // } 279 // }
279 // }).error(function(data , status){ 280 // }).error(function(data , status){
280 // layer.open({ 281 // layer.open({
281 // content: "租车失败" + JSON.stringify(data), 282 // content: "租车失败" + JSON.stringify(data),
282 // time:2 283 // time:2
283 // }); 284 // });
284 // }); 285 // });
285 // } 286 // }
286 // }); 287 // });
287 } 288 }
288 }) 289 })
289 $rootScope.$watch("openDetail",function(newVal, oldVal){ 290 $rootScope.$watch("openDetail", function (newVal, oldVal) {
290 if(newVal === oldVal) return; 291 if (newVal === oldVal) return;
291 292
292 if(newVal) { 293 if (newVal) {
293 dingdaService.getUnfinishedOrder().success(function(data , status){ 294 dingdaService.getUnfinishedOrder().success(function (data, status) {
294 if(data.meta.code == 200) { 295 if (data.meta.code == 200) {
295 if(!data.data.unfinishedOrder.id) { 296 if (!data.data.unfinishedOrder.id) {
296 layer.open({ 297 layer.open({
297 content: '租车完成', 298 content: '租车完成',
298 time:2 299 time: 2
299 }); 300 });
300 // alert("租车完成") 301 // alert("租车完成")
301 $state.go('main'); 302 $state.go('main');
302 } 303 }
303 } 304 }
304 305
305 if(data.data.unfinishedOrder.status == 200) { 306 if (data.data.unfinishedOrder.status == 200) {
306 $state.go('tripDetail' , { orderId : data.data.unfinishedOrder.id}); 307 $state.go('tripDetail', { orderId: data.data.unfinishedOrder.id });
307 } else { 308 } else {
308 $state.go('rentDetail', {}, {reload: true}); 309 $state.go('rentDetail', {}, { reload: true });
309 } 310 }
310 }).error(function(data , status) { 311 }).error(function (data, status) {
311 console.log(JSON.stringify(data)) 312 console.log(JSON.stringify(data))
312 }) 313 })
313 314
314 } 315 }
315 }) 316 })
316 $rootScope.$watch("openRing",function(newVal, oldVal){ 317 $rootScope.$watch("openRing", function (newVal, oldVal) {
317 // TODO open new message 318 // TODO open new message
318 }) 319 })
319 $rootScope.$watch("isLoadFinish" , function(newVal , oldVal){ 320 $rootScope.$watch("isLoadFinish", function (newVal, oldVal) {
320 if(newVal === oldVal) return; 321 if (newVal === oldVal) return;
321 if(newVal) { 322 if (newVal) {
322 if(document.getElementById("sliderMenu")){ 323 if (document.getElementById("sliderMenu")) {
323 document.getElementById("sliderMenu").style.display = "block"; 324 document.getElementById("sliderMenu").style.display = "block";
324 } 325 }
325 } 326 }
326 }) 327 })
327 328
328 document.getElementById("sliderMenu").addEventListener("touchmove", function(){ 329 document.getElementById("sliderMenu").addEventListener("touchmove", function () {
329 return; 330 return;
330 } , false); 331 }, false);
331 } 332 }
332 333
333 // mui.init(); 334 // mui.init();
334 initScan(); 335 initScan();
335 init(); 336 init();
336 337
337 338
338 }]); 339 }]);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!