q-koa 12.3.1 → 12.3.3

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.
@@ -295,10 +295,10 @@ exports.swagger = async (ctx) => {
295
295
  ctx.SUCCESS(apis)
296
296
  }
297
297
 
298
- exports.getLocation = async (ctx) => {
298
+ exports.getLocation = async (ctx, _data) => {
299
299
  const { app } = getAppByCtx(ctx)
300
300
 
301
- const { provinceName, cityName, address } = ctx.request.body
301
+ const { provinceName, cityName, address } = _data || ctx.request.body
302
302
  if (!provinceName || !cityName || !address) {
303
303
  return ctx.SUCCESS({
304
304
  longitude: null,
@@ -308,33 +308,51 @@ exports.getLocation = async (ctx) => {
308
308
  const appConfig = getConfig(app)
309
309
  const { tencent_key } = await appConfig.getObject('map')
310
310
 
311
- const geo = new Geo(tencent_key)
311
+ let geo
312
+ if (Array.isArray(tencent_key)) {
313
+ geo = new Geo(lodash.shuffle(tencent_key)[0])
314
+ } else {
315
+ geo = new Geo(tencent_key)
316
+ }
317
+
312
318
  const addressName = address || `${provinceName}${cityName}`
313
319
  const result = await geo.getToLngAndLat(addressName)
314
320
 
315
321
  const { lng: longitude, lat: latitude } = result.location
316
322
 
317
- return ctx.SUCCESS({
323
+ ctx.SUCCESS({
318
324
  longitude,
319
325
  latitude,
320
326
  })
327
+
328
+ return {
329
+ longitude,
330
+ latitude,
331
+ }
321
332
  }
322
333
 
323
- exports.getLngAndLat = async (ctx) => {
334
+ exports.getLngAndLat = async (ctx, _data) => {
324
335
  const { app } = getAppByCtx(ctx)
325
336
 
326
- const { longitude, latitude } = ctx.request.body
337
+ const { longitude, latitude } = _data || ctx.request.body
327
338
 
328
339
  const appConfig = getConfig(app)
329
340
  const { tencent_key } = await appConfig.getObject('map')
330
341
 
331
- const geo = new Geo(tencent_key)
342
+ let geo
343
+ if (Array.isArray(tencent_key)) {
344
+ geo = new Geo(lodash.shuffle(tencent_key)[0])
345
+ } else {
346
+ geo = new Geo(tencent_key)
347
+ }
348
+
332
349
  const res = await geo.getToLoation({
333
350
  longitude,
334
351
  latitude,
335
352
  })
336
353
 
337
- return ctx.SUCCESS(res)
354
+ ctx.SUCCESS(res)
355
+ return res
338
356
  }
339
357
 
340
358
  exports.syncModel = async (ctx) => {
@@ -44,6 +44,8 @@ exports.getObject = (config, app) => async (type) => {
44
44
  temObj[list[i].code] = Number(list[i].value)
45
45
  } else if (list[i].type === 'switch') {
46
46
  temObj[list[i].code] = Boolean(Number(list[i].value))
47
+ } else if (list[i].type === 'list' || list[i].type === 'json') {
48
+ temObj[list[i].code] = JSON.parse(list[i].value)
47
49
  } else {
48
50
  temObj[list[i].code] = list[i].value
49
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.3.1",
3
+ "version": "12.3.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {