Browse Source

添加车辆

master
unknown 12 months ago
parent
commit
6ba84aa80d
  1. 60
      components/callPhone/callPhone.vue
  2. 8
      config/api.js
  3. 60
      config/request.js
  4. 11
      pages.json
  5. 63
      pages/recordEntry/operate/mySchedule/plan/plan.vue
  6. 2
      pages/tabbar/mine/index.vue
  7. 43
      pages/userCenter/examinInfo/comp/examinItem.vue
  8. 92
      pages/userCenter/examinInfo/examinInfo.vue
  9. 6
      pages/userCenter/myCar/comp/unbind.vue
  10. 43
      pages/userCenter/myCar/myCar.vue
  11. 138
      pages/userCenter/myCar/notBound/notBound.vue
  12. 37
      pages/userCenter/studentComment/studentComment.vue
  13. 39
      store/modules/user.js

60
components/callPhone/callPhone.vue

@ -0,0 +1,60 @@
<template>
<view class="box">
<view class="phoneIcon" @click.stop="phoneClick">
<slot></slot>
</view>
<u-action-sheet :actions="servicePhone" :show="show" @select="callPhoneClick" :closeOnClickOverlay="true" @close="show=false" cancelText="取消"></u-action-sheet>
</view>
</template>
<script>
export default {
// props: {
// servicePhone: {
// type: Array,
// default: []
// }
// },
props: ['servicePhone'],
data() {
return {
// servicePhone: [
// {name: '18267103167'},
// {name: '18267103168'},
// ],
show: false
}
},
methods: {
phoneClick() {
if(!this.servicePhone) return false
if(this.servicePhone.length==1) {
this.callPhoneClick(this.servicePhone[0])
}else {
show=true
}
},
callPhoneClick(item) {
let phone = item.name
// #ifdef MP-WEIXIN
this.$u.utils.callPhone(phone)
// #endif
// #ifdef H5
var a = document.createElement('a')
a.setAttribute('href', 'tel:'+ phone)
document.body.appendChild(a)
a.click()
console.log(phone)
// #endif
this.show =false
},
}
}
</script>
<style>
</style>

8
config/api.js

@ -66,6 +66,14 @@ export const schoolCommentPage = (params) => http.get('business/school-comment/p
export const updatePassword = (data) => http.put('system/user/profile/update-password', data)
// 获得考场分页
export const simulationPage = (params) => http.get('business/booking/simulation-record/page', {params})
// 获得考场列分页
export const businessSitePage = (params) => http.get('business/site/page', {params})
// 教练绑定教练车
export const coachBinding = (data) => http.post('business/coach/binding', data)
// 取消绑定教练车
export const coachUnbinding = (data) => http.put('business/coach/unbinding', data)

60
config/request.js

@ -1,9 +1,6 @@
import { H5_API, WX_API,httpPrefix } from './site.config.js'
import { checkToken } from './utils'
const ContentType = ['application/json;charset=utf-8', 'application/x-www-form-urlencoded','multipart/form-data', 'application/x-www-form-urlencoded; charset=UTF-8'];
@ -24,7 +21,6 @@ module.exports = (vm) => {
// 请求拦截
uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
console.log(config)
let contentTypeIndex = config.header.contentType
if(contentTypeIndex) {
// alert(contentTypeIndex)
@ -42,53 +38,23 @@ module.exports = (vm) => {
if(noToken&&config.header.Authorization) {
delete config.header.Authorization
}
// get请求映射params参数
// console.log(config.method)
// if (config.method === 'GET' && config.params) {
// // config.params = qs.stringify(config.params, { allowDots: true })
// let url = config.url + '?';
// for (const propName of Object.keys(config.params)) {
// const value = config.params[propName];
// const part = encodeURIComponent(propName) + '='
// if (value !== null && typeof(value) !== "undefined") {
// if (typeof value === 'object') {
// for (const key of Object.keys(value)) {
// let params = propName + '[' + key + ']';
// const subPart = params + '='
// console.log(qs.stringify(value[key]))
// url += subPart + decodeURIComponent(value[key]) + "&";
// }
// } else {
// url += part + encodeURI(value) + "&";
// }
// }
// }
// url = url.slice(0, -1);
// // console.log(url)
// config.params = {};
// config.url = url;
// }
return config
}, config => { // 可使用async await 做异步操作
return Promise.reject(config)
})
// 响应拦截
uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
uni.$u.http.interceptors.response.use(async (response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
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==406&&response.config.url!='system/auth/refresh-token') {
await vm.$store.dispatch('refreshToken')
let obj = response.config
let method = obj.method.toLowerCase()
if(method=='get') {
return uni.$u.http[method](obj.url, {params: obj.params})
}else{
return uni.$u.http[method](obj.url, obj.data )
}
}
if(data.code==401) {
vm.$store.commit('goLogin')
@ -110,11 +76,7 @@ module.exports = (vm) => {
return new Promise(() => { })
}
}
// 如果不需要token就把header里的token删除,并且不需要去刷新token
let noToken = response.config.custom?.noToken
if(!noToken) {
checkToken(vm)
}
return data === undefined ? {} : data
}, (response) => {
// 对响应错误做点什么 (statusCode !== 200)

11
pages.json

@ -300,7 +300,7 @@
"style": {
"navigationBarTitleText": "考场信息",
"navigationStyle": "custom",
"enablePullDownRefresh": false,
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
},
@ -314,6 +314,15 @@
}
},
{
"path": "myCar/notBound/notBound",
"style": {
"navigationBarTitleText": "未绑定车辆",
"navigationStyle": "custom",
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
},
{
"path": "teachingData/teachingData",
"style": {
"navigationBarTitleText": "教学数据",

63
pages/recordEntry/operate/mySchedule/plan/plan.vue

@ -55,9 +55,7 @@
<view class="time_row" v-for="(item,index) in currentMould.detailVO" :key="index">
<text>{{item.startTime}} <text>-</text> {{item.endTime}}</text> <text>{{item.personCount}}</text>
</view>
<!-- <view class="time_row">
<text>8:00-9:00</text> <text>4</text>
</view> -->
</view>
<view class="row">
<view class="lab">训练科目</view>
@ -65,10 +63,16 @@
<myRadio @changeRadio="changeRadioSubject" :radioData="radiolist1" :radioVal="{value: form.subject}"></myRadio>
</view>
</view>
<view class="row">
<view class="lab">教练车</view>
<view class="rightCon">
<myRadio @changeRadio="changeCarNumber" :radioData="radiolist2" :radioVal="{value: form.carNumber}"></myRadio>
<view class="lab">选择教练车</view>
<view class="rightCon" @click="showCar=true">
<view class="inputBox">
<input type="text" v-model="form.carNumber" placeholder="请选择" disabled style="pointer-events: none;">
</view>
<view class="icon">
<u-icon name="arrow-right" :size="12" :color="'#696B72'"></u-icon>
</view>
</view>
</view>
<view class="row">
@ -90,11 +94,12 @@
@cancel="show=false"
></u-datetime-picker>
<u-picker :show="showSite" :columns="siteColumns" keyName="name" @confirm="changeSite" @cancel="showSite=false" ></u-picker>
<u-picker :show="showCar" :columns="carColumns" keyName="licnum" @confirm="changeCarNumber" @cancel="showCar=false" ></u-picker>
</view>
</template>
<script>
import { scheduleClassCreate, getClassDateLimit, trainingSiteList, } from '@/config/api.js'
import { scheduleClassCreate, getClassDateLimit, trainingSiteList, carPage} from '@/config/api.js'
export default {
data() {
return {
@ -103,16 +108,24 @@
maxDate: null,
show: false,
showSite: false,
showCar: false,
form: {
classDate: '',
carNumber: '',
subject: 0, //:023
openRange: 1, //01
openRange: '1', //01
siteName: '',
siteId: ''
},
formToast: {
classBeginDate: '请选择开始时间',
classEndDate: '请选择结束时间',
siteId: '请选择场地',
carNumber: '请选择车辆',
},
currentMould: {},
siteColumns: [],
carColumns: [],
radiolist1: [{
name: '不限制',
id: 0,
@ -129,17 +142,7 @@
disabled: false
},
],
radiolist2: [{
name: '浙A8888',
id: '浙A8888',
disabled: false
},
{
name: '浙A8889',
id: '浙A8889',
disabled: false
},
],
radiolist3: [{
name: '我的学员',
id: 0,
@ -158,6 +161,7 @@
this.form.coachId = this.vuex_coachId
this.getClassDateLimitFn()
this.trainingSiteListFn()
this.carPageFn()
uni.$on('chooseMould',(item)=>{
this.form.templateId = item.id
this.currentMould = item
@ -172,10 +176,17 @@
},
//
changeCarNumber(val) {
this.form.carNumber = val
const item = val.value[0]
this.showCar = false
this.form.carNumber = item.licnum
// console.log()
},
//
async scheduleClassCreateFn() {
for(let k in this.formToast) {
if(!this.form[k])
return this.$u.toast(this.formToast[k])
}
console.log(this.form)
const res = await scheduleClassCreate(this.form)
if(res.code==0) {
@ -230,7 +241,17 @@
const {data: res} = await getClassDateLimit(obj)
this.minDate = new Date(res.beginDateLimit)*1 + 86400000
this.maxDate = new Date(res.endDateLimit)*1
}
},
async carPageFn() {
let obj = {
pageNo: 1,
pageSize: 40,
schoolId: this.vuex_schoolId,
coachId: this.vuex_coachId
}
const {data: res} = await carPage(obj)
this.carColumns = [res.list]
},
}
}

2
pages/tabbar/mine/index.vue

@ -43,7 +43,7 @@
}
},
onLoad() {
this.$store.dispatch('refreshToken')
// this.$store.dispatch('refreshToken')
this.initMenu()
this.roleListFn()
},

43
pages/userCenter/examinInfo/comp/examinItem.vue

@ -2,33 +2,31 @@
<view class="li" @click="$goPage('/pages/indexEntry/examines/detail/detail')">
<view class="flex">
<view class="cover">
<image src="@/static/images/logo.png" mode=""></image>
<image :src="item.background" mode=""></image>
</view>
<view class="textCon">
<view class="name">江西海正驾校</view>
<view class="starBox">
<u-rate active-color="#1989FA" inactive-color="#1989FA" gutter="1" :size="16" :value="4" disabled></u-rate>
<view class="num">4.9</view>
</view>
<view class="modeCar">准考车型C1/C2</view>
</view>
<view class="pozPhone">
<image src="@/static/images/index/telephone.png" mode=""></image>
<view class="name oneRowText">{{ item.name }}</view>
<!-- <view class="starBox">
<u-rate active-color="#1989FA" inactive-color="#1989FA" gutter="1" :size="16" :value="item.star" readonly></u-rate>
<view class="num">没有返回字段</view>
</view> -->
<view class="modeCar">准考车型{{item.carType}}</view>
</view>
<callPhone :servicePhone="[item.phone]">
<view class="pozPhone">
<image src="@/static/images/index/telephone.png" mode=""></image>
</view>
</callPhone>
</view>
<view class="redBox">
<!-- <view class="icon">
<image src="@/static/images/index/ic_tongzhi.png" mode=""></image>
</view> -->
<!-- <view class="marqueeW"> -->
<u-notice-bar :text="'免费开放日免费开放日免费开放日免费开放日2023/08/08'" bgColor="#FBE8EA" color="#C12727" fontSize="12"></u-notice-bar>
<!-- </view> -->
<view class="redBox"v-if="item.notification&&item.notification.length">
<u-notice-bar :text="item.notification" bgColor="#FBE8EA" color="#C12727" fontSize="12"></u-notice-bar>
</view>
</view>
</template>
<script>
export default {
props: ['item'],
data() {
return {
text1: '免费开放日:2023/08/08 '
@ -38,6 +36,9 @@
</script>
<style lang="scss" scoped>
/deep/.redBox .u-notice__content__text{
line-height: 24rpx !important;
}
.flex {
position: relative;
.cover {
@ -50,9 +51,11 @@
.textCon {
flex: 1;
padding: 0 0 0 36rpx;
width: 0;
.name {
font-size: 32rpx;
font-weight: 600;
margin-bottom: 32rpx;
}
.starBox {
@ -67,11 +70,11 @@
.pozPhone {
position: absolute;
top: 50%;
right: 10rpx;
bottom: 0rpx;
right: 0rpx;
width: 72rpx;
height: 72rpx;
transform: translateY(-50%);
// transform: translateY(-50%);
}
}
.redBox {

92
pages/userCenter/examinInfo/examinInfo.vue

@ -1,50 +1,108 @@
<template>
<view class="pageBgImg">
<topNavbar title="考场信息"></topNavbar>
<view class="pad">
<view class="searchBox">
<searchRow placeholder="搜索考场名称"></searchRow>
</view>
<view class="tabs">
<view class="tab" v-for="(item,index) in tabData" :key="index" :class="{active: index==1}">{{ item.text }}</view>
<view class="main pageBg">
<view class="topBg">
<topNavbar title="考场信息"></topNavbar>
<view class="pad">
<view class="searchBox">
<searchRow placeholder="搜索考场名称" @searchFn="searchFn"></searchRow>
</view>
<view class="tabs">
<view class="tab" v-for="(item,index) in tabData" :key="index" :class="{active: params.siteType==item.id}" @click="changeTab(item)">{{ item.text }}</view>
</view>
</view>
</view>
<view class="pad" style="margin-top: 20rpx;">
<view class="list">
<view class="card">
<examinItem/>
<view class="card" v-for="(item,index) in list" :key="index">
<examinItem :item="item"/>
</view>
</view>
<view style="padding-bottom: 20rpx;" v-if="list.length">
<u-loadmore :status="status" />
</view>
<nodata v-if="!list.length&&status=='nomore'"></nodata>
</view>
</view>
</template>
<script>
import examinItem from './comp/examinItem'
import { businessSitePage } from '@/config/api.js'
export default {
components: { examinItem },
data() {
return {
tabData: [
{text: '全部', id: 1},
{text: '理论', id: 2},
{text: '科目二', id: 3},
{text: '科目三', id: 4},
]
{text: '全部', id: 0},
{text: '理论', id: 1},
{text: '科目二', id: 2},
{text: '科目三', id: 3},
],
params: {
pageSize: 20,
pageNo: 1,
schoolId: '',
siteType: '',//1. 2. 3. 4./
},
total: 20,
list: [],
status: 'loading'
}
},
onLoad() {
this.params.schoolId = this.vuex_schoolId
this.businessSitePageFn()
},
onPullDownRefresh() {
this.initList()
},
onReachBottom() {
if(this.total>this.list.length) this.businessSitePageFn()
},
methods: {
initList() {
this.params.pageNo = 1
this.list = []
this.status = 'loading'
this.businessSitePageFn()
},
async businessSitePageFn() {
let obj = Object.assign({},this.params)
const {data: res} = await businessSitePage(obj)
this.params.pageNo ++
this.list.push(...res.list)
this.total = res.total
if(this.list.length>=this.total) {
this.status = 'nomore'
}
},
searchFn(val) {
this.params.name = val
this.initList()
},
changeTab(item) {
this.params.siteType = item.id
this.initList()
}
}
}
</script>
<style lang="scss" scoped>
.topBg {
background: #1989fa;
}
.card {
padding: 32rpx 36rpx 26rpx 24rpx;
margin-bottom: 20rpx;
}
.searchBox {
padding: 20rpx 0;
padding: 20rpx 0 0rpx 0;
}
.tabs {
display: flex;
justify-content: space-between;
height: 110rpx;
height: 120rpx;
align-items: center;
.tab {
font-size: 28rpx;

6
pages/userCenter/myCar/comp/unbind.vue

@ -2,6 +2,7 @@
<view>
<u-swipe-action>
<u-swipe-action-item
@click="cancelBind"
:options="options1"
>
<slot></slot>
@ -24,6 +25,11 @@
}]
};
},
methods: {
cancelBind(val) {
this.$emit('cancelBind')
}
}
};
</script>

43
pages/userCenter/myCar/myCar.vue

@ -3,17 +3,17 @@
<topNavbar title="我的车辆"></topNavbar>
<view class="pad">
<view class="searcBox">
<searchRow placeholder="搜索车牌号" @searchFn="searchFn"></searchRow>
<searchRow placeholder="搜索车牌号" @searchFn="searchFn" ref="searchRef"></searchRow>
</view>
<!-- <view class="card" style="margin-bottom: 24rpx;">
<view class="card" style="margin-bottom: 24rpx;">
<view class="add">
<view class="lab">新增车辆</view>
<view class="btnBg">立即新增</view>
<view class="btnBg" @click="$goPage('/pages/userCenter/myCar/notBound/notBound')">立即新增</view>
</view>
</view> -->
</view>
<view class="ul">
<view class="card" v-for="(item,index) in list" :key="index">
<unbind v-if="identity== '实操教练'">
<unbind v-if="identity== '实操教练'" @cancelBind="cancelBind(item)">
<view class="li" >
<view class="plate">{{item.licnum}}</view>
<view class="name">{{item.manufacturer}}</view>
@ -34,7 +34,7 @@
</template>
<script>
import { carPage } from '@/config/api.js'
import { carPage, coachUnbinding } from '@/config/api.js'
import unbind from './comp/unbind.vue'
export default {
components: {
@ -53,16 +53,18 @@
},
onLoad() {
this.params.schoolId = this.vuex_schoolId
if(identity== '实操教练') {
if(this.identity== '实操教练') {
this.params.coachId = this.vuex_coachId
}
this.carPageFn()
},
onShow() {
if(this.params.licnum) this.$refs.searchRef.keyword = ''
this.params.licnum = ''
this.listInit()
},
onPullDownRefresh() {
this.list = []
this.params.pageNo = 1
this.carPageFn().then(()=>{uni.stopPullDownRefresh()})
this.listInit().then(()=>{uni.stopPullDownRefresh()})
},
onReachBottom() {
if(this.total>this.list.length) {
@ -70,6 +72,11 @@
}
},
methods: {
async listInit() {
this.list = []
this.params.pageNo = 1
await this.carPageFn()
},
async carPageFn() {
const {data: res} = await carPage(this.params)
this.params.pageNo ++
@ -84,8 +91,20 @@
this.list = []
this.params.pageNo = 1
this.carPageFn()
},
//
async cancelBind(item) {
let obj = {
"carId": item.id,
"coachId": this.vuex_coachId,
"coachName": this.vuex_userInfo.user.nickname
}
const res = await coachUnbinding(obj)
if(res.code==0) {
this.$u.toast('解绑成功')
this.listInit()
}
}
}
}
</script>

138
pages/userCenter/myCar/notBound/notBound.vue

@ -0,0 +1,138 @@
<template>
<view class="pageBgImg">
<topNavbar title="未绑定的车辆"></topNavbar>
<view class="pad">
<view class="searcBox">
<searchRow placeholder="搜索车牌号" @searchFn="searchFn"></searchRow>
</view>
<view class="ul">
<view class="card" v-for="(item,index) in list" :key="index">
<view class="name">车牌号{{item.licnum}}</view>
<view class="text">车辆型号{{item.manufacturer}}</view>
<view class="flex-b">
<view class="text">培训车型{{item.perdritype}}</view>
<view class="btnBg" @click="bindClick(item)">立即绑定</view>
</view>
</view>
</view>
<view style="padding-bottom: 20rpx;" v-if="list.length">
<u-loadmore :status="status" />
</view>
<nodata v-if="!list.length&&status=='nomore'"></nodata>
</view>
</view>
</template>
<script>
import { carPage, coachBinding } from '@/config/api.js'
export default {
data() {
return {
list: [],
params: {
pageNo: 1,
pageSize: 20,
coachId: 0
},
total: 20,
status: 'loading'
}
},
onLoad() {
this.params.schoolId = this.vuex_schoolId
this.carPageFn()
},
onPullDownRefresh() {
this.list = []
this.params.pageNo = 1
this.carPageFn().then(()=>{uni.stopPullDownRefresh()})
},
onReachBottom() {
if(this.total>this.list.length) {
this.carPageFn()
}
},
methods: {
async carPageFn() {
const {data: res} = await carPage(this.params)
this.params.pageNo ++
this.list.push(...res.list)
this.total = res.total
if(this.list.length>=this.total) this.status = 'nomore'
console.log(res)
},
searchFn(val) {
console.log(val)
this.params.licnum = val
this.list = []
this.params.pageNo = 1
this.carPageFn()
},
async coachBindingFn(item) {
let obj = {
"carId": item.id,
"coachId": this.vuex_coachId,
"coachName": this.vuex_userInfo.user.nickname
}
const res = await coachBinding(obj)
if(res.code==0) {
this.$u.toast('绑定成功')
setTimeout(()=>{
uni.navigateBack()
}, 1500)
}
console.log(res)
},
bindClick(item) {
let title = `确定要将 ${item.licnum} 教练车绑定到您的名下吗?`
let _this = this
uni.showModal({
title,
success: function(res) {
if (res.confirm) {
_this.coachBindingFn(item)
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
}
}
</script>
<style lang="scss" scoped>
.ul {
padding-top: 20rpx;
.card {
padding: 20rpx;
margin-bottom: 20rpx;
.name {
font-size: 28rpx;
font-weight: 550;
color: $themC;
}
.text {
margin-top: 16rpx;
font-size: 26rpx;
color: #333;
}
.flex-b {
.text {
}
.btnBg {
height: 60rpx;
line-height: 60rpx;
padding: 0 28rpx;
}
}
}
}
</style>

37
pages/userCenter/studentComment/studentComment.vue

@ -3,10 +3,10 @@
<topNavbar title="学员评价"></topNavbar>
<view class="pad">
<view class="searchBox">
<searchRow placeholder="搜索学员姓名"></searchRow>
<searchRow placeholder="搜索学员姓名" @searchFn="searchFn"></searchRow>
</view>
<view class="tabs">
<view class="tab" :class="{active: this.params.condition==0}" @click="changeTab(0)">全部0</view>
<view class="tab" :class="{active: this.params.condition==0}" @click="changeTab(0)">全部缺字段</view>
<view class="tab" :class="{active: this.params.condition==1}" @click="changeTab(1)">匿名1</view>
<view class="tab" :class="{active: this.params.condition==2}" @click="changeTab(2)">有图2</view>
<view class="tab" :class="{active: this.params.condition==3}" @click="changeTab(3)">有视频3</view>
@ -16,6 +16,11 @@
<commentItem :item="item" />
</view>
</view>
<view style="padding-bottom: 20rpx;" v-if="list.length">
<u-loadmore :status="status" />
</view>
<nodata v-if="!list.length&&status=='nomore'"></nodata>
</view>
</view>
</template>
@ -26,17 +31,12 @@
data() {
return {
list: [],
tabData: [
{id: 0, lab: '全部'},
{id: 1, lab: '有图'},
{id: 2, lab: '匿名'},
{id: 3, lab: '有视频'},
],
params: {
pageNo: 1,
pageSize: 20,
schoolId: '1590992062959960065',
condition: 0
schoolId: '',
condition: 0,
studentName: ''
},
// 0 1 2 3
total: 20,
@ -58,6 +58,10 @@
}
},
methods: {
searchFn(val) {
this.params.studentName = val
this.initList()
},
changeTab(val) {
this.params.condition = val
this.initList()
@ -65,13 +69,16 @@
initList() {
this.list = []
this.params.pageNo = 1
this.status = 'loading'
this.schoolCommentPageFn()
},
async schoolCommentPageFn() {
if(this.identity=='校长') {
var {data: res} = await schoolCommentPage(this.params)
}else {
var {data: res} = await coachCommentPage(this.params)
let obj = Object.assign({},this.params)
obj.coachId = this.vuex_coachId
var {data: res} = await coachCommentPage(obj)
}
this.params.pageNo ++
let arr = res.list.map(item=>{
@ -89,13 +96,7 @@
}
console.log(res)
},
searchFn(val) {
console.log(val)
this.params.name = val
this.list = []
this.params.pageNo = 1
this.schoolCommentPageFn()
}
}
}
</script>

39
store/modules/user.js

@ -14,7 +14,8 @@ const user = {
coach: '实操教练',
examSiteCoach: '考场模拟教练',
bookingSimulationTeacher: '模拟器老师'
}
},
apiOk: true
},
mutations: {
// 更新用户身份
@ -42,6 +43,9 @@ const user = {
return config
})
},
update_apiOk(state, payload) {
state.apiOk = payload
},
goLogin(state) {
uni.clearStorageSync()
state.vuex_loginInfo = {}
@ -62,16 +66,29 @@ const user = {
},
// 刷新token
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('system/auth/refresh-token?refreshToken='+ 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
return new Promise(async(resolve, reject)=>{
if(!state.apiOk) {
return state.refreshTokenFn
}
commit('update_apiOk',false)
state.refreshTokenFn = null
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
state.refreshTokenFn = await http.post('system/auth/refresh-token?refreshToken='+ refreshToken, config)
if(state.refreshTokenFn.data||state.refreshTokenFn.data.accessToken) {
commit('update_apiOk',true)
commit('update_vuex_loginInfo',state.refreshTokenFn.data)
uni.$u.http.setConfig((config) => {
config.header.Authorization = 'Bearer ' + state.refreshTokenFn.data.accessToken
return config
})
resolve(state.refreshTokenFn)
}else {
commit('update_apiOk',true)
commit('goLogin')
reject('刷新token失败了')
}
})
},
getCity({commit}) {

Loading…
Cancel
Save