Browse Source

日期处理

master
unknown 1 year ago
parent
commit
e8e79a81bf
  1. 3
      common/js/mixins.js
  2. 8
      config/api.js
  3. 35
      config/request.js
  4. 13
      config/utils.js
  5. 60
      pages/carEntry/simulateAppointment/comp/step1.vue
  6. 21
      pages/mineEntry/personaInfo/personaInfo.vue
  7. 38
      pages/tabbar/index/index.vue
  8. 2
      pages/tabbar/mine/index.vue
  9. 5
      pages/userCenter/login/loginByPhone.vue
  10. BIN
      static/images/index/ic_jsg.png
  11. 18
      store/modules/user.js

3
common/js/mixins.js

@ -5,7 +5,8 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
city: state=> state.user.vuex_cityInfo.city, 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() { data() {

8
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 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'}}) 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 }})

35
config/request.js

@ -1,5 +1,12 @@
import { H5_API, WX_API } from './site.config.js' import { H5_API, WX_API } from './site.config.js'
import { refreshToken } from '@/config/api.js'
import { checkToken } from './utils'
// 此vm参数为页面的实例,可以通过它引用vuex中的变量 // 此vm参数为页面的实例,可以通过它引用vuex中的变量
module.exports = (vm) => { module.exports = (vm) => {
@ -20,8 +27,20 @@ module.exports = (vm) => {
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{} // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
config.data = config.data || {} config.data = config.data || {}
// 根据custom参数中配置的是否需要token,添加对应的请求头 // 根据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 return config
}, config => { // 可使用async await 做异步操作 }, config => { // 可使用async await 做异步操作
return Promise.reject(config) return Promise.reject(config)
@ -32,6 +51,18 @@ module.exports = (vm) => {
const data = response.data const data = response.data
console.log('请求结果') console.log('请求结果')
console.log(data) 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 const custom = response.config?.custom
if (data.code !== 0) { if (data.code !== 0) {

13
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')
}
}

60
pages/carEntry/simulateAppointment/comp/step1.vue

@ -9,16 +9,16 @@
</view> </view>
</view> </view>
<view class="date_row"> <view class="date_row">
<view class="icon left">
<view class="icon left" @click="changeDateIndex(-1)">
<u-icon name="arrow-left" :size="12" :color="'#fff'"></u-icon> <u-icon name="arrow-left" :size="12" :color="'#fff'"></u-icon>
</view> </view>
<view class="dateArr"> <view class="dateArr">
<view class="date" v-for="(item,index) in dateArr" :key="index" :class="{active: index==1}">
<view class="date" v-for="(item,index) in dateArr[currentDay]" :key="index" :class="{active: index==1}">
<view class="week">{{ item.week }}</view> <view class="week">{{ item.week }}</view>
<view class="num">{{ item.num }}</view> <view class="num">{{ item.num }}</view>
</view> </view>
</view> </view>
<view class="icon right">
<view class="icon right" @click="changeDateIndex(1)">
<u-icon name="arrow-right" :size="12" :color="'#fff'"></u-icon> <u-icon name="arrow-right" :size="12" :color="'#fff'"></u-icon>
</view> </view>
</view> </view>
@ -68,18 +68,58 @@
export default { export default {
data() { data() {
return { 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: { 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) { changeStep(val) {
this.$emit('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;
} }
} }
} }

21
pages/mineEntry/personaInfo/personaInfo.vue

@ -5,7 +5,7 @@
<view class="card"> <view class="card">
<view class="row"> <view class="row">
<view class="lab">手机号</view> <view class="lab">手机号</view>
<view class="val">18267103167</view>
<view class="val">{{ vuex_userInfo.mobile }}</view>
</view> </view>
</view> </view>
@ -42,16 +42,33 @@
</view> </view>
</view> </view>
<view class="logout" @click="$goPage('/pages/userCenter/login/login')">退出登录</view>
<view class="logout" @click="logOutFn">退出登录</view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { logOut } from '@/config/api.js'
export default { export default {
methods: {
logOutFn() {
let _this = this
uni.showModal({
content: '确定要退出登录吗?',
success: async function (res) {
if (res.confirm) {
await logOut()
_this.$store.commit('goLogin')
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
} }
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

38
pages/tabbar/index/index.vue

@ -16,6 +16,7 @@
</view> </view>
</view> </view>
</u-navbar> --> </u-navbar> -->
<button @click="refereshFn">刷新token</button>
<view class="TopCon"> <view class="TopCon">
<view class="status_bar"></view> <view class="status_bar"></view>
<!-- 地址扫一扫 --> <!-- 地址扫一扫 -->
@ -39,7 +40,7 @@
<!-- 精钢区 --> <!-- 精钢区 -->
<view class="card traTop"> <view class="card traTop">
<view class="ul"> <view class="ul">
<view class="li" v-for="(item,index) in entrySection" :key="index" @click="goPageSection(item)">
<view class="li" v-for="(item,index) in entrySection" :key="index" @click="item.click(item)">
<view class="icon"> <view class="icon">
<image :src="item.icon" mode=""></image> <image :src="item.icon" mode=""></image>
</view> </view>
@ -123,26 +124,49 @@
entrySection: [{ entrySection: [{
text: '我要报名', text: '我要报名',
icon: require('../../../static/images/index/ic_baoming.png'), 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: '找驾校', text: '找驾校',
icon: require('../../../static/images/index/ic_jiaxiao.png'), 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: '找考场', text: '找考场',
icon: require('../../../static/images/index/ic_kaochang.png'), 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: '找陪练', text: '找陪练',
icon: require('../../../static/images/index/ic_peilian.png'), icon: require('../../../static/images/index/ic_peilian.png'),
click: (item)=>{
this.$u.toast('正在开发中,敬请期待...')
}
}, },
{ {
text: '理论学习', text: '理论学习',
icon: require('../../../static/images/index/ic_lilun.png'), 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: [{ moreSection: [{
@ -263,6 +287,10 @@
// } // }
}, },
methods: { methods: {
refereshFn() {
// this.$store.dispatch('refreshToken')
this.$store.dispatch('getUserInfo')
},
close() { close() {
}, },

2
pages/tabbar/mine/index.vue

@ -3,7 +3,7 @@
<!-- 学员名字 --> <!-- 学员名字 -->
<view class="top_row flex-b" @click="$goPage('/pages/mineEntry/personaInfo/personaInfo')"> <view class="top_row flex-b" @click="$goPage('/pages/mineEntry/personaInfo/personaInfo')">
<view class="flex"> <view class="flex">
<view class="userName">Hi大乔</view>
<view class="userName">Hi{{ vuex_userInfo.nickname?vuex_userInfo.nickname:vuex_userInfo.mobile}}</view>
<view class="arrowIcon"> <view class="arrowIcon">
<image src="../../../static/images/userCenter/ic_gengduo.png" mode=""></image> <image src="../../../static/images/userCenter/ic_gengduo.png" mode=""></image>
</view> </view>

5
pages/userCenter/login/loginByPhone.vue

@ -24,7 +24,7 @@
<view class="inputBox my"> <view class="inputBox my">
<u--input placeholder="请输入验证码" border="none" clearable style="height: 100%;" :clearable="false" v-model="FormData.code"></u--input> <u--input placeholder="请输入验证码" border="none" clearable style="height: 100%;" :clearable="false" v-model="FormData.code"></u--input>
</view> </view>
<view class="code" @tap='goSms' :class="{active: isPhone&&!codeOn}">{{codeText}}</view>
<view class="code" @click='goSms' :class="{active: isPhone&&!codeOn}">{{codeText}}</view>
</view> </view>
<view class="loginBtn" :class="{active: btnHighlight}" @click="submitFn"> </view> <view class="loginBtn" :class="{active: btnHighlight}" @click="submitFn"> </view>
<view style="margin-top: 40rpx;"> <view style="margin-top: 40rpx;">
@ -47,7 +47,8 @@
} }
}, },
onLoad() { onLoad() {
this.$store.dispatch('getUserInfo')
// this.$store.dispatch('getUserInfo')
}, },
computed: { computed: {
isPhone() { isPhone() {

BIN
static/images/index/ic_jsg.png

After

Width: 92  |  Height: 92  |  Size: 5.1 KiB

18
store/modules/user.js

@ -19,6 +19,14 @@ const user = {
update_vuex_userInfo(state, payload) { update_vuex_userInfo(state, payload) {
state.vuex_userInfo = payload state.vuex_userInfo = payload
uni.setStorageSync('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: { actions: {
@ -62,10 +70,18 @@ const user = {
commit('update_vuex_userInfo',res.data) commit('update_vuex_userInfo',res.data)
}, },
// 刷新token // 刷新token
async refreshToken({state}) {
async refreshToken({state, commit}) {
const http = uni.$u.http 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 let refreshToken = state.vuex_loginInfo.refreshToken
const res = await http.post('member/auth/refresh-token',{refreshToken}, config) 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
})
} }
} }
} }

Loading…
Cancel
Save