Files
cmgd-mini-app/unpackage/dist/dev/mp-weixin/api/request.js
2026-01-15 16:10:27 +08:00

52 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
const common_vendor = require("../common/vendor.js");
const config = require("../config.js");
const utils_helper = require("../utils/helper.js");
const request = (options) => {
return new Promise((resolve, reject) => {
common_vendor.index.request({
// 拼接完整请求URL基础URL + 路径 + 固定参数)
url: config.config.api_base_url + options.url + "&wxapp_id=" + config.config.wxapp_id + "&token=" + common_vendor.index.getStorageSync("token"),
method: options.method || "GET",
// 默认GET方法
data: options.data || options.params || {},
// 兼容data/params传参
dataType: options.dataType || "json",
// 默认json格式
responseType: options.responseType || "text",
// 默认text类型
// 请求成功回调
success(res) {
const ret = res.data;
switch (ret.code) {
case -1:
utils_helper.goToLoginPage();
break;
case 1:
resolve(ret.data);
break;
case 0:
common_vendor.index.showToast({
title: ret.msg || "操作失败",
// 显示错误信息
icon: "none"
// 不显示图标
});
break;
}
},
// 请求失败回调
fail(err) {
common_vendor.index.$emit("z-paging-error-emit");
reject(err);
common_vendor.index.showToast({
title: "网络请求失败",
icon: "none"
});
}
});
});
};
exports.request = request;
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/request.js.map