t-comm
Version:
专业、稳定、纯粹的工具库
110 lines (106 loc) • 2.44 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* 打开地图,查看位置
* @param param 参数
* @returns 查看Promise
* @example
* ```ts
* openLocationInMp({
* lat,
* lng,
* name,
* address,
* });
* ```
*/
function openLocationInMp(_a) {
var _b = _a.lat,
lat = _b === void 0 ? '' : _b,
_c = _a.lng,
lng = _c === void 0 ? '' : _c,
_d = _a.name,
name = _d === void 0 ? '' : _d,
_e = _a.address,
address = _e === void 0 ? '' : _e,
_f = _a.scale,
scale = _f === void 0 ? 18 : _f;
return new Promise(function (resolve, reject) {
uni.openLocation({
latitude: +lat,
longitude: +lng,
name: name,
address: address,
scale: scale,
success: function success(res) {
console.log('打开地图成功');
resolve(res);
},
fail: function fail(err) {
console.log('打开地图失败', err);
reject(err);
}
});
});
}
/**
* 打开地图,查看位置
* @param param 参数
* @returns 查看Promise
* @example
* ```ts
* openLocationInH5({
* lat,
* lng,
* name,
* address,
*
* context: this,
* route: '/map'
* });
* ```
*/
function openLocationInH5(_a) {
var _b = _a.lat,
lat = _b === void 0 ? '' : _b,
_c = _a.lng,
lng = _c === void 0 ? '' : _c,
_d = _a.name,
name = _d === void 0 ? '' : _d,
_e = _a.address,
address = _e === void 0 ? '' : _e,
route = _a.route,
context = _a.context;
var href = getOpenLocationUrl({
lat: lat,
lng: lng,
name: name,
address: address
});
if (route && context) {
context.$router.push({
path: route,
query: {
url: decodeURIComponent(href)
}
});
return Promise.resolve(1);
}
window.location.href = href;
return Promise.resolve(1);
}
function getOpenLocationUrl(_a) {
var _b = _a.lat,
lat = _b === void 0 ? '' : _b,
_c = _a.lng,
lng = _c === void 0 ? '' : _c,
_d = _a.name,
name = _d === void 0 ? '' : _d,
_e = _a.address,
address = _e === void 0 ? '' : _e;
var href = "https://apis.map.qq.com/uri/v1/marker?marker=coord:".concat(lat, ",").concat(lng, ";title:").concat(name, ";addr:").concat(address, "&referer=tip");
return href;
}
exports.getOpenLocationUrl = getOpenLocationUrl;
exports.openLocationInH5 = openLocationInH5;
exports.openLocationInMp = openLocationInMp;