var _createClass=function(){function o(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(t,e,i){return e&&o(t.prototype,e),i&&o(t,i),t}}();function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var ERROR_CONF={KEY_ERR:311,KEY_ERR_MSG:"key格式错误",PARAM_ERR:310,PARAM_ERR_MSG:"请求参数信息有误",SYSTEM_ERR:600,SYSTEM_ERR_MSG:"系统错误",WX_ERR_CODE:1e3,WX_OK_CODE:200},BASE_URL="https://apis.map.qq.com/ws/",URL_SEARCH=BASE_URL+"place/v1/search",URL_SUGGESTION=BASE_URL+"place/v1/suggestion",URL_GET_GEOCODER=BASE_URL+"geocoder/v1/",URL_CITY_LIST=BASE_URL+"district/v1/list",URL_AREA_LIST=BASE_URL+"district/v1/getchildren",URL_DISTANCE=BASE_URL+"distance/v1/",Utils={location2query:function(t){if("string"==typeof t)return t;for(var e="",i=0;i<t.length;i++){var o=t[i];e&&(e+=";"),o.location&&(e=e+o.location.lat+","+o.location.lng),o.latitude&&o.longitude&&(e=e+o.latitude+","+o.longitude)}return e},getWXLocation:function(t,e,i){wx.getLocation({type:"gcj02",success:t,fail:e,complete:i})},getLocationParam:function(t){"string"==typeof t&&(t=2===t.split(",").length?{latitude:t.split(",")[0],longitude:t.split(",")[1]}:{});return t},polyfillParam:function(t){t.success=t.success||function(){},t.fail=t.fail||function(){},t.complete=t.complete||function(){}},checkParamKeyEmpty:function(t,e){if(!t[e]){var i=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+e+"参数格式有误");return t.fail(i),t.complete(i),!0}return!1},checkKeyword:function(t){return!this.checkParamKeyEmpty(t,"keyword")},checkLocation:function(t){var e=this.getLocationParam(t.location);if(!e||!e.latitude||!e.longitude){var i=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+" location参数格式有误");return t.fail(i),t.complete(i),!1}return!0},buildErrorConfig:function(t,e){return{status:t,message:e}},buildWxRequestConfig:function(i,t){var o=this;return t.header={"content-type":"application/json"},t.method="GET",t.success=function(t){var e=t.data;0===e.status?i.success(e):i.fail(e)},t.fail=function(t){t.statusCode=ERROR_CONF.WX_ERR_CODE,i.fail(o.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,result.errMsg))},t.complete=function(t){switch(+t.statusCode){case ERROR_CONF.WX_ERR_CODE:i.complete(o.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,t.errMsg));break;case ERROR_CONF.WX_OK_CODE:var e=t.data;0===e.status?i.complete(e):i.complete(o.buildErrorConfig(e.status,e.message));break;default:i.complete(o.buildErrorConfig(ERROR_CONF.SYSTEM_ERR,ERROR_CONF.SYSTEM_ERR_MSG))}},t},locationProcess:function(e,t,i,o){var r=this;if(i=i||function(t){t.statusCode=ERROR_CONF.WX_ERR_CODE,e.fail(r.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,t.errMsg))},o=o||function(t){t.statusCode==ERROR_CONF.WX_ERR_CODE&&e.complete(r.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,t.errMsg))},e.location){if(r.checkLocation(e)){t(Utils.getLocationParam(e.location))}}else r.getWXLocation(t,i,o)}},QQMapWX=function(){function e(t){if(_classCallCheck(this,e),!t.key)throw Error("key值不能为�?");this.key=t.key}return _createClass(e,[{key:"search",value:function(e){if(e=e||{},Utils.polyfillParam(e),Utils.checkKeyword(e)){var i={keyword:e.keyword,orderby:e.orderby||"_distance",page_size:e.page_size||10,page_index:e.page_index||1,output:"json",key:this.key};e.address_format&&(i.address_format=e.address_format),e.filter&&(i.filter=e.filter);var o=e.distance||"1000",r=e.auto_extend||1;Utils.locationProcess(e,function(t){i.boundary="nearby("+t.latitude+","+t.longitude+","+o+","+r+")",wx.request(Utils.buildWxRequestConfig(e,{url:URL_SEARCH,data:i}))})}}},{key:"getSuggestion",value:function(t){if(t=t||{},Utils.polyfillParam(t),Utils.checkKeyword(t)){var e={keyword:t.keyword,region:t.region||"全国",region_fix:t.region_fix||0,policy:t.policy||0,output:"json",key:this.key};wx.request(Utils.buildWxRequestConfig(t,{url:URL_SUGGESTION,data:e}))}}},{key:"reverseGeocoder",value:function(e){e=e||{},Utils.polyfillParam(e);var i={coord_type:e.coord_type||5,get_poi:e.get_poi||0,output:"json",key:this.key};e.poi_options&&(i.poi_options=e.poi_options);Utils.locationProcess(e,function(t){i.location=t.latitude+","+t.longitude,wx.request(Utils.buildWxRequestConfig(e,{url:URL_GET_GEOCODER,data:i}))})}},{key:"geocoder",value:function(t){if(t=t||{},Utils.polyfillParam(t),!Utils.checkParamKeyEmpty(t,"address")){var e={address:t.address,output:"json",key:this.key};wx.request(Utils.buildWxRequestConfig(t,{url:URL_GET_GEOCODER,data:e}))}}},{key:"getCityList",value:function(t){t=t||{},Utils.polyfillParam(t);var e={output:"json",key:this.key};wx.request(Utils.buildWxRequestConfig(t,{url:URL_CITY_LIST,data:e}))}},{key:"getDistrictByCityId",value:function(t){if(t=t||{},Utils.polyfillParam(t),!Utils.checkParamKeyEmpty(t,"id")){var e={id:t.id||"",output:"json",key:this.key};wx.request(Utils.buildWxRequestConfig(t,{url:URL_AREA_LIST,data:e}))}}},{key:"calculateDistance",value:function(e){if(e=e||{},Utils.polyfillParam(e),!Utils.checkParamKeyEmpty(e,"to")){var i={mode:e.mode||"walking",to:Utils.location2query(e.to),output:"json",key:this.key};e.from&&(e.location=e.from),Utils.locationProcess(e,function(t){i.from=t.latitude+","+t.longitude,wx.request(Utils.buildWxRequestConfig(e,{url:URL_DISTANCE,data:i}))})}}}]),e}();module.exports=QQMapWX;
代码片段是一种可分享的小项目,可用于分享小程序和小游戏的开发经验、展示组件和 API 的使用、复现开发问题等等。分享代码片段会得到一个链接,所有拥有此分享链接的人可以在工具中导入此代码片段。如果网页可点击的链接指向的是分享链接,那么点击链接也会自动打开工具进入代码片段导入页。使用最新版的开发者工具可以使用 chrome 浏览器点此体验导入代码片段。
创建代码片段
在工具选择项目的界面中,右侧可以选择代码片段页卡,查看所有本地代码片段,在右下角可以点击创建代码片段。
创建代码片段需要填入代码片段名称、本地存放目录。AppID 不是必填项,如果需要演示依赖 AppID 的操作则需填写。如果存放目录是空目录,则可在下方选择小程序、小游戏等的快速启动模板。
信息填写正确后,点击创建即可完成创建并打开代码片段。
代码片段主界面
代码片段的主界面与普通项目主要有以下几点区别:
分享代码片段
在工具栏上点击分享按钮即可开启分享代码片段的流程,在分享信息中需要填写以下内容:
分享的小程序代码片段最大大小为 1MB,小游戏代码片段最大为 1MB
分享成功后会展示分享链接,可复制分享给其他开发者,其他开发者在工具中选择导入代码片段并粘贴链接即可导入。
分享的链接除了可以粘贴到导入页导入外,还可以设置为可点击的链接。如果
html
<a>
标签的href
属性设置为分享的链接,如<a href="https://developers.weixin.qq.com/s/76b799966b6ead1837edac517cc02e02">代码片段示例</a>
,则用户点击此链接时会自动打开工具进入代码片段导入页,最后点击导入即可完成导入。在开发者社区发帖时,如果想要提供 demo 示例,如果想要提供 demo 示例,可以插入一个链接为代码片段分享链接的超链接。导入代码片段
在选择代码片段的页面的右下角可以点击导入进入导入页,或者点击菜单栏上的项目选项卡下的导入代码片段来打开导入页。导入时需要填写分享链接或代码片段 ID。链接的最后一部分即是代码片段的 ID,如
https://developers.weixin.qq.com/s/76b799966b6ead1837edac517cc02e02
的 ID 为76b799966b6ead1837edac517cc02e02
。导入时可选择存放目录和 AppID。存放目录默认是在临时文件夹。
麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
用这个做一下吧