赞
踩
export default {
//接口请求域名配置
baseUrl : 'https://xxxx.com'
}
import config from "./config.js" const headers = {} const url = {} url.request = async (url, params = {}, method, needDataSource = 0, needToken = false, needLoading = true) => { if (needLoading == true) { uni.showLoading({ title: '加载中', }) } if (needToken) { //登录时存储token uni.setStorageSync('token',data.accessToken) const Authorization = uni.getStorageSync('token') //请求头拼接 headers['Authorization'] = 'Bearer '+Authorization }else { delete headers['Authorization']; } switch (needDataSource) { case 0: headers['x-datasource'] = 'shtraining' break; case 1: headers['x-datasource'] = 'shtraining-lab' break; } let full_url = config.baseUrl + url; return await uni.request({ url: full_url, header: headers, data: params||{}, method: method, }).then(res => { uni.hideLoading() if (!res) { return 0; } console.log(res.data); return res.data; }).catch(parmas => { uni.hideLoading() switch (parmas.code) { case 401: uni.clearStorageSync() break default: uni.showToast({ title: parmas.message, icon: 'none' }) return Promise.reject() break } }) } //导出 export default url
// 获取用户信息
public_api.getUserInfo = params => url.request('/api/usercenter/userDetails',params,'GET',0,true)
// 获取展区
public_api.getLabel = params => url.request('/api/show/getLabel', params, 'POST',1)
// 获取展商
public_api.getContent = params => url.request('/api/getContentByChannelId',params,'GET',1)
...
import Vue from 'vue'
import request from './util/request.js'
import api from "./util/publicapi.js"
Vue.prototype.$api = api
this.$api.getUserInfo({}).then(res=>{
console.log(res,'用户信息')
if(res.code ==0){
let data = res.data
this.userInfo = {
id:data.id,
uname: data.username,
avatar:data.identificationPhotoDefault
}
uni.setStorageSync('userInfo',data)
}
})
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。