mobileclient/api2_0.js

260 lines
6.6 KiB
JavaScript
Raw Normal View History

2024-02-29 15:11:26 +08:00
let baseurl = "http://192.168.6.75"
let pathname = window.location.host
2023-06-28 10:39:06 +08:00
function global_dev_fun(hots) {
2024-02-29 15:11:26 +08:00
if (hots.includes("test")) {
baseurl = "http://192.168.6.75"
return
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
if (hots.includes("pre")) {
baseurl = "http://pre.marketapi.1688sup.com"
return
2023-06-28 10:39:06 +08:00
}
if (
2024-02-29 15:11:26 +08:00
hots.includes("1688sup") ||
hots.includes("83323") ||
hots.includes("86885") ||
hots.includes("22233")
2023-06-28 10:39:06 +08:00
) {
2024-02-29 15:11:26 +08:00
baseurl = "https://marketapi.1688sup.com"
return
2023-06-28 10:39:06 +08:00
}
}
2024-02-29 15:11:26 +08:00
global_dev_fun(pathname)
2023-06-28 10:39:06 +08:00
//统一请求
axios.interceptors.request.use((config) => {
// config.headers.Version = 'v1.3.0';
2024-02-29 15:11:26 +08:00
return config
})
2023-06-28 10:39:06 +08:00
const req = {
//get请求
axiosGet(url, params) {
2024-02-29 15:11:26 +08:00
const obj = { method: "get", url: baseurl + url, params }
2023-06-28 10:39:06 +08:00
var result = axios(obj)
.then(function (res) {
2024-02-29 15:11:26 +08:00
return res.data
2023-06-28 10:39:06 +08:00
})
.catch(function (error) {
2024-02-29 15:11:26 +08:00
return
})
return result
2023-06-28 10:39:06 +08:00
},
//获取key列表
axiosPostgetKey(url, data) {
let result = axios({
2024-02-29 15:11:26 +08:00
method: "post",
2023-06-28 10:39:06 +08:00
url: baseurl + url,
data: data,
header: {
2024-02-29 15:11:26 +08:00
"Content-type": "application/x-www-form-urlencoded"
2023-06-28 10:39:06 +08:00
}
})
.then((res) => {
2024-02-29 15:11:26 +08:00
return res
2023-06-28 10:39:06 +08:00
})
.catch((error) => {
2024-02-29 15:11:26 +08:00
alert("服务器错误")
return "exception=" + error
})
return result
2023-06-28 10:39:06 +08:00
},
//post请求
axiosPost(url, data) {
let result = axios({
2024-02-29 15:11:26 +08:00
method: "post",
2023-06-28 10:39:06 +08:00
url: baseurl + url,
data: data,
header: {
2024-02-29 15:11:26 +08:00
"Content-type": "application/x-www-form-urlencoded"
2023-06-28 10:39:06 +08:00
}
})
.then((res) => {
2024-02-29 15:11:26 +08:00
return res.data
2023-06-28 10:39:06 +08:00
})
.catch((error) => {
// return "exception=" + error
2024-02-29 15:11:26 +08:00
})
return result
2023-06-28 10:39:06 +08:00
},
//put请求
axiosPut(url, data) {
let result = axios({
2024-02-29 15:11:26 +08:00
method: "put",
2023-06-28 10:39:06 +08:00
url: baseurl + url,
data: data,
header: {
2024-02-29 15:11:26 +08:00
"Content-type": "application/x-www-form-urlencoded"
2023-06-28 10:39:06 +08:00
}
})
.then((res) => {
2024-02-29 15:11:26 +08:00
return res.data
2023-06-28 10:39:06 +08:00
})
.catch((error) => {
2024-02-29 15:11:26 +08:00
alert("服务器错误")
return "exception=" + error
})
return result
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
}
2023-06-28 10:39:06 +08:00
//图形验证码
function captchaimg() {
2024-02-29 15:11:26 +08:00
let parmas = {}
let customsessionid = ""
const xhr = new XMLHttpRequest()
xhr.open("GET", baseurl + "/auth/login/verify")
2023-06-28 10:39:06 +08:00
// xhr.setRequestHeader('Version', 'v1.1.0');
2024-02-29 15:11:26 +08:00
xhr.responseType = "arraybuffer"
2023-06-28 10:39:06 +08:00
xhr.onreadystatechange = function (response) {
response.header = {
2024-02-29 15:11:26 +08:00
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
}
var img = document.getElementById("captcha_img")
var byteArray = new Uint8Array(response.target.response)
var binary = ""
2023-06-28 10:39:06 +08:00
for (var i = 0; i < byteArray.byteLength; i++) {
2024-02-29 15:11:26 +08:00
binary += String.fromCharCode(byteArray[i])
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
let str = "data:image/png;base64," + window.btoa(binary)
img.src = str
customsessionid = xhr.getResponseHeader("Unique-Str")
sessionStorage.setItem("unique_str", customsessionid)
}
xhr.send()
2023-06-28 10:39:06 +08:00
}
/*公共方法提取 */
2023-06-28 11:05:08 +08:00
//!商品的各种异常状态。1是可以兑换不作提示
//!type:1 兑换码 2:立减金 3:红包
2023-06-28 10:39:06 +08:00
const product_status = (status, row) => {
let obj = {
2024-02-29 15:11:26 +08:00
2: "还没开始哟,兑换时间为" + row.begin_time + "至" + row.end_time, //未开始
3: "当前商品兑换已结束", //作废key批次
4: "亲,仅可兑换一次哦!", //仅兑换一次
5: "当前商品兑换次数达到上限", //累计次数达到上限
6: "暂无库存,看看其他商品吧~", //无库存
7: "当前商品不可兑换", //其他商品处于兑换中
8: "当前商品正在兑换中", //已兑换次数
9: "当前商品兑换次数达到上限", //2023-04-07 全部兑换
10: "该商品暂无法兑换", //商品暂停
11: "兑换已过期,兑换时间为" + row.begin_time + "至" + row.end_time, //正常过期
15: "超过每月领取次数",
22: "您有未支付的订单"
}
if (row.type == 2 || (row.recharge_type == 2 && row.type == 1)) {
obj["20"] =
"该立减金商品不在生效时间范围内,生效时间为" +
2023-06-28 10:39:06 +08:00
row.entity.time_limit.effect_time.start_time +
2024-02-29 15:11:26 +08:00
"至" +
row.entity.time_limit.effect_time.end_time //不在生效时间范围内
obj["21"] =
"该立减金商品不在领取时间段内,领取时间段为" +
2023-06-28 10:39:06 +08:00
row.entity.time_limit.receive_time.start_time +
2024-02-29 15:11:26 +08:00
"至" +
row.entity.time_limit.receive_time.end_time //不在领取时间范围内
2023-06-28 10:39:06 +08:00
}
2023-06-28 11:05:08 +08:00
if (row.type == 3) {
2024-02-29 15:11:26 +08:00
obj["20"] =
"该红包商品不在生效时间范围内,生效时间为" +
2023-06-28 11:05:08 +08:00
row.entity.begin_time +
2024-02-29 15:11:26 +08:00
"至" +
row.entity.end_time //不在生效时间范围内
obj["21"] = "该红包商品不在领取时间段内"
2023-06-28 11:05:08 +08:00
}
2024-02-29 15:11:26 +08:00
return obj[status]
}
2023-06-28 10:39:06 +08:00
/* 周天排序 */
function sortWeeks(weeks) {
const staticWeeks = [
2024-02-29 15:11:26 +08:00
{ id: 1, name: "周一" },
{ id: 2, name: "周二" },
{ id: 3, name: "周三" },
{ id: 4, name: "周四" },
{ id: 5, name: "周五" },
{ id: 6, name: "周六" },
{ id: 7, name: "周日" }
]
2023-06-28 10:39:06 +08:00
var _weeks = weeks
.map((item) =>
staticWeeks.filter((item1) => item1.name === item || item1.id == item)
)
.flat(Infinity)
2024-02-29 15:11:26 +08:00
.sort((a, b) => a.id - b.id)
2023-06-28 10:39:06 +08:00
//将weeks清空并将排序好的值赋给weeks
2024-02-29 15:11:26 +08:00
const weeksData = []
2023-06-28 10:39:06 +08:00
if (isContinuityNum(_weeks.map((item) => item.id)) && _weeks.length > 1) {
2024-02-29 15:11:26 +08:00
weeksData.push(`${_weeks[0].name}${_weeks.slice(-1)[0].name}`)
2023-06-28 10:39:06 +08:00
} else {
for (var i = 0; i < _weeks.length; i++) {
2024-02-29 15:11:26 +08:00
weeksData.push(_weeks[i].name)
2023-06-28 10:39:06 +08:00
}
}
2024-02-29 15:11:26 +08:00
return weeksData
2023-06-28 10:39:06 +08:00
}
//判断一串数字是否是连续的
function isContinuityNum(num) {
2024-02-29 15:11:26 +08:00
let array = []
2023-06-28 10:39:06 +08:00
if (num instanceof Array) {
2024-02-29 15:11:26 +08:00
array = [...num]
2023-06-28 10:39:06 +08:00
} else {
2024-02-29 15:11:26 +08:00
array = Array.from(num.toString()) //转换为数组
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
var i = array[0]
var isContinuation = true
2023-06-28 10:39:06 +08:00
for (var e in array) {
if (array[e] != i) {
2024-02-29 15:11:26 +08:00
isContinuation = false
break
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
i++
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
return isContinuation
2023-06-28 10:39:06 +08:00
}
//判断是不是微信
function isWx() {
2024-02-29 15:11:26 +08:00
var ua = window.navigator.userAgent.toLowerCase()
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
return false
2023-06-28 10:39:06 +08:00
}
//判断是不是钉钉
function isAli() {
2024-02-29 15:11:26 +08:00
var ua = window.navigator.userAgent.toLowerCase()
if (ua.match(/dingtalk/i) == "dingtalk") {
return true
2023-06-28 10:39:06 +08:00
}
2024-02-29 15:11:26 +08:00
return false
2023-06-28 10:39:06 +08:00
}
//判断是不是微信小程序环境打开
function isWxminiprogram() {
2024-02-29 15:11:26 +08:00
const ua = navigator.userAgent.toLowerCase()
const isWeixin = ua.indexOf("micromessenger") != -1
2023-06-28 10:39:06 +08:00
if (isWeixin) {
2024-02-29 15:11:26 +08:00
if (window.__wxjs_environment == "miniprogram") {
return true
2023-06-28 10:39:06 +08:00
} else {
2024-02-29 15:11:26 +08:00
return false
2023-06-28 10:39:06 +08:00
}
} else {
2024-02-29 15:11:26 +08:00
return false
2023-06-28 10:39:06 +08:00
}
}