import baseurl from './baseurl.js' import { encrypt, decrypt } from '@/api/crypto.js' import { witch } from "@/api/witch"; var request = function(config) { if (uni.getStorageSync('openid')) { if (!config.header) { config.header = {} } config.header.openid = uni.getStorageSync('openid') config.header.appletType = '' } else { config.header = { appletType: '' } } if (witch == '1') { if (config.method == 'post' && config.url != '/applet/score/prizeExchange/approvalList') { config.data = encrypt(JSON.stringify(config.data)) } if (config.url == '/nurseApplet/chatRecord/updateReadStatus' || config.url == '/applet/register/editPrimaryAccountFlag') { config.data = encrypt(JSON.stringify(config.data)) } } 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: '' }); } return new Promise((resolve, rejected) => { uni.request({ url: baseurl + config.url, data: config.data, method: config.method, timeout: 60000, header: config.header, success(res) { uni.hideLoading(); if (witch == '1') { if (config.url != '/applet/score/prizeExchange/approvalList') { res.data = decrypt(res.data) res.data = JSON.parse(res.data) } } console.log(res.data) resolve(res.data) }, fail(err) { uni.hideLoading(); rejected(err) } }) }) } export default request