jufubao-forms 1.0.0-beta1
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.
- package/README.md +27 -0
- package/commands.js +84 -0
- package/commands.update.change.js +176 -0
- package/file.config.js +16 -0
- package/get.package.path.js +22 -0
- package/get.package.path.js.tpl +22 -0
- package/package.json +119 -0
- package/src/CreateClientID.js +16 -0
- package/src/ICONS.js +1148 -0
- package/src/common/authorize.js +261 -0
- package/src/common/getBusinessImageUrl.js +39 -0
- package/src/common/getServiceUrl.js +38 -0
- package/src/common/paysdk/jweixin.js +98 -0
- package/src/components/CusCouponChose/CusCouponChose.vue +1024 -0
- package/src/components/CusCouponItem/CusCouponItem.vue +298 -0
- package/src/components/CusEnter/CusEnter.vue +333 -0
- package/src/components/CusPoster/CusPoster.vue +213 -0
- package/src/components/CusPoster/CusSwiperDot.vue +234 -0
- package/src/components/CusProduct/CusProduct.vue +362 -0
- package/src/components/CusSwiperDot/CusSwiperDot.vue +234 -0
- package/src/components/CusTab/CusTab.vue +411 -0
- package/src/components/CusVideo/CusVideo.vue +170 -0
- package/src/components/JfbFormsDynamicForm/Api.js +66 -0
- package/src/components/JfbFormsDynamicForm/Attr.js +35 -0
- package/src/components/JfbFormsDynamicForm/JfbFormsDynamicForm.vue +767 -0
- package/src/components/JfbFormsDynamicForm/JfbFormsDynamicFormLess.less +79 -0
- package/src/components/JfbFormsDynamicForm/JfbFormsDynamicFormMixin.js +30 -0
- package/src/components/JfbFormsDynamicForm/Mock.js +194 -0
- package/src/components/JfbFormsDynamicForm/XdFormDate.vue +71 -0
- package/src/components/JfbFormsDynamicForm/ld-select/ld-select.vue +329 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/calendar-item.vue +177 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/calendar.vue +930 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/i18n/en.json +22 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/i18n/index.js +8 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/i18n/zh-Hans.json +22 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/i18n/zh-Hant.json +22 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/time-picker.vue +934 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/uni-datetime-picker.vue +1042 -0
- package/src/components/JfbFormsDynamicForm/uni-datetime-picker/util.js +403 -0
- package/src/components/JfbFormsList/Api.js +20 -0
- package/src/components/JfbFormsList/Attr.js +70 -0
- package/src/components/JfbFormsList/JfbFormsList.vue +228 -0
- package/src/components/JfbFormsList/JfbFormsListLess.less +79 -0
- package/src/components/JfbFormsList/JfbFormsListMixin.js +30 -0
- package/src/components/JfbFormsList/Mock.js +38 -0
- package/src/components/JfbFormsQuestionAndAnswer/Api.js +43 -0
- package/src/components/JfbFormsQuestionAndAnswer/Attr.js +14 -0
- package/src/components/JfbFormsQuestionAndAnswer/JfbFormsQuestionAndAnswer.vue +506 -0
- package/src/components/JfbFormsQuestionAndAnswer/JfbFormsQuestionAndAnswerLess.less +79 -0
- package/src/components/JfbFormsQuestionAndAnswer/JfbFormsQuestionAndAnswerMixin.js +30 -0
- package/src/components/JfbFormsQuestionAndAnswer/Mock.js +144 -0
- package/src/components/SkeProduct/SkeProduct.vue +241 -0
- package/src/config.app.plus.js +6 -0
- package/src/config.h5.js +13 -0
- package/src/config.mp.weixin.js +13 -0
- package/src/config.project.js +15 -0
- package/src/mixins/cardListMixins.js +187 -0
- package/src/mixins/colorCardMixins.js +122 -0
- package/src/mixins/componentsMixins.js +900 -0
- package/src/mixins/extsMixins.js +3 -0
- package/src/mixins/locationMixins.js +119 -0
- package/src/mixins/newLocaltionMixins.js +754 -0
- package/src/mixins/openDebuggerMixins.js +74 -0
- package/src/mixins/pageEditx.js +347 -0
- package/src/mixins/pageEvent.js +311 -0
- package/src/mixins/pageMain.js +120 -0
- package/src/mixins/pageUitls.js +738 -0
- package/src/mixins/posterMixins.js +122 -0
- package/src/mixins/scrollListFixedHeigthMixins.js +174 -0
- package/src/mocks.js +4 -0
|
@@ -0,0 +1,754 @@
|
|
|
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
|
+
debugger
|
|
391
|
+
console.warn(`location.fail`)
|
|
392
|
+
|
|
393
|
+
//首次定位
|
|
394
|
+
if(!storage.get(this.rejectSaveLong)){
|
|
395
|
+
storage.set(this.rejectSaveLong,1);
|
|
396
|
+
this.$xdLog.setProject('Location.wx.api.fail', {lng: null, lat: null, error:err});
|
|
397
|
+
cb(this.getLocationData()||undefined, false)
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if(this.$xdUniHelper.checkVarType(err) === 'object'
|
|
402
|
+
&& err.errMsg === 'getLocation:fail auth deny'
|
|
403
|
+
&& storage.get(this.rejectSaveLong)
|
|
404
|
+
) {
|
|
405
|
+
this.$xdConfirm({
|
|
406
|
+
title: "提示",
|
|
407
|
+
content:'请打开地理位置定位权限',
|
|
408
|
+
confirmText: "确定",
|
|
409
|
+
cancelText: "取消",
|
|
410
|
+
success:(res)=>{
|
|
411
|
+
if (res.confirm) {
|
|
412
|
+
wx.openSetting({
|
|
413
|
+
success: function (res) {},
|
|
414
|
+
});
|
|
415
|
+
} else if (res.cancel) {
|
|
416
|
+
console.log("用户点击取消");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
this.$xdLog.setProject('Location.wx.api.fail', {lng: null, lat: null, error:err});
|
|
422
|
+
cb(this.getLocationData()||undefined, false);
|
|
423
|
+
if(timer) clearTimeout(timer);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
//三秒超时
|
|
428
|
+
timer = setTimeout(()=>{
|
|
429
|
+
console.warn(`location.timeout`)
|
|
430
|
+
this.$xdLog.setProject('Location.wx.api.timeout', {lng: null, lat: null, message:'定位超时'});
|
|
431
|
+
cb(this.getLocationData()||undefined, false)
|
|
432
|
+
},5000)
|
|
433
|
+
},
|
|
434
|
+
//==微信小程序定位====================
|
|
435
|
+
// #endif
|
|
436
|
+
|
|
437
|
+
//==定位工具函数========================
|
|
438
|
+
setStorage(key,data,time= 0){
|
|
439
|
+
if(time === 0) storage.set(key,data);
|
|
440
|
+
else storage.set(key,data,time);
|
|
441
|
+
},
|
|
442
|
+
getStorage(key){
|
|
443
|
+
return storage.get(key);
|
|
444
|
+
},
|
|
445
|
+
delStorage(key) {
|
|
446
|
+
storage.remove(key);
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* @description 获取通过定位成功的经纬度获取到到城市
|
|
451
|
+
* @returns {string|*|null}
|
|
452
|
+
*/
|
|
453
|
+
getPrevUserCity(){
|
|
454
|
+
return storage.get(this.prevUserLocationCityKey);
|
|
455
|
+
},
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @description 设置通过定位成功的经纬度获取到到城市
|
|
459
|
+
* @param city
|
|
460
|
+
* @returns {string|*|null}
|
|
461
|
+
*/
|
|
462
|
+
setPrevUserCity(city){
|
|
463
|
+
storage.set(this.prevUserLocationCityKey,city);
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* @description 设置用户选择的保存城市信息
|
|
468
|
+
* @param city
|
|
469
|
+
* @returns {string|*|null}
|
|
470
|
+
*/
|
|
471
|
+
setUserSelectCity(city){
|
|
472
|
+
storage.set(this.prevUserSelectCityKey,city);
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @description 获取用户选择的保存城市信息
|
|
477
|
+
* @returns {string|*|null}
|
|
478
|
+
*/
|
|
479
|
+
getUserSelectCity(){
|
|
480
|
+
return storage.get(this.prevUserSelectCityKey);
|
|
481
|
+
},
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* @description 获取用户是否已进行定位成功操作
|
|
485
|
+
* @returns {string|*|null}
|
|
486
|
+
*/
|
|
487
|
+
getUserChangeCityStatue(){
|
|
488
|
+
return storage.get(this.userActionKey);
|
|
489
|
+
},
|
|
490
|
+
/**
|
|
491
|
+
* @description 设置用户是否已进行定位成功操作
|
|
492
|
+
* @returns {string|*|null}
|
|
493
|
+
*/
|
|
494
|
+
setUserChangeCityStatue(){
|
|
495
|
+
let time = getCacheTime(this,0.5, 0.01, 2);
|
|
496
|
+
storage.set(this.userActionKey, 1, time);
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @description 获取永久第三方定位信息
|
|
501
|
+
* @returns {string|*|null}
|
|
502
|
+
*/
|
|
503
|
+
getLocationData(){
|
|
504
|
+
return storage.get(this.locationStorageKey);
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @description 设置永久第三方定位信息
|
|
509
|
+
* @returns {string|*|null}
|
|
510
|
+
*/
|
|
511
|
+
setLocationData(location){
|
|
512
|
+
let time = getCacheTime(this,0.5, 0.04, 2);
|
|
513
|
+
storage.set(this.locationStorageKey,location,time);
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @description 获取定位成功并且定位城市与默认或者上次选中城市一致的值(只保存当前经纬度操作)
|
|
518
|
+
* @returns {string|*|null}
|
|
519
|
+
*/
|
|
520
|
+
getSameCityLocation(){
|
|
521
|
+
return storage.get(this.sameCityChangeLocationKey);
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* @description 设置位成功并且定位城市与默认或者上次选中城市一致的值(只保存当前经纬度操作)
|
|
526
|
+
* @returns {string|*|null}
|
|
527
|
+
*/
|
|
528
|
+
setSameCityLocation(location){
|
|
529
|
+
storage.set(this.sameCityChangeLocationKey,location);
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* @description 火星转百度坐标
|
|
536
|
+
* @param lng
|
|
537
|
+
* @param lat
|
|
538
|
+
* @returns {{latitude: *, longitude: *}}
|
|
539
|
+
*/
|
|
540
|
+
gcj02tobd09(lng, lat) {
|
|
541
|
+
let x_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
|
542
|
+
let PI = 3.1415926535897932384626;
|
|
543
|
+
let a = 6378245.0;
|
|
544
|
+
let ee = 0.00669342162296594323;
|
|
545
|
+
|
|
546
|
+
lat = +lat;
|
|
547
|
+
lng = +lng;
|
|
548
|
+
let z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
|
|
549
|
+
let theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
|
|
550
|
+
let bd_lng = z * Math.cos(theta) + 0.0065;
|
|
551
|
+
let bd_lat = z * Math.sin(theta) + 0.006;
|
|
552
|
+
return {longitude: bd_lng, latitude:bd_lat}
|
|
553
|
+
},
|
|
554
|
+
//==定位工具函数========================
|
|
555
|
+
|
|
556
|
+
//==城市相关=========================================
|
|
557
|
+
/**
|
|
558
|
+
* @description 定位完成处理(包括定位成功或者失败处理)
|
|
559
|
+
* @param location
|
|
560
|
+
* @param cb
|
|
561
|
+
*/
|
|
562
|
+
getLocationCity(location, cb){
|
|
563
|
+
this.getApiLocationCity(location,cb).then().catch();
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* @description 通过经纬度从服务器获取选中城市新
|
|
568
|
+
* @param location {Object|undefined}
|
|
569
|
+
* @param location.latitude {string}
|
|
570
|
+
* @param location.longitude {string}
|
|
571
|
+
* @param cb
|
|
572
|
+
*/
|
|
573
|
+
getApiLocationCity(location,cb){
|
|
574
|
+
let params = null
|
|
575
|
+
if(!location) params = {};
|
|
576
|
+
else params = JSON.parse(JSON.stringify(location));
|
|
577
|
+
this.$xdLog.setProject('Location.City.Ajax.Start', {location:location});
|
|
578
|
+
return new Promise((resolve, reject)=>{
|
|
579
|
+
this.getLoadingCityInfoByLocationLv4(params)
|
|
580
|
+
.then(res=>{
|
|
581
|
+
res.data['is_default'] = 'N';
|
|
582
|
+
if(location) res.data['is_default'] = 'Y';
|
|
583
|
+
setTimeout(()=>{
|
|
584
|
+
if(typeof cb === 'function') cb(res.data, location);
|
|
585
|
+
else this.setSelectCityData(res.data, location);
|
|
586
|
+
resolve(res)
|
|
587
|
+
this.$xdLog.setProject('Location.City.Ajax.Success', {location:location,city:res});
|
|
588
|
+
}, 1)
|
|
589
|
+
})
|
|
590
|
+
.catch(error=>{
|
|
591
|
+
this.$xdLog.setProject('Location.City.Ajax.Fail', {location:null});
|
|
592
|
+
this.setSelectCityData(this.getDefaultCity(), (location || this.getLocationData() || null));
|
|
593
|
+
})
|
|
594
|
+
})
|
|
595
|
+
},
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* @description 获取城市默认城市(站点 > 项目配置)
|
|
600
|
+
* @returns {Object|*}
|
|
601
|
+
*/
|
|
602
|
+
getDefaultCity(){
|
|
603
|
+
let siteCity = this.$settings.defaultCity
|
|
604
|
+
siteCity['is_default'] = 'D';
|
|
605
|
+
return siteCity;
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* @description 更新选中城市状态
|
|
610
|
+
* //is_default(获取方式) Y:正常 , N:无经纬度, D:默认值
|
|
611
|
+
* @param city
|
|
612
|
+
* @param location
|
|
613
|
+
*/
|
|
614
|
+
setSelectCityData(city ,location) {
|
|
615
|
+
//保证页面加载完成
|
|
616
|
+
setTimeout(()=>{
|
|
617
|
+
this.askUserAction(city, location, (status)=>{
|
|
618
|
+
if(status) this.handleSuccess(true,city,location);
|
|
619
|
+
else {
|
|
620
|
+
city = this.getPrevUserCity() || this.getDefaultCity()
|
|
621
|
+
this.handleSuccess(false, city, location);
|
|
622
|
+
}
|
|
623
|
+
})
|
|
624
|
+
}, 1)
|
|
625
|
+
},
|
|
626
|
+
|
|
627
|
+
getSpPath(dir , path ){
|
|
628
|
+
let reg = /@site_domain@/;
|
|
629
|
+
if(!/@site_domain@/.test(path)) return `/${dir}${path}`;
|
|
630
|
+
else return path.replace(reg, '');
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* @description 检查地址是否为用户登陆或者卡券登陆页面
|
|
635
|
+
* @returns {boolean}
|
|
636
|
+
*/
|
|
637
|
+
checkPathIsLoginAndOrCard() {
|
|
638
|
+
let pages = this.$xdUniHelper.parseURL();
|
|
639
|
+
let login_entry = this.brandInfo.login_entry|| this.$configProject.login_entry;
|
|
640
|
+
let card_entry = this.brandInfo.card_entry|| this.$configProject.card_entry;
|
|
641
|
+
|
|
642
|
+
// #ifdef H5
|
|
643
|
+
let userLogin = this.getSpPath(this.brandInfo.deploy_dir, login_entry);
|
|
644
|
+
let cardLogin = this.getSpPath(this.brandInfo.deploy_dir,card_entry);
|
|
645
|
+
return pages.path === cardLogin || pages.path === userLogin;
|
|
646
|
+
// #endif
|
|
647
|
+
|
|
648
|
+
// #ifdef MP-WEIXIN
|
|
649
|
+
let loginObj = parsePath(login_entry);
|
|
650
|
+
let cardObj = parsePath(card_entry);
|
|
651
|
+
return (cardObj.isSameApp && pages.path === cardObj.url)
|
|
652
|
+
|| (loginObj.isSameApp && pages.path === loginObj.url);
|
|
653
|
+
// #endif
|
|
654
|
+
},
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* @description 定位成功通知用户是否需要切换
|
|
658
|
+
* @param city
|
|
659
|
+
* @param location
|
|
660
|
+
* @param cb
|
|
661
|
+
*/
|
|
662
|
+
askUserAction(city, location, cb){
|
|
663
|
+
const prev = this.getUserSelectCity() || this.getPrevUserCity() || this.getDefaultCity();
|
|
664
|
+
const userActionStatus = this.getUserChangeCityStatue();
|
|
665
|
+
// const style = {};
|
|
666
|
+
// Object.keys(this.currentStyle).map(key=>{
|
|
667
|
+
// style[`$${key}`] = this.currentStyle[key];
|
|
668
|
+
// });
|
|
669
|
+
|
|
670
|
+
if(location) this.setSameCityLocation(location);
|
|
671
|
+
|
|
672
|
+
//定位成功进行静默返回(保存经纬度,不再城市选择页面,isSelect=true 要求实时定位功能)
|
|
673
|
+
if(this.isSelect && location) {
|
|
674
|
+
if(city.is_default === 'Y') {
|
|
675
|
+
this.setStorage(this.prevUserlocationCitySuccessKey,city);
|
|
676
|
+
this.setStorage(this.locationSuccessKey, location);
|
|
677
|
+
this.setStorage(this.locationLongStorageKey, location);
|
|
678
|
+
this.setLocationData(location);
|
|
679
|
+
this.locationEvent.map(item=>{
|
|
680
|
+
item({city, location})
|
|
681
|
+
})
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
//定位成功定位信息并且定位城市与默认或者上次选中城市一致(只保存当前经纬度操作)
|
|
687
|
+
if(location && (prev.city_code == city.city_code)) {
|
|
688
|
+
cb(false);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
//已选中定位操作
|
|
693
|
+
if(userActionStatus){
|
|
694
|
+
cb(false);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
//卡券登陆,用户登陆页面为静默模式
|
|
699
|
+
if(this.checkPathIsLoginAndOrCard()) {
|
|
700
|
+
cb(false);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
//定位成功并且获得城市信息处理
|
|
705
|
+
if(!this.isPop && location) {
|
|
706
|
+
if(city.is_default === 'Y') {
|
|
707
|
+
this.setStorage(this.prevUserlocationCitySuccessKey,city);
|
|
708
|
+
this.setStorage(this.locationSuccessKey, location);
|
|
709
|
+
cb(false);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
//未选择,定位成功定位信息,定位城市失败并且与用户上次选中城市不一致
|
|
717
|
+
if(!userActionStatus
|
|
718
|
+
&& location
|
|
719
|
+
&& (city && city.is_default !== 'Y' && (prev.city_code != city.city_code))
|
|
720
|
+
) {
|
|
721
|
+
this.show({
|
|
722
|
+
message:`已定位到您所在城市:${city.province_name} - ${city.city_name},是否需要切换?`,
|
|
723
|
+
confirmText: '切换到'
|
|
724
|
+
},(res)=>{
|
|
725
|
+
this.setUserChangeCityStatue();
|
|
726
|
+
if(res.cancel) cb(false)
|
|
727
|
+
else cb(true)
|
|
728
|
+
})
|
|
729
|
+
return
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
//未选择,定位成功定位信息,定位城市成功并且与用户上次选中城市不一致
|
|
734
|
+
if(!userActionStatus
|
|
735
|
+
&& location
|
|
736
|
+
&& (city && city.is_default === 'Y' && (prev.city_code != city.city_code))
|
|
737
|
+
) {
|
|
738
|
+
this.show({
|
|
739
|
+
message:`定位显示您在:${city.province_name} - ${city.city_name},是否需要切换?`,
|
|
740
|
+
confirmText: '切换到'
|
|
741
|
+
},(res)=>{
|
|
742
|
+
this.setUserChangeCityStatue();
|
|
743
|
+
if(res.cancel) cb(false)
|
|
744
|
+
else cb(true)
|
|
745
|
+
})
|
|
746
|
+
return
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
//其他情况
|
|
750
|
+
cb(false)
|
|
751
|
+
},
|
|
752
|
+
//==城市相关=========================================
|
|
753
|
+
},
|
|
754
|
+
}
|