diff --git a/config/api.js b/config/api.js index 915f2a7..5932087 100644 --- a/config/api.js +++ b/config/api.js @@ -4,10 +4,8 @@ */ // 开发环境 const dev = { - common: 'http://192.168.0.109:8890', - buyer: 'http://192.168.0.109:8888', - seller: 'http://192.168.0.109:8889', - manager: 'http://192.168.0.109:8887' + common: "https://common-api.pickmall.cn", + buyer: "https://buyer-api.pickmall.cn", }; // 生产环境 const prod = { diff --git a/pages.json b/pages.json index b86d1b5..0920b5b 100644 --- a/pages.json +++ b/pages.json @@ -707,12 +707,12 @@ "text": "分类" }, - { - "pagePath": "pages/navigation/point/point-mall", - "iconPath": "static/tabbar/point-mall.png", - "selectedIconPath": "static/tabbar/point-mall-s.png", - "text": "积分商城" - }, + // { + // "pagePath": "pages/navigation/point/point-mall", + // "iconPath": "static/tabbar/point-mall.png", + // "selectedIconPath": "static/tabbar/point-mall-s.png", + // "text": "积分商城" + // }, { "pagePath": "pages/tabbar/cart/cartList", "iconPath": "static/tabbar/cart.png", diff --git a/pages/product/goods.vue b/pages/product/goods.vue index a4eb03c..b03fc67 100644 --- a/pages/product/goods.vue +++ b/pages/product/goods.vue @@ -367,6 +367,7 @@ export default { }, }, mounted() { + const { windowHeight } = uni.getSystemInfoSync(); let bottomHeight = 0; let topHeight = 0; diff --git a/pages/product/product/popup/goods.vue b/pages/product/product/popup/goods.vue index 1e24d38..f2abb4b 100644 --- a/pages/product/product/popup/goods.vue +++ b/pages/product/product/popup/goods.vue @@ -197,13 +197,6 @@ export default { this.$emit("queryCart"); this.closeMask(); - } else { - uni.showToast({ - title: res.data.message, - duration: 2000, - icon: "none", - }); - return false; } }); } else { @@ -226,13 +219,7 @@ export default { )}`, }); } - else{ - uni.showToast({ - title: res.data.message, - duration: 2000, - icon: "none", - }); - } + }); } }, diff --git a/store/index.js b/store/index.js index fed4ede..c6e5d4b 100644 --- a/store/index.js +++ b/store/index.js @@ -7,51 +7,13 @@ Vue.use(Vuex); const store = new Vuex.Store({ state: { verificationKey: "", //获取key表示验证通过 - /** - * 是否需要强制登录 - */ - forcedLogin: false, - distributionId:"", //分销员Id 如果当前账户从未登录过时记录 hasLogin: storage.getHasLogin(), userInfo: storage.getUserInfo(), uuid: storage.getUuid(), token: "", - getHeadInfo: "", - getWeixinHeightInfo: "", }, mutations: { - /** - * 获取头部高度 异步使用 - * 文档链接在 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync - * */ - GET_HEAD_HEIGHT(state) { - return new Promise((resolve, reject) => { - state.getHeadInfo = uni.getSystemInfoSync(); - resolve(); - }); - }, - /** - * 获取微信小胶囊高度 */ - MP_WEIXIN_HEIGHT(state) { - // width number 宽度,单位:px - // height number 高度,单位:px - // top number 上边界坐标,单位:px - // right number 右边界坐标,单位:px - // bottom number 下边界坐标,单位:px - // left number 左边界坐标,单位:px - - state.getWeixinHeightInfo = uni.getMenuButtonBoundingClientRect(); - }, - // 前台存储登录状态 - SET_HAS_LOGIN(state, val) { - state.hasLogin = val; - }, - // 登录信息 - SET_USER_INFO(state, val) { - state.userInfo = val; - }, - login(state, userInfo) { state.userInfo = userInfo || {}; state.userName = diff --git a/utils/request.js b/utils/request.js index 1a4ed55..8998393 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,5 +1,4 @@ import Request from "@/lib/request/index.js"; -import { configHandle } from "@/utils/tools.js"; import { refreshTokenFn } from "@/api/login.js"; import storage from "@/utils/storage.js"; import { md5 } from "@/utils/md5.js"; @@ -84,7 +83,6 @@ function cleanStorage() { let http = new Request(); const refreshToken = getTokenDebounce(); -const reReqest = new Request(); http.setConfig((config) => { // 没有uuid创建 @@ -141,7 +139,10 @@ http.interceptors.response.use( // token存在并且token过期 let token = storage.getAccessToken(); - if (token && response.statusCode === 403) { + if ( + (token && response.statusCode === 403) || + response.data.status === 403 + ) { expireToken.includes(token) ? cleanStorage() : ""; // jwt token 过期了 expireToken.push(token); // 把过期token 储存 @@ -150,36 +151,44 @@ http.interceptors.response.use( // 本地储存的是过期token了,重新获取 const getTokenResult = await refreshToken(); if (getTokenResult === "success") { - // 获取新的token成功 - try { - const repeatRes = await reReqest.request( - configHandle(response.config) - ); - response = repeatRes; - } catch (err) {} + // 获取新的token成功 刷新当前页面 + + let routes = getCurrentPages(); // 获取当前打开过的页面路由数组 + let curRoute = routes[routes.length - 1].route; //获取当前页面路由 + let curParam = routes[routes.length - 1].options; //获取路由参数 + // 拼接参数 + let param = ""; + for (let key in curParam) { + param += "&" + key + "=" + curParam[key]; + } + + uni.redirectTo({ + url: "/" + curRoute + param.replace("&", "?"), + }); } else { cleanStorage(); } } else { - try { - const repeatRes = await reReqest.request( - configHandle(response.config) - ); - response = repeatRes; - } catch (err) { - cleanStorage(); - } + cleanStorage(); } // 如果当前返回没登录 - } else if (response.statusCode === 403 || response.data.code === 403) { + } else if ( + (!token && response.statusCode === 403) || + response.data.code === 403 + ) { cleanStorage(); // 如果当前状态码为正常但是success为不正常时 - } else if (response.statusCode == 200 && !response.data.success || response.statusCode == 400) { - uni.showToast({ - title: response.data.message , - icon: "none", - duration: 1500, - }); + } else if ( + (response.statusCode == 200 && !response.data.success) || + response.statusCode == 400 + ) { + if (response.data.message) { + uni.showToast({ + title: response.data.message, + icon: "none", + duration: 1500, + }); + } } return response; }, diff --git a/utils/tools.js b/utils/tools.js index 204386d..c2e119d 100644 --- a/utils/tools.js +++ b/utils/tools.js @@ -1,49 +1,3 @@ -import Foundation from '@/utils/Foundation.js'; -import { - md5 -} from '@/utils/md5.js'; -import storage from "@/utils/storage.js"; -import store from "@/store/index.js"; - -// 重新整理一下config -const configHandle = (config) => { - // 'development', 'production' - if (process.env.NODE_ENV === 'development') { - const nonce = Foundation.randomString(6) - const timestamp = parseInt(new Date().getTime() / 1000) - const sign = md5( nonce + timestamp + storage.getAccessToken()) - if (config.url.indexOf('?') === -1) { - config.url = `${config.url}?&nonce=${nonce}×tamp=${timestamp}&sign=${sign}` - } else { - let params = urlParse(config.url); - console.info(params); - let url = config.url.split('?')[0]; - params = { ...params, - nonce, - timestamp, - sign - }; - let str = ''; - for (var k in params) { - console.info(k, params[k]) - str += '&' + k + '=' + params[k]; - } - str = str.substr(1); - config.url = `${url}?${str}`; - } - config.header = { - ...config.header, - uuid: storage.getUuid() - } - } else { - config.header = { - ...config.header, - Authorization: storage.getAccessToken(), - uuid: storage.getUuid() - } - } - return config -} /** * 解析url参数 @@ -51,59 +5,59 @@ const configHandle = (config) => { * @return Object {id:12345,a:b} */ function urlParse(url) { - let obj = {}; - let reg = /[?&][^?&]+=[^?&]+/g; - let arr = url.match(reg); - if (arr) { - arr.forEach((item) => { - let tempArr = item.substring(1).split('='); - let key = decodeURIComponent(tempArr[0]); - let val = decodeURIComponent(tempArr.splice(1).join('=')); - obj[key] = val; - }); - } - return obj; -}; + let obj = {}; + let reg = /[?&][^?&]+=[^?&]+/g; + let arr = url.match(reg); + if (arr) { + arr.forEach((item) => { + let tempArr = item.substring(1).split("="); + let key = decodeURIComponent(tempArr[0]); + let val = decodeURIComponent(tempArr.splice(1).join("=")); + obj[key] = val; + }); + } + return obj; +} const getNetworkType = () => { - uni.getNetworkType({ - success: (res) => { - if (res.networkType === 'none') { - uni.showToast({ - title: '网络好像有点问题,请检查后重试!', - duration: 2000, - icon: 'none' - }); - let pages = getCurrentPages(); - if (pages.length) { - let route = pages[pages.length - 1].route; - if (route !== 'pages/empty/empty') { - uni.navigateTo({ - url: `/pages/empty/empty?type=wifi` - }) - } - }else{ - uni.navigateTo({ - url: `/pages/empty/empty?type=wifi` - }) - } - } - } - }) -} + uni.getNetworkType({ + success: (res) => { + if (res.networkType === "none") { + uni.showToast({ + title: "网络好像有点问题,请检查后重试!", + duration: 2000, + icon: "none", + }); + let pages = getCurrentPages(); + if (pages.length) { + let route = pages[pages.length - 1].route; + if (route !== "pages/empty/empty") { + uni.navigateTo({ + url: `/pages/empty/empty?type=wifi`, + }); + } + } else { + uni.navigateTo({ + url: `/pages/empty/empty?type=wifi`, + }); + } + } + }, + }); +}; const throttle = (fn, that, gapTime) => { - // export function throttle(fn, gapTime) { - if (gapTime == null || gapTime == undefined) { - gapTime = 1800 - } - let _lastTime = that.lastTime - let _nowTime = +new Date() - if (_nowTime - _lastTime > gapTime || !_lastTime) { - fn.apply(that, arguments) //将this和参数传给原函数 - that.lastTime = _nowTime - } -} + // export function throttle(fn, gapTime) { + if (gapTime == null || gapTime == undefined) { + gapTime = 1800; + } + let _lastTime = that.lastTime; + let _nowTime = +new Date(); + if (_nowTime - _lastTime > gapTime || !_lastTime) { + fn.apply(that, arguments); //将this和参数传给原函数 + that.lastTime = _nowTime; + } +}; /** * 计算传秒数的倒计时【天、时、分、秒】 @@ -111,33 +65,39 @@ const throttle = (fn, that, gapTime) => { * @returns {{day : *, hours : *, minutes : *, seconds : *}} */ const countTimeDown = (seconds) => { - const leftTime = (time) => { - if (time < 10) time = '0' + time - return time + '' - } - return { - day: leftTime(parseInt(seconds / 60 / 60 / 24, 10)), - hours: leftTime(parseInt(seconds / 60 / 60 % 24, 10)), - minutes: leftTime(parseInt(seconds / 60 % 60, 10)), - seconds: leftTime(parseInt(seconds % 60, 10)) - } -} + const leftTime = (time) => { + if (time < 10) time = "0" + time; + return time + ""; + }; + return { + day: leftTime(parseInt(seconds / 60 / 60 / 24, 10)), + hours: leftTime(parseInt((seconds / 60 / 60) % 24, 10)), + minutes: leftTime(parseInt((seconds / 60) % 60, 10)), + seconds: leftTime(parseInt(seconds % 60, 10)), + }; +}; /** * 计算当前时间到第二天0点的倒计时[秒] * @returns {number} */ const theNextDayTime = () => { - const nowDate = new Date() - const time = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate() + 1, 0, 0, 0).getTime() - - nowDate.getTime() - return parseInt(time / 1000) -} + const nowDate = new Date(); + const time = + new Date( + nowDate.getFullYear(), + nowDate.getMonth(), + nowDate.getDate() + 1, + 0, + 0, + 0 + ).getTime() - nowDate.getTime(); + return parseInt(time / 1000); +}; export { - //configHandle, - getNetworkType, - throttle, - countTimeDown, - theNextDayTime -} + getNetworkType, + throttle, + countTimeDown, + theNextDayTime, +};