etms_wechat_mini_oem/yunbainian/etms_wechat_mini/com.js

112 lines
2.7 KiB
JavaScript

const config = require("./config");
export function etmsPostTemp(rot, jsonData, callBack) {
var requestUrl = `${config.bascUrl}${rot}`;
return new Promise((resolve, reject) => {
wx.request({
url: requestUrl,
data: jsonData,
method: "POST",
success(result) {
console.log(result);
if (result.data.code === "10000") {
callBack(result.data.resultData);
resolve()
} else {
wx.showToast({
title: result.data.message,
icon: "error",
duration: 2000,
});
}
},
fail({
errMsg
}) {
console.log("request fail", errMsg);
reject()
},
});
})
}
export function etmsPost(logininfo, rot, jsonData, callBack, failBack) {
var requestUrl = `${config.bascUrl}${rot}`;
wx.request({
url: requestUrl,
data: jsonData,
method: "POST",
header: {
"etms-s": logininfo.s,
"etms-l": logininfo.u,
"etms-o": logininfo.openId,
"etms-u": logininfo.unionid,
},
success(result) {
console.log(result);
if (result.data.code === "10000") {
callBack(result.data.resultData);
} else {
wx.showToast({
title: result.data.message,
icon: "none",
duration: 2000,
});
if (failBack) {
failBack(result.data);
}
}
},
fail({
errMsg
}) {
console.log("request fail", errMsg);
},
});
}
export function etmsPost2(logininfo, rot, jsonData, failBack) {
try {
var requestUrl = `${config.bascUrl}${rot}`;
console.log(123111)
return new Promise((resolve, reject) => {
wx.request({
url: requestUrl,
method: 'POST',
data: jsonData,
header: {
"etms-s": logininfo.s,
"etms-l": logininfo.u,
"etms-o": logininfo.openId,
"etms-u": logininfo.unionid,
},
success(res) {
console.log(123444)
if (res.statusCode === 200) {
if (res.data.code === "10000") {
resolve(res.data.resultData); // 成功时返回数据
} else {
wx.showToast({
title: res.data.message,
icon: "none",
duration: 2000,
});
if (failBack) {
failBack(res.data);
}
}
} else {
reject(new Error(`Server responded with status code ${res.statusCode}`));
}
},
fail(err) {
reject(new Error('Network error or request failed'));
}
});
});
} catch (ex) {
console.log(ex)
}
}