| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import Request from 'luch-request'
- // let baseURL='http://139.9.103.171:9091/'
- let baseURL='https://wuye.58fo.com/api/'
- const http = new Request()
- http.setConfig((config) => { /* 设置全局配置 */
- config.baseURL = baseURL /* 根域名不同 */
- config.header = {
- ...config.header,
- }
- return config
- })
- http.interceptors.request.use((config) => { /* 请求之前拦截器。可以使用async await 做异步操作 */
- config.header = {
- ...config.header,
- cookie: "access-token="+uni.getStorageSync("access-token")
- }
- return config
- }, (config) => {
- return Promise.reject(config)
- })
- http.interceptors.response.use(async (response) => { /* 请求之后拦截器。可以使用async await 做异步操作 */
- if(response.data.code=="401"){
- uni.showModal({
- title: "请登录",
- content: response.data.msg,
- showCancel: false,
- success: (res) => {
- if (res.confirm) {
- uni.reLaunch({
- url: "/pages/login/login",
- })
- }
- }
- })
- return;
- }
- return response.data
- }, (err) => { // 请求错误做点什么
- uni.showToast({
- icon: 'none',
- position: 'bottom',
- title: '网络异常'
- })
- return err
- })
- export {
- http
- }
|