ipink-util
Version:
util.js
109 lines (108 loc) • 3.22 kB
TypeScript
export type ErrorType = {
errCode?: string | number;
errMsg?: string;
msg?: string;
};
export type RectType = {
width: number;
height: number;
};
/**
* @desc 获取本地文件路径
* @param path { string }
* @return: { string }
*/
export declare function getLocalFilePath(path: string): string;
/**
* chooseImage 选择图片并加工为base64;
* count: 一次性选择数量
* type: 选择图片方式
* extension: H5上上传图片格式
* width: 支付宝小程序canvas 宽度, 不指定默认设备宽度(windowWidth)
* height: 支付宝小程序canvas 高度, 不指定默认380px (不指定可能导致图片变形)
*/
export type ChooseImageOption = {
/** @desc 上传数量 **/
count?: number;
/** @desc 打开相机方式 1: 相机, 2: 相册, 3:全部 **/
sourceType?: 1 | 2 | 3;
/** @desc 固定不变 **/
fileType?: "image" | "video" | "audio";
/** @desc 文件后缀限制 **/
extension?: string[];
showToast?: boolean;
};
export type ChooseImageAlipayResult = {
/** @desc 图片文件路径 **/
apFilePathsV2?: string[];
/** @desc 图片文件路径 **/
apFilePaths: string;
/** @desc 图片文件路径 Android使用 **/
tempFilePaths: string;
/** @desc 图片多媒体LocalId iOS使用 **/
localIds?: string;
/** @desc 是否返回成功 **/
success?: boolean;
/** @desc 错误码 **/
errorCode?: string;
tempFiles?: File[];
};
/**
* @desc 选取文件 ( 用于 支付宝公众号 | uniapp )
* @param params { ChooseImageOption }
* @return: { Promise<string[]> }
*/
export declare function chooseImage(params: ChooseImageOption): Promise<string[]>;
/**
* @desc 获取图片信息 ( 用于 uniapp | 微信公众号 )
* @param params { ChooseImageOption }
* @return: { Promise<string[]> }
*/
export declare function getImageInfo(url: string): Promise<UniApp.GetImageInfoSuccessData | ErrorType>;
type Path2Base64Result = {
base64?: string;
file?: string;
info?: RectType | WechatMiniprogram.ReadFileSuccessCallbackResult;
err?: ErrorType;
};
/**
* @desc 文件路径转换base64
* @param path { string }
* @param info { string }
* @param path { string }
* @return: { Promise<string[]> }
*/
export declare function pathToBase64(path: string, info?: RectType, width?: number, height?: number): Promise<Path2Base64Result>;
/**
* @desc Basr64 转换为 path
* @param param { type }
* @return:
*/
export declare function base64ToPath(base64: string): Promise<string | ErrorType>;
type ChooseVideoOptions = {
sourceType: 1 | 2 | 3;
maxDuration?: any;
camera?: any;
compressed?: boolean;
showToast?: boolean;
};
/**
* @desc 选择视频
* @param options { ChooseVideoOptions }
* @return: { Promise<string[]> }
*/
export declare function chooseVideo(options?: ChooseVideoOptions): Promise<string[]>;
type ChooseFileOptions = {
count?: number;
extension?: string[];
type?: any;
sourceType?: 1 | 2 | 3;
showToast?: boolean;
};
/**
* @desc 选择视频
* @param param { type }
* @return:
*/
export declare function chooseOtherFile(options?: ChooseFileOptions): Promise<string[]>;
export {};