jufubao-base 1.0.238-beta1 → 1.0.238-beta68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,753 @@
1
+ 'use strict';
2
+
3
+ import {mapActions, mapMutations, mapState} from "vuex";
4
+ import storage from "@/common/storage";
5
+ import {isWechat, isPlatform, baseEnvTypeReg} from "@/utils/xd.base";
6
+ import {getCacheTime} from "@/common/common";
7
+ import {parsePath} from "@/utils/linkUrl";
8
+ // #ifdef H5
9
+ import cookie from "@/common/cookie";
10
+ // #endif
11
+
12
+ export default {
13
+ data(){
14
+ return {
15
+
16
+ //微信判断用户拒绝授权服务
17
+ rejectSave: 'xd-user-reject-location',
18
+
19
+ //微信小程序用户是否拒绝授权服务(永久)
20
+ rejectSaveLong:'xd-user-reject-long-location',
21
+
22
+ //保存上一次定位信息(正式缓冲2小时,测试机环境0.5小时)
23
+ locationStorageKey: "xd_three_map",
24
+
25
+ //永久保存上一次定位信息
26
+ locationLongStorageKey: 'xd_three_map_long',
27
+
28
+ //定位成功保存数据(定位成功就保存等待有组件需要弹出时候转化xd_three_map)
29
+ locationSuccessKey: 'xd_three_map_success',
30
+
31
+ //相同城市临是存储第三方定位信息(页面卸载,页面销毁此数据转化为第三方xd_three_map保存数据)
32
+ sameCityChangeLocationKey: 'xd_same_city_change_three_map',
33
+
34
+
35
+ //上一次使用定位城市
36
+ prevUserLocationCityKey:'xd_user_current_access_city',
37
+
38
+ //用户选中处理
39
+ prevUserSelectCityKey:'xd_user_select_access_city',
40
+
41
+ //定位成功保存数据(定位成功就保存等待有组件需要弹出时候转化 prevUserLocationCityKey)
42
+ prevUserlocationCitySuccessKey: 'xd_user_location_success_city',
43
+
44
+ //用户是否确认过操作逻辑
45
+ userActionKey: 'xd_user_succes_is_change_city' ,
46
+
47
+ //百度定位
48
+ initBaidu: false,
49
+ baiduAKConfig: null,
50
+ baiduMap:null,
51
+ center: 15,
52
+ baiduCb:null,
53
+
54
+ // #ifdef H5
55
+ //微信SDK初始化失败
56
+ loadingStatusKey:'jfb-wx-location-reload-status',
57
+ // #endif
58
+ }
59
+ },
60
+ computed:{
61
+ ...mapState(['siteInfo','locationLock','locationEvent','currentStyle','brandInfo'])
62
+ },
63
+
64
+ created() {
65
+ if(this.$configProject.isPreview) {
66
+ this.$emit('cityAndLocation', {location:{}, city:this.getDefaultCity()});
67
+ this.$emit('done', {});
68
+ this.$emit('city', this.getDefaultCity());
69
+ console.warn(`Success.Location.isPreview: ${JSON.stringify({city:this.getDefaultCity(),location:{}})}`)
70
+ }
71
+ else{
72
+ //百度定位
73
+ this.baiduAKConfig = this.baiduAk || this.$settings.baiduAk;
74
+ this.setLocationEvent(({city,location})=>{
75
+ this.$emit('cityAndLocation', {location, city});
76
+ this.$emit('done', location);
77
+ this.$emit('city', city);
78
+ this.setLocationLock(false);
79
+ console.warn(`Success.Location: ${JSON.stringify({city,location})}`)
80
+ this.$xdLog.setProject('Location.$emit.Done', {location,city});
81
+ });
82
+
83
+ if(!this.locationLock){
84
+ this.setLocationLock(true);
85
+ this.LocationInit();
86
+ }
87
+ }
88
+
89
+ },
90
+ methods:{
91
+ ...mapMutations([
92
+ //设置临时第三方定位缓冲
93
+ 'setLocationInfo',
94
+ //清除临时第三方定位缓冲
95
+ 'clearLocation',
96
+ //设置城市信息
97
+ 'setCityInfo',
98
+ //设置定位锁(防止同时使用定位组件)
99
+ 'setLocationLock',
100
+ //定位成功事件
101
+ 'setLocationEvent',
102
+ //设置定位信息
103
+ 'setLocationCity'
104
+ ]),
105
+
106
+ //微信定位授权
107
+ ...mapActions(['getH5WxAuthorize']),
108
+
109
+ //获取定位成功
110
+ ...mapActions('wxAuthorize', [
111
+ 'getLoadingCityInfoByLocationLv4'
112
+ ]),
113
+
114
+ /**
115
+ * @description 成功进行事件分发与更新定位变量状态
116
+ * @param city
117
+ * @param location
118
+ * @param isUpdate 是需要更新定位信息与选择城市
119
+ */
120
+ handleSuccess(isUpdate, city, location){
121
+ if(isUpdate) {
122
+ console.warn(`Success.Location.update: ${JSON.stringify({city,location})}`)
123
+ this.$xdLog.setProject('Location.Success.Location.update', {city,location});
124
+ //更新本地存储
125
+ this.setUserSelectCity(city);
126
+ this.setPrevUserCity(city);
127
+ this.setLocationData(location);
128
+ this.delStorage(this.locationSuccessKey);
129
+ this.delStorage(this.prevUserlocationCitySuccessKey)
130
+ //更新状态
131
+ this.setLocationCity({city, location});
132
+ }
133
+ if(location) this.setStorage(this.locationLongStorageKey, location)
134
+ setTimeout(()=>{
135
+ console.warn(`Success.Location.upEvent: ${JSON.stringify({city,location})}`)
136
+ this.locationEvent.map(item=>{
137
+ this.$xdLog.setProject('Location.Success.Location.upEvent', {city,location});
138
+ item({city, location})
139
+ })
140
+
141
+ },1)
142
+
143
+ },
144
+
145
+ /**
146
+ * @description 重新定位
147
+ * @param cb 成功回调方法
148
+ * @return cb(city, location)
149
+ */
150
+ reloadLocation(cb) {
151
+ this.checkLocationType((location, status)=>{
152
+ this.getLocationCity(location, (city, location)=>{
153
+ if(typeof cb === 'function') {
154
+ cb(city, location);
155
+ }
156
+ })
157
+ })
158
+ },
159
+
160
+ /**
161
+ * @description 检查使用某种模式进行定位
162
+ * @param cb
163
+ */
164
+ checkLocationType(cb){
165
+ const location = this.getLocationData();
166
+
167
+ if(location) {
168
+ cb(location, true);
169
+ return;
170
+ }
171
+
172
+ //#ifdef H5
173
+ if(isWechat()) {
174
+ this.wxLocation(cb)
175
+ return
176
+ }
177
+
178
+ //百度定位
179
+ if(this.baidu){
180
+ if(!this.baiduAKConfig) {
181
+ console.error('请传入百度AK值')
182
+ throw new Error('请传入百度AK值');
183
+ } else {
184
+ this.baiduCb = cb;
185
+ if(this.baiduMap) {
186
+ this.baiduLocation(this.baiduMap)
187
+ } else this.initBaidu = true;
188
+ }
189
+ }
190
+ //#endif
191
+
192
+ // #ifdef MP-WEIXIN
193
+ this.wxMpLocationInit(cb)
194
+ // #endif
195
+
196
+ },
197
+
198
+ /**
199
+ * @description 定位初始化入口
200
+ */
201
+ LocationInit(){
202
+ const prevCity = this.getPrevUserCity();
203
+ const prevLocation = this.getLocationData();
204
+ const locationSuccess = this.getStorage(this.locationSuccessKey);
205
+ const locationCitySuccess = this.getStorage(this.prevUserlocationCitySuccessKey);
206
+ const userActionStatus = this.getUserChangeCityStatue();
207
+
208
+ //定位成功
209
+ if(prevLocation && prevCity && prevCity.is_default === 'Y') {
210
+ console.warn(`Location.cache.init:${JSON.stringify({prevLocation,prevCity})}`);
211
+ this.$xdLog.setProject('Location.Success.Location.cache', {city:prevCity,location:prevLocation});
212
+ this.handleSuccess(false, prevCity, prevLocation);
213
+ return;
214
+ }
215
+
216
+ //已选中当没有同意切换定位(不再城市选择页面,isSelect=true 要求实时定位功能)
217
+ if(userActionStatus && !this.isSelect) {
218
+ console.warn(`Location.user.noChange:${JSON.stringify({prevLocation,prevCity:this.getDefaultCity()})}`);
219
+ this.handleSuccess(false, this.getDefaultCity(), prevLocation);
220
+ return;
221
+ }
222
+
223
+ //定位成功并且通过经纬度获取城市信息成功(通过静默模式定位成功度)
224
+ if(!userActionStatus && locationSuccess && (locationCitySuccess && locationCitySuccess.is_default === 'Y')) {
225
+ if(this.isPop) {
226
+ this.show({
227
+ message:`定位显示您在:${locationCitySuccess.province_name} - ${locationCitySuccess.city_name},是否需要切换?`,
228
+ confirmText: '切换到'
229
+ },(res)=>{
230
+ this.setUserChangeCityStatue();
231
+ if(res.confirm) this.handleSuccess(true, locationCitySuccess,locationSuccess);
232
+ else this.handleSuccess(false, locationCitySuccess,locationSuccess);
233
+ this.delStorage(this.locationSuccessKey);
234
+ this.delStorage(this.prevUserlocationCitySuccessKey);
235
+ })
236
+ return;
237
+ }
238
+ }
239
+
240
+
241
+ //定位城市信息
242
+ this.checkLocationType((location, status)=>{
243
+ console.warn(`Location.Api.init:${JSON.stringify({prevLocation,prevCity})}`)
244
+ //定位成功
245
+ if(status) this.getLocationCity(location)
246
+ //定位失败
247
+ else this.handleSuccess(false, this.getDefaultCity(), location);
248
+ })
249
+ },
250
+
251
+
252
+ show({message,confirmText}, cb){
253
+ uni.showModal({
254
+ title: '温馨提示',
255
+ content: message,
256
+ confirmText: confirmText || '切换到',
257
+ success: (res) => {
258
+ cb(res)
259
+ }
260
+ });
261
+ },
262
+
263
+ // #ifdef H5
264
+ //==微信定位=======================
265
+ /**
266
+ * @description微信定位
267
+ */
268
+ wxLocation(cb){
269
+ //微信SDK初始化失败不在加载
270
+ if(cookie.get(this.locationSuccessKey)) {
271
+ return
272
+ }
273
+
274
+ //启动微信授权功能
275
+ this.getH5WxAuthorize({jsApiList: ['openLocation', 'getLocation']})
276
+ .then(({jwxSDK}) => {
277
+
278
+ //pc端端微信环境直接返回
279
+ if(isPlatform().isPc || (jwxSDK && typeof jwxSDK.getLocation !== 'function')) {
280
+ this.$xdLog.setProject('Location.wx.jwxSDK.not.support', {lng: null, lat: null});
281
+ setTimeout(()=>{
282
+ cb(this.getLocationData()||undefined,false)
283
+ },1)
284
+ return
285
+ }
286
+
287
+ //手机端微信环境
288
+ jwxSDK.getLocation({
289
+ type: 'gcj02',
290
+ success: (res) => {
291
+ let location = this.gcj02tobd09(res.longitude, res.latitude);
292
+ let locationInfo = {
293
+ latitude: location['latitude'],
294
+ longitude: location['longitude'],
295
+ address: {}
296
+ };
297
+ this.$xdLog.setProject('Location.wx.api.done', {
298
+ lng: location.longitude,
299
+ lat: location.latitude
300
+ });
301
+ setTimeout(()=>{
302
+ cb(locationInfo, true)
303
+ },1)
304
+
305
+ },
306
+ fail: (e) => {
307
+ this.$xdLog.setProject('Location.wx.api.fail', {lng: null, lat: null, error:e});
308
+ cb(this.getLocationData()||undefined, false)
309
+ },
310
+ cancel: (e) => {
311
+ this.$xdLog.setProject('Location.wx.api.cancel', {lng: null, lat: null});
312
+ cb(this.getLocationData()||undefined, false)
313
+ }
314
+ });
315
+ })
316
+ .catch(res => {
317
+ cookie.set(this.locationSuccessKey,'Y')
318
+ this.$xdLog.setProject('Location.wx.jwxSDK.fail', {
319
+ lng: null,
320
+ lat: null
321
+ });
322
+ cb(this.getLocationData()||undefined)
323
+ });
324
+ },
325
+ //==微信定位=======================
326
+
327
+ //==baidu定位=======================
328
+ baiduLocation(BMap){
329
+ let geolocation = new BMap['Geolocation']();
330
+ geolocation['enableSDKLocation']();
331
+ geolocation.getCurrentPosition(
332
+ (location) => {
333
+ let point = this.$xdUniHelper.cloneDeep(location.point);
334
+ let locationInfo = {
335
+ latitude: point['lat'],
336
+ longitude: point['lng'],
337
+ address: location.address
338
+ };
339
+ setTimeout(()=>{
340
+ this.$xdLog.setProject('Location.Baidu.SDK.Success', {location:locationInfo});
341
+ this.baiduCb(locationInfo, true);
342
+ this.baiduCb = null;
343
+ },1)
344
+
345
+ },
346
+ (error) => {
347
+ this.baiduCb(this.getLocationData()||undefined,false);
348
+ this.baiduCb = null;
349
+ this.$xdLog.setProject('Location.Baidu.SDK.Fail', {location:null});
350
+ }
351
+ )
352
+ },
353
+
354
+ handleBaiduReady({BMap,map}){
355
+ this.baiduMap = BMap;
356
+ this.baiduLocation(BMap);
357
+ this.$xdLog.setProject('Location.Baidu.Init.Success', {location:locationInfo});
358
+ },
359
+ //==baidu定位=======================
360
+ // #endif
361
+
362
+ // #ifdef MP-WEIXIN
363
+ //==微信小程序定位====================
364
+ wxMpLocationInit(cb){
365
+ let timer = null;
366
+ console.warn(`location.start`)
367
+
368
+ wx.getFuzzyLocation({
369
+ type: 'gcj02',
370
+ geocode: true,
371
+ success: (res)=> {
372
+ console.warn(`location.success`)
373
+ let location = this.gcj02tobd09(res.longitude, res.latitude);
374
+ let locationInfo = {
375
+ latitude: location['latitude'],
376
+ longitude: location['longitude'],
377
+ address: {}
378
+ };
379
+ this.$xdLog.setProject('Location.wx.mp.api.done', {
380
+ lng: location.longitude,
381
+ lat: location.latitude
382
+ });
383
+ setTimeout(()=>{
384
+ cb(locationInfo, true)
385
+ },1);
386
+
387
+ if(timer) clearTimeout(timer);
388
+ },
389
+ fail: (err)=>{
390
+ console.warn(`location.fail`)
391
+
392
+ //首次定位
393
+ if(!storage.get(this.rejectSaveLong)){
394
+ storage.set(this.rejectSaveLong,1);
395
+ this.$xdLog.setProject('Location.wx.api.fail', {lng: null, lat: null, error:err});
396
+ cb(this.getLocationData()||undefined, false)
397
+ return
398
+ }
399
+
400
+ if(this.$xdUniHelper.checkVarType(err) === 'object'
401
+ && err.errMsg === 'getLocation:fail auth deny'
402
+ && storage.get(this.rejectSaveLong)
403
+ ) {
404
+ this.$xdConfirm({
405
+ title: "提示",
406
+ content:'请打开地理位置定位权限',
407
+ confirmText: "确定",
408
+ cancelText: "取消",
409
+ success:(res)=>{
410
+ if (res.confirm) {
411
+ wx.openSetting({
412
+ success: function (res) {},
413
+ });
414
+ } else if (res.cancel) {
415
+ console.log("用户点击取消");
416
+ }
417
+ }
418
+ })
419
+ }
420
+ this.$xdLog.setProject('Location.wx.api.fail', {lng: null, lat: null, error:err});
421
+ cb(this.getLocationData()||undefined, false);
422
+ if(timer) clearTimeout(timer);
423
+ }
424
+ });
425
+
426
+ //三秒超时
427
+ timer = setTimeout(()=>{
428
+ console.warn(`location.timeout`)
429
+ this.$xdLog.setProject('Location.wx.api.timeout', {lng: null, lat: null, message:'定位超时'});
430
+ cb(this.getLocationData()||undefined, false)
431
+ },5000)
432
+ },
433
+ //==微信小程序定位====================
434
+ // #endif
435
+
436
+ //==定位工具函数========================
437
+ setStorage(key,data,time= 0){
438
+ if(time === 0) storage.set(key,data);
439
+ else storage.set(key,data,time);
440
+ },
441
+ getStorage(key){
442
+ return storage.get(key);
443
+ },
444
+ delStorage(key) {
445
+ storage.remove(key);
446
+ },
447
+
448
+ /**
449
+ * @description 获取通过定位成功的经纬度获取到到城市
450
+ * @returns {string|*|null}
451
+ */
452
+ getPrevUserCity(){
453
+ return storage.get(this.prevUserLocationCityKey);
454
+ },
455
+
456
+ /**
457
+ * @description 设置通过定位成功的经纬度获取到到城市
458
+ * @param city
459
+ * @returns {string|*|null}
460
+ */
461
+ setPrevUserCity(city){
462
+ storage.set(this.prevUserLocationCityKey,city);
463
+ },
464
+
465
+ /**
466
+ * @description 设置用户选择的保存城市信息
467
+ * @param city
468
+ * @returns {string|*|null}
469
+ */
470
+ setUserSelectCity(city){
471
+ storage.set(this.prevUserSelectCityKey,city);
472
+ },
473
+
474
+ /**
475
+ * @description 获取用户选择的保存城市信息
476
+ * @returns {string|*|null}
477
+ */
478
+ getUserSelectCity(){
479
+ return storage.get(this.prevUserSelectCityKey);
480
+ },
481
+
482
+ /**
483
+ * @description 获取用户是否已进行定位成功操作
484
+ * @returns {string|*|null}
485
+ */
486
+ getUserChangeCityStatue(){
487
+ return storage.get(this.userActionKey);
488
+ },
489
+ /**
490
+ * @description 设置用户是否已进行定位成功操作
491
+ * @returns {string|*|null}
492
+ */
493
+ setUserChangeCityStatue(){
494
+ let time = getCacheTime(this,0.5, 0.01, 2);
495
+ storage.set(this.userActionKey, 1, time);
496
+ },
497
+
498
+ /**
499
+ * @description 获取永久第三方定位信息
500
+ * @returns {string|*|null}
501
+ */
502
+ getLocationData(){
503
+ return storage.get(this.locationStorageKey);
504
+ },
505
+
506
+ /**
507
+ * @description 设置永久第三方定位信息
508
+ * @returns {string|*|null}
509
+ */
510
+ setLocationData(location){
511
+ let time = getCacheTime(this,0.5, 0.04, 2);
512
+ storage.set(this.locationStorageKey,location,time);
513
+ },
514
+
515
+ /**
516
+ * @description 获取定位成功并且定位城市与默认或者上次选中城市一致的值(只保存当前经纬度操作)
517
+ * @returns {string|*|null}
518
+ */
519
+ getSameCityLocation(){
520
+ return storage.get(this.sameCityChangeLocationKey);
521
+ },
522
+
523
+ /**
524
+ * @description 设置位成功并且定位城市与默认或者上次选中城市一致的值(只保存当前经纬度操作)
525
+ * @returns {string|*|null}
526
+ */
527
+ setSameCityLocation(location){
528
+ storage.set(this.sameCityChangeLocationKey,location);
529
+ },
530
+
531
+
532
+
533
+ /**
534
+ * @description 火星转百度坐标
535
+ * @param lng
536
+ * @param lat
537
+ * @returns {{latitude: *, longitude: *}}
538
+ */
539
+ gcj02tobd09(lng, lat) {
540
+ let x_PI = 3.14159265358979324 * 3000.0 / 180.0;
541
+ let PI = 3.1415926535897932384626;
542
+ let a = 6378245.0;
543
+ let ee = 0.00669342162296594323;
544
+
545
+ lat = +lat;
546
+ lng = +lng;
547
+ let z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
548
+ let theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
549
+ let bd_lng = z * Math.cos(theta) + 0.0065;
550
+ let bd_lat = z * Math.sin(theta) + 0.006;
551
+ return {longitude: bd_lng, latitude:bd_lat}
552
+ },
553
+ //==定位工具函数========================
554
+
555
+ //==城市相关=========================================
556
+ /**
557
+ * @description 定位完成处理(包括定位成功或者失败处理)
558
+ * @param location
559
+ * @param cb
560
+ */
561
+ getLocationCity(location, cb){
562
+ this.getApiLocationCity(location,cb).then().catch();
563
+ },
564
+
565
+ /**
566
+ * @description 通过经纬度从服务器获取选中城市新
567
+ * @param location {Object|undefined}
568
+ * @param location.latitude {string}
569
+ * @param location.longitude {string}
570
+ * @param cb
571
+ */
572
+ getApiLocationCity(location,cb){
573
+ let params = null
574
+ if(!location) params = {};
575
+ else params = JSON.parse(JSON.stringify(location));
576
+ this.$xdLog.setProject('Location.City.Ajax.Start', {location:location});
577
+ return new Promise((resolve, reject)=>{
578
+ this.getLoadingCityInfoByLocationLv4(params)
579
+ .then(res=>{
580
+ res.data['is_default'] = 'N';
581
+ if(location) res.data['is_default'] = 'Y';
582
+ setTimeout(()=>{
583
+ if(typeof cb === 'function') cb(res.data, location);
584
+ else this.setSelectCityData(res.data, location);
585
+ resolve(res)
586
+ this.$xdLog.setProject('Location.City.Ajax.Success', {location:location,city:res});
587
+ }, 1)
588
+ })
589
+ .catch(error=>{
590
+ this.$xdLog.setProject('Location.City.Ajax.Fail', {location:null});
591
+ this.setSelectCityData(this.getDefaultCity(), (location || this.getLocationData() || null));
592
+ })
593
+ })
594
+ },
595
+
596
+
597
+ /**
598
+ * @description 获取城市默认城市(站点 > 项目配置)
599
+ * @returns {Object|*}
600
+ */
601
+ getDefaultCity(){
602
+ let siteCity = this.$settings.defaultCity
603
+ siteCity['is_default'] = 'D';
604
+ return siteCity;
605
+ },
606
+
607
+ /**
608
+ * @description 更新选中城市状态
609
+ * //is_default(获取方式) Y:正常 , N:无经纬度, D:默认值
610
+ * @param city
611
+ * @param location
612
+ */
613
+ setSelectCityData(city ,location) {
614
+ //保证页面加载完成
615
+ setTimeout(()=>{
616
+ this.askUserAction(city, location, (status)=>{
617
+ if(status) this.handleSuccess(true,city,location);
618
+ else {
619
+ city = this.getPrevUserCity() || this.getDefaultCity()
620
+ this.handleSuccess(false, city, location);
621
+ }
622
+ })
623
+ }, 1)
624
+ },
625
+
626
+ getSpPath(dir , path ){
627
+ let reg = /@site_domain@/;
628
+ if(!/@site_domain@/.test(path)) return `/${dir}${path}`;
629
+ else return path.replace(reg, '');
630
+ },
631
+
632
+ /**
633
+ * @description 检查地址是否为用户登陆或者卡券登陆页面
634
+ * @returns {boolean}
635
+ */
636
+ checkPathIsLoginAndOrCard() {
637
+ let pages = this.$xdUniHelper.parseURL();
638
+ let login_entry = this.brandInfo.login_entry|| this.$configProject.login_entry;
639
+ let card_entry = this.brandInfo.card_entry|| this.$configProject.card_entry;
640
+
641
+ // #ifdef H5
642
+ let userLogin = this.getSpPath(this.brandInfo.deploy_dir, login_entry);
643
+ let cardLogin = this.getSpPath(this.brandInfo.deploy_dir,card_entry);
644
+ return pages.path === cardLogin || pages.path === userLogin;
645
+ // #endif
646
+
647
+ // #ifdef MP-WEIXIN
648
+ let loginObj = parsePath(login_entry);
649
+ let cardObj = parsePath(card_entry);
650
+ return (cardObj.isSameApp && pages.path === cardObj.url)
651
+ || (loginObj.isSameApp && pages.path === loginObj.url);
652
+ // #endif
653
+ },
654
+
655
+ /**
656
+ * @description 定位成功通知用户是否需要切换
657
+ * @param city
658
+ * @param location
659
+ * @param cb
660
+ */
661
+ askUserAction(city, location, cb){
662
+ const prev = this.getUserSelectCity() || this.getPrevUserCity() || this.getDefaultCity();
663
+ const userActionStatus = this.getUserChangeCityStatue();
664
+ // const style = {};
665
+ // Object.keys(this.currentStyle).map(key=>{
666
+ // style[`$${key}`] = this.currentStyle[key];
667
+ // });
668
+
669
+ if(location) this.setSameCityLocation(location);
670
+
671
+ //定位成功进行静默返回(保存经纬度,不再城市选择页面,isSelect=true 要求实时定位功能)
672
+ if(this.isSelect && location) {
673
+ if(city.is_default === 'Y') {
674
+ this.setStorage(this.prevUserlocationCitySuccessKey,city);
675
+ this.setStorage(this.locationSuccessKey, location);
676
+ this.setStorage(this.locationLongStorageKey, location);
677
+ this.setLocationData(location);
678
+ this.locationEvent.map(item=>{
679
+ item({city, location})
680
+ })
681
+ return;
682
+ }
683
+ }
684
+
685
+ //定位成功定位信息并且定位城市与默认或者上次选中城市一致(只保存当前经纬度操作)
686
+ if(location && (prev.city_code == city.city_code)) {
687
+ cb(false);
688
+ return;
689
+ }
690
+
691
+ //已选中定位操作
692
+ if(userActionStatus){
693
+ cb(false);
694
+ return;
695
+ }
696
+
697
+ //卡券登陆,用户登陆页面为静默模式
698
+ if(this.checkPathIsLoginAndOrCard()) {
699
+ cb(false);
700
+ return;
701
+ }
702
+
703
+ //定位成功并且获得城市信息处理
704
+ if(!this.isPop && location) {
705
+ if(city.is_default === 'Y') {
706
+ this.setStorage(this.prevUserlocationCitySuccessKey,city);
707
+ this.setStorage(this.locationSuccessKey, location);
708
+ cb(false);
709
+ return;
710
+ }
711
+ }
712
+
713
+
714
+
715
+ //未选择,定位成功定位信息,定位城市失败并且与用户上次选中城市不一致
716
+ if(!userActionStatus
717
+ && location
718
+ && (city && city.is_default !== 'Y' && (prev.city_code != city.city_code))
719
+ ) {
720
+ this.show({
721
+ message:`已定位到您所在城市:${city.province_name} - ${city.city_name},是否需要切换?`,
722
+ confirmText: '切换到'
723
+ },(res)=>{
724
+ this.setUserChangeCityStatue();
725
+ if(res.cancel) cb(false)
726
+ else cb(true)
727
+ })
728
+ return
729
+ }
730
+
731
+
732
+ //未选择,定位成功定位信息,定位城市成功并且与用户上次选中城市不一致
733
+ if(!userActionStatus
734
+ && location
735
+ && (city && city.is_default === 'Y' && (prev.city_code != city.city_code))
736
+ ) {
737
+ this.show({
738
+ message:`定位显示您在:${city.province_name} - ${city.city_name},是否需要切换?`,
739
+ confirmText: '切换到'
740
+ },(res)=>{
741
+ this.setUserChangeCityStatue();
742
+ if(res.cancel) cb(false)
743
+ else cb(true)
744
+ })
745
+ return
746
+ }
747
+
748
+ //其他情况
749
+ cb(false)
750
+ },
751
+ //==城市相关=========================================
752
+ },
753
+ }