提交 cdb00d7a 作者: 姚志忠

修改定位问题

父级 352458cc
import { import {
EventEmitter, EventEmitter,
get, get,
post, post,
...@@ -77,7 +77,149 @@ const buildings = [ ...@@ -77,7 +77,149 @@ const buildings = [
buildingId: "3307001301397", buildingId: "3307001301397",
latlng: { lat: 29.327742, lng: 120.103138}, latlng: { lat: 29.327742, lng: 120.103138},
floors: ["1F", "2F", "3F", "4F"], floors: ["1F", "2F", "3F", "4F"],
scale: 18.2, scale: 17,
formats: [
{
"key": "N_01_1_CQWJ",
"zone": "01",
"floor": 1,
"name": "充气玩具",
"nameEn": "充气玩具"
},
{
"key": "N_01_1_DDWJ",
"zone": "01",
"floor": 1,
"name": "电动玩具",
"nameEn": "电动玩具"
},
{
"key": "N_01_1_GYP",
"zone": "01",
"floor": 1,
"name": "玩具/饰品",
"nameEn": "玩具/饰品"
},
{
"key": "N_01_1_HL",
"zone": "01",
"floor": 1,
"name": "花类",
"nameEn": "花类"
},
{
"key": "N_01_1_HLPJ",
"zone": "01",
"floor": 1,
"name": "花类配件",
"nameEn": "花类配件"
},
{
"key": "N_01_1_MBRWJ",
"zone": "01",
"floor": 1,
"name": "毛绒玩具",
"nameEn": "毛绒玩具"
},
{
"key": "N_01_1_PTWJ",
"zone": "01",
"floor": 1,
"name": "普通玩具",
"nameEn": "普通玩具"
},
{
"key": "N_01_1_SPPJ",
"zone": "01",
"floor": 1,
"name": "饰品配件(东扩)",
"nameEn": "饰品配件"
},
{
"key": "N_01_2_SP",
"zone": "01",
"floor": 2,
"name": "饰品/饰品配件(东扩)",
"nameEn": "饰品/饰品配件"
},
{
"key": "N_01_2_TS",
"zone": "01",
"floor": 2,
"name": "头饰",
"nameEn": "头饰"
},
{
"key": "N_01_2_ZBSS",
"zone": "01",
"floor": 2,
"name": "珠宝首饰",
"nameEn": "珠宝首饰"
},
{
"key": "N_01_3_CQSJ",
"zone": "01",
"floor": 3,
"name": "瓷器水晶",
"nameEn": "瓷器水晶"
},
{
"key": "N_01_3_LYGY",
"zone": "01",
"floor": 3,
"name": "旅游工艺",
"nameEn": "旅游工艺"
},
{
"key": "N_01_3_SP",
"zone": "01",
"floor": 3,
"name": "饰品(东扩)",
"nameEn": "饰品"
},
{
"key": "N_01_3_SPPJ",
"zone": "01",
"floor": 3,
"name": "饰品配件",
"nameEn": "饰品配件"
},
{
"key": "N_01_3_XQGY",
"zone": "01",
"floor": 3,
"name": "喜庆工艺",
"nameEn": "喜庆工艺"
},
{
"key": "N_01_3_XK",
"zone": "01",
"floor": 3,
"name": "相框",
"nameEn": "相框"
},
{
"key": "N_01_3_ZSGY",
"zone": "01",
"floor": 3,
"name": "装饰工艺",
"nameEn": "装饰工艺"
},
{
"key": "N_01_4_GYP",
"zone": "01",
"floor": 4,
"name": "生产企业直销中心",
"nameEn": "生产企业直销中心"
},
{
"key": "N_01_4_HLPJ",
"zone": "01",
"floor": 4,
"name": "花类配件(东扩)",
"nameEn": "花类配件(东扩)"
}
],
}, },
{ {
name: "二区", name: "二区",
...@@ -88,7 +230,100 @@ const buildings = [ ...@@ -88,7 +230,100 @@ const buildings = [
buildingId: "3307001732882", buildingId: "3307001732882",
latlng: { lat: 29.334626, lng: 120.106744}, latlng: { lat: 29.334626, lng: 120.106744},
floors: ["1F", "2F", "3F"], floors: ["1F", "2F", "3F"],
scale: 18.2, scale: 17,
formats:[
{
"key": "N_02_1_LPBZ",
"zone": "02",
"floor": 1,
"name": "礼品包装",
"nameEn": "礼品包装"
},
{
"key": "N_02_1_SJ",
"zone": "02",
"floor": 1,
"name": "伞具",
"nameEn": "伞具"
},
{
"key": "N_02_1_XB",
"zone": "02",
"floor": 1,
"name": "箱包",
"nameEn": "箱包"
},
{
"key": "N_02_1_YPD",
"zone": "02",
"floor": 1,
"name": "雨披-袋",
"nameEn": "雨披-袋"
},
{
"key": "N_02_2_CL",
"zone": "02",
"floor": 2,
"name": "车类",
"nameEn": "车类"
},
{
"key": "N_02_2_DGCP",
"zone": "02",
"floor": 2,
"name": "电工产品",
"nameEn": "电工产品"
},
{
"key": "N_02_2_SJ",
"zone": "02",
"floor": 2,
"name": "锁具",
"nameEn": "锁具"
},
{
"key": "N_02_2_WJGJPJ",
"zone": "02",
"floor": 2,
"name": "五金工具-配件",
"nameEn": "五金工具-配件"
},
{
"key": "N_02_3_DXQC",
"zone": "02",
"floor": 3,
"name": "电讯器材",
"nameEn": "电讯器材"
},
{
"key": "N_02_3_DZYBQZXQC",
"zone": "02",
"floor": 3,
"name": "电子仪表仪器-照相器材",
"nameEn": "电子仪表仪器-照相器材"
},
{
"key": "N_02_3_WJCW",
"zone": "02",
"floor": 3,
"name": "五金厨卫",
"nameEn": "五金厨卫"
},
{
"key": "N_02_3_XJD",
"zone": "02",
"floor": 3,
"name": "小家电",
"nameEn": "小家电"
},
{
"key": "N_02_3_ZB",
"zone": "02",
"floor": 3,
"name": "钟表",
"nameEn": "钟表"
}
]
}, },
{ {
name: "二区东", name: "二区东",
...@@ -122,20 +357,20 @@ const buildingNameNameEnMap = buildings.reduce( ...@@ -122,20 +357,20 @@ const buildingNameNameEnMap = buildings.reduce(
); );
const isTest = false; const isTest = false;
export const qmurl = isTest export const qmurl = isTest
? "https://tencent.chinagoods.com" ? "https://yiwutest.123.1000my.com"
: "https://tencent.chinagoods.com"; : "https://tencent.chinagoods.com";
export const marketurl = isTest export const marketurl = isTest
? "https://testapiserver.chinagoods.com" ? "https://yiwutest.123.1000my.com"
: "https://apiserver.chinagoods.com"; : "https://apiserver.chinagoods.com";
export const uploadurl = isTest export const uploadurl = isTest
? "https://testkunapi.chinagoods.com" ? "https://yiwutest.123.1000my.com"
: "https://kunapi.chinagoods.com"; : "https://kunapi.chinagoods.com";
export const salt = "chinagoods2024"; export const salt = "chinagoods2024";
sensors.init({ sensors.init({
server_url: server_url:
"https://event-tracking.chinagoods.com/sa.gif?project=market_navigation_t&remark=online", "https://event-tracking.chinagoods.com/sa.gif?project=market_navigation_t&remark=online",
show_log: false, //是否开启日志 show_log: false, //鏄惁寮€鍚棩蹇?
name: "sensors", name: "sensors",
allow_amend_share_path: true, allow_amend_share_path: true,
global_properties: { global_properties: {
...@@ -186,10 +421,47 @@ App({ ...@@ -186,10 +421,47 @@ App({
this.refreshCollection(); this.refreshCollection();
this.refreshItinerary(); this.refreshItinerary();
this.checkUpdate(); this.checkUpdate();
this.initBuildingByLocation();
const callback = (res) => console.log("userTriggerTranslation", res); const callback = (res) => console.log("userTriggerTranslation", res);
wx.onUserTriggerTranslation(callback); wx.onUserTriggerTranslation(callback);
}, },
/**
* 首次启动时,根据 GPS 定位自动切换到用户所在的区
*/
initBuildingByLocation() {
wx.getLocation({
type: 'gcj02',
isHighAccuracy: false,
success: ({ latitude, longitude }) => {
console.log('定位成功', latitude, longitude);
let nearest = null;
let minDist = Infinity;
buildings.forEach((building) => {
const dlat = building.latlng.lat - latitude;
const dlng = building.latlng.lng - longitude;
const dist = dlat * dlat + dlng * dlng;
if (dist < minDist) {
minDist = dist;
nearest = building;
}
});
const THRESHOLD = 0.00008;
if (nearest && minDist < THRESHOLD) {
if (this.currentBuilding.name !== nearest.name) {
this.currentBuilding = nearest;
console.log('initBuildingByLocation 切换到:', nearest.name);
this.events.emit('building', nearest);
}
} else {
console.log('用户不在义乌市场范围内,保持默认区:', this.currentBuilding.name);
}
},
fail: (e) => {
console.log('定位失败,保持默认区', e);
},
});
},
checkUpdate() { checkUpdate() {
if (wx.canIUse("getUpdateManager")) { if (wx.canIUse("getUpdateManager")) {
const updateManager = wx.getUpdateManager(); const updateManager = wx.getUpdateManager();
...@@ -359,7 +631,6 @@ App({ ...@@ -359,7 +631,6 @@ App({
.filter(Boolean), .filter(Boolean),
); );
} catch (error) {} } catch (error) {}
this.events.emit("globalData"); this.events.emit("globalData");
} catch (error) { } catch (error) {
console.error(error); console.error(error);
...@@ -390,11 +661,10 @@ App({ ...@@ -390,11 +661,10 @@ App({
if (this.lastSetBuildingTime && now - this.lastSetBuildingTime < 1000) { if (this.lastSetBuildingTime && now - this.lastSetBuildingTime < 1000) {
return false; return false;
} }
if (!currentBuilding) return false; if (!currentBuilding) return false;
if (this.currentBuilding.name === currentBuilding.name) return false; if (this.currentBuilding.name === currentBuilding.name) return false;
this.currentBuilding = currentBuilding; this.currentBuilding = currentBuilding;
console.log(this.currentBuilding, "setBuilding");
this.lastSetBuildingTime = now; this.lastSetBuildingTime = now;
this.events.emit("building", currentBuilding); this.events.emit("building", currentBuilding);
return true; return true;
...@@ -436,7 +706,6 @@ App({ ...@@ -436,7 +706,6 @@ App({
], ],
}); });
const themeInstance = new plugin.Theme(); const themeInstance = new plugin.Theme();
themeInstance.setGlobalThemeColor({ themeInstance.setGlobalThemeColor({
colorPrimary: "#E32424", colorPrimary: "#E32424",
lightColorPrimary: "#fef0eb", lightColorPrimary: "#fef0eb",
...@@ -466,24 +735,15 @@ App({ ...@@ -466,24 +735,15 @@ App({
data: { data }, data: { data },
} = await post( } = await post(
`${qmurl}/api/v1/applet/searchShopFacilityList`, `${qmurl}/api/v1/applet/searchShopFacilityList`,
{ { keyword, zone: building.zone },
keyword,
zone: building.zone,
},
{ lang: "zh" }, { lang: "zh" },
); );
// 提取需要查询的店铺信息
const shopInfoList = data.map(({ shopType, shopId }) => ({ const shopInfoList = data.map(({ shopType, shopId }) => ({
shopType, shopType,
shopId, shopId,
boothNo: "", // 这里 boothNo 可能需要从其他地方获取,暂时设为空 boothNo: "",
})); }));
// 批量获取店铺详情
const shopDetails = await poiApi.getListByIds(shopInfoList); const shopDetails = await poiApi.getListByIds(shopInfoList);
// 创建临时映射,用于快速查找店铺详情
const shopDetailMap = {}; const shopDetailMap = {};
if (shopDetails) { if (shopDetails) {
shopDetails.forEach((detail, index) => { shopDetails.forEach((detail, index) => {
...@@ -491,10 +751,8 @@ App({ ...@@ -491,10 +751,8 @@ App({
shopDetailMap[`${shopType}_${shopId}`] = detail; shopDetailMap[`${shopType}_${shopId}`] = detail;
}); });
} }
const list = data const list = data
.map(({ shopType, shopId }) => { .map(({ shopType, shopId }) => {
// 从批量获取的详情中查找
const detail = shopDetailMap[`${shopType}_${shopId}`]; const detail = shopDetailMap[`${shopType}_${shopId}`];
return detail; return detail;
}) })
...@@ -508,7 +766,7 @@ App({ ...@@ -508,7 +766,7 @@ App({
floorName: poi.tx.poi_fl_name, floorName: poi.tx.poi_fl_name,
latitude: lat, latitude: lat,
longitude: lng, longitude: lng,
category: poi.facility ? "周边" : poi.ywZh.frontIndustryCategory, category: poi.facility ? "周边" : poi.ywZh.frontnameCategory,
distance: getDistance(latitude, longitude, lat, lng), distance: getDistance(latitude, longitude, lat, lng),
}; };
}); });
...@@ -539,9 +797,7 @@ App({ ...@@ -539,9 +797,7 @@ App({
if (this.globalData.user) { if (this.globalData.user) {
return true; return true;
} else { } else {
wx.navigateTo({ wx.navigateTo({ url: "/pages/login/index" });
url: "/pages/login/index",
});
return false; return false;
} }
}, },
......
...@@ -71,6 +71,7 @@ Component({ ...@@ -71,6 +71,7 @@ Component({
donothing() {}, donothing() {},
changeBuilding({ currentTarget: { id } }) { changeBuilding({ currentTarget: { id } }) {
const building = this.data.buildings[id]; const building = this.data.buildings[id];
console.log('changeBuilding',this.data.buildings[id])
getApp().setBuilding(building); getApp().setBuilding(building);
getApp().blurPoi(); getApp().blurPoi();
this.setData({ showBuildings: false }); this.setData({ showBuildings: false });
......
...@@ -29,7 +29,11 @@ Component({ ...@@ -29,7 +29,11 @@ Component({
setText() { setText() {
const { isEn, shop } = this.data; const { isEn, shop } = this.data;
const { enAddr, buildingFloor, street } = getAddr(shop, isEn); const { enAddr, buildingFloor, street } = getAddr(shop, isEn);
this.setData({ enAddr, buildingFloor, street });
// 过滤掉"国际商贸城"字样
const filteredBuildingFloor = buildingFloor ? buildingFloor.replace(/国际商贸城/g, '') : '';
this.setData({ enAddr, buildingFloor: filteredBuildingFloor, street });
}, },
}, },
lifetimes: { lifetimes: {
......
...@@ -84,7 +84,9 @@ Page({ ...@@ -84,7 +84,9 @@ Page({
onCurrentBuildingChange() { onCurrentBuildingChange() {
this.getActs(); this.getActs();
if (!this.data.focusedPoi) { if (!this.data.focusedPoi) {
this.setFloorName(getApp().currentBuilding.floors[0]); // 默认展示一楼
let isFrisfloor=getApp().currentBuilding.floors.indexOf('1F')
this.setFloorName(getApp().currentBuilding.floors[isFrisfloor]);
} }
if (!this.data.isIndex) { if (!this.data.isIndex) {
if (this.data.activeId) this.setFacilities(this.data.activeId); if (this.data.activeId) this.setFacilities(this.data.activeId);
...@@ -412,6 +414,7 @@ Page({ ...@@ -412,6 +414,7 @@ Page({
const building = getApp().buildings.find( const building = getApp().buildings.find(
(building) => building.buildingId && building.buildingId === buildingId, (building) => building.buildingId && building.buildingId === buildingId,
); );
if (building) { if (building) {
getApp().setBuilding(building); getApp().setBuilding(building);
this.setFloorName(floorName); this.setFloorName(floorName);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论