-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
278 lines (277 loc) · 11.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>vue城市列表</title>
<!-- <script src="/static/common/hplus/js/jQuery.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=6ee71f2fd5eece7797fafe8b9f7a090a&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder"></script>
<link rel="stylesheet" type="text/css" href="./css/reset.css">
<link rel="stylesheet" type="text/css" href="./css/city.css">
<script src="./js/bscroll.min.js"></script>
<script src="./js/city.js"></script>
<script src="./js/getping.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.mycity {
text-align: center;
font-size: 12px;
margin: 20px 0;
}
.list-box {
padding: 0 43px;
}
.list-item {
height: 43px;
line-height: 42px;
border-bottom: 1px solid #ECECEC;
text-align: center;
}
.list-item input {
border:none;
text-align: center;
outline: none;
}
.small-icon {
display: inline-block;
width: 100%;
height: 100%;
vertical-align: top;
}
.toast {
position: fixed;
z-index: 2000;
left: 50%;
top:45%;
transition:all .5s;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
text-align: center;
border-radius: 5px;
color:#FFF;
background: rgba(17, 17, 17, 0.7);
height: 45px;
line-height: 45px;
padding: 0 15px;
max-width: 150px;
}
</style>
</head>
<body>
<div id="app" style="font-size: 14px;color: #292929;font-family: '微软雅黑'">
<div class="mycity" @click="selectLocation()">
我的城市: <span id="qyxs" style="color:#FF0000">{{location}}</span> [更改]
</div>
<div v-show="isShowCitys" class="city">
<div style="text-align: center;position: fixed;top: 0;height: 32px;width:100%;line-height: 32px;z-index: 300;background-color: #FFF;box-shadow: 0 0 2px rgba(0,0,0,.2)
">
我的城市: <span id="qyxs" style="color:#FF0000">{{location}}</span>
</div>
<div class="city-wrapper city-wrapper-hook">
<div class="scroller-hook">
<div class="cities cities-hook">
<div v-for="i in cityData">
<div class="title">{{i.name}}</div>
<ul>
<li v-for="item in i.cities" class="item city-click" :data-name="item.name" :data-id="item.code"><span :data-item="JSON.stringify(item)" @touchstart="chooseCity" @touchend="touchUp" class="border-1px name">{{item.name}}</span>
</li>
</ul>
</div>
</div>
</div>
<div class="shortcut shortcut-hook" style="right: 50px;top:100px !important;" @touchstart="touchIndex">
<ul style="width: 100px;text-align: left;padding: 20px 0">
<li v-for="i in cityData" :data-anchor="i.name" class="item">{{i.name.substr(0, 1)}}</li>
</ul>
</div>
</div>
</div>
<div class="toast" v-show="toastShow">
{{toastText}}
</div>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
initY: 0,
origin: 'http://192.168.99.205:800',
captchaBoxShow: false,
test: '测试',
countTime: 0,
countTimer: null,
time: 60,
location: '定位中',
submit: {
sms_captcha : '',
captcha : '',
area_code : '',
_token : '',
},
map: new AMap.Map("container", {
resizeEnable: true,
//city: citycode,
zoom: 17, //地图显示的缩放级别
keyboardEnable: false,
citylimit: true,
resizeEnable: true
}),
cityWrapper: document.querySelector('.city-wrapper-hook'),
cityScroller: document.querySelector('.scroller-hook'),
cities: document.querySelector('.cities-hook'),
shortcut: document.querySelector('.shortcut-hook'),
shortcutList: [],
cityData: cityData,// 数据源
scroll: null,
anchorMap: {},
touch: {},
toastShow: false,
isShowCitys: false,
toastText: '',
},
methods: {
toast (str) {
let v = this
v.toastText = str
v.toastShow = true
setTimeout(function(){
v.toastShow = false
}, 1500)
},
chooseCity (e) {
this.initY = e.changedTouches[0].screenY
},
touchUp (e) {
let currentY = e.changedTouches[0].screenY,
cha = currentY - this.initY,
item = JSON.parse(e.target.dataset.item)
if (-10 < cha && cha < 10) {
this.isShowCitys = false
this.location = item.name
this.submit.area_code = item.code
}
},
selectLocation () {
let v = this
this.isShowCitys = true
this.$nextTick(function() {
this.initCities()
})
},
geocoder_CallBack: function (data) {
let v = this
var adcode3 = data.regeocode.addressComponent.adcode;
var address = data.regeocode.formattedAddress; //返回地址描述
var csqy = data.regeocode.addressComponent.district; //地区
var csadcode = data.regeocode.addressComponent.adcode; //区域编码
this.submit.area_code = csadcode
var citycode2 = csadcode.substr(0, 4) + "00"; //省份编码
var codes = adcode3.substr(0, 4) + "00";
var citys2 = data.regeocode.addressComponent.city;
var poiArr = data.regeocode.pois; //坐标
var resultCount = poiArr.length;
v.location = csqy
var dz = data.regeocode.formattedAddress;
var lng = data.regeocode.roads[0].location.lng;
var lat = data.regeocode.roads[0].location.lat;
},
zddw: function () {
//初始定位
let v = this
v.map.plugin('AMap.Geolocation', function() {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true, //是否使用高精度定位,默认:true
//timeout: 10000, //超过10秒后停止定位,默认:无穷大
buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
noIpLocate: 0, //IP定位,0-3,0都可以使用
noGeoLocation: 0, //浏览器定位 0-3,
showCircle: false, //去除定位蓝圈
buttonPosition: 'RT',
extensions: 'all'
});
v.map.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
});
//解析定位结果
function onComplete(data) {
var str = [];
str.push(data.position.lng);
str.push(data.position.lat);
var geocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
});
geocoder.getAddress(str, function(status, result) {
if (status === 'complete' && result.info === 'OK') {
v.geocoder_CallBack(result);
}
});
}
// 解析定位错误信息
function onError(data) {
alert('定位失败,请手动选择所在区域');
}
},
initCities: function () {
let v = this
let y = 0;
var titleHeight = 28
var itemHeight = 44
v.cityData.forEach(function(e){
let name = e.name.substr(0, 1)
let len = e.cities.length
v.anchorMap[name] = y
y -= titleHeight + len * itemHeight
})
v.shortcut = document.querySelector('.shortcut-hook')
v.cityWrapper = document.querySelector('.city-wrapper-hook')
v.shortcut.style.top = (v.cityWrapper.clientHeight - v.shortcut.clientHeight) / 2 + 'px';
v.scroll = new window.BScroll(v.cityWrapper, {
probeType: 3
})
// console.log(v.scroll, 'v.scroll')
// v.scroll.hasVerticalScroll = true
// v.scroll.wrapperHeight = $('body').height()
v.scroll.scrollTo(0, 0);
},
touchIndex: function (e) {
// console.log(e, 'e')
let v = this
let anchor = e.target.getAttribute('data-anchor')
// console.log(anchor ,'anchor')
let firstTouch = e.touches[0]
v.touch.y1 = firstTouch.pageY
v.touch.anchor = anchor
v.scrollTo(anchor)
},
scrollTo: function (anchor) {
let v = this
v.cityScroller = document.querySelector('.scroller-hook')
var maxScrollY = v.cityWrapper.clientHeight - v.cityScroller.clientHeight
var y = Math.min(0, Math.max(maxScrollY, v.anchorMap[anchor]))
if (typeof y !== 'undefined') {
v.scroll.scrollTo(0, y);
}
},
},
mounted: function () {
let v = this
this.zddw()
v.initCities()
},
})
</script>
</html>