From e8e79a81bf0a49fe4d5f34ab012f13f6f14efd69 Mon Sep 17 00:00:00 2001 From: unknown <331404948@qq.com> Date: Tue, 19 Sep 2023 19:31:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/mixins.js | 3 +- config/api.js | 8 +-- config/request.js | 35 ++++++++++++- config/utils.js | 13 +++++ pages/carEntry/simulateAppointment/comp/step1.vue | 60 ++++++++++++++++++---- pages/mineEntry/personaInfo/personaInfo.vue | 23 +++++++-- pages/tabbar/index/index.vue | 38 ++++++++++++-- pages/tabbar/mine/index.vue | 2 +- pages/userCenter/login/loginByPhone.vue | 5 +- static/images/index/ic_jsg.png | Bin 0 -> 5228 bytes store/modules/user.js | 18 ++++++- 11 files changed, 176 insertions(+), 29 deletions(-) create mode 100644 config/utils.js create mode 100644 static/images/index/ic_jsg.png diff --git a/common/js/mixins.js b/common/js/mixins.js index bdfe885..07e9e85 100644 --- a/common/js/mixins.js +++ b/common/js/mixins.js @@ -5,7 +5,8 @@ export default { computed: { ...mapState({ city: state=> state.user.vuex_cityInfo.city, - vuex_cityInfo: state=> state.user.vuex_cityInfo + vuex_cityInfo: state=> state.user.vuex_cityInfo, + vuex_userInfo: state=> state.user.vuex_userInfo }), }, data() { diff --git a/config/api.js b/config/api.js index f7da277..5d72ef9 100644 --- a/config/api.js +++ b/config/api.js @@ -5,13 +5,13 @@ var http = uni.$u.http // 隐私政策 export const getAgreement = (params, config = {}) => http.post('/util/manage/getAgreement.do', params, config) // 验证码登录 -export const loginSMS = (data) => http.post('member/auth/sms-login', data) +export const loginSMS = (data) => http.post('member/auth/sms-login', data, { custom: { noToken: true }}) // 登录发验证码 -export const getLoginCode = (data) => http.post('member/auth/send-sms-code', data) +export const getLoginCode = (data) => http.post('member/auth/send-sms-code', data, { custom: { noToken: true }}) // 获取个人信息 export const getUserInfo = (data) => http.post('member/user/get', {header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}}) -// 刷新token -export const refreshToken = (data) => http.post('member/auth/refresh-token', data) +// 退出登录 +export const logOut = (data={}) => http.post('member/auth/logout', data, { custom: { noToken: true }}) diff --git a/config/request.js b/config/request.js index 6054ae0..567f460 100644 --- a/config/request.js +++ b/config/request.js @@ -1,5 +1,12 @@ import { H5_API, WX_API } from './site.config.js' +import { refreshToken } from '@/config/api.js' + +import { checkToken } from './utils' + + + + // 此vm参数为页面的实例,可以通过它引用vuex中的变量 module.exports = (vm) => { @@ -20,8 +27,20 @@ module.exports = (vm) => { // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{} config.data = config.data || {} // 根据custom参数中配置的是否需要token,添加对应的请求头 - // config.header.Authorization = 'Bearer ' + vm.$store.state.user.vuex_loginInfo.accessToken - + console.log('--------------') + console.log(config) + let token = vm.$store.state.user.vuex_loginInfo.accessToken + if(token) { + config.header.Authorization = 'Bearer ' + token + } + // 如果不需要token就把header里的token删除,并且不需要去刷新token + let noToken = config.custom?.noToken + if(noToken&&config.header.Authorization) { + delete config.header.Authorization + } + if(!noToken) { + checkToken(vm) + } return config }, config => { // 可使用async await 做异步操作 return Promise.reject(config) @@ -32,6 +51,18 @@ module.exports = (vm) => { const data = response.data console.log('请求结果') console.log(data) + if(data.code==406) { + // vm.$store.dispatch('refreshToken') + uni.$u.toast('登录过期,请重新登录') + setTimeout(()=>{ + vm.$store.commit('goLogin') + },1500) + return false + } + if(data.code==401) { + vm.$store.commit('goLogin') + } + // 自定义参数 const custom = response.config?.custom if (data.code !== 0) { diff --git a/config/utils.js b/config/utils.js new file mode 100644 index 0000000..ee71161 --- /dev/null +++ b/config/utils.js @@ -0,0 +1,13 @@ + +export function checkToken (vm) { + let expiresTime = vm.$store.state.user.vuex_loginInfo.expiresTime + let nowTime = new Date() * 1 + console.log('超时了') + console.log(expiresTime) + if(nowTime>expiresTime*1) { + vm.$store.commit('goLogin') + // 如果小于20分钟就刷新一下token && + }else if((expiresTime*1 - nowTime) / 60000 < 10 ) { + vm.$store.dispatch('refreshToken') + } +} \ No newline at end of file diff --git a/pages/carEntry/simulateAppointment/comp/step1.vue b/pages/carEntry/simulateAppointment/comp/step1.vue index f46141d..9257271 100644 --- a/pages/carEntry/simulateAppointment/comp/step1.vue +++ b/pages/carEntry/simulateAppointment/comp/step1.vue @@ -9,16 +9,16 @@ - + - + {{ item.week }} {{ item.num }} - + @@ -68,18 +68,58 @@ export default { data() { return { - dateArr: [ - {week: '一', num: '08'}, - {week: '二', num: '09'}, - {week: '三', num: '10'}, - {week: '四', num: '11'}, - {week: '五', num: '12'}, - ] + dateArr: [], + currentDay: 0 } }, + mounted() { + const startDate = new Date('2023-09-06'); + const endDate = new Date('2023-09-19'); + const dateRange = this.getDates(startDate, endDate); + console.log(dateRange) + let tmp = [] + dateRange.forEach((date) => { + let dateStr = date.toISOString().split('T')[0] + let dd = dateStr.split('-')[2] + const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六']; + const dayOfWeek = date.getDay(); + const weekName = daysOfWeek[dayOfWeek]; + console.log(dateStr) + console.log(weekName) + if(tmp.length==0) { + this.dateArr.push(tmp) + } + let obj = { + week: weekName, + num: dd + } + tmp.push(obj) + if(tmp.length==5) { + tmp = [] + } + }); + console.log(this.dateArr) + }, methods: { + changeDateIndex(num) { + if(this.currentDay==0&&num==-1) return + if(this.currentDay==this.dateArr.length-1&&num==1) return + this.currentDay = this.currentDay + num + console.log(this.currentDay) + }, changeStep(val) { this.$emit('changeStep', val) + }, + getDates(startDate, endDate) { + const dates = []; + let currentDate = new Date(startDate); + + while (currentDate <= endDate) { + dates.push(new Date(currentDate)); + currentDate.setDate(currentDate.getDate() + 1); + } + + return dates; } } } diff --git a/pages/mineEntry/personaInfo/personaInfo.vue b/pages/mineEntry/personaInfo/personaInfo.vue index 4a699a7..b0fe35e 100644 --- a/pages/mineEntry/personaInfo/personaInfo.vue +++ b/pages/mineEntry/personaInfo/personaInfo.vue @@ -5,7 +5,7 @@ 手机号 - 18267103167 + {{ vuex_userInfo.mobile }} @@ -42,15 +42,32 @@ - 退出登录 + 退出登录 diff --git a/pages/tabbar/index/index.vue b/pages/tabbar/index/index.vue index 847bb84..f7813dc 100644 --- a/pages/tabbar/index/index.vue +++ b/pages/tabbar/index/index.vue @@ -16,6 +16,7 @@ --> + @@ -39,7 +40,7 @@ - + @@ -123,26 +124,49 @@ entrySection: [{ text: '我要报名', icon: require('../../../static/images/index/ic_baoming.png'), - url: '/pages/indexEntry/enroll/enroll' + url: '/pages/indexEntry/enroll/enroll', + click: (item)=>{ + this.$goPage(item.url) + } }, { text: '找驾校', icon: require('../../../static/images/index/ic_jiaxiao.png'), - url: '/pages/indexEntry/findShcool/findShcool' + url: '/pages/indexEntry/findShcool/findShcool', + click: (item)=>{ + this.$goPage(item.url) + } }, { text: '找考场', icon: require('../../../static/images/index/ic_kaochang.png'), - url: '/pages/indexEntry/examines/examines' + url: '/pages/indexEntry/examines/examines', + click: (item)=>{ + this.$goPage(item.url) + } + }, + { + text: '找驾驶馆', + icon: require('../../../static/images/index/ic_peilian.png'), + url: '/pages/carEntry/simulateAppointment/simulateAppointment', + click: (item)=>{ + this.$goPage(item.url) + } }, { text: '找陪练', icon: require('../../../static/images/index/ic_peilian.png'), + click: (item)=>{ + this.$u.toast('正在开发中,敬请期待...') + } }, { text: '理论学习', icon: require('../../../static/images/index/ic_lilun.png'), - url: '/pages/indexEntry/theory/theory' + url: '/pages/indexEntry/theory/theory', + click: (item)=>{ + this.$goPage(item.url) + } }, ], moreSection: [{ @@ -263,6 +287,10 @@ // } }, methods: { + refereshFn() { + // this.$store.dispatch('refreshToken') + this.$store.dispatch('getUserInfo') + }, close() { }, diff --git a/pages/tabbar/mine/index.vue b/pages/tabbar/mine/index.vue index ecdb05a..cf5f09e 100644 --- a/pages/tabbar/mine/index.vue +++ b/pages/tabbar/mine/index.vue @@ -3,7 +3,7 @@ - Hi,大乔 + Hi,{{ vuex_userInfo.nickname?vuex_userInfo.nickname:vuex_userInfo.mobile}} diff --git a/pages/userCenter/login/loginByPhone.vue b/pages/userCenter/login/loginByPhone.vue index a114074..d6d2129 100644 --- a/pages/userCenter/login/loginByPhone.vue +++ b/pages/userCenter/login/loginByPhone.vue @@ -24,7 +24,7 @@ - {{codeText}} + {{codeText}} 登 录 @@ -47,7 +47,8 @@ } }, onLoad() { - this.$store.dispatch('getUserInfo') + // this.$store.dispatch('getUserInfo') + }, computed: { isPhone() { diff --git a/static/images/index/ic_jsg.png b/static/images/index/ic_jsg.png new file mode 100644 index 0000000000000000000000000000000000000000..f5e71ccbac9ade7cc15ee17ce48c778e501e977f GIT binary patch literal 5228 zcmV-y6qDPx#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91T%ZF01ONa40RR91TmS$70AUEp9{>Oo)=5M`RCodHT?u>?Mb>{45^_U; z-~kbWTu~y6%CSHI381ci9=Hk~>w2Mb3M(q8e6T96;JP9zcr2@{yLhmyEU5d*8G!&A z5LgHpPC)~@as?7{5XgN0fAv&P&twuZp?e6B_xts{>guZZUj6I!tLo}wTvEfx?RG~U zJ0@*Th_rQcE0YwLNV3}{^}yrZZi#ofB%Wp?osV=r%H_MuAh~neYrL0VP1Hg0`)D=9^4y(`^CFq1z;7h{7BqJ(ZzD5U>+9A8T zGENKN06DC57!;(Jt5bzDJ$g3kl%G#qQQ8Trw8kbvM9{aIQJQO9tqr zILrQ4$1RhhqFmd8mk?YHM*#=W7aw=a^Jvrn0F5)b<`QfygN?JoUGg-5-|3X4jsT7r z9a(rxo`6R`g+@d2six3M9W=MsjO z;c-!}1$OGS?KJ1~4q#6K(DToDu!%4o25n)R*fzUBx5dMYirmSVU(LeIqmx~R)g(Cp zDGQ!CFgn_`>s0MJWe-1E?7j{&kacG(*aR4D>&!N?t)~_6f@AJ`V8C2hlyIts)cE>F z8|Ql3Ty1l!?cs=RkK;P+UCctltF8SEtH`#p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