Files
tripellet-merchant/util/api.js

56 lines
1.6 KiB
JavaScript
Raw Permalink 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.

import config from "@/common/config";
import _this from "../main.js";
//1、首先创建一个工具包utils
//2、创建一个api.js文件
//3、编写api.js内容
//创建一个常量 conset BASE_URL作为默认url地址
// console.log('语言',_this.$i18n.locale);
export const myRequest = (option) => {
//将封装好的函数导入出去
return new Promise((resolve, reject) => {
uni.request({
url: config.baseUrl + option.url, //传入url地址
data: option.data || {}, //请求数据
method: option.method || "GET", //请求方法
header: option.header || {
// 根据实际接口设计 key 取 token 或者 authorization
lang: _this.$i18n.locale || "zh-CN",
// #ifdef MP-WEIXIN
app_type: "miniprogram",
// #endif
// #ifndef MP-WEIXIN
app_type: "app",
// #endif
},
success: (res) => {
console.log("全局", res);
if (res.data.status == 3) {
console.log("接口删除token");
// uni.$u.toast(res.data.msg);
}
//相应成功回调函数
if (res.statusCode !== 201 && res.statusCode !== 200) {
console.log("获取数据失败!");
// uni.showToast({
// title: "获取数据失败!",
// icon: "none",
// });
}
resolve(res); // 将请求结果resolve出去
},
fail: (err) => {
console.log("请求接口失败");
// uni.showToast({
// title: "请求接口失败",
// icon: "none",
// });
// rej;
// ect(err);
},
});
});
};