修改小程序无法更改定位的问题
This commit is contained in:
parent
e13b06ece0
commit
f5d3cd79de
@ -2,35 +2,19 @@
|
|||||||
<view class="city-select-page" v-if="loading">
|
<view class="city-select-page" v-if="loading">
|
||||||
<view class="white_container padding_bottom40">
|
<view class="white_container padding_bottom40">
|
||||||
<!-- 搜索框 -->
|
<!-- 搜索框 -->
|
||||||
<u-search
|
<u-search placeholder="输入城市进行搜索" :value="searchValue" @search="handleSearch" @change="handleSearch"
|
||||||
placeholder="输入城市进行搜索"
|
:showAction="false" height="70" searchIconSize="40" shape="round"></u-search>
|
||||||
:value="searchValue"
|
|
||||||
@search="handleSearch"
|
|
||||||
@change="handleSearch"
|
|
||||||
:showAction="false"
|
|
||||||
height="70"
|
|
||||||
searchIconSize="40"
|
|
||||||
shape="round"
|
|
||||||
></u-search>
|
|
||||||
<view v-if="searchValue" class="search_popup">
|
<view v-if="searchValue" class="search_popup">
|
||||||
<view v-if="searchRes.length === 0" class="list-item">暂无搜索结果</view>
|
<view v-if="searchRes.length === 0" class="list-item">暂无搜索结果</view>
|
||||||
<view
|
<view v-else v-for="(item, index) in searchRes" :key="index"
|
||||||
v-else
|
:class="['list-item', index === searchRes.length - 1 && 'no_border']" @click="headerSelectMapClick(item)">
|
||||||
v-for="(item, index) in searchRes"
|
|
||||||
:key="index"
|
|
||||||
:class="['list-item', index === searchRes.length - 1 && 'no_border']"
|
|
||||||
@click="headerSelectMapClick(item)"
|
|
||||||
>
|
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="!searchValue">
|
<view v-if="!searchValue">
|
||||||
<!-- 当前定位城市 -->
|
<!-- 当前定位城市 -->
|
||||||
<view class="current-city">
|
<view class="current-city">
|
||||||
<image
|
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Index_add.png" mode="widthFix" />
|
||||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/Index_add.png"
|
|
||||||
mode="widthFix"
|
|
||||||
/>
|
|
||||||
<text>当前定位城市 {{ location.cityName }}</text>
|
<text>当前定位城市 {{ location.cityName }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -38,13 +22,8 @@
|
|||||||
<view class="hot-cities">
|
<view class="hot-cities">
|
||||||
<text class="title">国内热门城市</text>
|
<text class="title">国内热门城市</text>
|
||||||
<view class="city-list">
|
<view class="city-list">
|
||||||
<view
|
<view v-for="(item, index) in hotCityList" class="city_name" :key="index"
|
||||||
v-for="(item, index) in hotCityList"
|
@click="headerSelectMapClick(item)">{{ item.name }}</view>
|
||||||
class="city_name"
|
|
||||||
:key="index"
|
|
||||||
@click="headerSelectMapClick(item)"
|
|
||||||
>{{ item.name }}</view
|
|
||||||
>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -52,28 +31,15 @@
|
|||||||
|
|
||||||
<view v-if="!searchValue" class="container">
|
<view v-if="!searchValue" class="container">
|
||||||
<!-- 左侧列表 -->
|
<!-- 左侧列表 -->
|
||||||
<scroll-view
|
<scroll-view class="list-scroll" scroll-y :scroll-into-view="activeId" @scroll="handleScroll">
|
||||||
class="list-scroll"
|
<view v-for="(group, index) in groupedData" :key="index" class="white_container" :id="'group-' + group.letter">
|
||||||
scroll-y
|
|
||||||
:scroll-into-view="activeId"
|
|
||||||
@scroll="handleScroll"
|
|
||||||
>
|
|
||||||
<view
|
|
||||||
v-for="(group, index) in groupedData"
|
|
||||||
:key="index"
|
|
||||||
class="white_container"
|
|
||||||
:id="'group-' + group.letter"
|
|
||||||
>
|
|
||||||
<!-- 字母标题 -->
|
<!-- 字母标题 -->
|
||||||
<view class="letter-title">{{ group.letter }}</view>
|
<view class="letter-title">{{ group.letter }}</view>
|
||||||
<!-- 列表项 -->
|
<!-- 列表项 -->
|
||||||
<!-- TODO: 小程序编译避坑指南: -->
|
<!-- TODO: 小程序编译避坑指南: -->
|
||||||
<view
|
<view v-for="(item, ind) in group.list" :key="item.id"
|
||||||
v-for="(item, ind) in group.list"
|
|
||||||
:key="item.id"
|
|
||||||
:class="['list-item', ind === group.list.length - 1 && 'no_border']"
|
:class="['list-item', ind === group.list.length - 1 && 'no_border']"
|
||||||
@click="() => { headerSelectMapClick(item) }"
|
@click="() => { headerSelectMapClick(item) }">
|
||||||
>
|
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -81,12 +47,7 @@
|
|||||||
|
|
||||||
<!-- 右侧索引栏 -->
|
<!-- 右侧索引栏 -->
|
||||||
<view class="index-bar">
|
<view class="index-bar">
|
||||||
<view
|
<view v-for="(letter, index) in letters" :key="index" class="index-item" @tap="scrollToLetter(letter)">
|
||||||
v-for="(letter, index) in letters"
|
|
||||||
:key="index"
|
|
||||||
class="index-item"
|
|
||||||
@tap="scrollToLetter(letter)"
|
|
||||||
>
|
|
||||||
{{ letter }}
|
{{ letter }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -96,7 +57,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { apiArr } from "../../api/area.js";
|
import { apiArr } from "../../api/area.js";
|
||||||
import { request, debounce } from "../../utils/index.js";
|
import { request, debounce, NavgateTo } from "../../utils/index.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -182,14 +143,38 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 更新页面数据,如标记点等
|
// 更新页面数据,如标记点等
|
||||||
|
// 提取城市名称,添加防御性检查
|
||||||
|
let cityName = '';
|
||||||
|
let district = '';
|
||||||
|
let region = '';
|
||||||
|
|
||||||
|
// 提取城市名
|
||||||
|
const cityMatch = res.address.match(/(.*?(?:省|自治区)|^)(.*?)(?:市|地区|盟|州|县|区)?$/);
|
||||||
|
if (cityMatch && cityMatch[2]) {
|
||||||
|
const cityMatch2 = cityMatch[2].match(/(.*市)/);
|
||||||
|
if (cityMatch2 && cityMatch2[1]) {
|
||||||
|
cityName = cityMatch2[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取区县
|
||||||
|
const districtMatch = res.address.match(/市(.*)/);
|
||||||
|
if (districtMatch && districtMatch[1]) {
|
||||||
|
district = districtMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取省市区
|
||||||
|
const regionMatch = res.address.match(/^(.*?省.*?(?:市|自治州|盟).*?(?:县|区|旗))/);
|
||||||
|
if (regionMatch && regionMatch[1]) {
|
||||||
|
region = regionMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
const selectLocation = {
|
const selectLocation = {
|
||||||
cityName: res.address
|
cityName: cityName,
|
||||||
.match(/(.*?(?:省|自治区)|^)(.*?)(?:市|地区|盟|州|县|区)?$/)[2]
|
district: district,
|
||||||
.match(/(.*市)/)[1],
|
|
||||||
district: res.address.match(/市(.*)/)[1],
|
|
||||||
lat: res.latitude,
|
lat: res.latitude,
|
||||||
lng: res.longitude,
|
lng: res.longitude,
|
||||||
region: res.address.match(/^(.*?省.*?(?:市|自治州|盟).*?(?:县|区|旗))/)[1], // 省市区
|
region: region,
|
||||||
};
|
};
|
||||||
uni.setStorageSync("location", selectLocation); // 缓存数据信息
|
uni.setStorageSync("location", selectLocation); // 缓存数据信息
|
||||||
// uni.setStorageSync('city', selectLocation.cityName); // 缓存数据信息
|
// uni.setStorageSync('city', selectLocation.cityName); // 缓存数据信息
|
||||||
@ -203,8 +188,8 @@ export default {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleSearch: debounce(function(keyword) {
|
handleSearch: debounce(function (keyword) {
|
||||||
if(keyword === '') {
|
if (keyword === '') {
|
||||||
this.searchValue = '';
|
this.searchValue = '';
|
||||||
this.searchRes = [];
|
this.searchRes = [];
|
||||||
return;
|
return;
|
||||||
@ -266,7 +251,7 @@ export default {
|
|||||||
mask: true
|
mask: true
|
||||||
})
|
})
|
||||||
const params = {
|
const params = {
|
||||||
ad_level:2
|
ad_level: 2
|
||||||
}
|
}
|
||||||
const res = await request(apiArr.getRegionList, 'POST', params, { silent: false });
|
const res = await request(apiArr.getRegionList, 'POST', params, { silent: false });
|
||||||
// TODO: 数据量返回过于庞大,只获取所需信息,其他内容舍弃
|
// TODO: 数据量返回过于庞大,只获取所需信息,其他内容舍弃
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user