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 0000000..f5e71cc
Binary files /dev/null and b/static/images/index/ic_jsg.png differ
diff --git a/store/modules/user.js b/store/modules/user.js
index 6ad7a23..d5c3f45 100644
--- a/store/modules/user.js
+++ b/store/modules/user.js
@@ -19,6 +19,14 @@ const user = {
update_vuex_userInfo(state, payload) {
state.vuex_userInfo = payload
uni.setStorageSync('vuex_userInfo', payload);
+ },
+ goLogin(state) {
+ uni.clearStorageSync()
+ state.vuex_loginInfo = {}
+ state.vuex_userInfo = {}
+ uni.navigateTo({
+ url: '/pages/userCenter/login/loginByPhone'
+ })
}
},
actions: {
@@ -62,10 +70,18 @@ const user = {
commit('update_vuex_userInfo',res.data)
},
// 刷新token
- async refreshToken({state}) {
+ async refreshToken({state, commit}) {
const http = uni.$u.http
+ let config = { header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, custom: { noToken: true } }
let refreshToken = state.vuex_loginInfo.refreshToken
const res = await http.post('member/auth/refresh-token',{refreshToken}, config)
+ console.log('刷新token结果')
+ console.log(res)
+ commit('update_vuex_loginInfo',res.data)
+ uni.$u.http.setConfig((config) => {
+ config.header.Authorization = 'Bearer ' + res.data.accessToken
+ return config
+ })
}
}
}