Skip to content

Commit cdb16a8

Browse files
committed
新增调高德地图
1 parent 1c906eb commit cdb16a8

File tree

9 files changed

+321
-2
lines changed

9 files changed

+321
-2
lines changed

project.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"description": "项目配置文件。",
33
"setting": {
4-
"urlCheck": true,
4+
"urlCheck": false,
55
"es6": false,
66
"postcss": true,
77
"minified": true,

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
// 这个字段走 app.json
1313
config: {
1414
// 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
15-
"pages": ["pages/feedback/main", "pages/order/main", "pages/cart/main", "pages/collectlist/main", "pages/addressSelect/main", "pages/addaddress/main", "pages/address/main", "^pages/index/main", "pages/search/main", "pages/my/main", "pages/login/main", "pages/category/main", "pages/categorylist/main", "pages/topic/main", "pages/goods/main", "pages/logs/main", "pages/branddetail/main", "pages/brandlist/main", "pages/newgoods/main", "pages/practice/main", "pages/topicdetail/main"],
15+
"pages": ["pages/feedback/main", "pages/order/main", "pages/cart/main", "pages/mappage/main", "pages/collectlist/main", "pages/addressSelect/main", "pages/addaddress/main", "pages/address/main", "^pages/index/main", "pages/search/main", "pages/my/main", "pages/login/main", "pages/category/main", "pages/categorylist/main", "pages/topic/main", "pages/goods/main", "pages/logs/main", "pages/branddetail/main", "pages/brandlist/main", "pages/newgoods/main", "pages/practice/main", "pages/topicdetail/main"],
1616
"window": {
1717
"backgroundTextStyle": "light",
1818
"navigationBarBackgroundColor": "#fff",

src/pages/index/index.vue

+42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<template>
22
<div class="index">
3+
<div class="search">
4+
<div @click="toMappage">{{cityName}}</div>
5+
<div @click="toSearch">
6+
<input type="text" placeholder="搜索商品">
7+
<span class="icon"></span>
8+
</div>
9+
</div>
310
<div class="swiper">
411
<swiper class="swiper-container" indicator-dots="true" autoplay="true" interval="3000" circular="true" duration="500">
512
<block v-for="(item, index) in banner " :key="index">
@@ -116,13 +123,23 @@
116123
</template>
117124

118125
<script>
126+
import amapFile from "../../utils/amap-wx";
119127
import { get } from "../../utils";
120128
export default {
129+
onLoad() {
130+
this.getCityName();
131+
},
132+
onShow() {
133+
if (wx.getStorageSync("cityName")) {
134+
this.cityName = wx.getStorageSync("cityName");
135+
}
136+
},
121137
mounted() {
122138
this.getData();
123139
},
124140
data() {
125141
return {
142+
cityName: "定位中..",
126143
banner: [],
127144
channel: [],
128145
brandList: [],
@@ -134,6 +151,31 @@ export default {
134151
},
135152
components: {},
136153
methods: {
154+
toMappage() {
155+
wx.navigateTo({ url: "/pages/mappage/main" });
156+
},
157+
getCityName() {
158+
var _this = this;
159+
var myAmapFun = new amapFile.AMapWX({ key: "e545e7f79a643f23aef187add14e4548" });
160+
myAmapFun.getRegeo({
161+
success: function(data) {
162+
//成功回调
163+
console.log(data);
164+
// data[0].regeocodeData.formatted_address
165+
_this.cityName = data[0].regeocodeData.formatted_address;
166+
},
167+
fail: function(info) {
168+
//失败回调
169+
console.log(info);
170+
//如果用户拒绝授权
171+
// 默认为北京
172+
_this.cityName = "北京市";
173+
}
174+
});
175+
},
176+
toSearch() {
177+
wx.navigateTo({ url: "/pages/search/main" });
178+
},
137179
async getData() {
138180
const data = await get("/index/index");
139181
this.banner = data.banner;

0 commit comments

Comments
 (0)