279 lines
6.7 KiB
JavaScript
279 lines
6.7 KiB
JavaScript
let baseurl = "http://192.168.6.75";
|
||
let pathname = window.location.host;
|
||
|
||
function global_dev_fun(hots) {
|
||
if (hots.includes("test")) {
|
||
baseurl = "http://192.168.6.75";
|
||
return;
|
||
}
|
||
|
||
if (hots.includes("pre")) {
|
||
baseurl = "http://pre.marketapi.1688sup.com";
|
||
return;
|
||
}
|
||
|
||
if (
|
||
hots.includes("1688sup") ||
|
||
hots.includes("83323") ||
|
||
hots.includes("86885") ||
|
||
hots.includes("22233")
|
||
) {
|
||
baseurl = "https://marketapi.1688sup.com";
|
||
return;
|
||
}
|
||
}
|
||
|
||
global_dev_fun(pathname);
|
||
|
||
//统一请求
|
||
axios.interceptors.request.use((config) => {
|
||
// config.headers.Version = 'v1.3.0';
|
||
return config;
|
||
});
|
||
|
||
const req = {
|
||
//get请求
|
||
axiosGet(url, params) {
|
||
const obj = { method: "get", url: baseurl + url, params };
|
||
var result = axios(obj)
|
||
.then(function (res) {
|
||
return res.data;
|
||
})
|
||
.catch(function (error) {
|
||
return;
|
||
});
|
||
return result;
|
||
},
|
||
|
||
//获取key列表
|
||
axiosPostgetKey(url, data) {
|
||
let result = axios({
|
||
method: "post",
|
||
url: baseurl + url,
|
||
data: data,
|
||
header: {
|
||
"Content-type": "application/x-www-form-urlencoded"
|
||
}
|
||
})
|
||
.then((res) => {
|
||
return res;
|
||
})
|
||
.catch((error) => {
|
||
alert("服务器错误");
|
||
return "exception=" + error;
|
||
});
|
||
return result;
|
||
},
|
||
//post请求
|
||
axiosPost(url, data) {
|
||
let result = axios({
|
||
method: "post",
|
||
url: baseurl + url,
|
||
data: data,
|
||
header: {
|
||
"Content-type": "application/x-www-form-urlencoded"
|
||
}
|
||
})
|
||
.then((res) => {
|
||
return res.data;
|
||
})
|
||
.catch((error) => {
|
||
// return "exception=" + error
|
||
});
|
||
return result;
|
||
},
|
||
//put请求
|
||
axiosPut(url, data) {
|
||
let result = axios({
|
||
method: "put",
|
||
url: baseurl + url,
|
||
data: data,
|
||
header: {
|
||
"Content-type": "application/x-www-form-urlencoded"
|
||
}
|
||
})
|
||
.then((res) => {
|
||
return res.data;
|
||
})
|
||
.catch((error) => {
|
||
alert("服务器错误");
|
||
return "exception=" + error;
|
||
});
|
||
return result;
|
||
}
|
||
};
|
||
|
||
//图形验证码
|
||
function captchaimg() {
|
||
let parmas = {};
|
||
let customsessionid = "";
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.open("GET", baseurl + "/auth/login/verify");
|
||
// xhr.setRequestHeader('Version', 'v1.1.0');
|
||
xhr.responseType = "arraybuffer";
|
||
xhr.onreadystatechange = function (response) {
|
||
response.header = {
|
||
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 = "";
|
||
for (var i = 0; i < byteArray.byteLength; i++) {
|
||
binary += String.fromCharCode(byteArray[i]);
|
||
}
|
||
let str = "data:image/png;base64," + window.btoa(binary);
|
||
img.src = str;
|
||
customsessionid = xhr.getResponseHeader("Unique-Str");
|
||
sessionStorage.setItem("unique_str", customsessionid);
|
||
};
|
||
xhr.send();
|
||
}
|
||
|
||
/*公共方法提取 */
|
||
//!商品的各种异常状态。1是可以兑换,不作提示
|
||
//!type:1 兑换码 2:立减金 3:红包
|
||
const product_status = (status, row) => {
|
||
const message = JSON.parse(sessionStorage.getItem("message"));
|
||
const messageCurrent = {};
|
||
message.map((item) => {
|
||
if (item.type == row.type || item.type == 0) {
|
||
return (messageCurrent[item.message_type] = replaceVariables(
|
||
row.type,
|
||
item,
|
||
row
|
||
));
|
||
}
|
||
});
|
||
return messageCurrent[status];
|
||
};
|
||
|
||
/* 替换变量 */
|
||
function replaceVariables(type, val, row) {
|
||
let mes = "";
|
||
let prompt = val.customize || val.default;
|
||
switch (Number(type)) {
|
||
case 2:
|
||
mes = prompt
|
||
.replace(
|
||
"${effect_time_start}",
|
||
row.entity.time_limit.effect_time.start_time
|
||
)
|
||
.replace(
|
||
"${effect_time_end}",
|
||
row.entity.time_limit.effect_time.end_time
|
||
)
|
||
.replace("${start_time}", row.entity.time_limit.receive_time.start_time)
|
||
.replace("${end_time}", row.entity.time_limit.receive_time.end_time);
|
||
break;
|
||
case 3:
|
||
mes = prompt
|
||
.replace("${effect_time_start}", row.entity.begin_time)
|
||
.replace("${effect_time_end}", row.entity.end_time);
|
||
break;
|
||
default:
|
||
mes = prompt
|
||
.replace("${start_time}", row.begin_time)
|
||
.replace("${end_time}", row.end_time)
|
||
.replace("${effect_time_start}", row.begin_time)
|
||
.replace("${effect_time_end}", row.end_time);
|
||
break;
|
||
}
|
||
return mes;
|
||
}
|
||
|
||
/* 周天排序 */
|
||
function sortWeeks(weeks) {
|
||
const staticWeeks = [
|
||
{ id: 1, name: "周一" },
|
||
{ id: 2, name: "周二" },
|
||
{ id: 3, name: "周三" },
|
||
{ id: 4, name: "周四" },
|
||
{ id: 5, name: "周五" },
|
||
{ id: 6, name: "周六" },
|
||
{ id: 7, name: "周日" }
|
||
];
|
||
|
||
var _weeks = weeks
|
||
.map((item) =>
|
||
staticWeeks.filter((item1) => item1.name === item || item1.id == item)
|
||
)
|
||
.flat(Infinity)
|
||
.sort((a, b) => a.id - b.id);
|
||
|
||
//将weeks清空并将排序好的值赋给weeks
|
||
const weeksData = [];
|
||
if (isContinuityNum(_weeks.map((item) => item.id)) && _weeks.length > 1) {
|
||
weeksData.push(`${_weeks[0].name} 至 ${_weeks.slice(-1)[0].name}`);
|
||
} else {
|
||
for (var i = 0; i < _weeks.length; i++) {
|
||
weeksData.push(_weeks[i].name);
|
||
}
|
||
}
|
||
|
||
return weeksData;
|
||
}
|
||
|
||
//判断一串数字是否是连续的
|
||
function isContinuityNum(num) {
|
||
let array = [];
|
||
if (num instanceof Array) {
|
||
array = [...num];
|
||
} else {
|
||
array = Array.from(num.toString()); //转换为数组
|
||
}
|
||
|
||
var i = array[0];
|
||
var isContinuation = true;
|
||
for (var e in array) {
|
||
if (array[e] != i) {
|
||
isContinuation = false;
|
||
break;
|
||
}
|
||
i++;
|
||
}
|
||
return isContinuation;
|
||
}
|
||
|
||
//判断是不是微信
|
||
function isWx() {
|
||
var ua = window.navigator.userAgent.toLowerCase();
|
||
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//判断是不是钉钉
|
||
function isAli() {
|
||
var ua = window.navigator.userAgent.toLowerCase();
|
||
if (ua.match(/dingtalk/i) == "dingtalk") {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//判断是不是微信小程序环境打开
|
||
function isWxminiprogram() {
|
||
const ua = navigator.userAgent.toLowerCase();
|
||
const isWeixin = ua.indexOf("micromessenger") != -1;
|
||
if (isWeixin) {
|
||
if (window.__wxjs_environment == "miniprogram") {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/* 自定义按钮文案 */
|
||
function buttonTextFun(type, code) {
|
||
const buttonData = JSON.parse(sessionStorage.getItem("bm_auth")).button_conf;
|
||
const lastText = buttonData.filter(
|
||
(item) => item.type == type && item.code == code
|
||
)[0];
|
||
return lastText.custom || lastText.default;
|
||
}
|