feat: 透传request和uploadFile参数给原生wx接口

This commit is contained in:
ivinwu
2022-01-17 16:46:00 +08:00
parent 6a475eb20d
commit 41d415cd94
6 changed files with 21 additions and 52 deletions

View File

@@ -1,4 +1,4 @@
const weRequest = require('./request');
import weRequest from './request';
Page({
data: {},
@@ -11,23 +11,12 @@ Page({
data: {
id: id
},
enableHttp2: true,
timeout: 1000,
showLoading: true,
success: function (data) {
console.log(data);
},
codeToSessionFail: function() {
},
fail:function(obj, res) {
if(codeToSessionFail) {
} else {
}
// code to session
// ...
}
})
},
upload: function() {

View File

@@ -6,7 +6,7 @@ weRequest.init({
// [可选] 请求URL的固定前缀可不配置默认为空
urlPerfix: "https://www.example.com/",
// [必填] 触发重新登录的条件res为CGI返回的数据
loginTrigger: function (res) {
loginTrigger: function (res: any) {
// 此处例子当返回数据中的字段errcode等于-1会自动触发重新登录
return res.errcode == -1;
},
@@ -33,22 +33,22 @@ weRequest.init({
// [可选] 登录重试次数当连续请求登录接口返回失败次数超过这个次数将不再重试登录可不配置默认为重试3次
reLoginLimit: 2,
// [必填] 触发请求成功的条件
successTrigger: function (res) {
successTrigger: function (res: any) {
// 此处例子当返回数据中的字段errcode等于0时代表请求成功其他情况都认为业务逻辑失败
return res.errcode == 0;
},
// [可选] 成功之后返回数据;可不配置
successData: function (res) {
successData: function (res: any) {
// 此处例子返回数据中的字段data为业务接受到的数据
return res.data;
},
// [可选] 当CGI返回错误时弹框提示的标题文字
errorTitle: function(res) {
errorTitle: function(res: any) {
// 此处例子当返回数据中的字段errcode等于0x10040730时错误弹框的标题是“温馨提示”其他情况下则是“操作失败”
return res.errcode == 0x10040730 ? '温馨提示' : '操作失败'
},
// [可选] 当CGI返回错误时弹框提示的内容文字
errorContent: function(res) {
errorContent: function(res: any) {
// 此处例子返回数据中的字段msg为错误弹框的提示内容文字
return res.msg ? res.msg : '服务可能存在异常,请稍后重试'
},