diff --git a/src/mixins/http.js b/src/mixins/http.js index 1482e71..1b83c61 100644 --- a/src/mixins/http.js +++ b/src/mixins/http.js @@ -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) }) diff --git a/src/pages/index.vue b/src/pages/index.vue index b6ac877..347c5b1 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -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); diff --git a/src/util/http.js b/src/util/http.js index 7a06d93..9e90fd1 100644 --- a/src/util/http.js +++ b/src/util/http.js @@ -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) } @@ -27,7 +35,7 @@ async function requestWithBind(method, url, params = {}, handler = {}) { } } }) - throw "未绑定账号" + throw '未绑定账号' } else { return request(method, url, params, handler) } @@ -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)