2024-08-22 09:48:00 +08:00
|
|
|
import tools from '@/toolJs/tools.js'
|
2024-05-02 15:59:36 +08:00
|
|
|
import store from '../store'
|
2024-12-14 09:42:21 +08:00
|
|
|
let baseUrl = "https://tc.pcxbc.com"
|
|
|
|
|
// let baseUrl = "https://tc.pcxbc.com/testedition"
|
2024-05-02 15:59:36 +08:00
|
|
|
const httpRequest = (url, method = "get", data) => {
|
|
|
|
|
let httpDefaultOpts = {
|
|
|
|
|
url: baseUrl + url,
|
|
|
|
|
data: data,
|
|
|
|
|
method: method,
|
|
|
|
|
header: {
|
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
2024-08-30 18:03:10 +08:00
|
|
|
'content-type': 'application/json; charset=UTF-8',
|
2024-05-02 15:59:36 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
let promise = new Promise(function(resolve, reject) {
|
|
|
|
|
uni.request(httpDefaultOpts).then(
|
|
|
|
|
(res) => {
|
|
|
|
|
uni.hideLoading()
|
2024-05-29 16:35:45 +08:00
|
|
|
if (res[1].data.code == 20001) {
|
2025-04-18 14:53:38 +08:00
|
|
|
uni.$emit('need-login');
|
2024-05-02 15:59:36 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (res[1].statusCode != 200) {
|
2024-05-29 16:35:45 +08:00
|
|
|
tools.msg(res[1].data.msg)
|
2024-05-02 15:59:36 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resolve(res[1].data)
|
|
|
|
|
}
|
|
|
|
|
).catch(
|
|
|
|
|
(response) => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
reject(response)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
return promise
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
const get = (url, data) => {
|
2024-11-12 15:38:28 +08:00
|
|
|
data.token = uni.getStorageSync('token')
|
|
|
|
|
data.aan_id = uni.getStorageSync('aan_id')
|
2025-04-18 14:53:38 +08:00
|
|
|
data.language = uni.getLocale() == 'zh-Hans' ? "zh" : uni.getLocale()
|
2024-05-02 15:59:36 +08:00
|
|
|
return httpRequest(url, 'get', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const post = (url, data) => {
|
2024-11-12 15:38:28 +08:00
|
|
|
data.token = uni.getStorageSync('token')
|
|
|
|
|
data.aan_id = uni.getStorageSync('aan_id')
|
2025-04-18 14:53:38 +08:00
|
|
|
data.language = uni.getLocale() == 'zh-Hans' ? "zh" : uni.getLocale()
|
2024-05-02 15:59:36 +08:00
|
|
|
return httpRequest(url, 'post', data)
|
|
|
|
|
}
|
|
|
|
|
export default {
|
|
|
|
|
baseUrl,
|
|
|
|
|
get,
|
|
|
|
|
post
|
|
|
|
|
}
|