Commit e2ea09c34b7fc6d669e58eb0281882fe53385bd6
1 parent
6eea308a
12345工单
Showing
8 changed files
with
1747 additions
and
0 deletions
api/work.js
... | ... | @@ -17,6 +17,10 @@ export const apiStaffListByDeptId = (params) => request.get('/system/user/yh/sel |
17 | 17 | } |
18 | 18 | }) |
19 | 19 | |
20 | +// 获取12345工单列表 | |
21 | +export const hotlinecaseList = (params) => request.get('/business/hotlinecase/list', params) | |
22 | + | |
23 | + | |
20 | 24 | // 获取养护、巡检计划列表 |
21 | 25 | export const apiInspectionList = (params) => request.post('/app/maintain/plan/listForPage', params) |
22 | 26 | // 获取养护、巡检计划详情 | ... | ... |
pages.json
... | ... | @@ -47,6 +47,19 @@ |
47 | 47 | } |
48 | 48 | }, |
49 | 49 | { |
50 | + "path": "pages/work/daily/workOrder", | |
51 | + "style": { | |
52 | + "navigationBarTitleText": "12345工单" | |
53 | + } | |
54 | + }, | |
55 | + { | |
56 | + "path": "pages/work/daily/workOrderDetail", | |
57 | + "style": { | |
58 | + "navigationBarTitleText": "12345工单详情" | |
59 | + } | |
60 | + }, | |
61 | + | |
62 | + { | |
50 | 63 | "path": "pages/work/daily/history", |
51 | 64 | "style": { |
52 | 65 | "navigationBarTitleText": "历史记录" | ... | ... |
pages/work/daily/qqmap-wx-jssdk.js
0 → 100644
1 | +/** | |
2 | + * 微信小程序JavaScriptSDK | |
3 | + * | |
4 | + * @version 1.1 | |
5 | + * @date 2019-01-20 | |
6 | + */ | |
7 | + | |
8 | +var ERROR_CONF = { | |
9 | + KEY_ERR: 311, | |
10 | + KEY_ERR_MSG: 'key格式错误', | |
11 | + PARAM_ERR: 310, | |
12 | + PARAM_ERR_MSG: '请求参数信息有误', | |
13 | + SYSTEM_ERR: 600, | |
14 | + SYSTEM_ERR_MSG: '系统错误', | |
15 | + WX_ERR_CODE: 1000, | |
16 | + WX_OK_CODE: 200 | |
17 | +}; | |
18 | +var BASE_URL = 'https://apis.map.qq.com/ws/'; | |
19 | +var URL_SEARCH = BASE_URL + 'place/v1/search'; | |
20 | +var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion'; | |
21 | +var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/'; | |
22 | +var URL_CITY_LIST = BASE_URL + 'district/v1/list'; | |
23 | +var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren'; | |
24 | +var URL_DISTANCE = BASE_URL + 'distance/v1/'; | |
25 | +var EARTH_RADIUS = 6378136.49; | |
26 | +var Utils = { | |
27 | + /** | |
28 | + * 得到终点query字符串 | |
29 | + * @param {Array|String} 检索数据 | |
30 | + */ | |
31 | + location2query(data) { | |
32 | + if (typeof data == 'string') { | |
33 | + return data; | |
34 | + } | |
35 | + var query = ''; | |
36 | + for (var i = 0; i < data.length; i++) { | |
37 | + var d = data[i]; | |
38 | + if (!!query) { | |
39 | + query += ';'; | |
40 | + } | |
41 | + if (d.location) { | |
42 | + query = query + d.location.lat + ',' + d.location.lng; | |
43 | + } | |
44 | + if (d.latitude && d.longitude) { | |
45 | + query = query + d.latitude + ',' + d.longitude; | |
46 | + } | |
47 | + } | |
48 | + return query; | |
49 | + }, | |
50 | + | |
51 | + /** | |
52 | + * 计算角度 | |
53 | + */ | |
54 | + rad(d) { | |
55 | + return d * Math.PI / 180.0; | |
56 | + }, | |
57 | + /** | |
58 | + * 处理终点location数组 | |
59 | + * @return 返回终点数组 | |
60 | + */ | |
61 | + getEndLocation(location){ | |
62 | + var to = location.split(';'); | |
63 | + var endLocation = []; | |
64 | + for (var i = 0; i < to.length; i++) { | |
65 | + endLocation.push({ | |
66 | + lat: parseFloat(to[i].split(',')[0]), | |
67 | + lng: parseFloat(to[i].split(',')[1]) | |
68 | + }) | |
69 | + } | |
70 | + return endLocation; | |
71 | + }, | |
72 | + | |
73 | + /** | |
74 | + * 计算两点间直线距离 | |
75 | + * @param a 表示纬度差 | |
76 | + * @param b 表示经度差 | |
77 | + * @return 返回的是距离,单位m | |
78 | + */ | |
79 | + getDistance(latFrom, lngFrom, latTo, lngTo) { | |
80 | + var radLatFrom = this.rad(latFrom); | |
81 | + var radLatTo = this.rad(latTo); | |
82 | + var a = radLatFrom - radLatTo; | |
83 | + var b = this.rad(lngFrom) - this.rad(lngTo); | |
84 | + var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2))); | |
85 | + distance = distance * EARTH_RADIUS; | |
86 | + distance = Math.round(distance * 10000) / 10000; | |
87 | + return parseFloat(distance.toFixed(0)); | |
88 | + }, | |
89 | + /** | |
90 | + * 使用微信接口进行定位 | |
91 | + */ | |
92 | + getWXLocation(success, fail, complete) { | |
93 | + wx.getLocation({ | |
94 | + type: 'gcj02', | |
95 | + success: success, | |
96 | + fail: fail, | |
97 | + complete: complete | |
98 | + }); | |
99 | + }, | |
100 | + | |
101 | + /** | |
102 | + * 获取location参数 | |
103 | + */ | |
104 | + getLocationParam(location) { | |
105 | + if (typeof location == 'string') { | |
106 | + var locationArr = location.split(','); | |
107 | + if (locationArr.length === 2) { | |
108 | + location = { | |
109 | + latitude: location.split(',')[0], | |
110 | + longitude: location.split(',')[1] | |
111 | + }; | |
112 | + } else { | |
113 | + location = {}; | |
114 | + } | |
115 | + } | |
116 | + return location; | |
117 | + }, | |
118 | + | |
119 | + /** | |
120 | + * 回调函数默认处理 | |
121 | + */ | |
122 | + polyfillParam(param) { | |
123 | + param.success = param.success || function () { }; | |
124 | + param.fail = param.fail || function () { }; | |
125 | + param.complete = param.complete || function () { }; | |
126 | + }, | |
127 | + | |
128 | + /** | |
129 | + * 验证param对应的key值是否为空 | |
130 | + * | |
131 | + * @param {Object} param 接口参数 | |
132 | + * @param {String} key 对应参数的key | |
133 | + */ | |
134 | + checkParamKeyEmpty(param, key) { | |
135 | + if (!param[key]) { | |
136 | + var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key +'参数格式有误'); | |
137 | + param.fail(errconf); | |
138 | + param.complete(errconf); | |
139 | + return true; | |
140 | + } | |
141 | + return false; | |
142 | + }, | |
143 | + | |
144 | + /** | |
145 | + * 验证参数中是否存在检索词keyword | |
146 | + * | |
147 | + * @param {Object} param 接口参数 | |
148 | + */ | |
149 | + checkKeyword(param){ | |
150 | + return !this.checkParamKeyEmpty(param, 'keyword'); | |
151 | + }, | |
152 | + | |
153 | + /** | |
154 | + * 验证location值 | |
155 | + * | |
156 | + * @param {Object} param 接口参数 | |
157 | + */ | |
158 | + checkLocation(param) { | |
159 | + var location = this.getLocationParam(param.location); | |
160 | + if (!location || !location.latitude || !location.longitude) { | |
161 | + var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误'); | |
162 | + param.fail(errconf); | |
163 | + param.complete(errconf); | |
164 | + return false; | |
165 | + } | |
166 | + return true; | |
167 | + }, | |
168 | + | |
169 | + /** | |
170 | + * 构造错误数据结构 | |
171 | + * @param {Number} errCode 错误码 | |
172 | + * @param {Number} errMsg 错误描述 | |
173 | + */ | |
174 | + buildErrorConfig(errCode, errMsg) { | |
175 | + return { | |
176 | + status: errCode, | |
177 | + message: errMsg | |
178 | + }; | |
179 | + }, | |
180 | + | |
181 | + /** | |
182 | + * | |
183 | + * 数据处理函数 | |
184 | + * 根据传入参数不同处理不同数据 | |
185 | + * @param {String} feature 功能名称 | |
186 | + * search 地点搜索 | |
187 | + * suggest关键词提示 | |
188 | + * reverseGeocoder逆地址解析 | |
189 | + * geocoder地址解析 | |
190 | + * getCityList获取城市列表:父集 | |
191 | + * getDistrictByCityId获取区县列表:子集 | |
192 | + * calculateDistance距离计算 | |
193 | + * @param {Object} param 接口参数 | |
194 | + * @param {Object} data 数据 | |
195 | + */ | |
196 | + handleData(param,data,feature){ | |
197 | + if (feature === 'search') { | |
198 | + var searchResult = data.data; | |
199 | + var searchSimplify = []; | |
200 | + for (var i = 0; i < searchResult.length; i++) { | |
201 | + searchSimplify.push({ | |
202 | + id: searchResult[i].id || null, | |
203 | + title: searchResult[i].title || null, | |
204 | + latitude: searchResult[i].location && searchResult[i].location.lat || null, | |
205 | + longitude: searchResult[i].location && searchResult[i].location.lng || null, | |
206 | + address: searchResult[i].address || null, | |
207 | + category: searchResult[i].category || null, | |
208 | + tel: searchResult[i].tel || null, | |
209 | + adcode: searchResult[i].ad_info && searchResult[i].ad_info.adcode || null, | |
210 | + city: searchResult[i].ad_info && searchResult[i].ad_info.city || null, | |
211 | + district: searchResult[i].ad_info && searchResult[i].ad_info.district || null, | |
212 | + province: searchResult[i].ad_info && searchResult[i].ad_info.province || null | |
213 | + }) | |
214 | + } | |
215 | + param.success(data, { | |
216 | + searchResult: searchResult, | |
217 | + searchSimplify: searchSimplify | |
218 | + }) | |
219 | + } else if (feature === 'suggest') { | |
220 | + var suggestResult = data.data; | |
221 | + var suggestSimplify = []; | |
222 | + for (var i = 0; i < suggestResult.length; i++) { | |
223 | + suggestSimplify.push({ | |
224 | + adcode: suggestResult[i].adcode || null, | |
225 | + address: suggestResult[i].address || null, | |
226 | + category: suggestResult[i].category || null, | |
227 | + city: suggestResult[i].city || null, | |
228 | + district: suggestResult[i].district || null, | |
229 | + id: suggestResult[i].id || null, | |
230 | + latitude: suggestResult[i].location && suggestResult[i].location.lat || null, | |
231 | + longitude: suggestResult[i].location && suggestResult[i].location.lng || null, | |
232 | + province: suggestResult[i].province || null, | |
233 | + title: suggestResult[i].title || null, | |
234 | + type: suggestResult[i].type || null | |
235 | + }) | |
236 | + } | |
237 | + param.success(data, { | |
238 | + suggestResult: suggestResult, | |
239 | + suggestSimplify: suggestSimplify | |
240 | + }) | |
241 | + } else if (feature === 'reverseGeocoder') { | |
242 | + var reverseGeocoderResult = data.result; | |
243 | + var reverseGeocoderSimplify = { | |
244 | + address: reverseGeocoderResult.address || null, | |
245 | + latitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lat || null, | |
246 | + longitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lng || null, | |
247 | + adcode: reverseGeocoderResult.ad_info && reverseGeocoderResult.ad_info.adcode || null, | |
248 | + city: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.city || null, | |
249 | + district: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.district || null, | |
250 | + nation: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.nation || null, | |
251 | + province: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.province || null, | |
252 | + street: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street || null, | |
253 | + street_number: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street_number || null, | |
254 | + recommend: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.recommend || null, | |
255 | + rough: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.rough || null | |
256 | + }; | |
257 | + if (reverseGeocoderResult.pois) {//判断是否返回周边poi | |
258 | + var pois = reverseGeocoderResult.pois; | |
259 | + var poisSimplify = []; | |
260 | + for (var i = 0;i < pois.length;i++) { | |
261 | + poisSimplify.push({ | |
262 | + id: pois[i].id || null, | |
263 | + title: pois[i].title || null, | |
264 | + latitude: pois[i].location && pois[i].location.lat || null, | |
265 | + longitude: pois[i].location && pois[i].location.lng || null, | |
266 | + address: pois[i].address || null, | |
267 | + category: pois[i].category || null, | |
268 | + adcode: pois[i].ad_info && pois[i].ad_info.adcode || null, | |
269 | + city: pois[i].ad_info && pois[i].ad_info.city || null, | |
270 | + district: pois[i].ad_info && pois[i].ad_info.district || null, | |
271 | + province: pois[i].ad_info && pois[i].ad_info.province || null | |
272 | + }) | |
273 | + } | |
274 | + param.success(data,{ | |
275 | + reverseGeocoderResult: reverseGeocoderResult, | |
276 | + reverseGeocoderSimplify: reverseGeocoderSimplify, | |
277 | + pois: pois, | |
278 | + poisSimplify: poisSimplify | |
279 | + }) | |
280 | + } else { | |
281 | + param.success(data, { | |
282 | + reverseGeocoderResult: reverseGeocoderResult, | |
283 | + reverseGeocoderSimplify: reverseGeocoderSimplify | |
284 | + }) | |
285 | + } | |
286 | + } else if (feature === 'geocoder') { | |
287 | + var geocoderResult = data.result; | |
288 | + var geocoderSimplify = { | |
289 | + title: geocoderResult.title || null, | |
290 | + latitude: geocoderResult.location && geocoderResult.location.lat || null, | |
291 | + longitude: geocoderResult.location && geocoderResult.location.lng || null, | |
292 | + adcode: geocoderResult.ad_info && geocoderResult.ad_info.adcode || null, | |
293 | + province: geocoderResult.address_components && geocoderResult.address_components.province || null, | |
294 | + city: geocoderResult.address_components && geocoderResult.address_components.city || null, | |
295 | + district: geocoderResult.address_components && geocoderResult.address_components.district || null, | |
296 | + street: geocoderResult.address_components && geocoderResult.address_components.street || null, | |
297 | + street_number: geocoderResult.address_components && geocoderResult.address_components.street_number || null, | |
298 | + level: geocoderResult.level || null | |
299 | + }; | |
300 | + param.success(data,{ | |
301 | + geocoderResult: geocoderResult, | |
302 | + geocoderSimplify: geocoderSimplify | |
303 | + }); | |
304 | + } else if (feature === 'getCityList') { | |
305 | + var provinceResult = data.result[0]; | |
306 | + var cityResult = data.result[1]; | |
307 | + var districtResult = data.result[2]; | |
308 | + param.success(data,{ | |
309 | + provinceResult: provinceResult, | |
310 | + cityResult: cityResult, | |
311 | + districtResult: districtResult | |
312 | + }); | |
313 | + } else if (feature === 'getDistrictByCityId') { | |
314 | + var districtByCity = data.result[0]; | |
315 | + param.success(data, districtByCity); | |
316 | + } else if (feature === 'calculateDistance') { | |
317 | + var calculateDistanceResult = data.result.elements; | |
318 | + var distance = []; | |
319 | + for (var i = 0; i < calculateDistanceResult.length; i++){ | |
320 | + distance.push(calculateDistanceResult[i].distance); | |
321 | + } | |
322 | + param.success(data, { | |
323 | + calculateDistanceResult: calculateDistanceResult, | |
324 | + distance: distance | |
325 | + }); | |
326 | + } else { | |
327 | + param.success(data); | |
328 | + } | |
329 | + }, | |
330 | + | |
331 | + /** | |
332 | + * 构造微信请求参数,公共属性处理 | |
333 | + * | |
334 | + * @param {Object} param 接口参数 | |
335 | + * @param {Object} param 配置项 | |
336 | + * @param {String} feature 方法名 | |
337 | + */ | |
338 | + buildWxRequestConfig(param, options, feature) { | |
339 | + var that = this; | |
340 | + options.header = { "content-type": "application/json" }; | |
341 | + options.method = 'GET'; | |
342 | + options.success = function (res) { | |
343 | + var data = res.data; | |
344 | + if (data.status === 0) { | |
345 | + that.handleData(param, data, feature); | |
346 | + } else { | |
347 | + param.fail(data); | |
348 | + } | |
349 | + }; | |
350 | + options.fail = function (res) { | |
351 | + res.statusCode = ERROR_CONF.WX_ERR_CODE; | |
352 | + param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
353 | + }; | |
354 | + options.complete = function (res) { | |
355 | + var statusCode = +res.statusCode; | |
356 | + switch(statusCode) { | |
357 | + case ERROR_CONF.WX_ERR_CODE: { | |
358 | + param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
359 | + break; | |
360 | + } | |
361 | + case ERROR_CONF.WX_OK_CODE: { | |
362 | + var data = res.data; | |
363 | + if (data.status === 0) { | |
364 | + param.complete(data); | |
365 | + } else { | |
366 | + param.complete(that.buildErrorConfig(data.status, data.message)); | |
367 | + } | |
368 | + break; | |
369 | + } | |
370 | + default:{ | |
371 | + param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG)); | |
372 | + } | |
373 | + | |
374 | + } | |
375 | + }; | |
376 | + return options; | |
377 | + }, | |
378 | + | |
379 | + /** | |
380 | + * 处理用户参数是否传入坐标进行不同的处理 | |
381 | + */ | |
382 | + locationProcess(param, locationsuccess, locationfail, locationcomplete) { | |
383 | + var that = this; | |
384 | + locationfail = locationfail || function (res) { | |
385 | + res.statusCode = ERROR_CONF.WX_ERR_CODE; | |
386 | + param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
387 | + }; | |
388 | + locationcomplete = locationcomplete || function (res) { | |
389 | + if (res.statusCode == ERROR_CONF.WX_ERR_CODE) { | |
390 | + param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
391 | + } | |
392 | + }; | |
393 | + if (!param.location) { | |
394 | + that.getWXLocation(locationsuccess, locationfail, locationcomplete); | |
395 | + } else if (that.checkLocation(param)) { | |
396 | + var location = Utils.getLocationParam(param.location); | |
397 | + locationsuccess(location); | |
398 | + } | |
399 | + } | |
400 | +}; | |
401 | + | |
402 | + | |
403 | +class QQMapWX { | |
404 | + | |
405 | + /** | |
406 | + * 构造函数 | |
407 | + * | |
408 | + * @param {Object} options 接口参数,key 为必选参数 | |
409 | + */ | |
410 | + constructor(options) { | |
411 | + if (!options.key) { | |
412 | + throw Error('key值不能为空'); | |
413 | + } | |
414 | + this.key = options.key; | |
415 | + }; | |
416 | + | |
417 | + /** | |
418 | + * POI周边检索 | |
419 | + * | |
420 | + * @param {Object} options 接口参数对象 | |
421 | + * | |
422 | + * 参数对象结构可以参考 | |
423 | + * @see http://lbs.qq.com/webservice_v1/guide-search.html | |
424 | + */ | |
425 | + search(options) { | |
426 | + var that = this; | |
427 | + options = options || {}; | |
428 | + | |
429 | + Utils.polyfillParam(options); | |
430 | + | |
431 | + if (!Utils.checkKeyword(options)) { | |
432 | + return; | |
433 | + } | |
434 | + | |
435 | + var requestParam = { | |
436 | + keyword: options.keyword, | |
437 | + orderby: options.orderby || '_distance', | |
438 | + page_size: options.page_size || 10, | |
439 | + page_index: options.page_index || 1, | |
440 | + output: 'json', | |
441 | + key: that.key | |
442 | + }; | |
443 | + | |
444 | + if (options.address_format) { | |
445 | + requestParam.address_format = options.address_format; | |
446 | + } | |
447 | + | |
448 | + if (options.filter) { | |
449 | + requestParam.filter = options.filter; | |
450 | + } | |
451 | + | |
452 | + var distance = options.distance || "1000"; | |
453 | + var auto_extend = options.auto_extend || 1; | |
454 | + var region = null; | |
455 | + var rectangle = null; | |
456 | + | |
457 | + //判断城市限定参数 | |
458 | + if (options.region) { | |
459 | + region = options.region; | |
460 | + } | |
461 | + | |
462 | + //矩形限定坐标(暂时只支持字符串格式) | |
463 | + if (options.rectangle) { | |
464 | + rectangle = options.rectangle; | |
465 | + } | |
466 | + | |
467 | + var locationsuccess = function (result) { | |
468 | + if (region && !rectangle) { | |
469 | + //城市限定参数拼接 | |
470 | + requestParam.boundary = "region(" + region + "," + auto_extend + "," + result.latitude + "," + result.longitude + ")"; | |
471 | + } else if (rectangle && !region) { | |
472 | + //矩形搜索 | |
473 | + requestParam.boundary = "rectangle(" + rectangle + ")"; | |
474 | + } else { | |
475 | + requestParam.boundary = "nearby(" + result.latitude + "," + result.longitude + "," + distance + "," + auto_extend + ")"; | |
476 | + } | |
477 | + wx.request(Utils.buildWxRequestConfig(options, { | |
478 | + url: URL_SEARCH, | |
479 | + data: requestParam | |
480 | + }, 'search')); | |
481 | + }; | |
482 | + Utils.locationProcess(options, locationsuccess); | |
483 | + }; | |
484 | + | |
485 | + /** | |
486 | + * sug模糊检索 | |
487 | + * | |
488 | + * @param {Object} options 接口参数对象 | |
489 | + * | |
490 | + * 参数对象结构可以参考 | |
491 | + * http://lbs.qq.com/webservice_v1/guide-suggestion.html | |
492 | + */ | |
493 | + getSuggestion(options) { | |
494 | + var that = this; | |
495 | + options = options || {}; | |
496 | + Utils.polyfillParam(options); | |
497 | + | |
498 | + if (!Utils.checkKeyword(options)) { | |
499 | + return; | |
500 | + } | |
501 | + | |
502 | + var requestParam = { | |
503 | + keyword: options.keyword, | |
504 | + region: options.region || '全国', | |
505 | + region_fix: options.region_fix || 0, | |
506 | + policy: options.policy || 0, | |
507 | + page_size: options.page_size || 10,//控制显示条数 | |
508 | + page_index: options.page_index || 1,//控制页数 | |
509 | + get_subpois : options.get_subpois || 0,//返回子地点 | |
510 | + output: 'json', | |
511 | + key: that.key | |
512 | + }; | |
513 | + //长地址 | |
514 | + if (options.address_format) { | |
515 | + requestParam.address_format = options.address_format; | |
516 | + } | |
517 | + //过滤 | |
518 | + if (options.filter) { | |
519 | + requestParam.filter = options.filter; | |
520 | + } | |
521 | + //排序 | |
522 | + if (options.location) { | |
523 | + var locationsuccess = function (result) { | |
524 | + requestParam.location = result.latitude + ',' + result.longitude; | |
525 | + wx.request(Utils.buildWxRequestConfig(options, { | |
526 | + url: URL_SUGGESTION, | |
527 | + data: requestParam | |
528 | + }, "suggest")); | |
529 | + }; | |
530 | + Utils.locationProcess(options, locationsuccess); | |
531 | + } else { | |
532 | + wx.request(Utils.buildWxRequestConfig(options, { | |
533 | + url: URL_SUGGESTION, | |
534 | + data: requestParam | |
535 | + }, "suggest")); | |
536 | + } | |
537 | + }; | |
538 | + | |
539 | + /** | |
540 | + * 逆地址解析 | |
541 | + * | |
542 | + * @param {Object} options 接口参数对象 | |
543 | + * | |
544 | + * 请求参数结构可以参考 | |
545 | + * http://lbs.qq.com/webservice_v1/guide-gcoder.html | |
546 | + */ | |
547 | + reverseGeocoder(options) { | |
548 | + var that = this; | |
549 | + options = options || {}; | |
550 | + Utils.polyfillParam(options); | |
551 | + var requestParam = { | |
552 | + coord_type: options.coord_type || 5, | |
553 | + get_poi: options.get_poi || 0, | |
554 | + output: 'json', | |
555 | + key: that.key | |
556 | + }; | |
557 | + if (options.poi_options) { | |
558 | + requestParam.poi_options = options.poi_options | |
559 | + } | |
560 | + | |
561 | + var locationsuccess = function (result) { | |
562 | + requestParam.location = result.latitude + ',' + result.longitude; | |
563 | + wx.request(Utils.buildWxRequestConfig(options, { | |
564 | + url: URL_GET_GEOCODER, | |
565 | + data: requestParam | |
566 | + }, 'reverseGeocoder')); | |
567 | + }; | |
568 | + Utils.locationProcess(options, locationsuccess); | |
569 | + }; | |
570 | + | |
571 | + /** | |
572 | + * 地址解析 | |
573 | + * | |
574 | + * @param {Object} options 接口参数对象 | |
575 | + * | |
576 | + * 请求参数结构可以参考 | |
577 | + * http://lbs.qq.com/webservice_v1/guide-geocoder.html | |
578 | + */ | |
579 | + geocoder(options) { | |
580 | + var that = this; | |
581 | + options = options || {}; | |
582 | + Utils.polyfillParam(options); | |
583 | + | |
584 | + if (Utils.checkParamKeyEmpty(options, 'address')) { | |
585 | + return; | |
586 | + } | |
587 | + | |
588 | + var requestParam = { | |
589 | + address: options.address, | |
590 | + output: 'json', | |
591 | + key: that.key | |
592 | + }; | |
593 | + | |
594 | + //城市限定 | |
595 | + if (options.region) { | |
596 | + requestParam.region = options.region; | |
597 | + } | |
598 | + | |
599 | + wx.request(Utils.buildWxRequestConfig(options, { | |
600 | + url: URL_GET_GEOCODER, | |
601 | + data: requestParam | |
602 | + },'geocoder')); | |
603 | + }; | |
604 | + | |
605 | + | |
606 | + /** | |
607 | + * 获取城市列表 | |
608 | + * | |
609 | + * @param {Object} options 接口参数对象 | |
610 | + * | |
611 | + * 请求参数结构可以参考 | |
612 | + * http://lbs.qq.com/webservice_v1/guide-region.html | |
613 | + */ | |
614 | + getCityList(options) { | |
615 | + var that = this; | |
616 | + options = options || {}; | |
617 | + Utils.polyfillParam(options); | |
618 | + var requestParam = { | |
619 | + output: 'json', | |
620 | + key: that.key | |
621 | + }; | |
622 | + | |
623 | + wx.request(Utils.buildWxRequestConfig(options, { | |
624 | + url: URL_CITY_LIST, | |
625 | + data: requestParam | |
626 | + },'getCityList')); | |
627 | + }; | |
628 | + | |
629 | + /** | |
630 | + * 获取对应城市ID的区县列表 | |
631 | + * | |
632 | + * @param {Object} options 接口参数对象 | |
633 | + * | |
634 | + * 请求参数结构可以参考 | |
635 | + * http://lbs.qq.com/webservice_v1/guide-region.html | |
636 | + */ | |
637 | + getDistrictByCityId(options) { | |
638 | + var that = this; | |
639 | + options = options || {}; | |
640 | + Utils.polyfillParam(options); | |
641 | + | |
642 | + if (Utils.checkParamKeyEmpty(options, 'id')) { | |
643 | + return; | |
644 | + } | |
645 | + | |
646 | + var requestParam = { | |
647 | + id: options.id || '', | |
648 | + output: 'json', | |
649 | + key: that.key | |
650 | + }; | |
651 | + | |
652 | + wx.request(Utils.buildWxRequestConfig(options, { | |
653 | + url: URL_AREA_LIST, | |
654 | + data: requestParam | |
655 | + },'getDistrictByCityId')); | |
656 | + }; | |
657 | + | |
658 | + /** | |
659 | + * 用于单起点到多终点的路线距离(非直线距离)计算: | |
660 | + * 支持两种距离计算方式:步行和驾车。 | |
661 | + * 起点到终点最大限制直线距离10公里。 | |
662 | + * | |
663 | + * 新增直线距离计算。 | |
664 | + * | |
665 | + * @param {Object} options 接口参数对象 | |
666 | + * | |
667 | + * 请求参数结构可以参考 | |
668 | + * http://lbs.qq.com/webservice_v1/guide-distance.html | |
669 | + */ | |
670 | + calculateDistance(options) { | |
671 | + var that = this; | |
672 | + options = options || {}; | |
673 | + Utils.polyfillParam(options); | |
674 | + | |
675 | + if (Utils.checkParamKeyEmpty(options, 'to')) { | |
676 | + return; | |
677 | + } | |
678 | + | |
679 | + var requestParam = { | |
680 | + mode: options.mode || 'walking', | |
681 | + to: Utils.location2query(options.to), | |
682 | + output: 'json', | |
683 | + key: that.key | |
684 | + }; | |
685 | + | |
686 | + if (options.from) { | |
687 | + options.location = options.from; | |
688 | + } | |
689 | + | |
690 | + //计算直线距离 | |
691 | + if(requestParam.mode == 'straight'){ | |
692 | + var locationsuccess = function (result) { | |
693 | + var locationTo = Utils.getEndLocation(requestParam.to);//处理终点坐标 | |
694 | + var data = { | |
695 | + message:"query ok", | |
696 | + result:{ | |
697 | + elements:[] | |
698 | + }, | |
699 | + status:0 | |
700 | + }; | |
701 | + for (var i = 0; i < locationTo.length; i++) { | |
702 | + data.result.elements.push({//将坐标存入 | |
703 | + distance: Utils.getDistance(result.latitude, result.longitude, locationTo[i].lat, locationTo[i].lng), | |
704 | + duration:0, | |
705 | + from:{ | |
706 | + lat: result.latitude, | |
707 | + lng:result.longitude | |
708 | + }, | |
709 | + to:{ | |
710 | + lat: locationTo[i].lat, | |
711 | + lng: locationTo[i].lng | |
712 | + } | |
713 | + }); | |
714 | + } | |
715 | + var calculateResult = data.result.elements; | |
716 | + var distanceResult = []; | |
717 | + for (var i = 0; i < calculateResult.length; i++) { | |
718 | + distanceResult.push(calculateResult[i].distance); | |
719 | + } | |
720 | + return options.success(data,{ | |
721 | + calculateResult: calculateResult, | |
722 | + distanceResult: distanceResult | |
723 | + }); | |
724 | + }; | |
725 | + | |
726 | + Utils.locationProcess(options, locationsuccess); | |
727 | + } else { | |
728 | + var locationsuccess = function (result) { | |
729 | + requestParam.from = result.latitude + ',' + result.longitude; | |
730 | + wx.request(Utils.buildWxRequestConfig(options, { | |
731 | + url: URL_DISTANCE, | |
732 | + data: requestParam | |
733 | + },'calculateDistance')); | |
734 | + }; | |
735 | + | |
736 | + Utils.locationProcess(options, locationsuccess); | |
737 | + } | |
738 | + } | |
739 | +}; | |
740 | + | |
741 | +module.exports = QQMapWX; | |
0 | 742 | \ No newline at end of file | ... | ... |
pages/work/daily/workOrder.vue
0 → 100644
1 | +<template> | |
2 | + <view class="container"> | |
3 | + <z-paging ref="paging" v-model="dataList" @query="queryList" :auto="false" > | |
4 | + | |
5 | + <view class="ul fs-p20"> | |
6 | + <view class="li fs-bg__white fs-p30 fs-size__h4 fs-radius__sm fs-mt20" v-for="(item, index) in dataList"> | |
7 | + <view @click="toDetails(item.planNo)"> | |
8 | + <view class="fs-flex__between"> | |
9 | + <view class="fs-weight__bold fs-flex1 fs-ellipsis">{{item.planName}}</view> | |
10 | + <tui-text v-if="item.planStatus" text="已完成" type="success"></tui-text> | |
11 | + <tui-text v-else text="未完成" type="danger"></tui-text> | |
12 | + </view> | |
13 | + <view class="fs-flex fs-mt20"> | |
14 | + <view class="fs-flex1">编码:{{item.hotlinenumber}}</view> | |
15 | + <view class="fs-flex1">周期:{{item.levelValue}}{{item.cycleName}}</view> | |
16 | + </view> | |
17 | + <view class="fs-flex fs-mt20"> | |
18 | + <view class="fs-flex1">养护类型:{{item.maintainTypeName}}</view> | |
19 | + <view class="fs-flex1">养护等级:{{item.curingLevelName}}</view> | |
20 | + </view> | |
21 | + <view class="fs-flex__between fs-mt20"> | |
22 | + <view class="fs-flex1">计划次数:{{item.planNum}}</view> | |
23 | + <view class="fs-flex1">完成次数:{{item.planFinishNum}}</view> | |
24 | + </view> | |
25 | + </view> | |
26 | + | |
27 | + </view> | |
28 | + </view> | |
29 | + </z-paging> | |
30 | + </view> | |
31 | +</template> | |
32 | + | |
33 | +<script> | |
34 | +// const QQMapWX = require('./utils/qqmap-wx-jssdk.js') | |
35 | +// 实例化API核心类 | |
36 | +// let qqMap = new QQMapWX({ | |
37 | +// key: 'H77BZ-RVOKL-UOXPH-EXMFC-5XSGT-YDFIC' | |
38 | +// }); | |
39 | +import { hotlinecaseList } from '@/api/work' | |
40 | +import { useCounterStore } from '@/stores/counter' | |
41 | +export default { | |
42 | + data() { | |
43 | + return { | |
44 | + dataList: [], | |
45 | + qqmapsdk:null | |
46 | + } | |
47 | + }, | |
48 | + onLoad() { | |
49 | + // this.qqmapsdk = new QQMapWX({ | |
50 | + // key: 'H77BZ-RVOKL-UOXPH-EXMFC-5XSGT-YDFIC' | |
51 | + // }) | |
52 | + }, | |
53 | + onShow(){ | |
54 | + if (this.$refs.paging) { | |
55 | + this.$refs.paging.refresh() // 重置到第一页并触发query事件 | |
56 | + } | |
57 | + const address = '北京市海淀区中关村大街' | |
58 | + | |
59 | + // this.qqmapsdk.geocoder({ | |
60 | + // address: address, | |
61 | + // success: (res) => { | |
62 | + // if (res.status === 0) { | |
63 | + // this.location = res.result.location | |
64 | + // console.log('解析成功:', res.result.location) | |
65 | + // } else { | |
66 | + // console.error('解析失败:', res.message) | |
67 | + // } | |
68 | + // }, | |
69 | + // fail: (err) => { | |
70 | + // console.error('接口调用失败:', err) | |
71 | + // } | |
72 | + // }) | |
73 | + | |
74 | + }, | |
75 | + methods: { | |
76 | + // 获取巡检列表 | |
77 | + queryList() { | |
78 | + const useCounter = useCounterStore() | |
79 | + console.log(useCounter.userInfo.userId) | |
80 | + const params = { | |
81 | + dispperson:useCounter.userInfo.userId, | |
82 | + taskstate:'gdtype02' | |
83 | + } | |
84 | + hotlinecaseList({data:params}).then(res => { | |
85 | + this.$refs.paging.complete(res.rows) | |
86 | + }) | |
87 | + }, | |
88 | + | |
89 | + // 跳转详情 | |
90 | + toDetails(planno) { | |
91 | + uni.$tui.href(`/pages/work/daily/inspection/details?planno=${planno}`) | |
92 | + }, | |
93 | + // 跳转记录 | |
94 | + toRecord(planno) { | |
95 | + uni.$tui.href(`/pages/work/daily/inspection/record?planno=${planno}`) | |
96 | + } | |
97 | + } | |
98 | +} | |
99 | +</script> | |
100 | + | |
101 | +<style lang="scss" scoped> | |
102 | +.ul .li:first-child { | |
103 | + margin-top: 0; | |
104 | +} | |
105 | +</style> | ... | ... |
pages/work/daily/workOrderDetail.vue
0 → 100644
1 | +<template> | |
2 | + <view class="container"> | |
3 | + <tui-list-cell :hover="false"> | |
4 | + <view class="fs-flex__between"><view>问题单号</view><view>{{info.problemNo}}</view></view> | |
5 | + </tui-list-cell> | |
6 | + <tui-list-cell :hover="false"> | |
7 | + <view class="fs-flex__between"><view class="basis">道路名称</view><view>{{info.roadName}}</view></view> | |
8 | + </tui-list-cell> | |
9 | + <tui-list-cell :hover="false"> | |
10 | + <view class="fs-flex__between"><view>养护级别</view><view>{{info.curingLevelName}}</view></view> | |
11 | + </tui-list-cell> | |
12 | + <tui-list-cell :hover="false"> | |
13 | + <view class="fs-flex__between"><view>养护组长</view><view>{{info.leaderUserName}}</view></view> | |
14 | + </tui-list-cell> | |
15 | + <tui-list-cell :hover="false"> | |
16 | + <view class="fs-flex__between"> | |
17 | + <view>紧急程度</view> | |
18 | + <view> | |
19 | + <tui-text v-if="info.pressingType == 1" type="primary" text="特急"></tui-text> | |
20 | + <tui-text v-else-if="info.pressingType == 2" type="primary" text="紧急"></tui-text> | |
21 | + <tui-text v-else-if="info.pressingType == 3" type="primary" text="一般"></tui-text> | |
22 | + </view> | |
23 | + </view> | |
24 | + </tui-list-cell> | |
25 | + <tui-list-cell :hover="false"> | |
26 | + <view class="fs-flex__between"> | |
27 | + <view>指派状态</view> | |
28 | + <view> | |
29 | + <tui-text v-if="info.distributeStatus == 2" text="已指派" type="success"></tui-text> | |
30 | + <tui-text v-else text="待指派" type="danger"></tui-text> | |
31 | + </view> | |
32 | + </view> | |
33 | + </tui-list-cell> | |
34 | + <tui-list-cell :hover="false"> | |
35 | + <view class="fs-flex__between"> | |
36 | + <view>领导确认状态</view> | |
37 | + <view> | |
38 | + <tui-text v-if="info.leaderConfrimStatus == 1" text="待确认" type="warning"></tui-text> | |
39 | + <tui-text v-else-if="info.leaderConfrimStatus == 2" text="已确认" type="success"></tui-text> | |
40 | + <tui-text v-else-if="info.leaderConfrimStatus == 3" text="已拒绝" type="danger"></tui-text> | |
41 | + </view> | |
42 | + </view> | |
43 | + </tui-list-cell> | |
44 | + <tui-list-cell :hover="false"> | |
45 | + <view class="fs-flex__between"><view>问题来源</view><view>{{info.problemSourceName}}</view></view> | |
46 | + </tui-list-cell> | |
47 | + <tui-list-cell :hover="false"> | |
48 | + <view class="fs-flex__between"> | |
49 | + <view class="basis">具体位置</view> | |
50 | + <view @click="openMap(info.lat, info.lon, info.lonLatAddress)"> | |
51 | + <tui-text type="primary" decoration="underline" :text="info.lonLatAddress"></tui-text> | |
52 | + </view> | |
53 | + </view> | |
54 | + </tui-list-cell> | |
55 | + <tui-list-cell :hover="false"> | |
56 | + <view class="fs-flex__between"><view>提交日期</view><view>{{info.createTime}}</view></view> | |
57 | + </tui-list-cell> | |
58 | + <tui-list-cell :hover="false"> | |
59 | + <view class="fs-flex__between"><view class="basis">问题描述</view><view>{{info.remark}}</view></view> | |
60 | + </tui-list-cell> | |
61 | + <tui-list-cell :hover="false"> | |
62 | + <view class="fs-flex__between"> | |
63 | + <view>问题图片</view> | |
64 | + <view class="fs-flex"> | |
65 | + <view class="fs-ml20" v-for="(value, key) in info.imgList"> | |
66 | + <tui-lazyload-img radius="12rpx" width="150rpx" height="150rpx" mode="aspectFill" :src="value" @click="previewImage('imgList',key)"></tui-lazyload-img> | |
67 | + </view> | |
68 | + </view> | |
69 | + </view> | |
70 | + </tui-list-cell> | |
71 | + <tui-list-cell :hover="false"> | |
72 | + <view class="fs-flex__between"> | |
73 | + <view>街景图片</view> | |
74 | + <view class="fs-flex"> | |
75 | + <view class="fs-ml20" v-for="(value, key) in info.streetImgList"> | |
76 | + <tui-lazyload-img radius="12rpx" width="150rpx" height="150rpx" mode="aspectFill" :src="value" @click="previewImage('streetImgList',key)"></tui-lazyload-img> | |
77 | + </view> | |
78 | + </view> | |
79 | + </view> | |
80 | + </tui-list-cell> | |
81 | + <tui-list-cell :hover="false" unlined> | |
82 | + <view class="fs-flex__between fs-safe__area"> | |
83 | + <view>远景图片</view> | |
84 | + <view class="fs-flex"> | |
85 | + <view class="fs-ml20" v-for="(value, key) in info.longRangeImgList"> | |
86 | + <tui-lazyload-img radius="12rpx" width="150rpx" height="150rpx" mode="aspectFill" :src="value" @click="previewImage('longRangeImgList',key)"></tui-lazyload-img> | |
87 | + </view> | |
88 | + </view> | |
89 | + </view> | |
90 | + </tui-list-cell> | |
91 | + </view> | |
92 | +</template> | |
93 | + | |
94 | +<script> | |
95 | +import { apiCaseDetail } from '@/api/work' | |
96 | +export default { | |
97 | + data() { | |
98 | + return { | |
99 | + info: {} | |
100 | + } | |
101 | + }, | |
102 | + onLoad(options) { | |
103 | + this.getCaseDetail(options.problem_no) | |
104 | + }, | |
105 | + methods: { | |
106 | + // 获取问题详情 | |
107 | + getCaseDetail(problem_no) { | |
108 | + apiCaseDetail({data:{problem_no}}).then(res => { | |
109 | + this.info = res.data | |
110 | + }) | |
111 | + }, | |
112 | + // 图片预览 | |
113 | + previewImage(index, key) { | |
114 | + const imageList = this.info[index] | |
115 | + uni.previewImage({ | |
116 | + current: imageList[key], | |
117 | + loop: true, | |
118 | + urls: imageList | |
119 | + }) | |
120 | + }, | |
121 | + // 查看地图 | |
122 | + openMap(latitude, longitude, address) { | |
123 | + uni.openLocation({ | |
124 | + latitude: latitude, | |
125 | + longitude: longitude, | |
126 | + address: address | |
127 | + }) | |
128 | + } | |
129 | + } | |
130 | +} | |
131 | +</script> | |
132 | + | |
133 | +<style lang="scss" scoped> | |
134 | +.basis { | |
135 | + flex-basis: 180rpx; | |
136 | + flex-shrink: 0; | |
137 | +} | |
138 | +</style> | ... | ... |
pages/work/index.vue
... | ... | @@ -23,6 +23,11 @@ |
23 | 23 | <image class="fs-mb10 icon" src="/static/images/work/itmeHome6.png"></image> |
24 | 24 | <text>历史记录</text> |
25 | 25 | </view> |
26 | + | |
27 | + <view class="fs-flex__column fs-items__center item" v-if="inspectionRoles.includes(userInfo.postId)" @click="href('/pages/work/daily/workOrder')"> | |
28 | + <image class="fs-mb10 icon" src="/static/images/work/workorder.png"></image> | |
29 | + <text>12345工单</text> | |
30 | + </view> | |
26 | 31 | </view> |
27 | 32 | </view> |
28 | 33 | <view class="fs-mt30 fs-py36 fs-px30 fs-bg__white fs-radius__sm"> | ... | ... |
static/images/work/workorder.png
0 → 100644
1.14 KB
utils/qqmap-wx-jssdk.js
0 → 100644
1 | +/** | |
2 | + * 微信小程序JavaScriptSDK | |
3 | + * | |
4 | + * @version 1.1 | |
5 | + * @date 2019-01-20 | |
6 | + */ | |
7 | + | |
8 | +var ERROR_CONF = { | |
9 | + KEY_ERR: 311, | |
10 | + KEY_ERR_MSG: 'key格式错误', | |
11 | + PARAM_ERR: 310, | |
12 | + PARAM_ERR_MSG: '请求参数信息有误', | |
13 | + SYSTEM_ERR: 600, | |
14 | + SYSTEM_ERR_MSG: '系统错误', | |
15 | + WX_ERR_CODE: 1000, | |
16 | + WX_OK_CODE: 200 | |
17 | +}; | |
18 | +var BASE_URL = 'https://apis.map.qq.com/ws/'; | |
19 | +var URL_SEARCH = BASE_URL + 'place/v1/search'; | |
20 | +var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion'; | |
21 | +var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/'; | |
22 | +var URL_CITY_LIST = BASE_URL + 'district/v1/list'; | |
23 | +var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren'; | |
24 | +var URL_DISTANCE = BASE_URL + 'distance/v1/'; | |
25 | +var EARTH_RADIUS = 6378136.49; | |
26 | +var Utils = { | |
27 | + /** | |
28 | + * 得到终点query字符串 | |
29 | + * @param {Array|String} 检索数据 | |
30 | + */ | |
31 | + location2query(data) { | |
32 | + if (typeof data == 'string') { | |
33 | + return data; | |
34 | + } | |
35 | + var query = ''; | |
36 | + for (var i = 0; i < data.length; i++) { | |
37 | + var d = data[i]; | |
38 | + if (!!query) { | |
39 | + query += ';'; | |
40 | + } | |
41 | + if (d.location) { | |
42 | + query = query + d.location.lat + ',' + d.location.lng; | |
43 | + } | |
44 | + if (d.latitude && d.longitude) { | |
45 | + query = query + d.latitude + ',' + d.longitude; | |
46 | + } | |
47 | + } | |
48 | + return query; | |
49 | + }, | |
50 | + | |
51 | + /** | |
52 | + * 计算角度 | |
53 | + */ | |
54 | + rad(d) { | |
55 | + return d * Math.PI / 180.0; | |
56 | + }, | |
57 | + /** | |
58 | + * 处理终点location数组 | |
59 | + * @return 返回终点数组 | |
60 | + */ | |
61 | + getEndLocation(location){ | |
62 | + var to = location.split(';'); | |
63 | + var endLocation = []; | |
64 | + for (var i = 0; i < to.length; i++) { | |
65 | + endLocation.push({ | |
66 | + lat: parseFloat(to[i].split(',')[0]), | |
67 | + lng: parseFloat(to[i].split(',')[1]) | |
68 | + }) | |
69 | + } | |
70 | + return endLocation; | |
71 | + }, | |
72 | + | |
73 | + /** | |
74 | + * 计算两点间直线距离 | |
75 | + * @param a 表示纬度差 | |
76 | + * @param b 表示经度差 | |
77 | + * @return 返回的是距离,单位m | |
78 | + */ | |
79 | + getDistance(latFrom, lngFrom, latTo, lngTo) { | |
80 | + var radLatFrom = this.rad(latFrom); | |
81 | + var radLatTo = this.rad(latTo); | |
82 | + var a = radLatFrom - radLatTo; | |
83 | + var b = this.rad(lngFrom) - this.rad(lngTo); | |
84 | + var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2))); | |
85 | + distance = distance * EARTH_RADIUS; | |
86 | + distance = Math.round(distance * 10000) / 10000; | |
87 | + return parseFloat(distance.toFixed(0)); | |
88 | + }, | |
89 | + /** | |
90 | + * 使用微信接口进行定位 | |
91 | + */ | |
92 | + getWXLocation(success, fail, complete) { | |
93 | + wx.getLocation({ | |
94 | + type: 'gcj02', | |
95 | + success: success, | |
96 | + fail: fail, | |
97 | + complete: complete | |
98 | + }); | |
99 | + }, | |
100 | + | |
101 | + /** | |
102 | + * 获取location参数 | |
103 | + */ | |
104 | + getLocationParam(location) { | |
105 | + if (typeof location == 'string') { | |
106 | + var locationArr = location.split(','); | |
107 | + if (locationArr.length === 2) { | |
108 | + location = { | |
109 | + latitude: location.split(',')[0], | |
110 | + longitude: location.split(',')[1] | |
111 | + }; | |
112 | + } else { | |
113 | + location = {}; | |
114 | + } | |
115 | + } | |
116 | + return location; | |
117 | + }, | |
118 | + | |
119 | + /** | |
120 | + * 回调函数默认处理 | |
121 | + */ | |
122 | + polyfillParam(param) { | |
123 | + param.success = param.success || function () { }; | |
124 | + param.fail = param.fail || function () { }; | |
125 | + param.complete = param.complete || function () { }; | |
126 | + }, | |
127 | + | |
128 | + /** | |
129 | + * 验证param对应的key值是否为空 | |
130 | + * | |
131 | + * @param {Object} param 接口参数 | |
132 | + * @param {String} key 对应参数的key | |
133 | + */ | |
134 | + checkParamKeyEmpty(param, key) { | |
135 | + if (!param[key]) { | |
136 | + var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key +'参数格式有误'); | |
137 | + param.fail(errconf); | |
138 | + param.complete(errconf); | |
139 | + return true; | |
140 | + } | |
141 | + return false; | |
142 | + }, | |
143 | + | |
144 | + /** | |
145 | + * 验证参数中是否存在检索词keyword | |
146 | + * | |
147 | + * @param {Object} param 接口参数 | |
148 | + */ | |
149 | + checkKeyword(param){ | |
150 | + return !this.checkParamKeyEmpty(param, 'keyword'); | |
151 | + }, | |
152 | + | |
153 | + /** | |
154 | + * 验证location值 | |
155 | + * | |
156 | + * @param {Object} param 接口参数 | |
157 | + */ | |
158 | + checkLocation(param) { | |
159 | + var location = this.getLocationParam(param.location); | |
160 | + if (!location || !location.latitude || !location.longitude) { | |
161 | + var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误'); | |
162 | + param.fail(errconf); | |
163 | + param.complete(errconf); | |
164 | + return false; | |
165 | + } | |
166 | + return true; | |
167 | + }, | |
168 | + | |
169 | + /** | |
170 | + * 构造错误数据结构 | |
171 | + * @param {Number} errCode 错误码 | |
172 | + * @param {Number} errMsg 错误描述 | |
173 | + */ | |
174 | + buildErrorConfig(errCode, errMsg) { | |
175 | + return { | |
176 | + status: errCode, | |
177 | + message: errMsg | |
178 | + }; | |
179 | + }, | |
180 | + | |
181 | + /** | |
182 | + * | |
183 | + * 数据处理函数 | |
184 | + * 根据传入参数不同处理不同数据 | |
185 | + * @param {String} feature 功能名称 | |
186 | + * search 地点搜索 | |
187 | + * suggest关键词提示 | |
188 | + * reverseGeocoder逆地址解析 | |
189 | + * geocoder地址解析 | |
190 | + * getCityList获取城市列表:父集 | |
191 | + * getDistrictByCityId获取区县列表:子集 | |
192 | + * calculateDistance距离计算 | |
193 | + * @param {Object} param 接口参数 | |
194 | + * @param {Object} data 数据 | |
195 | + */ | |
196 | + handleData(param,data,feature){ | |
197 | + if (feature === 'search') { | |
198 | + var searchResult = data.data; | |
199 | + var searchSimplify = []; | |
200 | + for (var i = 0; i < searchResult.length; i++) { | |
201 | + searchSimplify.push({ | |
202 | + id: searchResult[i].id || null, | |
203 | + title: searchResult[i].title || null, | |
204 | + latitude: searchResult[i].location && searchResult[i].location.lat || null, | |
205 | + longitude: searchResult[i].location && searchResult[i].location.lng || null, | |
206 | + address: searchResult[i].address || null, | |
207 | + category: searchResult[i].category || null, | |
208 | + tel: searchResult[i].tel || null, | |
209 | + adcode: searchResult[i].ad_info && searchResult[i].ad_info.adcode || null, | |
210 | + city: searchResult[i].ad_info && searchResult[i].ad_info.city || null, | |
211 | + district: searchResult[i].ad_info && searchResult[i].ad_info.district || null, | |
212 | + province: searchResult[i].ad_info && searchResult[i].ad_info.province || null | |
213 | + }) | |
214 | + } | |
215 | + param.success(data, { | |
216 | + searchResult: searchResult, | |
217 | + searchSimplify: searchSimplify | |
218 | + }) | |
219 | + } else if (feature === 'suggest') { | |
220 | + var suggestResult = data.data; | |
221 | + var suggestSimplify = []; | |
222 | + for (var i = 0; i < suggestResult.length; i++) { | |
223 | + suggestSimplify.push({ | |
224 | + adcode: suggestResult[i].adcode || null, | |
225 | + address: suggestResult[i].address || null, | |
226 | + category: suggestResult[i].category || null, | |
227 | + city: suggestResult[i].city || null, | |
228 | + district: suggestResult[i].district || null, | |
229 | + id: suggestResult[i].id || null, | |
230 | + latitude: suggestResult[i].location && suggestResult[i].location.lat || null, | |
231 | + longitude: suggestResult[i].location && suggestResult[i].location.lng || null, | |
232 | + province: suggestResult[i].province || null, | |
233 | + title: suggestResult[i].title || null, | |
234 | + type: suggestResult[i].type || null | |
235 | + }) | |
236 | + } | |
237 | + param.success(data, { | |
238 | + suggestResult: suggestResult, | |
239 | + suggestSimplify: suggestSimplify | |
240 | + }) | |
241 | + } else if (feature === 'reverseGeocoder') { | |
242 | + var reverseGeocoderResult = data.result; | |
243 | + var reverseGeocoderSimplify = { | |
244 | + address: reverseGeocoderResult.address || null, | |
245 | + latitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lat || null, | |
246 | + longitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lng || null, | |
247 | + adcode: reverseGeocoderResult.ad_info && reverseGeocoderResult.ad_info.adcode || null, | |
248 | + city: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.city || null, | |
249 | + district: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.district || null, | |
250 | + nation: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.nation || null, | |
251 | + province: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.province || null, | |
252 | + street: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street || null, | |
253 | + street_number: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street_number || null, | |
254 | + recommend: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.recommend || null, | |
255 | + rough: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.rough || null | |
256 | + }; | |
257 | + if (reverseGeocoderResult.pois) {//判断是否返回周边poi | |
258 | + var pois = reverseGeocoderResult.pois; | |
259 | + var poisSimplify = []; | |
260 | + for (var i = 0;i < pois.length;i++) { | |
261 | + poisSimplify.push({ | |
262 | + id: pois[i].id || null, | |
263 | + title: pois[i].title || null, | |
264 | + latitude: pois[i].location && pois[i].location.lat || null, | |
265 | + longitude: pois[i].location && pois[i].location.lng || null, | |
266 | + address: pois[i].address || null, | |
267 | + category: pois[i].category || null, | |
268 | + adcode: pois[i].ad_info && pois[i].ad_info.adcode || null, | |
269 | + city: pois[i].ad_info && pois[i].ad_info.city || null, | |
270 | + district: pois[i].ad_info && pois[i].ad_info.district || null, | |
271 | + province: pois[i].ad_info && pois[i].ad_info.province || null | |
272 | + }) | |
273 | + } | |
274 | + param.success(data,{ | |
275 | + reverseGeocoderResult: reverseGeocoderResult, | |
276 | + reverseGeocoderSimplify: reverseGeocoderSimplify, | |
277 | + pois: pois, | |
278 | + poisSimplify: poisSimplify | |
279 | + }) | |
280 | + } else { | |
281 | + param.success(data, { | |
282 | + reverseGeocoderResult: reverseGeocoderResult, | |
283 | + reverseGeocoderSimplify: reverseGeocoderSimplify | |
284 | + }) | |
285 | + } | |
286 | + } else if (feature === 'geocoder') { | |
287 | + var geocoderResult = data.result; | |
288 | + var geocoderSimplify = { | |
289 | + title: geocoderResult.title || null, | |
290 | + latitude: geocoderResult.location && geocoderResult.location.lat || null, | |
291 | + longitude: geocoderResult.location && geocoderResult.location.lng || null, | |
292 | + adcode: geocoderResult.ad_info && geocoderResult.ad_info.adcode || null, | |
293 | + province: geocoderResult.address_components && geocoderResult.address_components.province || null, | |
294 | + city: geocoderResult.address_components && geocoderResult.address_components.city || null, | |
295 | + district: geocoderResult.address_components && geocoderResult.address_components.district || null, | |
296 | + street: geocoderResult.address_components && geocoderResult.address_components.street || null, | |
297 | + street_number: geocoderResult.address_components && geocoderResult.address_components.street_number || null, | |
298 | + level: geocoderResult.level || null | |
299 | + }; | |
300 | + param.success(data,{ | |
301 | + geocoderResult: geocoderResult, | |
302 | + geocoderSimplify: geocoderSimplify | |
303 | + }); | |
304 | + } else if (feature === 'getCityList') { | |
305 | + var provinceResult = data.result[0]; | |
306 | + var cityResult = data.result[1]; | |
307 | + var districtResult = data.result[2]; | |
308 | + param.success(data,{ | |
309 | + provinceResult: provinceResult, | |
310 | + cityResult: cityResult, | |
311 | + districtResult: districtResult | |
312 | + }); | |
313 | + } else if (feature === 'getDistrictByCityId') { | |
314 | + var districtByCity = data.result[0]; | |
315 | + param.success(data, districtByCity); | |
316 | + } else if (feature === 'calculateDistance') { | |
317 | + var calculateDistanceResult = data.result.elements; | |
318 | + var distance = []; | |
319 | + for (var i = 0; i < calculateDistanceResult.length; i++){ | |
320 | + distance.push(calculateDistanceResult[i].distance); | |
321 | + } | |
322 | + param.success(data, { | |
323 | + calculateDistanceResult: calculateDistanceResult, | |
324 | + distance: distance | |
325 | + }); | |
326 | + } else { | |
327 | + param.success(data); | |
328 | + } | |
329 | + }, | |
330 | + | |
331 | + /** | |
332 | + * 构造微信请求参数,公共属性处理 | |
333 | + * | |
334 | + * @param {Object} param 接口参数 | |
335 | + * @param {Object} param 配置项 | |
336 | + * @param {String} feature 方法名 | |
337 | + */ | |
338 | + buildWxRequestConfig(param, options, feature) { | |
339 | + var that = this; | |
340 | + options.header = { "content-type": "application/json" }; | |
341 | + options.method = 'GET'; | |
342 | + options.success = function (res) { | |
343 | + var data = res.data; | |
344 | + if (data.status === 0) { | |
345 | + that.handleData(param, data, feature); | |
346 | + } else { | |
347 | + param.fail(data); | |
348 | + } | |
349 | + }; | |
350 | + options.fail = function (res) { | |
351 | + res.statusCode = ERROR_CONF.WX_ERR_CODE; | |
352 | + param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
353 | + }; | |
354 | + options.complete = function (res) { | |
355 | + var statusCode = +res.statusCode; | |
356 | + switch(statusCode) { | |
357 | + case ERROR_CONF.WX_ERR_CODE: { | |
358 | + param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
359 | + break; | |
360 | + } | |
361 | + case ERROR_CONF.WX_OK_CODE: { | |
362 | + var data = res.data; | |
363 | + if (data.status === 0) { | |
364 | + param.complete(data); | |
365 | + } else { | |
366 | + param.complete(that.buildErrorConfig(data.status, data.message)); | |
367 | + } | |
368 | + break; | |
369 | + } | |
370 | + default:{ | |
371 | + param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG)); | |
372 | + } | |
373 | + | |
374 | + } | |
375 | + }; | |
376 | + return options; | |
377 | + }, | |
378 | + | |
379 | + /** | |
380 | + * 处理用户参数是否传入坐标进行不同的处理 | |
381 | + */ | |
382 | + locationProcess(param, locationsuccess, locationfail, locationcomplete) { | |
383 | + var that = this; | |
384 | + locationfail = locationfail || function (res) { | |
385 | + res.statusCode = ERROR_CONF.WX_ERR_CODE; | |
386 | + param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
387 | + }; | |
388 | + locationcomplete = locationcomplete || function (res) { | |
389 | + if (res.statusCode == ERROR_CONF.WX_ERR_CODE) { | |
390 | + param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); | |
391 | + } | |
392 | + }; | |
393 | + if (!param.location) { | |
394 | + that.getWXLocation(locationsuccess, locationfail, locationcomplete); | |
395 | + } else if (that.checkLocation(param)) { | |
396 | + var location = Utils.getLocationParam(param.location); | |
397 | + locationsuccess(location); | |
398 | + } | |
399 | + } | |
400 | +}; | |
401 | + | |
402 | + | |
403 | +class QQMapWX { | |
404 | + | |
405 | + /** | |
406 | + * 构造函数 | |
407 | + * | |
408 | + * @param {Object} options 接口参数,key 为必选参数 | |
409 | + */ | |
410 | + constructor(options) { | |
411 | + if (!options.key) { | |
412 | + throw Error('key值不能为空'); | |
413 | + } | |
414 | + this.key = options.key; | |
415 | + }; | |
416 | + | |
417 | + /** | |
418 | + * POI周边检索 | |
419 | + * | |
420 | + * @param {Object} options 接口参数对象 | |
421 | + * | |
422 | + * 参数对象结构可以参考 | |
423 | + * @see http://lbs.qq.com/webservice_v1/guide-search.html | |
424 | + */ | |
425 | + search(options) { | |
426 | + var that = this; | |
427 | + options = options || {}; | |
428 | + | |
429 | + Utils.polyfillParam(options); | |
430 | + | |
431 | + if (!Utils.checkKeyword(options)) { | |
432 | + return; | |
433 | + } | |
434 | + | |
435 | + var requestParam = { | |
436 | + keyword: options.keyword, | |
437 | + orderby: options.orderby || '_distance', | |
438 | + page_size: options.page_size || 10, | |
439 | + page_index: options.page_index || 1, | |
440 | + output: 'json', | |
441 | + key: that.key | |
442 | + }; | |
443 | + | |
444 | + if (options.address_format) { | |
445 | + requestParam.address_format = options.address_format; | |
446 | + } | |
447 | + | |
448 | + if (options.filter) { | |
449 | + requestParam.filter = options.filter; | |
450 | + } | |
451 | + | |
452 | + var distance = options.distance || "1000"; | |
453 | + var auto_extend = options.auto_extend || 1; | |
454 | + var region = null; | |
455 | + var rectangle = null; | |
456 | + | |
457 | + //判断城市限定参数 | |
458 | + if (options.region) { | |
459 | + region = options.region; | |
460 | + } | |
461 | + | |
462 | + //矩形限定坐标(暂时只支持字符串格式) | |
463 | + if (options.rectangle) { | |
464 | + rectangle = options.rectangle; | |
465 | + } | |
466 | + | |
467 | + var locationsuccess = function (result) { | |
468 | + if (region && !rectangle) { | |
469 | + //城市限定参数拼接 | |
470 | + requestParam.boundary = "region(" + region + "," + auto_extend + "," + result.latitude + "," + result.longitude + ")"; | |
471 | + } else if (rectangle && !region) { | |
472 | + //矩形搜索 | |
473 | + requestParam.boundary = "rectangle(" + rectangle + ")"; | |
474 | + } else { | |
475 | + requestParam.boundary = "nearby(" + result.latitude + "," + result.longitude + "," + distance + "," + auto_extend + ")"; | |
476 | + } | |
477 | + wx.request(Utils.buildWxRequestConfig(options, { | |
478 | + url: URL_SEARCH, | |
479 | + data: requestParam | |
480 | + }, 'search')); | |
481 | + }; | |
482 | + Utils.locationProcess(options, locationsuccess); | |
483 | + }; | |
484 | + | |
485 | + /** | |
486 | + * sug模糊检索 | |
487 | + * | |
488 | + * @param {Object} options 接口参数对象 | |
489 | + * | |
490 | + * 参数对象结构可以参考 | |
491 | + * http://lbs.qq.com/webservice_v1/guide-suggestion.html | |
492 | + */ | |
493 | + getSuggestion(options) { | |
494 | + var that = this; | |
495 | + options = options || {}; | |
496 | + Utils.polyfillParam(options); | |
497 | + | |
498 | + if (!Utils.checkKeyword(options)) { | |
499 | + return; | |
500 | + } | |
501 | + | |
502 | + var requestParam = { | |
503 | + keyword: options.keyword, | |
504 | + region: options.region || '全国', | |
505 | + region_fix: options.region_fix || 0, | |
506 | + policy: options.policy || 0, | |
507 | + page_size: options.page_size || 10,//控制显示条数 | |
508 | + page_index: options.page_index || 1,//控制页数 | |
509 | + get_subpois : options.get_subpois || 0,//返回子地点 | |
510 | + output: 'json', | |
511 | + key: that.key | |
512 | + }; | |
513 | + //长地址 | |
514 | + if (options.address_format) { | |
515 | + requestParam.address_format = options.address_format; | |
516 | + } | |
517 | + //过滤 | |
518 | + if (options.filter) { | |
519 | + requestParam.filter = options.filter; | |
520 | + } | |
521 | + //排序 | |
522 | + if (options.location) { | |
523 | + var locationsuccess = function (result) { | |
524 | + requestParam.location = result.latitude + ',' + result.longitude; | |
525 | + wx.request(Utils.buildWxRequestConfig(options, { | |
526 | + url: URL_SUGGESTION, | |
527 | + data: requestParam | |
528 | + }, "suggest")); | |
529 | + }; | |
530 | + Utils.locationProcess(options, locationsuccess); | |
531 | + } else { | |
532 | + wx.request(Utils.buildWxRequestConfig(options, { | |
533 | + url: URL_SUGGESTION, | |
534 | + data: requestParam | |
535 | + }, "suggest")); | |
536 | + } | |
537 | + }; | |
538 | + | |
539 | + /** | |
540 | + * 逆地址解析 | |
541 | + * | |
542 | + * @param {Object} options 接口参数对象 | |
543 | + * | |
544 | + * 请求参数结构可以参考 | |
545 | + * http://lbs.qq.com/webservice_v1/guide-gcoder.html | |
546 | + */ | |
547 | + reverseGeocoder(options) { | |
548 | + var that = this; | |
549 | + options = options || {}; | |
550 | + Utils.polyfillParam(options); | |
551 | + var requestParam = { | |
552 | + coord_type: options.coord_type || 5, | |
553 | + get_poi: options.get_poi || 0, | |
554 | + output: 'json', | |
555 | + key: that.key | |
556 | + }; | |
557 | + if (options.poi_options) { | |
558 | + requestParam.poi_options = options.poi_options | |
559 | + } | |
560 | + | |
561 | + var locationsuccess = function (result) { | |
562 | + requestParam.location = result.latitude + ',' + result.longitude; | |
563 | + wx.request(Utils.buildWxRequestConfig(options, { | |
564 | + url: URL_GET_GEOCODER, | |
565 | + data: requestParam | |
566 | + }, 'reverseGeocoder')); | |
567 | + }; | |
568 | + Utils.locationProcess(options, locationsuccess); | |
569 | + }; | |
570 | + | |
571 | + /** | |
572 | + * 地址解析 | |
573 | + * | |
574 | + * @param {Object} options 接口参数对象 | |
575 | + * | |
576 | + * 请求参数结构可以参考 | |
577 | + * http://lbs.qq.com/webservice_v1/guide-geocoder.html | |
578 | + */ | |
579 | + geocoder(options) { | |
580 | + var that = this; | |
581 | + options = options || {}; | |
582 | + Utils.polyfillParam(options); | |
583 | + | |
584 | + if (Utils.checkParamKeyEmpty(options, 'address')) { | |
585 | + return; | |
586 | + } | |
587 | + | |
588 | + var requestParam = { | |
589 | + address: options.address, | |
590 | + output: 'json', | |
591 | + key: that.key | |
592 | + }; | |
593 | + | |
594 | + //城市限定 | |
595 | + if (options.region) { | |
596 | + requestParam.region = options.region; | |
597 | + } | |
598 | + | |
599 | + wx.request(Utils.buildWxRequestConfig(options, { | |
600 | + url: URL_GET_GEOCODER, | |
601 | + data: requestParam | |
602 | + },'geocoder')); | |
603 | + }; | |
604 | + | |
605 | + | |
606 | + /** | |
607 | + * 获取城市列表 | |
608 | + * | |
609 | + * @param {Object} options 接口参数对象 | |
610 | + * | |
611 | + * 请求参数结构可以参考 | |
612 | + * http://lbs.qq.com/webservice_v1/guide-region.html | |
613 | + */ | |
614 | + getCityList(options) { | |
615 | + var that = this; | |
616 | + options = options || {}; | |
617 | + Utils.polyfillParam(options); | |
618 | + var requestParam = { | |
619 | + output: 'json', | |
620 | + key: that.key | |
621 | + }; | |
622 | + | |
623 | + wx.request(Utils.buildWxRequestConfig(options, { | |
624 | + url: URL_CITY_LIST, | |
625 | + data: requestParam | |
626 | + },'getCityList')); | |
627 | + }; | |
628 | + | |
629 | + /** | |
630 | + * 获取对应城市ID的区县列表 | |
631 | + * | |
632 | + * @param {Object} options 接口参数对象 | |
633 | + * | |
634 | + * 请求参数结构可以参考 | |
635 | + * http://lbs.qq.com/webservice_v1/guide-region.html | |
636 | + */ | |
637 | + getDistrictByCityId(options) { | |
638 | + var that = this; | |
639 | + options = options || {}; | |
640 | + Utils.polyfillParam(options); | |
641 | + | |
642 | + if (Utils.checkParamKeyEmpty(options, 'id')) { | |
643 | + return; | |
644 | + } | |
645 | + | |
646 | + var requestParam = { | |
647 | + id: options.id || '', | |
648 | + output: 'json', | |
649 | + key: that.key | |
650 | + }; | |
651 | + | |
652 | + wx.request(Utils.buildWxRequestConfig(options, { | |
653 | + url: URL_AREA_LIST, | |
654 | + data: requestParam | |
655 | + },'getDistrictByCityId')); | |
656 | + }; | |
657 | + | |
658 | + /** | |
659 | + * 用于单起点到多终点的路线距离(非直线距离)计算: | |
660 | + * 支持两种距离计算方式:步行和驾车。 | |
661 | + * 起点到终点最大限制直线距离10公里。 | |
662 | + * | |
663 | + * 新增直线距离计算。 | |
664 | + * | |
665 | + * @param {Object} options 接口参数对象 | |
666 | + * | |
667 | + * 请求参数结构可以参考 | |
668 | + * http://lbs.qq.com/webservice_v1/guide-distance.html | |
669 | + */ | |
670 | + calculateDistance(options) { | |
671 | + var that = this; | |
672 | + options = options || {}; | |
673 | + Utils.polyfillParam(options); | |
674 | + | |
675 | + if (Utils.checkParamKeyEmpty(options, 'to')) { | |
676 | + return; | |
677 | + } | |
678 | + | |
679 | + var requestParam = { | |
680 | + mode: options.mode || 'walking', | |
681 | + to: Utils.location2query(options.to), | |
682 | + output: 'json', | |
683 | + key: that.key | |
684 | + }; | |
685 | + | |
686 | + if (options.from) { | |
687 | + options.location = options.from; | |
688 | + } | |
689 | + | |
690 | + //计算直线距离 | |
691 | + if(requestParam.mode == 'straight'){ | |
692 | + var locationsuccess = function (result) { | |
693 | + var locationTo = Utils.getEndLocation(requestParam.to);//处理终点坐标 | |
694 | + var data = { | |
695 | + message:"query ok", | |
696 | + result:{ | |
697 | + elements:[] | |
698 | + }, | |
699 | + status:0 | |
700 | + }; | |
701 | + for (var i = 0; i < locationTo.length; i++) { | |
702 | + data.result.elements.push({//将坐标存入 | |
703 | + distance: Utils.getDistance(result.latitude, result.longitude, locationTo[i].lat, locationTo[i].lng), | |
704 | + duration:0, | |
705 | + from:{ | |
706 | + lat: result.latitude, | |
707 | + lng:result.longitude | |
708 | + }, | |
709 | + to:{ | |
710 | + lat: locationTo[i].lat, | |
711 | + lng: locationTo[i].lng | |
712 | + } | |
713 | + }); | |
714 | + } | |
715 | + var calculateResult = data.result.elements; | |
716 | + var distanceResult = []; | |
717 | + for (var i = 0; i < calculateResult.length; i++) { | |
718 | + distanceResult.push(calculateResult[i].distance); | |
719 | + } | |
720 | + return options.success(data,{ | |
721 | + calculateResult: calculateResult, | |
722 | + distanceResult: distanceResult | |
723 | + }); | |
724 | + }; | |
725 | + | |
726 | + Utils.locationProcess(options, locationsuccess); | |
727 | + } else { | |
728 | + var locationsuccess = function (result) { | |
729 | + requestParam.from = result.latitude + ',' + result.longitude; | |
730 | + wx.request(Utils.buildWxRequestConfig(options, { | |
731 | + url: URL_DISTANCE, | |
732 | + data: requestParam | |
733 | + },'calculateDistance')); | |
734 | + }; | |
735 | + | |
736 | + Utils.locationProcess(options, locationsuccess); | |
737 | + } | |
738 | + } | |
739 | +}; | |
740 | + | |
741 | +module.exports = QQMapWX; | |
0 | 742 | \ No newline at end of file | ... | ... |