@tarojs/taro-h5 3.6.24-nightly.8 → 3.6.24-patch.0
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.
|
@@ -57,16 +57,16 @@ function createLocationChooser(handler, key = LOCATION_APIKEY, mapOpt = {}) {
|
|
|
57
57
|
* 打开地图选择位置。
|
|
58
58
|
*/
|
|
59
59
|
const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
|
|
60
|
-
const key = LOCATION_APIKEY;
|
|
61
60
|
const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete });
|
|
62
61
|
return new Promise((resolve, reject) => {
|
|
63
62
|
const chooseLocation = {};
|
|
64
|
-
if (
|
|
63
|
+
if (typeof LOCATION_APIKEY === 'undefined') {
|
|
65
64
|
console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY');
|
|
66
65
|
return handle.fail({
|
|
67
66
|
errMsg: 'LOCATION_APIKEY needed'
|
|
68
67
|
}, { resolve, reject });
|
|
69
68
|
}
|
|
69
|
+
const key = LOCATION_APIKEY;
|
|
70
70
|
const onMessage = event => {
|
|
71
71
|
// 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
|
|
72
72
|
const loc = event.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chooseLocation.js","sources":["../../../src/api/location/chooseLocation.ts"],"sourcesContent":["import './style.scss'\r\n\r\nimport Taro from '@tarojs/api'\r\nimport { stringify } from 'query-string'\r\n\r\nimport { MethodHandler } from '../../utils/handler'\r\n\r\nlet container: HTMLDivElement | null = null\r\nfunction createLocationChooser (handler, key = LOCATION_APIKEY, mapOpt: Taro.chooseLocation.Option['mapOpts'] = {}) {\r\n const { latitude, longitude, ...opts } = mapOpt\r\n const query = {\r\n key,\r\n type: 1,\r\n coord: mapOpt.coord ?? [latitude, longitude].every(e => Number(e) >= 0) ? `${latitude},${longitude}` : undefined,\r\n referer: 'myapp',\r\n ...opts\r\n }\r\n if (!container) {\r\n const html = `\r\n<div class='taro_choose_location'>\r\n <div class='taro_choose_location_bar'>\r\n <div class='taro_choose_location_back'></div>\r\n <p class='taro_choose_location_title'>位置</p>\r\n <button class='taro_choose_location_submit'>完成</button>\r\n </div>\r\n <iframe class='taro_choose_location_frame' frameborder='0' src=\"https://apis.map.qq.com/tools/locpicker?${stringify(query, { arrayFormat: 'comma', skipNull: true })}\" />\r\n</div>\r\n`\r\n container = document.createElement('div')\r\n container.innerHTML = html\r\n }\r\n const main: HTMLDivElement = container.querySelector('.taro_choose_location') as HTMLDivElement\r\n\r\n function show () {\r\n setTimeout(() => {\r\n main.style.top = '0'\r\n })\r\n }\r\n\r\n function hide () {\r\n main.style.top = '100%'\r\n }\r\n\r\n function back () {\r\n hide()\r\n handler({ errMsg: 'cancel' })\r\n }\r\n\r\n function submit () {\r\n hide()\r\n handler()\r\n }\r\n\r\n function remove () {\r\n container?.remove()\r\n container = null\r\n window.removeEventListener('popstate', back)\r\n }\r\n\r\n container.querySelector('.taro_choose_location_back')?.addEventListener('click', back)\r\n container.querySelector('.taro_choose_location_submit')?.addEventListener('click', submit)\r\n\r\n window.addEventListener('popstate', back)\r\n\r\n return {\r\n show,\r\n remove,\r\n container,\r\n }\r\n}\r\n\r\n/**\r\n * 打开地图选择位置。\r\n */\r\nexport const chooseLocation: typeof Taro.chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {\r\n const
|
|
1
|
+
{"version":3,"file":"chooseLocation.js","sources":["../../../src/api/location/chooseLocation.ts"],"sourcesContent":["import './style.scss'\r\n\r\nimport Taro from '@tarojs/api'\r\nimport { stringify } from 'query-string'\r\n\r\nimport { MethodHandler } from '../../utils/handler'\r\n\r\nlet container: HTMLDivElement | null = null\r\nfunction createLocationChooser (handler, key = LOCATION_APIKEY, mapOpt: Taro.chooseLocation.Option['mapOpts'] = {}) {\r\n const { latitude, longitude, ...opts } = mapOpt\r\n const query = {\r\n key,\r\n type: 1,\r\n coord: mapOpt.coord ?? [latitude, longitude].every(e => Number(e) >= 0) ? `${latitude},${longitude}` : undefined,\r\n referer: 'myapp',\r\n ...opts\r\n }\r\n if (!container) {\r\n const html = `\r\n<div class='taro_choose_location'>\r\n <div class='taro_choose_location_bar'>\r\n <div class='taro_choose_location_back'></div>\r\n <p class='taro_choose_location_title'>位置</p>\r\n <button class='taro_choose_location_submit'>完成</button>\r\n </div>\r\n <iframe class='taro_choose_location_frame' frameborder='0' src=\"https://apis.map.qq.com/tools/locpicker?${stringify(query, { arrayFormat: 'comma', skipNull: true })}\" />\r\n</div>\r\n`\r\n container = document.createElement('div')\r\n container.innerHTML = html\r\n }\r\n const main: HTMLDivElement = container.querySelector('.taro_choose_location') as HTMLDivElement\r\n\r\n function show () {\r\n setTimeout(() => {\r\n main.style.top = '0'\r\n })\r\n }\r\n\r\n function hide () {\r\n main.style.top = '100%'\r\n }\r\n\r\n function back () {\r\n hide()\r\n handler({ errMsg: 'cancel' })\r\n }\r\n\r\n function submit () {\r\n hide()\r\n handler()\r\n }\r\n\r\n function remove () {\r\n container?.remove()\r\n container = null\r\n window.removeEventListener('popstate', back)\r\n }\r\n\r\n container.querySelector('.taro_choose_location_back')?.addEventListener('click', back)\r\n container.querySelector('.taro_choose_location_submit')?.addEventListener('click', submit)\r\n\r\n window.addEventListener('popstate', back)\r\n\r\n return {\r\n show,\r\n remove,\r\n container,\r\n }\r\n}\r\n\r\n/**\r\n * 打开地图选择位置。\r\n */\r\nexport const chooseLocation: typeof Taro.chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {\r\n const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete })\r\n return new Promise((resolve, reject) => {\r\n const chooseLocation: Partial<Taro.chooseLocation.SuccessCallbackResult> = {}\r\n if (typeof LOCATION_APIKEY === 'undefined') {\r\n console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY')\r\n return handle.fail({\r\n errMsg: 'LOCATION_APIKEY needed'\r\n }, { resolve, reject })\r\n }\r\n \r\n const key = LOCATION_APIKEY\r\n\r\n const onMessage = event => {\r\n // 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息\r\n const loc = event.data\r\n\r\n // 防止其他应用也会向该页面 post 信息,需判断 module 是否为'locationPicker'\r\n if (!loc || loc.module !== 'locationPicker') return\r\n\r\n chooseLocation.name = loc.poiname\r\n chooseLocation.address = loc.poiaddress\r\n chooseLocation.latitude = loc.latlng.lat\r\n chooseLocation.longitude = loc.latlng.lng\r\n }\r\n\r\n const chooser = createLocationChooser(res => {\r\n window.removeEventListener('message', onMessage, false)\r\n setTimeout(() => {\r\n chooser.remove()\r\n }, 300)\r\n if (res) {\r\n return handle.fail(res, { resolve, reject })\r\n } else {\r\n if (chooseLocation.latitude && chooseLocation.longitude) {\r\n return handle.success(chooseLocation, { resolve, reject })\r\n } else {\r\n return handle.fail({}, { resolve, reject })\r\n }\r\n }\r\n }, key, mapOpts)\r\n\r\n document.body.appendChild(chooser.container)\r\n\r\n window.addEventListener('message', onMessage, false)\r\n chooser.show()\r\n })\r\n}\r\n"],"names":[],"mappings":";;;;;AAOA,IAAI,SAAS,GAA0B,IAAI,CAAA;AAC3C,SAAS,qBAAqB,CAAE,OAAO,EAAE,GAAG,GAAG,eAAe,EAAE,MAAA,GAAgD,EAAE,EAAA;;AAChH,IAAA,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAc,GAAA,MAAM,EAAf,IAAI,GAAK,MAAA,CAAA,MAAM,EAAzC,CAAA,UAAA,EAAA,WAAA,CAAgC,CAAS,CAAA;IAC/C,MAAM,KAAK,GACT,MAAA,CAAA,MAAA,CAAA,EAAA,GAAG,EACH,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,CAAA,CAAA,EAAA,GAAA,MAAM,CAAC,KAAK,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,KA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MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;QACpD,OAAO,CAAC,IAAI,EAAE,CAAA;AAChB,KAAC,CAAC,CAAA;AACJ;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2932,16 +2932,16 @@ function createLocationChooser(handler, key = LOCATION_APIKEY, mapOpt = {}) {
|
|
|
2932
2932
|
* 打开地图选择位置。
|
|
2933
2933
|
*/
|
|
2934
2934
|
const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
|
|
2935
|
-
const key = LOCATION_APIKEY;
|
|
2936
2935
|
const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete });
|
|
2937
2936
|
return new Promise((resolve, reject) => {
|
|
2938
2937
|
const chooseLocation = {};
|
|
2939
|
-
if (
|
|
2938
|
+
if (typeof LOCATION_APIKEY === 'undefined') {
|
|
2940
2939
|
console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY');
|
|
2941
2940
|
return handle.fail({
|
|
2942
2941
|
errMsg: 'LOCATION_APIKEY needed'
|
|
2943
2942
|
}, { resolve, reject });
|
|
2944
2943
|
}
|
|
2944
|
+
const key = LOCATION_APIKEY;
|
|
2945
2945
|
const onMessage = event => {
|
|
2946
2946
|
// 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
|
|
2947
2947
|
const loc = event.data;
|