diff --git a/uni_modules/uni-map-common/changelog.md b/uni_modules/uni-map-common/changelog.md index 21749635b8ef5ac61c6e736afed4ada96df5e5a6..fce0a0fb7a8938e291e45a5c31c99b8805b359a2 100644 --- a/uni_modules/uni-map-common/changelog.md +++ b/uni_modules/uni-map-common/changelog.md @@ -1,3 +1,5 @@ +## 1.1.4(2024-11-21) +新增 参数payload的接收和验证示例 ## 1.1.3(2024-11-11) 优化 chooseLocation 函数供 uni-app x 的 uni.chooseLocation 使用 ## 1.1.2(2024-10-21) diff --git a/uni_modules/uni-map-common/package.json b/uni_modules/uni-map-common/package.json index daf00bb1c01ac020b81ec1dbbff6bdafd035ff57..4648c4289ee2361425f6cf0a19c172782627f0af 100644 --- a/uni_modules/uni-map-common/package.json +++ b/uni_modules/uni-map-common/package.json @@ -1,7 +1,7 @@ { "id": "uni-map-common", "displayName": "uni-map-common地图服务端API", - "version": "1.1.3", + "version": "1.1.4", "description": "聚合了多家地图供应商的服务端API,几行代码即可快速接入地图API", "keywords": [ "uni-map-common", @@ -32,7 +32,7 @@ "npmurl": "" }, "uni_modules": { - "dependencies": [], + "dependencies": ["uni-config-center"], "encrypt": [], "platforms": { "cloud": { diff --git a/uni_modules/uni-map-common/uniCloud/cloudfunctions/common/uni-map-common/package.json b/uni_modules/uni-map-common/uniCloud/cloudfunctions/common/uni-map-common/package.json index dfbb59e8faa97e441c5eaec35188e151cb7e4dac..75cd3d92731c60be0bce5d70e0f5832d835d5af9 100644 --- a/uni_modules/uni-map-common/uniCloud/cloudfunctions/common/uni-map-common/package.json +++ b/uni_modules/uni-map-common/uniCloud/cloudfunctions/common/uni-map-common/package.json @@ -13,7 +13,7 @@ "uni-config-center": "file:..\/..\/..\/..\/..\/uni-config-center\/uniCloud\/cloudfunctions\/common\/uni-config-center" }, "origin-plugin-dev-name": "uni-map-common", - "origin-plugin-version": "1.1.3", + "origin-plugin-version": "1.1.4", "plugin-dev-name": "uni-map-common", - "plugin-version": "1.1.3" + "plugin-version": "1.1.4" } \ No newline at end of file diff --git a/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/index.obj.js b/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/index.obj.js index 0211e7c11fba3402b9980e9ce9124939172ff486..b41bfa66239a7adcd234e8d2def0e75672db15a6 100644 --- a/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/index.obj.js +++ b/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/index.obj.js @@ -21,6 +21,16 @@ const $ = _.aggregate; const opendbPoiDB = db.collection("opendb-poi"); +class MyError extends Error { + constructor(errMsg, errCode = -1) { + super(errMsg); + this.err = { + errCode, + errMsg + } + } +} + module.exports = { _before: function() { // 如果配置中心不存在地图配置,则使用本地地图配置 @@ -33,7 +43,6 @@ module.exports = { provider = defaultProvider, needOriginalResult = false } = params[0] || {}; - console.log('provider: ', provider) const key = UniMapConfig.key[provider] || LocalMapConfig.key[provider]; if (!key) { throw { errCode: -1, errMsg: `请在uni-config-center/uni-map/config.js中或LocalMapConfig中配置地图供应商${provider}对应的key` }; @@ -45,10 +54,39 @@ module.exports = { needOriginalResult }); this.uniMap = uniMap; + // // 在这里可以做一些统一的前置处理,比如权限校验、参数校验等 + // let { + // payload, // payload参数为前端传递的参数,可以在前端调用uni.chooseLocation时传递 + // } = this.getParams()[0] || {}; + // if (!payload) { + // throw new MyError("payload参数不能为空", -1); + // } + // // 如果业务在uniCloud上,则直接在这里写判断逻辑即可 + // if (true) { + // throw new MyError("权限不足", -1); + // } + + // // 如果业务不在uniCloud上,可通过 uniCloud.request 调用自己的服务进行校验 + // const requestRes = await uniCloud.request({ + // method: 'POST', + // url: '你自己的接口地址', + // data: payload, + // }); + // // 约定errCode不为0代表校验失败,errMsg为失败原因 + // if (requestRes.data.errCode !== 0) { + // throw new MyError(requestRes.data.errMsg, requestRes.data.errCode); + // } + }, - _after: function(error, res) { - if (error) { - throw error; // 如果方法抛出错误,也直接抛出不处理 + _after: function(err, res) { + if (err) { + if (err.err) { + return err.err; + } + if (err.errCode) { + return err; + } + throw err; // 如果方法抛出错误,也直接抛出不处理 } console.log("result", res.result); return res; @@ -58,15 +96,17 @@ module.exports = { let res = {}; let { action, - data, + data, needOriginalResult } = parame; - // 初始化实例 // 获取uniMap实例 const uniMap = this.uniMap; // 调用API let result = await uniMap[action](data); res.result = needOriginalResult ? result.originalResult : result; + // 模拟错误 + // res.errCode = 121; + // res.errMsg = '此key每日调用量已达到上限' return res; }, // 经纬度坐标转地址 @@ -448,7 +488,7 @@ module.exports = { /** * 生成在指定经纬度圆内的随机坐标 - + const latitude = 39.908823; // 指定纬度 const longitude = 116.39747; // 指定经度 const radiusInKm = 10; // 指定圆的半径(单位:千米) @@ -484,7 +524,7 @@ function getRandomCoordinateWithinRadius(longitude, latitude, radiusInKm) { /** * 计算坐标B在坐标A的方向,0代表正西方 90 代表正北方 - + const latitude = 39.908823; // 指定纬度 const longitude = 116.39747; // 指定经度 const radiusInKm = 10; // 指定圆的半径(单位:千米) @@ -515,4 +555,4 @@ function calculateDirectionAngle(coordA, coordB) { angleDegrees = (angleDegrees > 180) ? angleDegrees - 180 : angleDegrees + 180; angleDegrees -= 90; // 以正西方为0°表示,因此需要-90 return angleDegrees; -} \ No newline at end of file +} diff --git a/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/package.json b/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/package.json index 5d4ecb9210470e97ffc29fa611df9f2712bf4951..1d2344152349345a35d2c6e28573a8183628f797 100644 --- a/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/package.json +++ b/uni_modules/uni-map-common/uniCloud/cloudfunctions/uni-map-co/package.json @@ -1,9 +1,12 @@ { - "name": "uni-map-co", - "dependencies": { - "uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center", - "uni-map-common": "file:../common/uni-map-common", - "uni-id-common": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common" - }, - "extensions": {} + "name": "uni-map-co", + "dependencies": { + "uni-config-center": "file:..\/..\/..\/..\/uni-config-center\/uniCloud\/cloudfunctions\/common\/uni-config-center", + "uni-map-common": "file:..\/common\/uni-map-common" + }, + "extensions": {}, + "origin-plugin-dev-name": "uni-map-common", + "origin-plugin-version": "1.1.4", + "plugin-dev-name": "uni-map-common", + "plugin-version": "1.1.4" } \ No newline at end of file