xinelu-applet-ui/api/request.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-09-19 15:16:00 +08:00
import baseurl from './baseurl.js'
2024-06-25 18:25:50 +08:00
import {
encrypt,
decrypt
} from './crypto.js'
var witch = '1' //1加密 2不加密
2023-09-19 15:16:00 +08:00
var request = function(config) {
2024-04-18 15:00:46 +08:00
if (uni.getStorageSync('openid')) {
2024-04-18 15:11:38 +08:00
if (!config.header) {
config.header = {}
}
2024-04-18 15:00:46 +08:00
config.header.openid = uni.getStorageSync('openid')
2024-05-31 17:27:27 +08:00
config.header.appletType = ''
} else {
config.header = {
appletType: ''
}
2024-04-18 15:00:46 +08:00
}
2024-06-25 18:25:50 +08:00
if (witch == '1' && config.method == 'post' && config.url != '/applet/score/prizeExchange/approvalList') {
config.data = encrypt(JSON.stringify(config.data))
}
if (witch == '1' && config.url == '/nurseApplet/chatRecord/updateReadStatus' || config.url ==
'/applet/register/editPrimaryAccountFlag') {
config.data = encrypt(JSON.stringify(config.data))
}
2024-04-18 15:00:46 +08:00
const urls = config.url.split('?')[0]
if (config.url != '/nurseApplet/chatRecord/updateReadStatus' && config.url !=
"/nurseApplet/chatRecord/sendMessage" && config.url !=
`/applet/sign/apply/checkSignApply/` + uni.getStorageSync('userinfo').cardNo && urls !=
`/nurseApplet/chatRecord/getChatRecord` && urls != '/applet/register/wxSportDecrypt') {
uni.showLoading({
title: ''
});
}
2023-09-19 15:16:00 +08:00
return new Promise((resolve, rejected) => {
uni.request({
url: baseurl + config.url,
data: config.data,
method: config.method,
2023-10-12 09:47:40 +08:00
timeout: 60000,
2023-10-10 14:43:59 +08:00
header: config.header,
2023-09-19 15:16:00 +08:00
success(res) {
uni.hideLoading();
2024-06-25 18:25:50 +08:00
if (witch == '1') {
res.data = decrypt(res.data)
res.data = JSON.parse(res.data)
}
console.log(res.data)
2023-09-19 15:16:00 +08:00
resolve(res.data)
},
fail(err) {
uni.hideLoading();
rejected(err)
}
})
})
}
2023-11-01 14:30:45 +08:00
export default request