Skip to content

Commit 553f24d

Browse files
author
fanny
committed
对接了热门城市和城市组的接口
1 parent 8b24a63 commit 553f24d

File tree

6 files changed

+131
-25
lines changed

6 files changed

+131
-25
lines changed

src/commitDetail.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ d5c6d2bf873068e96234181d1afc507fce71a19a
2020
6f37a2e017ae903142b25db9a9e67b06e5138412
2121
*** 增加一个scroll事件的监听test.vue
2222

23-
*** 完成通用组件
23+
*** 新增alertTip.vue css rule

src/components/header/head.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ export default {
3333
},
3434
mounted () {
3535
// 获取用户信息
36-
this.$axios.get(urls.user + '?user_id=' + getStore('user_id')).then((res) => {
37-
this.$store.commit('GET_USERINFO', res)
38-
})
36+
let userId = getStore('user_id')
37+
if (userId) {
38+
this.$axios.get(urls.user + '?user_id=' + userId).then((res) => {
39+
this.$store.commit('GET_USERINFO', res)
40+
})
41+
}
3942
},
4043
props: ['signinUp', 'headTitle', 'goBack'],
4144
computed: {

src/config/env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let routerMode = 'hash'
99
let imgBaseUrl = ''
1010
if (process.env.NODE_ENV === 'development') {
1111
imgBaseUrl = '/img/'
12-
baseUrl = '//elm.cangdu.org'
12+
baseUrl = '//localhost:8001'
1313
} else if (process.env.NODE_ENV === 'production') {
1414
baseUrl = '//elm.cangdu.org'
1515
imgBaseUrl = '//elm.cangdu.org/img/'

src/main.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@ const axiosIns = axios.create()
2525
// 在main.js设置全局的请求次数,请求的间隙
2626
axiosIns.defaults.retry = 4
2727
axiosIns.defaults.retryDelay = 1000
28-
axiosIns.defaults.timeout = 5000
28+
axiosIns.defaults.timeout = 20000
2929
axiosIns.defaults.baseURL = baseUrl
3030
// 添加请求拦截器
3131
axiosIns.interceptors.request.use(function (config) {
32-
// 在发送请求之前做些什么
33-
// const token = window.localStorage.getItem('token')
34-
// 把token放到header里面
35-
// if (token) {
36-
// config.headers['token'] = token
37-
// }
3832
return config
3933
}, function (error) {
4034
// 对请求错误做些什么
@@ -78,10 +72,10 @@ ajaxMethod.forEach((method) => {
7872
api[method] = function (uri, data, config) {
7973
return new Promise(function (resolve, reject) {
8074
axiosIns[method](uri, data, config).then((response) => {
81-
if (response.data.code === 401) {
75+
if (response.data.status === 401) {
8276
instance.$router.replace('/login')
83-
} else if (response.data.code === 200) {
84-
resolve(response)
77+
} else if (response.data.status === 200) {
78+
resolve(response.data.data)
8579
}
8680
}).catch(function (error) {
8781
console.log(error)

src/page/home/home.vue

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@
33
<head-top signin-up='home'>
44
<span slot='logo' class="head_logo" @click="reload">ele.me</span>
55
</head-top>
6+
<nav class="city_nav">
7+
<div class="city_tip">
8+
<span>当前定位城市:</span>
9+
<span>定位不准确, 请在城市列表中选择</span>
10+
</div>
11+
<router-link :to="'/city/' + guessCityid" class="guess_city">
12+
<span>{{guessCity}}</span>
13+
<svg class="arrow_right">
14+
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#arrow-right"></use>
15+
</svg>
16+
</router-link>
17+
<section class="hot_city_container">
18+
<h4 class="city_title">热门城市</h4>
19+
<ul class="citylistul clear">
20+
<router-link tag="li" v-for="item in hotcity" :to="'/city/' + item.id" :key="item.id">{{item.name}}</router-link>
21+
</ul>
22+
</section>
23+
<section class="group_city_container">
24+
<ul class="letter_classify">
25+
<li class="letter_classify_li" v-for="(value, key, index) in sortgroupcity" :key="key">
26+
<h4 class="city_title">{{key}}
27+
<span v-if="index === 0">(按字母排序)</span>
28+
</h4>
29+
<ul class="groupcity_name_container citylistul clear">
30+
<router-link tag="li" v-for="item in value" :to="'/city/' + item.id" :key="item.id" class="ellipsis">{{item.name}}</router-link>
31+
</ul>
32+
</li>
33+
</ul>
34+
</section>
35+
</nav>
636
</div>
737
</template>
838
<script>
@@ -18,16 +48,12 @@ export default {
1848
}
1949
},
2050
mounted () {
21-
// 获取当前城市
2251
// 获取热门城市
23-
let guessCityObj = this.getCity('guess')
24-
this.hotcity = this.getCity('hot')
52+
this.getHotCity('hot')
2553
// 获取所有城市
26-
this.groupcity = this.getCity('group')
27-
if (this.guessCity) {
28-
this.guessCity = guessCityObj.name
29-
this.guessCityid = guessCityObj.id
30-
}
54+
this.getGroupCity('group')
55+
// 获取猜想城市
56+
// this.getGuessCity('guess')
3157
},
3258
components: {
3359
headTop
@@ -44,11 +70,26 @@ export default {
4470
}
4571
return sortobj
4672
}
73+
4774
},
4875
methods: {
49-
getCity (typeValue) {
76+
getGuessCity (typeValue) {
77+
this.$axios.get(urls.city + '?type=' + typeValue).then((res) => {
78+
this.guessCityObj = res
79+
if (this.guessCityObj) {
80+
this.guessCity = this.guessCityObj.name
81+
this.guessCityid = this.guessCityObj.id
82+
}
83+
})
84+
},
85+
getGroupCity (typeValue) {
86+
this.$axios.get(urls.city + '?type=' + typeValue).then((res) => {
87+
this.groupcity = res
88+
})
89+
},
90+
getHotCity (typeValue) {
5091
this.$axios.get(urls.city + '?type=' + typeValue).then((res) => {
51-
return res
92+
this.hotcity = res
5293
})
5394
},
5495
// 点击图标刷新页面

src/style/home.scss

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,72 @@
55
height: 1rem;
66
@include sc(.7rem, $fc);
77
font-weight: 400;
8+
}
9+
.city_nav {
10+
padding-top: 2.35rem;
11+
margin-bottom: .4rem;
12+
border-top: 1px solid $bc;
13+
.city_tip {
14+
@include fj;
15+
padding: 0 .45rem;
16+
line-height: 1.45rem;
17+
span:nth-of-type(1) {
18+
@include sc(.55rem, #666);
19+
}
20+
span:nth-of-type(2) {
21+
@include sc(.475rem, #9f9f9f);
22+
font-weight: 900;
23+
}
24+
}
25+
.guess_city {
26+
@include fj;
27+
padding: 0 .45rem;
28+
border-top: 1px solid $bc;
29+
border-bottom: 2px solid $bc;
30+
height: 1.8rem;
31+
@include font(0.75rem, 1.8rem);
32+
span:nth-of-type(1) {
33+
color:$blue;
34+
}
35+
.arrow_right {
36+
@include wh(.6rem, 1.6rem);
37+
fill: #999;
38+
}
39+
}
40+
}
41+
.hot_city_container {
42+
margin-bottom: .4rem;
43+
background-color: $fc;
44+
}
45+
.citylistul {
46+
li {
47+
float: left;
48+
border-bottom: .025rem solid $bc;
49+
border-right: .025rem solid $bc;
50+
@include wh (25%, 1.75rem);
51+
@include font(.6rem, 1.75rem);
52+
text-align: center;
53+
color: $blue;
54+
}
55+
li:nth-of-type(4n){
56+
border-right: none;
57+
}
58+
}
59+
.city_title {
60+
border-top: 2px solid $bc;
61+
border-bottom: 1px solid $bc;
62+
@include font(0.55rem, 1.45rem, "Helvetica Neue");
63+
text-indent: 0.45rem;
64+
color: #666;
65+
font-weight: 400;
66+
}
67+
.letter_classify_li{
68+
margin-bottom: 0.4rem;
69+
border-bottom: 1px solid $bc;
70+
background-color: $fc;
71+
.groupcity_name_container{
72+
li{
73+
color: #666;
74+
}
75+
}
876
}

0 commit comments

Comments
 (0)