1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // const serverAddress = 'http://localhost:8099/store-api/';
- // const serverAddress = 'http://localhost:6060';
- // const serverAddress = 'http://192.168.0.206:6060';
- // const serverAddress = 'https://test-plateform.` uxianxin.com/home-api';
- const serverAddress = 'https://test-server.uxianxin.com:8888/api';
- const config = {
- // redirect_uri:'https://test-plateform.uxianxin.com/%23/pages/login/index',
- redirect_uri:'https://test-server.uxianxin.com:8888/%23/pages/login/index',
- }
- let bindToGlobal = (obj, key) => {
- if (typeof window[key] === 'undefined') {
- window[key] = {};
- }
- for (let i in obj) {
- window[key][i] = obj[i]
- }
- }
- bindToGlobal(config,'_const')
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
- // baseUrl: 'http://youanju.yajkj.com',
- baseUrl:serverAddress,
- dataType: 'json',
- loadingText: '请求中...', // 请求loading中的文字提示
- loadingTime: 100, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
- originalData: false, // 是否在拦截器中返回服务端的原始数据
- loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
- // header:{
- // 'Authorization': uni.getStorageSync("claims")
- // }
- });
- //新系统图片域名前缀
- Vue.prototype.$fileHost = 'http://fresh-life.oss-cn-shanghai.aliyuncs.com/'
- // 请求拦截,配置Token等参数
- Vue.prototype.$u.http.interceptor.request = (config) => {
- const token = uni.getStorageSync('token');
- const secret = uni.getStorageSync('secret');
- const claims = uni.getStorageSync("claims");
- config.header.token = token;
- config.header.secret = secret;
- config.header.Authorization = claims;
- Vue.prototype.$u.http.setConfig({
- showLoading: config.header.showLoading || false, // 是否显示请求中的loading
- });
- return config;
- }
- // 响应拦截,判断状态码是否通过
- Vue.prototype.$u.http.interceptor.response = (res) => {
- // console.log(JSON.stringify("------------"))
- // console.log(JSON.stringify(res))
- // console.log(res)
- if(res.code == 200) {
- // console.log("11111")
- return res;
- }else if(res.code == 401){
- // console.log("22222")
- uni.showToast({
- title:"登录过期,请重新登录",
- duration:1500, mask:false, icon:'none'
- });
- //此时应重新登录
- // console.log("goto--login")
- uni.navigateTo({
- url: '/pages/index/login'
- })
- return res;
- } else {
- // console.log("33333")
- uni.showToast({
- title: res.msg == null ? "出错了" : res.msg,
- duration:1500, mask:false, icon:'none'
- });
- return res;
- }
- }
- }
- export default {
- install,
- }
|