You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
5.0 KiB
181 lines
5.0 KiB
|
|
import addApi from '../../common/sdk/qqmap-wx-jssdk.min.js'; // 引入
|
|
|
|
const user = {
|
|
state: {
|
|
identity: uni.getStorageSync('identity')?uni.getStorageSync('identity'):1,
|
|
vuex_cityInfo: uni.getStorageSync('vuex_cityInfo') ? uni.getStorageSync('vuex_cityInfo') : {city: '杭州市'},
|
|
vuex_userInfo: uni.getStorageSync('vuex_userInfo') ? uni.getStorageSync('vuex_userInfo') : {user:{}},
|
|
vuex_loginInfo: uni.getStorageSync('vuex_loginInfo') ? uni.getStorageSync('vuex_loginInfo') : {},
|
|
vuex_TenantId: uni.getStorageSync('vuex_TenantId') ? uni.getStorageSync('vuex_TenantId') : '',
|
|
vuex_role: {
|
|
// schoolManager
|
|
manager: '校长',
|
|
schoolFinance: '驾校财务',
|
|
coach: '实操教练',
|
|
examSiteCoach: '考场模拟教练',
|
|
bookingSimulationTeacher: '模拟器老师'
|
|
},
|
|
apiOk: true
|
|
},
|
|
mutations: {
|
|
// 更新用户身份
|
|
upDateIdentity(state, val) {
|
|
state.identity = val
|
|
uni.setStorageSync('identity', val);
|
|
},
|
|
update_vuex_cityInfo(state, payload) {
|
|
state.vuex_cityInfo = payload
|
|
uni.setStorageSync('vuex_cityInfo', payload);
|
|
},
|
|
update_vuex_loginInfo(state, payload) {
|
|
state.vuex_loginInfo = payload
|
|
uni.setStorageSync('vuex_loginInfo', payload);
|
|
},
|
|
update_vuex_userInfo(state, payload) {
|
|
state.vuex_userInfo = payload
|
|
uni.setStorageSync('vuex_userInfo', payload);
|
|
},
|
|
upDateTenantId(state, val) {
|
|
state.vuex_TenantId = val
|
|
uni.setStorageSync('vuex_TenantId', val);
|
|
uni.$u.http.setConfig((config) => {
|
|
config.header['tenant-id'] = val
|
|
return config
|
|
})
|
|
},
|
|
update_apiOk(state, payload) {
|
|
state.apiOk = payload
|
|
},
|
|
goLogin(state) {
|
|
uni.clearStorageSync()
|
|
state.vuex_loginInfo = {}
|
|
state.vuex_userInfo = {}
|
|
state.vuex_TenantId = ''
|
|
uni.navigateTo({
|
|
url: '/pages/login/login'
|
|
})
|
|
}
|
|
},
|
|
actions: {
|
|
// 获取用户信息
|
|
async getUserInfo({commit}) {
|
|
const http = uni.$u.http
|
|
let config = { custom: { auth: false }, header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'} }
|
|
const res = await http.get('system/auth/get-permission-info-app',config)
|
|
commit('update_vuex_userInfo',res.data)
|
|
},
|
|
// 刷新token
|
|
async refreshToken({state, commit}) {
|
|
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}) {
|
|
return new Promise((resolve, reject) => {
|
|
// #ifdef APP-PLUS||H5
|
|
getCityInfo(resolve, reject,commit)
|
|
// #endif
|
|
// #ifdef MP-WEIXIN
|
|
uni.authorize({
|
|
scope: 'scope.userLocation',
|
|
success() {
|
|
getCityInfo(resolve, reject,commit)
|
|
},
|
|
fail: function(res4) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '小程序想要获取您的地里位置',
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
uni.openSetting({
|
|
success(res) {
|
|
getCityInfo(resolve, reject,commit)
|
|
}
|
|
});
|
|
} else if (res.cancel) {
|
|
console.log('用户点击取消');
|
|
}
|
|
}
|
|
})
|
|
},
|
|
})
|
|
// #endif
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
function getCityInfo(resolve, reject, commit) {
|
|
uni.showLoading({
|
|
title: '加载中...'
|
|
})
|
|
var qqmapKey = new qqmapWx({
|
|
key: '2BTBZ-6BQRB-ZG4UG-NOYYG-KZMH7-B4BYN'
|
|
})
|
|
uni.getLocation({
|
|
type: 'wgs84',
|
|
// type: 'gcj02',
|
|
success: function(res) {
|
|
console.log('当前位置的经度:' + res.longitude);
|
|
console.log('当前位置的纬度:' + res.latitude);
|
|
qqmapKey.reverseGeocoder({
|
|
location: {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude
|
|
},
|
|
success(res2) {
|
|
// console.log('城市信息')
|
|
// console.log(res2.result)
|
|
let result = res2.result
|
|
let obj = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
city: result.address_component.city,
|
|
cityCode: result.ad_info.adcode,
|
|
province: result.address_component.province,
|
|
district: result.address_component.district
|
|
}
|
|
commit('update_vuex_cityInfo', obj)
|
|
resolve(obj)
|
|
uni.hideLoading();
|
|
|
|
},
|
|
fail: function(res3) {
|
|
reject(res3)
|
|
uni.hideLoading();
|
|
},
|
|
})
|
|
},
|
|
fail(e) {
|
|
console.log(e)
|
|
}
|
|
})
|
|
}
|
|
export default user
|
|
|
|
|
|
|
|
|
|
|