导游中台-游客端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

11 months ago
import Vue from 'vue'
import store from '@/store'
11 months ago
let NEWAPIURL = process.env.NODE_ENV == 'development' ? 'http://47.103.142.123:1010' : 'http://47.103.142.123:1010'
11 months ago
Vue.prototype.NEWAPIURL = NEWAPIURL
// #ifdef H5
11 months ago
NEWAPIURL = '/api'
11 months ago
// #endif
Vue.prototype.Post = (params, apiurl) => {
11 months ago
if (uni.getStorageSync('userInfo') && JSON.parse(uni.getStorageSync('userInfo')).token) params.merchants_token = JSON.parse(uni.getStorageSync('userInfo')).token
else if (store.state.user.userInfo.token) params.merchants_token = store.state.user.userInfo.token
11 months ago
return new Promise((resolve, reject) => {
uni.showLoading({
title: '加载中'
})
uni.request({
method: params.method || 'GET',
url: NEWAPIURL + apiurl,
data: params || {},
header: params.header || {
'content-type': 'application/json',
11 months ago
'merchants_token': params.merchants_token || ''
11 months ago
},
success: res => {
uni.hideLoading()
console.log('success', res.data)
if (res.data.code === 200 || res.data.code === 1) {
resolve(res.data)
} else {
setTimeout(() => {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
reject(null)
}, 0)
if (res.data.code === 401) {
store.commit('changeLoginPath')
}
}
},
fail: err => {
console.log('err', err)
uni.hideLoading()
setTimeout(() => {
uni.showToast({
title: err.msg || err.data.msg,
icon: 'none'
})
}, 0)
if (err.data.code === 401) {
store.commit('changeLoginPath')
}
reject(err)
}
})
})
}
export default NEWAPIURL