upload project
This commit is contained in:
commit
06961cae04
422 changed files with 110626 additions and 0 deletions
252
subpackages/map-extras/searchLocation/searchLocation.js
Normal file
252
subpackages/map-extras/searchLocation/searchLocation.js
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
const mapConfig = require('../../../utils/map-config.js');
|
||||
const config = require('../../../config/config.js');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
searchKeyword: '',
|
||||
searchResults: [],
|
||||
showSearchTips: true,
|
||||
showNoResults: false,
|
||||
currentCity: '乌鲁木齐市'
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
// 设置导航栏标题
|
||||
wx.setNavigationBarTitle({
|
||||
title: '搜索地点'
|
||||
});
|
||||
|
||||
// 获取用户当前位置和城市
|
||||
this.getUserCurrentLocation();
|
||||
},
|
||||
|
||||
// 获取用户当前位置和城市
|
||||
getUserCurrentLocation: function() {
|
||||
wx.showLoading({
|
||||
title: '获取位置中...',
|
||||
});
|
||||
|
||||
// 获取经纬度信息
|
||||
wx.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (res) => {
|
||||
const latitude = res.latitude;
|
||||
const longitude = res.longitude;
|
||||
|
||||
// 通过经纬度获取城市信息
|
||||
wx.request({
|
||||
url: 'https://restapi.amap.com/v3/geocode/regeo',
|
||||
method: 'GET',
|
||||
data: {
|
||||
key: config.amapKey || mapConfig.MAP_CONFIG.amapKey,
|
||||
location: `${longitude},${latitude}`,
|
||||
extensions: 'all'
|
||||
},
|
||||
success: (regeoRes) => {
|
||||
|
||||
wx.hideLoading();
|
||||
|
||||
if (regeoRes.data.status === '1' && regeoRes.data.regeocode) {
|
||||
const city = regeoRes.data.regeocode.addressComponent.city ||
|
||||
regeoRes.data.regeocode.addressComponent.province;
|
||||
|
||||
if (city) {
|
||||
this.setData({
|
||||
currentCity: city
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('获取城市信息失败:', error);
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
currentCity: '乌鲁木齐市'
|
||||
});
|
||||
wx.showToast({
|
||||
title: '无法获取城市信息,使用默认城市乌鲁木齐',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('获取位置失败:', error);
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
currentCity: '乌鲁木齐市'
|
||||
});
|
||||
wx.showToast({
|
||||
title: '无法获取位置信息,使用默认城市乌鲁木齐',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onSearchInput: function(e) {
|
||||
const keyword = e.detail.value;
|
||||
this.setData({
|
||||
searchKeyword: keyword,
|
||||
showSearchTips: keyword.length === 0 && this.data.searchResults.length === 0,
|
||||
showNoResults: false
|
||||
});
|
||||
|
||||
if (keyword.trim()) {
|
||||
this.onSearch();
|
||||
}
|
||||
},
|
||||
|
||||
// 搜索事件
|
||||
onSearch: function() {
|
||||
const keyword = this.data.searchKeyword.trim();
|
||||
if (!keyword) {
|
||||
wx.showToast({
|
||||
title: '请输入搜索关键词',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载提示
|
||||
wx.showLoading({
|
||||
title: '搜索中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
wx.request({
|
||||
url: 'https://restapi.amap.com/v3/place/text',
|
||||
method: 'GET',
|
||||
data: {
|
||||
key: config.amapKey || mapConfig.MAP_CONFIG.amapKey,
|
||||
keywords: keyword,
|
||||
city: this.data.currentCity,
|
||||
citylimit: true,
|
||||
offset: 20,
|
||||
extensions: 'all'
|
||||
},
|
||||
success: (res) => {
|
||||
|
||||
wx.hideLoading();
|
||||
|
||||
if (res.data.status === '1' && res.data.pois && res.data.pois.length > 0) {
|
||||
this.setData({
|
||||
searchResults: res.data.pois,
|
||||
showSearchTips: false,
|
||||
showNoResults: false
|
||||
});
|
||||
} else {
|
||||
this.setData({
|
||||
searchResults: [],
|
||||
showSearchTips: false,
|
||||
showNoResults: true
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('搜索地点失败:', error);
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '搜索失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 选择搜索结果中的地点
|
||||
selectLocation: function(e) {
|
||||
const { id } = e.currentTarget.dataset;
|
||||
const resultIndex = parseInt(id);
|
||||
if (this.data.searchResults[resultIndex]) {
|
||||
const selectedPoi = this.data.searchResults[resultIndex];
|
||||
|
||||
|
||||
console.log('选择的地点原始数据:', JSON.stringify(selectedPoi, null, 2)); console.log('地点距离:', typeof selectedPoi.distance === 'undefined' ? '无' : JSON.stringify(selectedPoi.distance));
|
||||
|
||||
const locationData = {
|
||||
name: selectedPoi.name || '',
|
||||
address: selectedPoi.address || '',
|
||||
distance: Array.isArray(selectedPoi.distance) ?
|
||||
(selectedPoi.distance.length > 0 ? selectedPoi.distance[0] : '') :
|
||||
(selectedPoi.distance || ''),
|
||||
location: selectedPoi.location || '',
|
||||
type: selectedPoi.type || '',
|
||||
typecode: selectedPoi.typecode || ''
|
||||
};
|
||||
|
||||
if (!locationData.name && locationData.address) {
|
||||
locationData.name = locationData.address;
|
||||
}
|
||||
if (!locationData.address && locationData.name) {
|
||||
locationData.address = locationData.name;
|
||||
}
|
||||
|
||||
wx.setStorageSync('selectedPoi', locationData);
|
||||
|
||||
let storedData = wx.getStorageSync('selectedPoi');
|
||||
|
||||
if (JSON.stringify(storedData) !== JSON.stringify(locationData)) {
|
||||
console.warn('存储数据不匹配,重新保存...');
|
||||
wx.setStorageSync('selectedPoi', locationData);
|
||||
storedData = wx.getStorageSync('selectedPoi');
|
||||
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const finalStoredData = wx.getStorageSync('selectedPoi');
|
||||
|
||||
const pages = getCurrentPages();
|
||||
|
||||
let publishPage = null;
|
||||
for (let i = pages.length - 1; i >= 0; i--) {
|
||||
if (pages[i].route === 'subpackages/media/edits/edits') {
|
||||
publishPage = pages[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (publishPage) {
|
||||
if (publishPage.receiveLocationData && typeof publishPage.receiveLocationData === 'function') {
|
||||
|
||||
publishPage.receiveLocationData(locationData);
|
||||
} else {
|
||||
|
||||
publishPage.setData({
|
||||
currentLocation: locationData.address || locationData.name || locationData.toString(),
|
||||
locationName: locationData.name || locationData.address || locationData.toString(),
|
||||
distance: locationData.distance || '',
|
||||
fullAddress: locationData.address && locationData.address !== locationData.name ? locationData.address : ''
|
||||
});
|
||||
console.log('已通过页面栈设置发布页数据:', {
|
||||
currentLocation: locationData.address || locationData.name || locationData.toString(),
|
||||
locationName: locationData.name || locationData.address || locationData.toString(),
|
||||
distance: locationData.distance || '',
|
||||
fullAddress: locationData.address && locationData.address !== locationData.name ? locationData.address : ''
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
let delta = 1;
|
||||
for (let i = pages.length - 1; i >= 0; i--) {
|
||||
if (pages[i].route === 'subpackages/media/edits/edits') {
|
||||
delta = pages.length - 1 - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 返回到发布页
|
||||
wx.navigateBack({ delta: delta });
|
||||
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
|
||||
// 取消搜索
|
||||
onCancel: function() {
|
||||
wx.navigateBack();
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"navigationBarTitleText": "搜索地点",
|
||||
"navigationBarBackgroundColor": "#121212",
|
||||
"navigationBarTextStyle": "white",
|
||||
"enablePullDownRefresh": false,
|
||||
"usingComponents": {}
|
||||
}
|
||||
39
subpackages/map-extras/searchLocation/searchLocation.wxml
Normal file
39
subpackages/map-extras/searchLocation/searchLocation.wxml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<view class="search-page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-header">
|
||||
<view class="search-box">
|
||||
<image src="/images/Search.png" class="search-icon"></image>
|
||||
<input type="text" placeholder="请输入地点关键词" placeholder-class="search-placeholder" value="{{searchKeyword}}" bindinput="onSearchInput" confirm-type="search" bindconfirm="onSearch" />
|
||||
</view>
|
||||
<view class="cancel-button" bindtap="onCancel">取消</view>
|
||||
</view>
|
||||
|
||||
<!-- 搜索结果区域 -->
|
||||
<view class="search-results" wx:if="{{searchResults.length > 0}}">
|
||||
<view class="search-results-title">搜索结果</view>
|
||||
<view class="results-list">
|
||||
<view
|
||||
wx:for="{{searchResults}}"
|
||||
wx:key="id"
|
||||
class="result-item"
|
||||
bindtap="selectLocation"
|
||||
data-id="{{index}}"
|
||||
>
|
||||
<view class="location-info">
|
||||
<view class="location-name">{{item.name}}</view>
|
||||
<view class="location-address">{{item.address || '地址未知'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 搜索提示 -->
|
||||
<view class="search-tips" wx:elif="{{showSearchTips}}">
|
||||
<view class="tips-content">请输入关键词进行搜索</view>
|
||||
</view>
|
||||
|
||||
<!-- 无结果提示 -->
|
||||
<view class="no-results" wx:elif="{{showNoResults}}">
|
||||
<view class="no-results-content">未找到相关地点</view>
|
||||
</view>
|
||||
</view>
|
||||
115
subpackages/map-extras/searchLocation/searchLocation.wxss
Normal file
115
subpackages/map-extras/searchLocation/searchLocation.wxss
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
.search-page {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* 搜索栏样式 */
|
||||
.search-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 30rpx;
|
||||
background-color: #121212;
|
||||
border-bottom: 1rpx solid #333;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: #2c2c2c;
|
||||
border: 2rpx solid #ffffff;
|
||||
border-radius: 44rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 88rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
margin-left: 20rpx;
|
||||
margin-right: 20rpx;
|
||||
filter: invert(0.3) brightness(100%);
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
flex: 1;
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.search-placeholder {
|
||||
color: #888;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.cancel-button {
|
||||
font-size: 28rpx;
|
||||
color: #ffffff;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
/* 搜索结果样式 */
|
||||
.search-results {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20rpx 30rpx;
|
||||
}
|
||||
|
||||
.search-results-title {
|
||||
font-size: 28rpx;
|
||||
color: #888;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.results-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
background-color: #1a1a1a;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.result-item:active {
|
||||
background-color: #2c2c2c;
|
||||
}
|
||||
|
||||
.location-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.location-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.location-address {
|
||||
font-size: 28rpx;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
/* 搜索提示样式 */
|
||||
.search-tips,
|
||||
.no-results {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #888;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.tips-content,
|
||||
.no-results-content {
|
||||
text-align: center;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue