Skip to content

Commit

Permalink
优化了用户主页的滚动
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrone2333 committed Aug 17, 2018
1 parent 68d7885 commit 231a118
Show file tree
Hide file tree
Showing 13 changed files with 505 additions and 384 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea/
10 changes: 10 additions & 0 deletions .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

483 changes: 300 additions & 183 deletions .idea/workspace.xml

Large diffs are not rendered by default.

41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 46 additions & 31 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const axios = require('axios').create({
})

// 设置重试次数及重试延迟
axios.defaults.retry = 4
axios.defaults.retry = 2
axios.defaults.retryDelay = 1000
// http response 拦截器
axios.interceptors.response.use(
Expand All @@ -35,18 +35,26 @@ axios.interceptors.response.use(
// 如请求正确,则将 loading 关闭
Vue.$vux.loading.hide()

// 统一管理error的错误
if (response.data.errno === 401) {
Vue.$vux.toast.show({
text: response.data.message,
type: "warn",
})

router.replace({
path: 'login',
path: '/login',
query: {
redirect: router.currentRoute.fullPath
}
})
} else if (response.data.errno === -1
|| response.data.errno === 1
|| response.data.errno === 3) {
Vue.$vux.toast.show({
text: response.data.message || "出错了",
type: "warn",
})
}


Expand Down Expand Up @@ -79,44 +87,51 @@ axios.interceptors.response.use(
type: "warn",
})
break
default:


}
}

// 请求失败后重试
let config = error.config
// 如果 config 不存在,或 retry 未设置, reject
if (!config || !config.retry) {
return Promise.reject(error)
}

// 保存重试次数
config.__retryCount = config.__retryCount || 0
// 请求超时后重试
if (error.code === 'ECONNABORTED' && error.message.indexOf('timeout') !== -1) {
let config = error.config
// 如果 config 不存在,或 retry 未设置, reject
if (!config || !config.retry) {
return Promise.reject(error)
}

// 重试次数大于设置的次数,reject
if (config.__retryCount >= config.retry) {
Vue.$vux.loading.hide()
return Promise.reject(error)
}
console.log(`第 ${config.__retryCount + 1} 次重试`)
// 保存重试次数
config.__retryCount = config.__retryCount || 0

// 重试统计 +1
config.__retryCount += 1
// 重试次数大于设置的次数,reject
if (config.__retryCount >= config.retry) {
Vue.$vux.loading.hide()
return Promise.reject(error)
}
console.log(`请求超时,第 ${config.__retryCount + 1} 次重试`)

// 创建一个 promise 处理新请求
return new Promise(resolve => {
setTimeout(resolve, config.retryDelay || 1)
}).then(() => {
if (!Vue.$vux.loading.isVisible()) {
// 重试统计 +1
config.__retryCount += 1

Vue.$vux.loading.show({
text: "网络错误,正在重试",
})
}
return axios(config)
})
// 创建一个 promise 处理新请求
return new Promise(resolve => {
setTimeout(resolve, config.retryDelay || 1)
}).then(() => {

// 显示一个loading
if (!Vue.$vux.loading.isVisible()) {
Vue.$vux.loading.show({
text: "请求超时,正在重试",
})
}
return axios(config)
})


}


return Promise.reject(error)

},
)
Expand Down
13 changes: 5 additions & 8 deletions src/components/article/read_article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
<!--评论列表-->
<div class="comments" v-if="commentList.length ">
<div class="comment-wrapper" v-for="(val,key) in commentList">
<div class="avatar">
<div class="avatar" @click="clickSomebody(val.from_id)">
<img :src="val.avatar" alt="">
</div>
<div class="comment-right">
<div class="nickname">{{val.from_nickname}}</div>
<div class="content">
<a href="" class="at-someone">{{!val.is_for_author ?"@" +val.to_nickname + "\t" :"" }}</a>
<span @click="clickSomebody(val.to_id)" class="at-someone">{{!val.is_for_author ?"@" +val.to_nickname + "\t" :"" }}</span>
{{val.content}}
</div>
<div class="footer">
Expand Down Expand Up @@ -154,6 +154,9 @@
})
},
clickSomebody(userId){
this.$router.push({name: 'user', params: {id: userId}})
},
toggleCollect() {
if (!this.$store.state.user.user.id) {
this.$vux.toast.show({
Expand Down Expand Up @@ -274,12 +277,6 @@
text: res.message,
type: "success",
})
} else {
_this.$vux.toast.show({
text: res.message,
type: "warn",
})
}
_this.fetchData()
_this.initcollectList()
Expand Down
Loading

0 comments on commit 231a118

Please sign in to comment.