123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const rootDocment = 'https://yhq-xcx.wenxingshuju.com' // 请求地址 - 生产环境
- // const rootDocment = 'http://39.106.149.78:10201' // 请求地址 - 测试环境
- const req = (url, method, data, selfHeader) => {
- const dataes = {
- 'user_id': uni.getStorageSync('user_id'),
- 'ttl': uni.getStorageSync('ttl'),
- 'sign': uni.getStorageSync('sign'),
- }
- const header = {
- 'sessionKey': uni.getStorageSync('session_key') ? uni.getStorageSync('session_key') : false
- }
- return new Promise((resolve, reject) => {
- uni.request({
- url:`${rootDocment}${url}`,
- data: data ? Object.assign(dataes, data) : dataes,
- method: method,
- header: selfHeader ? Object.assign(header, selfHeader) : header,
- success: function (res) {
- console.log('util::url => ', `${rootDocment}${url}`)
- console.log('util::success res => ', res)
- resolve(res)
- },
- fail: function (err) {
- console.log('util::url => ', `${rootDocment}${url}`)
- console.log('util::fail err => ', err)
- reject(err)
- }
- })
- })
- }
- const get = (url, data, header = {}) => {
- return req(url, 'GET', data, {
- ...header
- })
- }
- const post = (url, data, header = {}) => {
- return req(url, 'POST', data, {
- 'Content-Type': 'application/x-www-form-urlencoded',
- ...header,
- })
- }
- const postJSON = (url, data, header = {}) => {
- return req(url, 'POST', data, {
- 'Content-Type': 'application/json',
- ...header,
- })
- }
- export {
- req,
- rootDocment,
- get,
- post,
- postJSON,
- }
|