UNPKG

fastchar-appjs

Version:

快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html,不使用vue单页面功能。

215 lines (214 loc) 7.62 kB
import { AxiosPromise } from "axios"; /** * FastServer 创息公司请求服务器接口工具类 * @author Janesen */ export declare namespace FastServer { /** * 基本的网络请求接口 */ class Base { constructor(); /** * 获取请求接口的默认头信息配置 */ static getHeaderConfig(): any; /** * 获取地址栏携带的参数 * @param paramName 参数名 */ static getWindowUrlParam(paramName: string): string | null; /** * 获取地址栏携带的参数对象信息 */ static getWindowUrlInfo(): any; /** * 获取url的参数 * @param url 地址 * @param paramName 参数名 */ static getUrlParam(url: string, paramName: string): string | null; /** * 获取url的参数实体对象 * @param url 地址 */ static getUrlParamInfo(url: string): any; /** * 追加url参数 * @param url * @param params */ static appendUrlParams(url: string, params: any): string; /** * 合并多个FormData参数 * @param formData */ static mergeFormData(...formData: FormData[]): FormData; /** * 如果是formData对象则转转换参数为object对象 * @param param */ static convertToObject(param: any): object; /** * 转换参数为FormData格式 * @param param 任意格式的参数,FormData、Object、Function */ static convertToFormData(param: any): FormData; /** * 合并参数并转换为FormData格式 * @param params 任意多个参数,FormData、Object、Function */ static mergeParams(...params: any[]): FormData; /** * 将数组格式的参数合并 * @param params 数组 */ static mergeParamsByArray(params: any[]): FormData; /** * 发起接口请求 * @param method 请求方法,例如,post、get * @param url 请求地址 * @param params 请求参数 */ static doRequest(method: string, url: string, params: any): AxiosPromise; /** * 执行post请求 * @param url 请求地址 * @param params 请求参数,可为object或formdata */ static doPost(url: string, params: any): AxiosPromise; /** * 执行get请求 * @param url 请求接口地址 * @param params 请求接口参数 */ static doGet(url: string, params?: any): AxiosPromise; } /** * 创息公司系统的接口请求类 */ class Croshe extends Base { /** * 获取接口的全局参数,同步获取了原生APP的全局参数 */ static getFinalParams(): Promise<any>; /** * 发起请求接口 * @param method 请求方法,例如:post、get * @param url 接口地址 完整的地址,例如:http://loalhost:8080/user/login * @param params 参数 * @param config 请求配置 * @param callBack 请求接口回调函数,在使用alwaysCache和alwaysBackRequest参数为true时,必须使用回调函数接收 */ static request(method: string, url: string, params: any, config?: FastRequestConfig, callBack?: (result: FastResponseData) => void): Promise<FastResponseData>; /** * post请求接口 * @param url 接口地址 完整的地址,例如:http://loalhost:8080/user/login * @param params 参数 * @param config 请求配置 * @param callBack 请求接口回调函数,在使用alwaysCache和alwaysBackRequest参数为true时,必须使用回调函数接收 */ static post(url: string, params: any, config?: FastRequestConfig, callBack?: (result: FastResponseData) => void): Promise<FastResponseData>; /** * get请求接口 * @param url 接口地址 完整的地址,例如:http://loalhost:8080/user/login * @param params 参数 * @param config 请求配置 * @param callBack 请求接口回调函数,在使用alwaysCache和alwaysBackRequest参数为true时,必须使用回调函数接收 */ static get(url: string, params: any, config?: FastRequestConfig, callBack?: (result: FastResponseData) => void): Promise<FastResponseData>; /** * 构建接口请求的缓存key * @param url 请求地址 * @param params 请求参数 */ static buildCacheKey(url: string, params: any): string; } /** * 创息公司接口返回数据的格式解析类 */ class FastResponseData { responseData: any; cacheData: boolean; requestConfig: FastRequestConfig; constructor(responseData: any, cacheData?: boolean); /** * 获取接口返回的原始数据 */ getResponseData(): any; /** * 判断当前回调的数据是否是缓存的数据 */ isCacheData(): boolean; /** * 判断接口是否请求成功-success */ isSuccess(): boolean; /** * 获取接口请求返回的状态值-code */ getCode(): number; /** * 获取接口请求返回的消息提示-message */ getMessage(): string; /** * 获取接口请求返回的数据-data */ getData(): any; /** * 获取接口请求返回的其他数据,例如:data_1、data_2 * @param suffixIndex 数据后缀,例如:data_1 后缀传 1 */ getOtherData(suffixIndex: number): any; /** * 判断接口返回的数据data是否是分页的数据 */ isPageData(): boolean; /** * 获取接口返回的数据列表,如果data是分页数据则返回分页的列表,否则返回data */ getList(): any[]; /** * 获取接口列表分页数据的页数 */ getPage(): number; /** * 获取接口列表分页数据的总页数 */ getTotalPage(): number; /** * 获取接口列表分页数据的总行数 */ getTotalRow(): number; /** * 获取接口列表分页数据的每页大小 */ getPageSize(): number; /** * 是否已加载结束,当page>=totalPage 或 list 为空时,认为加载已结束 */ isFinished(): boolean; } /** * 接口请求配置类 */ class FastRequestConfig { /** * 是否追加全局参数,默认true */ finalParams: boolean; /** * 是否缓存数据,true:检测到有当前接口的缓存数据时,将回调缓存的数据 */ cache: boolean; /** * 是否总是缓存数据,true:无论是否已有缓存数据,都将请求接口并刷新当前缓存的数据,不支持then方法接收 */ alwaysCache: boolean; /** * 是否总是回调接口请求返回的数据,true:如果有缓存第一次回调缓存数据,第二次回调接口返回的数据,否则值回调一次接口返回的数据,不支持then方法接收 */ alwaysBackRequest: boolean; } }