caiyunyi/utils/api.js
ylj20011123 5d8cf4605f update
2025-07-07 20:02:40 +08:00

170 lines
4.9 KiB
JavaScript

import Store from '../store/index.js'
import { encryptAES } from './handleAes.js'
// 静态图片地址
let url = 'https://gsyw.eshangtech.com/MobileServicePlatform/Handler/handler_ajax.ashx' // 移动业务请求路由
let coopUrl = 'https://mp.eshangtech.com/Coop.Merchant/Handler/handler_ajax.ashx' // 合作商户请求路由
let mpUrl = 'https://eshangtech.com/Coop.Merchant/Handler/handler_ajax.ashx' // 合作商户请求路由
let webUrl = 'https://api.eshangtech.com' // webapi
// let webUrl = 'http://192.168.10.125:8900/' // webapi
let staticImagePath = 'https://eshangtech.com/ShopICO'
// let nodeUrl = 'https://es.robot-z.cn'
let nodeUrl = 'https://es.eshangtech.com'
let javaUrl = `https://admin.es.eshangtech.com/platform`
let zzyLocal = `https://api.eshangtech.com/MemberApi`
// let javaUrl = `http://10.104.1.175:8070/platform`
let type = uni.getSystemInfoSync();
let loginType = ''
if (type.platform === "android" && type.uniPlatform === "app") {
loginType = "android"
} else if (type.uniPlatform === "mp-weixin") {
loginType = "min"
}
const api = {
url: url,
staticImagePath,
request(method, data, control, isWebApi) {
if (method === 'POST') {
uni.showLoading({
title: '加载中...',
mask: true
})
}
return new Promise((resolve, reject) => {
// uni.getAccountInfoSync().miniProgram.appId
data.appId = data.appId || 'wxee018fb96955552a' // 'wx4c497eddcec4a0e7'
data.weChatAppId = data.appId || 'wxee018fb96955552a' // 'wx4c497eddcec4a0e7'
data.wechatAppAppId = data.appId || 'wxee018fb96955552a' // 'wx4c497eddcec4a0e7'
data.ownerUnitId = '911'
data.Membership_Id = Store.getters.user.MEMBERSHIP_ID || Store.getters.user.MemberShipID || data.MEMBERSHIP_ID || ''
data.MembershipId = Store.getters.user.MEMBERSHIP_ID || Store.getters.user.MemberShipID || data.MEMBERSHIP_ID || ''
if (data.type === 'encryption') {
}
let requstOptions = {
url: isWebApi ? this.url + control : this.url,
data: data.type === 'encryption' ? {
name: "",
value: encryptAES(JSON.stringify(data))
} : data.type === 'encryption1' ? {
postData: encryptAES(JSON.stringify(data))
} : data,
method: method
}
if (method === 'POST') {
if (data.requestType === 'application/x-www-form-urlencoded') {
requstOptions.header = {
'content-type': 'application/x-www-form-urlencoded'
}
} else {
requstOptions.header = {
'content-type': 'application/json'
// application/json
}
}
}
requstOptions.success = function (res) {
// success
if (res.statusCode !== 200 && res.statusCode !== 201) {
uni.hideLoading()
uni.showToast({
title: '网络出错,稍后再试',
icon: 'none'
})
return false
}
if (method === 'POST') {
uni.hideLoading()
if (res.data.ResultCode !== '999' && res.data.ResultCode !== '100') {
if (res.data.ResultDesc) {
// uni.showModal({
// title: '温馨提示',
// content: res.data.ResultDesc,
// showCancel: false,
// confirmText: '确定',
// confirmColor: '#3CC51F'
// })
}
}
}
uni.hideLoading()
resolve(res.data)
}
requstOptions.fail = function (error) {
// fail
if (method === 'POST') {
uni.hideLoading()
}
reject(error) // 请求失败
return false
}
requstOptions.complete = function () {
// complete
if (method === 'POST') {
uni.hideLoading()
}
}
uni.request(requstOptions)
})
},
getCoop(data) {
this.url = coopUrl
return this.request('GET', data)
},
postCoop(data) {
this.url = coopUrl
return this.request('POST', data)
},
mpPost(data) {
this.url = mpUrl
return this.request('POST', data)
},
$get(control, data) {
this.url = webUrl
return this.request('GET', data, control, true)
},
$post(control, data) {
this.url = webUrl
return this.request('POST', data, control, true)
},
$postNode(control, data) {
this.url = nodeUrl
return this.request('POST', data, control, true)
},
$javaGet(control, data) {
this.url = javaUrl
return this.request('GET', data, control, true)
},
$javaPost(control, data) {
this.url = javaUrl
return this.request('POST', data, control, true)
},
$zzyLocalPost(control, data) {
this.url = zzyLocal
return this.request('POST', data, control, true)
},
$zzyLocalGet(control, data) {
this.url = zzyLocal
return this.request('GET', data, control, true)
},
}
export default api // 暴露出来供其他文件引用