Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
修复首页今日课程表显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mohuishou committed Apr 10, 2018
1 parent 012755a commit bbfd624
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/mixins/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export default class HttpMixin extends wepy.mixin {
reject(res)
}
}
handler.fail = () => {
handler.fail = err => {
if (showToast) wepy.hideLoading && wepy.hideLoading()
if (showToast) this.ShowToast('网络错误', 'error', 3000)
reject('Network request failed')
if (showToast) this.ShowToast(JSON.stringify(err), 'error', 3000)
reject(err)
}
wepy.request(handler)
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
return;
}
const todaySchedule = [];
let today = new Date().getDay() || 7;
let today = new Date().getDay() + 1;
schedules[today].forEach(e => {
if (e.course_name) {
todaySchedule.push(e);
Expand Down
26 changes: 21 additions & 5 deletions src/util/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import {
domain
} from '../config'

const ShowToast = (msg, type = 'error', time = 2000) => {
wx.showToast({
title: msg,
icon: 'none',
duration: time
})
}

function GetWithBind(url, params = {}, handler = {}) {
return requestWithBind('GET', url, params, handler)
}
Expand All @@ -27,7 +35,7 @@ async function requestWithBind(method, url, params = {}, handler = {}) {
}
}
})
throw "未绑定账号"
throw '未绑定账号'
} else {
return request(method, url, params, handler)
}
Expand Down Expand Up @@ -59,14 +67,22 @@ function request(method, url, params = {}, handler = {}) {
})

return new Promise((resolve, reject) => {
handler.success = res => resolve(res.data)
handler.fail = () => {
handler.success = res => {
if (res.data.status === 0) {
ShowToast(res.data.msg, 'success')
resolve(res.data)
} else {
ShowToast(res.data.msg || res.data || '网络错误')
reject(res)
}
}
handler.fail = err => {
wx.showModal({
title: '网络错误',
content: '网络错误',
content: JSON.stringify(err),
showCancel: false
})
reject('Network request failed')
reject(err)
}
handler.complete = () => wx.hideLoading && wx.hideLoading()
wx.request(handler)
Expand Down

0 comments on commit bbfd624

Please sign in to comment.