import Vue from 'vue' import $store from '@/store' import $config from '@/config' import uni_request from './uni_request.js' /* 线上appid wxd684a5cf4af0a810 线上接口地址 http://api.woaidakele.cn *** index 页面中跳转的url 对应页面 每次上线之前查看 onLoad 中是否注释判断pifashang才能注释的代码 */ // const host = 'http://fuzai.woaidakele.cn' //测试 const host = 'http://api.app.cliu.cc' //正式环境 // const host = 'http://app.jiuweiyun.cn' //App测 // const host = 'http://test.woaidakele.cn' //测试环境 const port = 80 //正式环境 // const port =8081 //测 const url = '/api' // uni.onNetworkStatusChange(res => { $store.commit('device/NETWORKTYPE_CHANGE', res.networkType) }) // 网络类型变化监听 // uni.getNetworkType({ success(res) { $store.commit('device/NETWORKTYPE_CHANGE', res.networkType) }}) // 获取网络类型 const request = uni_request({ timeout: 123456, baseURL: `${host}:${port}${url}`, }) request.interceptors.request.use(config => { config.header.Authorization = 'Bearer ' + $store.state.app.token config.header.helper = $store.state.app.helper return config }) request.interceptors.response.use((response, ...args) => { // 拦截器 uni.hideLoading() uni.$emit('HIDELOADING') // 隐藏加载 uni.stopPullDownRefresh() // 停止下拉刷新 if (response.data.code == 451101) { // 助手请求验证 uni.showModal({ content: response.data.message || '操作失败', showCancel: false, success: function (res) { if (res.confirm) { $store.commit('app/LOGOUT') toWxchatLogin("/pages/login-reg/login-reg", null) uni.removeStorageSync('isHelper') } } }) return } if (response.statusCode === 200) { if (+response.data.code === 202) { uni.$emit('TOAST', response.data.message) } } else if (response.statusCode === 401) { // 服务器响应不为 200 的统一处理方法 uni.showModal({ content: '登录状态过期,请重新登录', showCancel: false, success: function (e) { if (e.confirm) { $store.commit('app/LOGOUT') toWxchatLogin("/pages/login-reg/login-reg", null) } } }) return uni.$emit('TOAST', '登录信息过期,请重新登录') uni.$emit('RELAUNCH') } else { uni.$emit('TOAST', `网络好像出了点问题:${response.statusCode}/${args[1]}`) } return response }) request.onerror = (...args) => { // 请求失败统一处理方法 uni.hideLoading() uni.$emit('HIDELOADING') // 隐藏加载 uni.stopPullDownRefresh() // 停止下拉刷新 // uni.$emit('TOAST', `网络好像出了点问题`) } function toWxchatLogin(url, state) { url = url || '/pages/index/index'; state = state || 'cli'; const redirect_uri = encodeURIComponent(`${$config.redirect_uri}/api/gzh#${url}`); const auth = () => (window.location.href = `${$config.wxURL}?appid=${ $config.appid }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`); auth(); }; export const AddQrCode = `${host}:${port}${url}/AddQrCode` //邀请客户链接(线下注册) export const AddQrCodeUp = `${host}:${port}${url}/AddQrCodeUp` //邀请客户链接(微店注册) export const QYInfo = `${host}:${port}${url}/QYInfo/Pdf` //获取合同详情 export default request export const FlashScreenUrl = 'https://api.jiuweiyun.cn/public/uploads/images/topics/420.jpg' // app 闪屏固定url export const ArticleURL = `${host}:${port}${url}/article/show_article` // 文章固定链接 export const UploadApplyImgUrl = `${host}:${port}${url}/apply/UploadApplyImg` //客户升降级上传图片 export const uploadCollectionImg = `${host}:${port}${url}/sharon/sharon/uploadCollectionImg` //沙龙添加收款图片 export const uploadSharonImg = `${host}:${port}${url}/sharon/sharon/uploadSharonImg` //添加沙龙图片 export const hostUrl = `${host}:${port}${url}` //添加沙龙图片 export const uploadFiveImage = `${host}:${port}${url}/team/uploadFiveImage` //上传申请人零售的收款凭证 export const UploadSzyImg = `${host}:${port}${url}/HuiFuSZ/ImageEnroll` //实战营人脸照片上传