发布支持引入typing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules/
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
8
build/api/getConfig.d.ts
vendored
Normal file
8
build/api/getConfig.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export interface IGetConfigResult {
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
sessionExpireTime?: number;
|
||||||
|
sessionExpireKey?: string;
|
||||||
|
sessionExpire?: number;
|
||||||
|
}
|
||||||
|
declare const _default: () => IGetConfigResult;
|
||||||
|
export default _default;
|
||||||
2
build/api/getSession.d.ts
vendored
Normal file
2
build/api/getSession.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: () => any;
|
||||||
|
export default _default;
|
||||||
29
build/api/init.d.ts
vendored
Normal file
29
build/api/init.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
export interface IInitOption {
|
||||||
|
codeToSession: ICodeToSessionOptions;
|
||||||
|
sessionName?: string;
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
doNotCheckSession?: boolean;
|
||||||
|
reLoginLimit?: number;
|
||||||
|
errorCallback?: null | Function;
|
||||||
|
reportCGI?: boolean | ((name: string, startTime: number, endTime: number, request?: () => void) => void);
|
||||||
|
mockJson?: TODO;
|
||||||
|
globalData?: boolean | object | Function;
|
||||||
|
sessionExpireKey: string;
|
||||||
|
loginTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
successTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
successData?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
errorTitle?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||||
|
errorContent?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||||
|
}
|
||||||
|
export interface ICodeToSessionOptions {
|
||||||
|
url?: string;
|
||||||
|
method?: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT' | 'string';
|
||||||
|
codeName?: string;
|
||||||
|
data?: string | IAnyObject | ArrayBuffer;
|
||||||
|
success?: Function;
|
||||||
|
fail?: Function;
|
||||||
|
report?: string;
|
||||||
|
}
|
||||||
|
declare const _default: (params: IInitOption) => void;
|
||||||
|
export default _default;
|
||||||
2
build/api/login.d.ts
vendored
Normal file
2
build/api/login.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: (callback: Function) => void;
|
||||||
|
export default _default;
|
||||||
7
build/api/request.d.ts
vendored
Normal file
7
build/api/request.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export interface IRequestOption extends wx.RequestOption {
|
||||||
|
beforeSend?: Function;
|
||||||
|
showLoading?: boolean | string;
|
||||||
|
report?: string;
|
||||||
|
}
|
||||||
|
declare const _default: (obj: IRequestOption) => void;
|
||||||
|
export default _default;
|
||||||
2
build/api/setSession.d.ts
vendored
Normal file
2
build/api/setSession.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: (session: any) => void;
|
||||||
|
export default _default;
|
||||||
2
build/api/uploadFile.d.ts
vendored
Normal file
2
build/api/uploadFile.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: (obj: any) => void;
|
||||||
|
export default _default;
|
||||||
24
build/index.d.ts
vendored
Normal file
24
build/index.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { IInitOption } from "./api/init";
|
||||||
|
import { IRequestOption } from "./api/request";
|
||||||
|
export interface IUploadFileOption extends wx.UploadFileOption {
|
||||||
|
beforeSend?: Function;
|
||||||
|
showLoading?: boolean | string;
|
||||||
|
report?: string;
|
||||||
|
}
|
||||||
|
export interface IGetConfigResult {
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
sessionExpireTime?: number;
|
||||||
|
sessionExpireKey?: string;
|
||||||
|
sessionExpire?: number;
|
||||||
|
}
|
||||||
|
export interface weRequest {
|
||||||
|
init?: (obj: IInitOption) => void;
|
||||||
|
request?: (option: IRequestOption) => void;
|
||||||
|
uploadFile?: (option: IUploadFileOption) => void;
|
||||||
|
getSession?: () => string;
|
||||||
|
getConfig?: () => IGetConfigResult;
|
||||||
|
login?: (callback: Function) => void;
|
||||||
|
setSession?: (x: string) => void;
|
||||||
|
}
|
||||||
|
declare const weRequestObject: weRequest;
|
||||||
|
export default weRequestObject;
|
||||||
8
build/module/cacheManager.d.ts
vendored
Normal file
8
build/module/cacheManager.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function get(obj: TODO): void;
|
||||||
|
declare function set(obj: TODO, realData: TODO): void;
|
||||||
|
declare const _default: {
|
||||||
|
get: typeof get;
|
||||||
|
set: typeof set;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
8
build/module/durationReporter.d.ts
vendored
Normal file
8
build/module/durationReporter.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function start(obj: TODO, name?: string): void;
|
||||||
|
declare function end(obj: TODO, name?: string): void;
|
||||||
|
declare const _default: {
|
||||||
|
start: typeof start;
|
||||||
|
end: typeof end;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
2
build/module/errorHandler.d.ts
vendored
Normal file
2
build/module/errorHandler.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: (obj: any, res: any) => void;
|
||||||
|
export default _default;
|
||||||
6
build/module/mockManager.d.ts
vendored
Normal file
6
build/module/mockManager.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function get(obj: TODO, method: "request" | "uploadFile"): any;
|
||||||
|
declare const _default: {
|
||||||
|
get: typeof get;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
8
build/module/requestHandler.d.ts
vendored
Normal file
8
build/module/requestHandler.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function request(obj: TODO): TODO;
|
||||||
|
declare function uploadFile(obj: TODO): TODO;
|
||||||
|
declare const _default: {
|
||||||
|
request: typeof request;
|
||||||
|
uploadFile: typeof uploadFile;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
3
build/module/responseHandler.d.ts
vendored
Normal file
3
build/module/responseHandler.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function response(res: wx.RequestSuccessCallbackResult | wx.UploadFileSuccessCallbackResult, obj: TODO, method: "request" | "uploadFile"): any;
|
||||||
|
export default response;
|
||||||
3
build/module/sessionManager.d.ts
vendored
Normal file
3
build/module/sessionManager.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function checkSession(callback: Function, obj: TODO): void;
|
||||||
|
export default checkSession;
|
||||||
3
build/store/config.d.ts
vendored
Normal file
3
build/store/config.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { IInitOption } from '../api/init';
|
||||||
|
declare const defaultConfig: IInitOption;
|
||||||
|
export default defaultConfig;
|
||||||
2
build/store/status.d.ts
vendored
Normal file
2
build/store/status.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: any;
|
||||||
|
export default _default;
|
||||||
8
build/util/flow.d.ts
vendored
Normal file
8
build/util/flow.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/// <reference types="wx" />
|
||||||
|
declare function emit(key: TODO): void;
|
||||||
|
declare function wait(key: TODO, callback: Function): void;
|
||||||
|
declare const _default: {
|
||||||
|
wait: typeof wait;
|
||||||
|
emit: typeof emit;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
7
build/util/loading.d.ts
vendored
Normal file
7
build/util/loading.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
declare function show(txt: boolean | string): void;
|
||||||
|
declare function hide(): void;
|
||||||
|
declare const _default: {
|
||||||
|
show: typeof show;
|
||||||
|
hide: typeof hide;
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
File diff suppressed because one or more lines are too long
2
build/weRequest.min.js
vendored
2
build/weRequest.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "weRequest",
|
"name": "wxapp-session-request",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "本工具通过拓展小程序的wx.request,让开发者通过简单的配置,实现自动管理登录态等功能",
|
"description": "本工具通过拓展小程序的wx.request,让开发者通过简单的配置,实现自动管理登录态等功能",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/IvinWu/weRequest.git"
|
"url": "https://github.com/IvinWu/weRequest.git"
|
||||||
},
|
},
|
||||||
"main": "./src/index.js",
|
"main": "build/weRequest.js",
|
||||||
|
"typings": "build/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack"
|
"build": "webpack"
|
||||||
},
|
},
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
"prettier": "^1.15.3",
|
"prettier": "^1.15.3",
|
||||||
"pretty-quick": "^1.8.0",
|
"pretty-quick": "^1.8.0",
|
||||||
"ts-loader": "^5.3.1",
|
"ts-loader": "^5.3.1",
|
||||||
|
"tslint": "^5.12.0",
|
||||||
"tslint-config-prettier": "^1.17.0",
|
"tslint-config-prettier": "^1.17.0",
|
||||||
"typescript": "^3.2.2",
|
"typescript": "^3.2.2",
|
||||||
"webpack": "^4.28.0",
|
"webpack": "^4.28.0",
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
import config from '../store/config'
|
import config from '../store/config'
|
||||||
import status from '../store/status'
|
import status from '../store/status'
|
||||||
|
|
||||||
|
export interface IGetConfigResult{
|
||||||
|
/* 在组件初始化时传入的请求URL的固定前缀 */
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
/* 在组件初始化时传入的用户登陆态设置本地缓存时间 */
|
||||||
|
sessionExpireTime?: number;
|
||||||
|
/* 在组件初始化时传入的用户登陆态本地缓存时间Storage的key */
|
||||||
|
sessionExpireKey?: string;
|
||||||
|
/* 用户登陆态本地缓存过期的时间戳 */
|
||||||
|
sessionExpire?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const configResult :IGetConfigResult = {
|
const configResult :IGetConfigResult = {
|
||||||
urlPerfix: config.urlPerfix,
|
urlPerfix: config.urlPerfix,
|
||||||
|
|||||||
@@ -1,6 +1,73 @@
|
|||||||
import defaultConfig from '../store/config'
|
import defaultConfig from '../store/config'
|
||||||
import status from '../store/status'
|
import status from '../store/status'
|
||||||
|
|
||||||
|
export interface IInitOption {
|
||||||
|
/* 用code换取session的CGI配置 */
|
||||||
|
codeToSession: ICodeToSessionOptions;
|
||||||
|
/* 储存在localStorage的session名称,且CGI请求的data中会自动带上以此为名称的session值;可不配置,默认为session */
|
||||||
|
sessionName?: string;
|
||||||
|
/* 请求URL的固定前缀,如果配置了,后续请求的URL都会自动加上这个前缀,如果是函数,则为函数的返回值 */
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
/* 是否需要调用checkSession,验证小程序的登录态过期;若业务不需要使用到session_key,则可配置为true */
|
||||||
|
doNotCheckSession?: boolean;
|
||||||
|
/* 登录重试次数,当连续请求登录接口返回失败次数超过这个次数,将不再重试登录 */
|
||||||
|
reLoginLimit?: number;
|
||||||
|
/* 当出现接口逻辑错误时,会执行统一的回调函数,这里可以做统一的错误上报等处理 */
|
||||||
|
errorCallback?: null | Function;
|
||||||
|
/* 接口返回成功之后,会执行统一的回调函数,这里可以做统一的耗时上报等处理 */
|
||||||
|
reportCGI?: boolean | ((
|
||||||
|
/* 调用的接口名字,可在request接口的report字段配置 */
|
||||||
|
name: string,
|
||||||
|
/* 发起请求时的时间戳 */
|
||||||
|
startTime: number,
|
||||||
|
/* 请求返回时的时间戳 */
|
||||||
|
endTime: number,
|
||||||
|
/* 请求方法,可用于上报 */
|
||||||
|
request?: () => void
|
||||||
|
) => void);
|
||||||
|
/* 可为接口提供mock数据 */
|
||||||
|
mockJson?: TODO;
|
||||||
|
/** 所有请求都会自动带上这里的参数 */
|
||||||
|
globalData?: boolean | object | Function;
|
||||||
|
/** session在本地缓存的key */
|
||||||
|
sessionExpireKey: string;
|
||||||
|
/* 触发重新登录的条件;参数为CGI返回的数据,返回需要重新登录的条件 */
|
||||||
|
loginTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
/* 触发请求成功的条件;参数为CGI返回的数据,返回接口逻辑成功的条件 */
|
||||||
|
successTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
/* 成功之后返回数据;参数为CGI返回的数据,返回逻辑需要使用的数据 */
|
||||||
|
successData?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
||||||
|
/* 接口逻辑失败时,错误弹窗的标题 */
|
||||||
|
errorTitle?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||||
|
/* 接口逻辑失败时,错误弹窗的内容 */
|
||||||
|
errorContent?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICodeToSessionOptions{
|
||||||
|
/* CGI的url */
|
||||||
|
url?: string;
|
||||||
|
/* 调用该CGI的方法 */
|
||||||
|
method?: 'OPTIONS'
|
||||||
|
| 'GET'
|
||||||
|
| 'HEAD'
|
||||||
|
| 'POST'
|
||||||
|
| 'PUT'
|
||||||
|
| 'DELETE'
|
||||||
|
| 'TRACE'
|
||||||
|
| 'CONNECT' | 'string',
|
||||||
|
/* CGI中传参时,存放code的名称 */
|
||||||
|
codeName?: string;
|
||||||
|
/* 登录接口需要的其他参数 */
|
||||||
|
data?: string | IAnyObject | ArrayBuffer;
|
||||||
|
/* 接口返回成功的函数;需要返回session的值 */
|
||||||
|
success?: Function;
|
||||||
|
/* code换取session的接口逻辑出错时,执行的函数,若配置了此函数,则不再默认弹窗报错 */
|
||||||
|
fail?: Function;
|
||||||
|
/* codeToSession的上报字段名 */
|
||||||
|
report?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default (params: IInitOption) => {
|
export default (params: IInitOption) => {
|
||||||
const config: IInitOption = {...params, ...defaultConfig}
|
const config: IInitOption = {...params, ...defaultConfig}
|
||||||
// 如果配置更改了session的存储名字,则重新获取一次session
|
// 如果配置更改了session的存储名字,则重新获取一次session
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
import requestHandler from '../module/requestHandler'
|
import requestHandler from '../module/requestHandler'
|
||||||
|
|
||||||
|
export interface IRequestOption extends wx.RequestOption {
|
||||||
|
/* 发起请求前执行的函数 */
|
||||||
|
beforeSend?: Function;
|
||||||
|
/* 请求过程页面是否展示全屏的loading */
|
||||||
|
showLoading?: boolean | string;
|
||||||
|
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
||||||
|
report?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default (obj: IRequestOption) => {
|
export default (obj: IRequestOption) => {
|
||||||
requestHandler.request(obj)
|
requestHandler.request(obj)
|
||||||
}
|
}
|
||||||
|
|||||||
71
src/index.ts
71
src/index.ts
@@ -1,19 +1,58 @@
|
|||||||
import init from './api/init'
|
import init from "./api/init";
|
||||||
import request from './api/request'
|
import request from "./api/request";
|
||||||
import uploadFile from './api/uploadFile'
|
import uploadFile from "./api/uploadFile";
|
||||||
import setSession from './api/setSession'
|
import setSession from "./api/setSession";
|
||||||
import login from './api/login'
|
import login from "./api/login";
|
||||||
import getSession from './api/getSession'
|
import getSession from "./api/getSession";
|
||||||
import getConfig from './api/getConfig'
|
import getConfig from "./api/getConfig";
|
||||||
|
import { IInitOption } from "./api/init";
|
||||||
|
import { IRequestOption } from "./api/request";
|
||||||
|
|
||||||
const weRequestObject: weRequest = {
|
export interface IUploadFileOption extends wx.UploadFileOption {
|
||||||
init,
|
/* 发起请求前执行的函数 */
|
||||||
request,
|
beforeSend?: Function;
|
||||||
uploadFile,
|
/* 请求过程页面是否展示全屏的loading */
|
||||||
setSession,
|
showLoading?: boolean | string;
|
||||||
login,
|
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
||||||
getSession,
|
report?: string;
|
||||||
getConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default weRequestObject
|
export interface IGetConfigResult {
|
||||||
|
/* 在组件初始化时传入的请求URL的固定前缀 */
|
||||||
|
urlPerfix?: string | (() => string);
|
||||||
|
/* 在组件初始化时传入的用户登陆态设置本地缓存时间 */
|
||||||
|
sessionExpireTime?: number;
|
||||||
|
/* 在组件初始化时传入的用户登陆态本地缓存时间Storage的key */
|
||||||
|
sessionExpireKey?: string;
|
||||||
|
/* 用户登陆态本地缓存过期的时间戳 */
|
||||||
|
sessionExpire?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface weRequest {
|
||||||
|
/** 小程序账号信息 */
|
||||||
|
init?: (obj: IInitOption) => void;
|
||||||
|
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
||||||
|
request?: (option: IRequestOption) => void;
|
||||||
|
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
||||||
|
uploadFile?: (option: IUploadFileOption) => void;
|
||||||
|
/* 获取本地缓存中用户票据的值 */
|
||||||
|
getSession?: () => string;
|
||||||
|
/* 获取weRequest的配置 */
|
||||||
|
getConfig?: () => IGetConfigResult;
|
||||||
|
/* [不建议使用] 在不发起业务请求的情况下,单独执行登录逻辑 */
|
||||||
|
login?: (callback: Function) => void;
|
||||||
|
/* [不建议使用] 设置用户票据的值 */
|
||||||
|
setSession?: (x: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const weRequestObject: weRequest = {
|
||||||
|
init,
|
||||||
|
request,
|
||||||
|
uploadFile,
|
||||||
|
setSession,
|
||||||
|
login,
|
||||||
|
getSession,
|
||||||
|
getConfig
|
||||||
|
};
|
||||||
|
|
||||||
|
export default weRequestObject;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { IInitOption } from '../api/init';
|
||||||
const defaultConfig: IInitOption = {
|
const defaultConfig: IInitOption = {
|
||||||
sessionName: "session",
|
sessionName: "session",
|
||||||
loginTrigger() {
|
loginTrigger() {
|
||||||
|
|||||||
123
src/typings/weRequest/index.d.ts
vendored
123
src/typings/weRequest/index.d.ts
vendored
@@ -1,123 +0,0 @@
|
|||||||
interface weRequest {
|
|
||||||
/** 小程序账号信息 */
|
|
||||||
init?: (obj: IInitOption) => void;
|
|
||||||
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
|
||||||
request?: (option: IRequestOption) => void;
|
|
||||||
/** 插件账号信息(仅在插件中调用时包含这一项) */
|
|
||||||
uploadFile?: (option: IUploadFileOption) => void;
|
|
||||||
/* 获取本地缓存中用户票据的值 */
|
|
||||||
getSession?: () => string;
|
|
||||||
/* 获取weRequest的配置 */
|
|
||||||
getConfig?: () => IGetConfigResult;
|
|
||||||
/* [不建议使用] 在不发起业务请求的情况下,单独执行登录逻辑 */
|
|
||||||
login?: (callback: Function) => void;
|
|
||||||
/* [不建议使用] 设置用户票据的值 */
|
|
||||||
setSession?: (x: string) => void;
|
|
||||||
}
|
|
||||||
interface IInitOption {
|
|
||||||
/* 用code换取session的CGI配置 */
|
|
||||||
codeToSession: ICodeToSessionOptions;
|
|
||||||
/* 储存在localStorage的session名称,且CGI请求的data中会自动带上以此为名称的session值;可不配置,默认为session */
|
|
||||||
sessionName?: string;
|
|
||||||
/* 请求URL的固定前缀,如果配置了,后续请求的URL都会自动加上这个前缀,如果是函数,则为函数的返回值 */
|
|
||||||
urlPerfix?: string | (() => string);
|
|
||||||
/* 是否需要调用checkSession,验证小程序的登录态过期;若业务不需要使用到session_key,则可配置为true */
|
|
||||||
doNotCheckSession?: boolean;
|
|
||||||
/* 登录重试次数,当连续请求登录接口返回失败次数超过这个次数,将不再重试登录 */
|
|
||||||
reLoginLimit?: number;
|
|
||||||
/* 当出现接口逻辑错误时,会执行统一的回调函数,这里可以做统一的错误上报等处理 */
|
|
||||||
errorCallback?: null | Function;
|
|
||||||
/* 接口返回成功之后,会执行统一的回调函数,这里可以做统一的耗时上报等处理 */
|
|
||||||
reportCGI?: boolean | ((
|
|
||||||
/* 调用的接口名字,可在request接口的report字段配置 */
|
|
||||||
name: string,
|
|
||||||
/* 发起请求时的时间戳 */
|
|
||||||
startTime: number,
|
|
||||||
/* 请求返回时的时间戳 */
|
|
||||||
endTime: number,
|
|
||||||
/* 请求方法,可用于上报 */
|
|
||||||
request?: () => void
|
|
||||||
) => void);
|
|
||||||
/* 可为接口提供mock数据 */
|
|
||||||
mockJson?: TODO;
|
|
||||||
/** 所有请求都会自动带上这里的参数 */
|
|
||||||
globalData?: boolean | object | Function;
|
|
||||||
/** session在本地缓存的key */
|
|
||||||
sessionExpireKey: string;
|
|
||||||
/* 触发重新登录的条件;参数为CGI返回的数据,返回需要重新登录的条件 */
|
|
||||||
loginTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
|
||||||
/* 触发请求成功的条件;参数为CGI返回的数据,返回接口逻辑成功的条件 */
|
|
||||||
successTrigger?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
|
||||||
/* 成功之后返回数据;参数为CGI返回的数据,返回逻辑需要使用的数据 */
|
|
||||||
successData?: (res: string | IAnyObject | ArrayBuffer) => boolean;
|
|
||||||
/* 接口逻辑失败时,错误弹窗的标题 */
|
|
||||||
errorTitle?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
|
||||||
/* 接口逻辑失败时,错误弹窗的内容 */
|
|
||||||
errorContent?: string | ((res: string | IAnyObject | ArrayBuffer) => string);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ICodeToSessionOptions{
|
|
||||||
/* CGI的url */
|
|
||||||
url?: string;
|
|
||||||
/* 调用该CGI的方法 */
|
|
||||||
method?: 'OPTIONS'
|
|
||||||
| 'GET'
|
|
||||||
| 'HEAD'
|
|
||||||
| 'POST'
|
|
||||||
| 'PUT'
|
|
||||||
| 'DELETE'
|
|
||||||
| 'TRACE'
|
|
||||||
| 'CONNECT' | 'string',
|
|
||||||
/* CGI中传参时,存放code的名称 */
|
|
||||||
codeName?: string;
|
|
||||||
/* 登录接口需要的其他参数 */
|
|
||||||
data?: string | IAnyObject | ArrayBuffer;
|
|
||||||
/* 接口返回成功的函数;需要返回session的值 */
|
|
||||||
success?: Function;
|
|
||||||
/* code换取session的接口逻辑出错时,执行的函数,若配置了此函数,则不再默认弹窗报错 */
|
|
||||||
fail?: Function;
|
|
||||||
/* codeToSession的上报字段名 */
|
|
||||||
report?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IReportCGIParam{
|
|
||||||
/* 调用的接口名字,可在request接口的report字段配置 */
|
|
||||||
name: string;
|
|
||||||
/* 发起请求时的时间戳 */
|
|
||||||
startTime: number;
|
|
||||||
/* 请求返回时的时间戳 */
|
|
||||||
endTime: number;
|
|
||||||
/* 请求方法,可用于上报 */
|
|
||||||
request: Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IRequestOption extends wx.RequestOption {
|
|
||||||
/* 发起请求前执行的函数 */
|
|
||||||
beforeSend?: Function;
|
|
||||||
/* 请求过程页面是否展示全屏的loading */
|
|
||||||
showLoading?: boolean | string;
|
|
||||||
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
|
||||||
report?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IUploadFileOption extends wx.UploadFileOption {
|
|
||||||
/* 发起请求前执行的函数 */
|
|
||||||
beforeSend?: Function;
|
|
||||||
/* 请求过程页面是否展示全屏的loading */
|
|
||||||
showLoading?: boolean | string;
|
|
||||||
/* 接口请求成功后将自动执行init()中配置的reportCGI函数,其中的name字段值为这里配置的值 */
|
|
||||||
report?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IGetConfigResult{
|
|
||||||
/* 在组件初始化时传入的请求URL的固定前缀 */
|
|
||||||
urlPerfix?: string | (() => string);
|
|
||||||
/* 在组件初始化时传入的用户登陆态设置本地缓存时间 */
|
|
||||||
sessionExpireTime?: number;
|
|
||||||
/* 在组件初始化时传入的用户登陆态本地缓存时间Storage的key */
|
|
||||||
sessionExpireKey?: string;
|
|
||||||
/* 用户登陆态本地缓存过期的时间戳 */
|
|
||||||
sessionExpire?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const weRequest: weRequest
|
|
||||||
@@ -1,32 +1,29 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strictNullChecks": true,
|
"outDir": "./build/",
|
||||||
"noImplicitAny": true,
|
"strictNullChecks": true,
|
||||||
"module": "CommonJS",
|
"noImplicitAny": true,
|
||||||
"target": "ES5",
|
"module": "CommonJS",
|
||||||
"allowJs": false,
|
"moduleResolution": "node",
|
||||||
"experimentalDecorators": true,
|
"target": "ES5",
|
||||||
"noImplicitThis": true,
|
"allowJs": false,
|
||||||
"noImplicitReturns": true,
|
"experimentalDecorators": true,
|
||||||
"alwaysStrict": true,
|
"noImplicitThis": true,
|
||||||
"inlineSourceMap": true,
|
"noImplicitReturns": true,
|
||||||
"inlineSources": true,
|
"alwaysStrict": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"inlineSourceMap": true,
|
||||||
"noUnusedLocals": true,
|
"inlineSources": true,
|
||||||
"noUnusedParameters": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"strict": true,
|
"noUnusedLocals": true,
|
||||||
"removeComments": true,
|
"noUnusedParameters": true,
|
||||||
"pretty": true,
|
"strict": true,
|
||||||
"strictPropertyInitialization": true,
|
"removeComments": true,
|
||||||
"typeRoots": ["./src/typings"],
|
"pretty": true,
|
||||||
"lib": ["es5", "es2015", "dom", "scripthost"]
|
"strictPropertyInitialization": true,
|
||||||
},
|
"typeRoots": ["./src/typings"],
|
||||||
"include": ["./src/**/*.ts"],
|
"lib": ["es5", "es2015", "dom", "scripthost"],
|
||||||
"exclude": [
|
"declaration": true
|
||||||
"node_modules",
|
},
|
||||||
"build",
|
"include": ["./src/**/*.ts"],
|
||||||
"**/*.spec.ts",
|
"exclude": ["node_modules", "build", "**/*.spec.ts", "**/*.d.ts"]
|
||||||
"**/*.d.ts"
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
19
tslint.json
19
tslint.json
@@ -1,6 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"defaultSeverity": "error",
|
||||||
"tslint:latest",
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
"tslint-config-prettier"
|
"jsRules": {},
|
||||||
]
|
"rules": {
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"no-empty": false,
|
||||||
|
"no-string-literal": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"no-empty-interface": false,
|
||||||
|
"prefer-conditional-expression": false,
|
||||||
|
"no-var-requires": false,
|
||||||
|
"no-console": false,
|
||||||
|
"no-object-literal-type-assertion": false
|
||||||
|
},
|
||||||
|
"rulesDirectory": []
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user