123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { playAudio } from '@/libs/tools.js'
- module.exports = (vm) => {
-
- uni.$u.http.setConfig((config) => {
-
- config.baseURL = 'http://192.168.2.117/qpls-md';
-
-
- config.custom.auth = true
- return config
- })
-
-
- uni.$u.http.interceptors.request.use((config) => {
-
- config.data = config.data || {}
-
- if(config?.custom?.auth) {
-
- config.header['access-token'] = vm.$store.state.vuex_token
- }
-
- return config
- }, config => {
- return Promise.reject(config)
- })
-
-
- uni.$u.http.interceptors.response.use((response) => {
- const data = response.data
-
-
- const custom = response.config?.custom
- if (data.status != 200) {
-
- if (custom.toast !== false) {
- uni.$u.toast(data.message)
- playAudio("warn")
- }
-
- if (custom?.catch) {
- return Promise.reject(data)
- } else {
-
- return data
- }
- }
- return data === undefined ? {} : data
- }, (response) => {
-
- return Promise.reject(response)
- })
- }
|