52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
"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
|