Files
dajiankang-uniapp/api/http.ts
PC-202306242200\Administrator 1c24452b6c first commit
2026-03-28 23:10:55 +08:00

69 lines
1.5 KiB
TypeScript

import { toast } from '@/utils/fun.js';
export const proxyObj = {
// 开发版
development: 'https://apidjk.jitujt.com',
// development: 'http://192.168.1.62:48080',
// development: 'http://192.168.1.191:48080',
// 正式版
production: 'https://apidjk.jitujt.com',
}
interface shortcutsType {
url : string
params : any
method : any
}
export const http = ({ url, params, method } : shortcutsType) => {
return new Promise((resolve, reject) => {
let Authorization : string = uni.getStorageSync('Authorization') || ''
let header = {
Authorization,
"Tenant-id": "134",
}
uni.request({
url: proxyObj[process.env.NODE_ENV || 'development'] + url,
data: params || {},
method: method || 'POST',
header: header,
success: (res : any) => {
const data = res.data
if (data.code == 401 || res.statusCode == 401) {
uni.removeStorageSync('Authorization');
uni.removeStorageSync('userInfo');
uni.showModal({
title: '提示',
content: `${Authorization ? '登录失效' : '你还未登录'},是否前往登录?`,
success: function (res) {
if (res.confirm) {
// uni.clearStorageSync();
uni.navigateTo({
url: '/pages/login/login'
})
} else if (res.cancel) {
uni.clearStorageSync();
console.log('用户点击取消');
}
}
});
reject(data)
return
}
if (data.code === 0) {
resolve(data.data || null)
} else {
toast(data.msg)
reject(data)
}
},
fail: (err) => {
reject(err)
}
})
});
};