mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 21:02:49 +00:00
perf: 添加定位签到
This commit is contained in:
parent
1b0ec71d93
commit
35e55b8677
50
public/tools/map/main.js
vendored
50
public/tools/map/main.js
vendored
@ -1,6 +1,5 @@
|
|||||||
class App {
|
class App {
|
||||||
static #eeui = null;
|
static #eeui = null;
|
||||||
static #geolocation = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.constructor.init();
|
this.constructor.init();
|
||||||
@ -11,7 +10,6 @@ class App {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
}
|
}
|
||||||
this.#eeui = requireModuleJs("eeui");
|
this.#eeui = requireModuleJs("eeui");
|
||||||
this.#geolocation = requireModuleJs("eeui/geolocation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setVariate(key, value) {
|
static async setVariate(key, value) {
|
||||||
@ -22,11 +20,11 @@ class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getLocation() {
|
static async getLocation() {
|
||||||
while (!this.#geolocation) {
|
while (!this.#eeui) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this.#geolocation.get((res) => {
|
this.#eeui.getGeolocation((res) => {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -202,7 +200,6 @@ class BaiduMapPicker {
|
|||||||
radius: 300, // 搜索半径,单位:300
|
radius: 300, // 搜索半径,单位:300
|
||||||
zoom: 16, // 地图缩放级别
|
zoom: 16, // 地图缩放级别
|
||||||
errtip: null, // 定位失败提示
|
errtip: null, // 定位失败提示
|
||||||
errclose: false, // 定位失败是否关闭页面
|
|
||||||
channel: null, // 回传数据通道
|
channel: null, // 回传数据通道
|
||||||
selectclose: false, // 选择地点是否关闭页面
|
selectclose: false, // 选择地点是否关闭页面
|
||||||
};
|
};
|
||||||
@ -322,10 +319,9 @@ class BaiduMapPicker {
|
|||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
|
|
||||||
// 初始化时自动定位
|
// 初始化时自动定位
|
||||||
this.getCurrentLocation().then((point) => {
|
this.getCurrentLocation().catch(error => {
|
||||||
if (point === null) {
|
this.locationError(error);
|
||||||
this.locationError();
|
}).finally(() => {
|
||||||
}
|
|
||||||
document.getElementById('map-location').style.display = 'block';
|
document.getElementById('map-location').style.display = 'block';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -348,7 +344,9 @@ class BaiduMapPicker {
|
|||||||
// 地图定位点击事件
|
// 地图定位点击事件
|
||||||
const mapLocation = document.getElementById('map-location');
|
const mapLocation = document.getElementById('map-location');
|
||||||
mapLocation.addEventListener('click', () => {
|
mapLocation.addEventListener('click', () => {
|
||||||
this.getCurrentLocation();
|
this.getCurrentLocation().catch(error => {
|
||||||
|
this.locationError(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,19 +355,24 @@ class BaiduMapPicker {
|
|||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
getCurrentLocation() {
|
getCurrentLocation() {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
Loader.show()
|
Loader.show()
|
||||||
App.getLocation().then(res => {
|
App.getLocation().then(res => {
|
||||||
Loader.hide()
|
Loader.hide()
|
||||||
if (App.isJson(res) && res.longitude && res.latitude) {
|
if (!App.isJson(res)) {
|
||||||
const bd09_coord = CoordTransform.wgs84toBd09(res.longitude, res.latitude);
|
console.error('定位失败', res);
|
||||||
const point = new BMap.Point(bd09_coord[0], bd09_coord[1]);
|
reject("result error");
|
||||||
this.updateCurrentPoint(point)
|
return;
|
||||||
resolve(point);
|
|
||||||
} else {
|
|
||||||
console.error('定位失败');
|
|
||||||
resolve(null);
|
|
||||||
}
|
}
|
||||||
|
if (res.status != 'success') {
|
||||||
|
console.error('定位失败', res);
|
||||||
|
reject(res.error || "unknown error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const bd09_coord = CoordTransform.wgs84toBd09(res.longitude, res.latitude);
|
||||||
|
const point = new BMap.Point(bd09_coord[0], bd09_coord[1]);
|
||||||
|
this.updateCurrentPoint(point)
|
||||||
|
resolve(point);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -576,12 +579,11 @@ class BaiduMapPicker {
|
|||||||
/**
|
/**
|
||||||
* 定位失败提示
|
* 定位失败提示
|
||||||
*/
|
*/
|
||||||
locationError() {
|
locationError(error) {
|
||||||
if (this.params.errtip) {
|
if (this.params.errtip) {
|
||||||
alert(this.params.errtip);
|
alert(this.params.errtip + ':' + error);
|
||||||
}
|
} else {
|
||||||
if (this.params.errclose) {
|
alert(error);
|
||||||
App.closePage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
class App {
|
class App {
|
||||||
static #eeui = null;
|
static #eeui = null;
|
||||||
static #geolocation = null;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.constructor.init();
|
this.constructor.init();
|
||||||
@ -11,7 +10,6 @@ class App {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
}
|
}
|
||||||
this.#eeui = requireModuleJs("eeui");
|
this.#eeui = requireModuleJs("eeui");
|
||||||
this.#geolocation = requireModuleJs("eeui/geolocation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setVariate(key, value) {
|
static async setVariate(key, value) {
|
||||||
@ -22,11 +20,11 @@ class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getLocation() {
|
static async getLocation() {
|
||||||
while (!this.#geolocation) {
|
while (!this.#eeui) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this.#geolocation.get((res) => {
|
this.#eeui.getGeolocation((res) => {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -202,7 +200,6 @@ class BaiduMapPicker {
|
|||||||
radius: 300, // 搜索半径,单位:300
|
radius: 300, // 搜索半径,单位:300
|
||||||
zoom: 16, // 地图缩放级别
|
zoom: 16, // 地图缩放级别
|
||||||
errtip: null, // 定位失败提示
|
errtip: null, // 定位失败提示
|
||||||
errclose: false, // 定位失败是否关闭页面
|
|
||||||
channel: null, // 回传数据通道
|
channel: null, // 回传数据通道
|
||||||
selectclose: false, // 选择地点是否关闭页面
|
selectclose: false, // 选择地点是否关闭页面
|
||||||
};
|
};
|
||||||
@ -322,10 +319,9 @@ class BaiduMapPicker {
|
|||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
|
|
||||||
// 初始化时自动定位
|
// 初始化时自动定位
|
||||||
this.getCurrentLocation().then((point) => {
|
this.getCurrentLocation().catch(error => {
|
||||||
if (point === null) {
|
this.locationError(error);
|
||||||
this.locationError();
|
}).finally(() => {
|
||||||
}
|
|
||||||
document.getElementById('map-location').style.display = 'block';
|
document.getElementById('map-location').style.display = 'block';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -348,7 +344,9 @@ class BaiduMapPicker {
|
|||||||
// 地图定位点击事件
|
// 地图定位点击事件
|
||||||
const mapLocation = document.getElementById('map-location');
|
const mapLocation = document.getElementById('map-location');
|
||||||
mapLocation.addEventListener('click', () => {
|
mapLocation.addEventListener('click', () => {
|
||||||
this.getCurrentLocation();
|
this.getCurrentLocation().catch(error => {
|
||||||
|
this.locationError(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,19 +355,24 @@ class BaiduMapPicker {
|
|||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
getCurrentLocation() {
|
getCurrentLocation() {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
Loader.show()
|
Loader.show()
|
||||||
App.getLocation().then(res => {
|
App.getLocation().then(res => {
|
||||||
Loader.hide()
|
Loader.hide()
|
||||||
if (App.isJson(res) && res.longitude && res.latitude) {
|
if (!App.isJson(res)) {
|
||||||
const bd09_coord = CoordTransform.wgs84toBd09(res.longitude, res.latitude);
|
console.error('定位失败', res);
|
||||||
const point = new BMap.Point(bd09_coord[0], bd09_coord[1]);
|
reject("result error");
|
||||||
this.updateCurrentPoint(point)
|
return;
|
||||||
resolve(point);
|
|
||||||
} else {
|
|
||||||
console.error('定位失败');
|
|
||||||
resolve(null);
|
|
||||||
}
|
}
|
||||||
|
if (res.status != 'success') {
|
||||||
|
console.error('定位失败', res);
|
||||||
|
reject(res.error || "unknown error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const bd09_coord = CoordTransform.wgs84toBd09(res.longitude, res.latitude);
|
||||||
|
const point = new BMap.Point(bd09_coord[0], bd09_coord[1]);
|
||||||
|
this.updateCurrentPoint(point)
|
||||||
|
resolve(point);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -576,12 +579,11 @@ class BaiduMapPicker {
|
|||||||
/**
|
/**
|
||||||
* 定位失败提示
|
* 定位失败提示
|
||||||
*/
|
*/
|
||||||
locationError() {
|
locationError(error) {
|
||||||
if (this.params.errtip) {
|
if (this.params.errtip) {
|
||||||
alert(this.params.errtip);
|
alert(this.params.errtip + ':' + error);
|
||||||
}
|
} else {
|
||||||
if (this.params.errclose) {
|
alert(error);
|
||||||
App.closePage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user