From c4c11781fb158b66e0bdc86ef7e5d6001a02d131 Mon Sep 17 00:00:00 2001 From: Gdpao <1341331954@qq.com> Date: Wed, 5 Aug 2020 21:06:29 +0800 Subject: [PATCH] gdpaoup --- App.vue | 21 ++++- common/http.interceptor.js | 26 +++++- components/index/daren-item/index.vue | 30 ++++-- components/index/video-item/index.vue | 22 ++++- components/informations/titles/titles.vue | 32 ++----- components/remaining/remaining.vue | 10 -- components/shop/group/item.vue | 8 +- pageA/login/login.vue | 2 +- pageA/pactList/pactList.vue | 19 +++- pageB/components/details/userinfo.vue | 103 ++++++++++++++------- pageB/details/index.vue | 108 +++++++++++++--------- pageB/photo/index.vue | 9 +- pages.json | 4 +- pages/index/index.vue | 61 ++++++++---- pages/information/information.vue | 9 +- 15 files changed, 305 insertions(+), 159 deletions(-) diff --git a/App.vue b/App.vue index 454e83a..0ff56fa 100644 --- a/App.vue +++ b/App.vue @@ -1,6 +1,9 @@ diff --git a/common/http.interceptor.js b/common/http.interceptor.js index 0dce389..5484ac8 100644 --- a/common/http.interceptor.js +++ b/common/http.interceptor.js @@ -3,8 +3,8 @@ const install = (Vue, vm) => { Vue.prototype.$u.http.setConfig({ baseUrl: 'https://dmmall.sdbairui.com/api', loadingText: '努力加载中~', - loadingTime: 800 - + loadingTime: 800, + // originalData: true }); // 请求拦截,配置Token等参数 @@ -17,6 +17,28 @@ const install = (Vue, vm) => { return config; } + + // 响应拦截,如配置,每次请求结束都会执行本方法 + Vue.prototype.$u.http.interceptor.response = (res) => { + if(parseInt(res.errCode) == 0) { + // res为服务端返回值,可能有errCode,result等字段 + // 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到 + // 如果配置了originalData为true,请留意这里的返回值 + return res; + } else if(res.errCode == 401) { + // 假设201为token失效,这里跳转登录 + vm.$u.toast('验证失败,请重新登录'); + setTimeout(() => { + // 此为uView的方法,详见路由相关文档 + vm.$u.route('/pageA/login/login') + }, 1500) + return false; + } else { + // 如果返回false,则会调用Promise的reject回调, + // 并将进入this.$u.post(url).then().catch(res=>{})的catch回调中,res为服务端的返回值 + return false; + } + } } diff --git a/components/index/daren-item/index.vue b/components/index/daren-item/index.vue index 98b26a2..844eb1a 100644 --- a/components/index/daren-item/index.vue +++ b/components/index/daren-item/index.vue @@ -1,6 +1,6 @@