diff --git a/admin-web/config/proxy/proxy.dev.js b/admin-web/config/proxy/proxy.dev.js index 958c70da5..f8fc22be5 100644 --- a/admin-web/config/proxy/proxy.dev.js +++ b/admin-web/config/proxy/proxy.dev.js @@ -2,7 +2,7 @@ export default { '/admin-api/': { - target: 'http://180.167.213.26:18083/', + target: 'http://127.0.0.1:18083/', // target: 'http://180.167.213.26:18083/', changeOrigin: true, pathRewrite: {}, diff --git a/admin-web/src/utils/cache.js b/admin-web/src/utils/cache.js index 491830084..e7ce31f07 100644 --- a/admin-web/src/utils/cache.js +++ b/admin-web/src/utils/cache.js @@ -3,8 +3,8 @@ // localStorage 操作 const cacheKeys = { - accessTokenKey: 'accessToken', - refreshTokenKey: 'refreshToken', + ACCESS_TOKEN: 'accessToken', + REFRESH_TOKEN: 'refreshToken', }; /// @@ -49,4 +49,4 @@ function removeLocalStorage(key) { } catch (e) { throw new Error(`localStorage 设置错误! ${e}`); } -} \ No newline at end of file +} diff --git a/mobile-web/src/config/request.js b/mobile-web/src/config/request.js index 5e0a412df..f429d5368 100644 --- a/mobile-web/src/config/request.js +++ b/mobile-web/src/config/request.js @@ -1,8 +1,9 @@ import axios from 'axios' import {baseUrl, dataSources} from './env'; import datas from '../data/data'; -import { getAccessToken } from '../utils/cache.js'; +import { getAccessToken, getRefreshToken } from '../utils/cache.js'; import { Dialog } from 'vant'; +import {setLoginToken} from "../utils/cache"; const serviceRouter = function(requestUrl) { function getConfig() { @@ -75,8 +76,9 @@ const serviceRouter = function(requestUrl) { // }); // } // } - const config = getConfig(); + + // TODO 芋艿,临时加下。 // const createServer = doCreateServer(config); const indexOf = requestUrl.indexOf("/", 1); const _urlPrefix = requestUrl.substring(0, indexOf); @@ -130,9 +132,10 @@ const servicef = function (parameter) { return service(parameter); }; - service.interceptors.request.use( config => { + // 记录下原始请求的地址 + config.originUrl = config.url; // Do something before request is sent // if (store.getters.token) { // // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改 @@ -144,7 +147,8 @@ service.interceptors.request.use( let url = config.url = config.url.replace(`${prefix}`, target); // TODO 芋艿,这些 url 不用增加认证 token 。可能这么写,有点脏,后面看看咋优化下。 if (url.indexOf('user-api/users/passport/mobile/send_register_code') !== -1 - || url.indexOf('user-api/users/passport/mobile/register') !== -1) { + || url.indexOf('user-api/users/passport/mobile/register') !== -1 + || url.indexOf('user-api/users/passport/refresh_token') !== -1) { return config; } @@ -152,7 +156,6 @@ service.interceptors.request.use( if (getAccessToken()) { config.headers['Authorization'] = `Bearer ${getAccessToken()}`; } - return config }, error => { @@ -162,6 +165,30 @@ service.interceptors.request.use( } ); +function refreshToken(lastResponse) { + // TODO 芋艿,可能会存在多个异步 callback 的情况。 + let refreshToken = getRefreshToken(); + return servicef({ + url: '/user-api/users/passport/refresh_token', + method: 'post', + params: { + refreshToken + } + }).then(data => { + // 设置新的 accessToken + setLoginToken(data.accessToken, data.refreshToken); + // 重新发起请求 + let config = lastResponse.config; + return servicef({ + url: config.originUrl, + method: config.method, + params: { + ...config.params, + } + }); + }); +} + // response interceptor service.interceptors.response.use( //response => response, @@ -194,7 +221,11 @@ service.interceptors.response.use( // TODO token 过期 // TODO 需要拿 refresh token 置换 - if (code === 1001001012) { + if (code === 1001001011 // 访问令牌不存在 + || code === 1001001013 // 访问令牌已失效 + || code === 1001001021 // 刷新令牌不存在 + || code === 1001001022 // 刷新令牌已过期 + || code === 1001001023) { // 刷新令牌已失效 Dialog.confirm({ title: '系统提示', message: res.message, @@ -210,6 +241,8 @@ service.interceptors.response.use( } } }); + } else if (code === 1001001012) { // 访问令牌已过期 + return refreshToken(response); } else { Dialog.alert({ title: '系统提示', diff --git a/mobile-web/src/config/router.js b/mobile-web/src/config/router.js index 859b7fcb3..d00ed074d 100644 --- a/mobile-web/src/config/router.js +++ b/mobile-web/src/config/router.js @@ -66,21 +66,24 @@ const routes = [ path: '/user/address', component: () => import('../page/user/address/list'), meta: { - title: '我的地址' + title: '我的地址', + requireAuth: true, } }, { path: '/user/address/edit', component: () => import('../page/user/address/edit'), meta: { - title: '修改地址' + title: '修改地址', + requireAuth: true, } }, { path: '/user/favorite', component: () => import('../page/user/favorite/list'), meta: { - title: '我的收藏' + title: '我的收藏', + requireAuth: true, } }, { @@ -102,21 +105,24 @@ const routes = [ path: '/user/order/:id', component: () => import('../page/user/order/list'), meta: { - title: '我的订单' + title: '我的订单', + requireAuth: true, } }, { path: '/user/order/info/:id', component: () => import('../page/user/order/info'), meta: { - title: '我的订单' + title: '我的订单', + requireAuth: true, } }, { path: '/user/order/logistics/:id', component: () => import('../page/user/order/logistics'), meta: { - title: '订单追踪' + title: '订单追踪', + requireAuth: true, } }, { @@ -172,7 +178,8 @@ const routes = [ name: 'cart', component: () => import('../page/cart/index'), meta: { - title: '购物车' + title: '购物车', + requireAuth: true, } }, { @@ -187,7 +194,8 @@ const routes = [ path: '/order/success', component: () => import('../page/shipping/order-success'), meta: { - title: '确认订单' + title: '确认订单', + requireAuth: true, } }, { @@ -208,7 +216,8 @@ const routes = [ path: '/pay', component: () => import('../page/pay/index'), meta: { - title: '收银台' + title: '收银台', + requireAuth: true, } } ]; diff --git a/mobile-web/src/page/page/index.vue b/mobile-web/src/page/page/index.vue index 75f2669a3..9093796b3 100644 --- a/mobile-web/src/page/page/index.vue +++ b/mobile-web/src/page/page/index.vue @@ -12,15 +12,37 @@ - + + + + + +
分类
+
+
+ + + +
热卖
+
+
+ + + +
新品
+
+
+
+ + -
+
-
+
@@ -28,21 +50,20 @@
diff --git a/mobile-web/src/page/user/order/info.vue b/mobile-web/src/page/user/order/info.vue index 0a2e48ad8..05caa56af 100644 --- a/mobile-web/src/page/user/order/info.vue +++ b/mobile-web/src/page/user/order/info.vue @@ -39,15 +39,16 @@
- - - + + + +
@@ -88,6 +89,9 @@ this.queryOrderPage(this.queryParams) }) }, + goPay(itemId) { + this.$router.push('/pay?appId=POd4RC6a&orderId=' + itemId + '&returnUrl=' + encodeURI('/user/order/info/' + itemId)); + }, }, mounted() { const { id } = this.$route.params; diff --git a/mobile-web/src/page/user/order/list.vue b/mobile-web/src/page/user/order/list.vue index c11a4abc8..c12c1e17c 100644 --- a/mobile-web/src/page/user/order/list.vue +++ b/mobile-web/src/page/user/order/list.vue @@ -33,7 +33,7 @@