microApi

微信小程序/uniapp/taro公共函数

Description:
  • 微信小程序/uniapp/taro公共函数

Source:
Author:
  • linjielinlin 993353454@qq.com

Members

(inner, constant) APP :object

Description:
  • APP:返回 uni/wx/taro实例

Source:

APP:返回 uni/wx/taro实例

Type:
  • object

(inner, constant) IS_H5 :boolean

Description:
  • IS_H5:是否为H5

Source:
Default Value:
  • false

IS_H5:是否为H5

Type:
  • boolean

(inner, constant) interceptors

Description:
  • 默认拦截函数obj

Source:

默认拦截函数obj

Methods

(inner) P(argApi, argOptions) → {promise}

Description:
  • wx/taro/uni api转Promise

Source:
Parameters:
Name Type Description
argApi string

需要转promise的API名称

argOptions object

{} api对应的配置,除了success和fail

Returns:
Type
promise

(inner) checkSetting(argSet) → {promise}

Description:
  • 检查用户授权状态,未授权弹出授权,(userInfo除外),将拿到的权限放在authSetting 中

Source:
Parameters:
Name Type Description
argSet string

要检查的权限,userInfo时:已授权会返回userInfo数据

Returns:
Type
promise

(inner) checkUpdate()

Description:
  • 检查是否有更新

Source:

(async, inner) clearStorageSync(argKey, argExtraKey:额外保留的key如:'vuex,ticket', isForce)

Description:
  • 退出登录或登录失效,清除本地数据

Source:
Parameters:
Name Type Description
argKey string

要删除的key,不填为删除全部

argExtraKey:额外保留的key如:'vuex,ticket' string
isForce boolean

是否强制删除全部

(async, inner) cloudApi(argOption) → {promise}

Description:
  • 小程序云函数调用

Source:
Parameters:
Name Type Description
argOption string

云函数配置

Returns:
Type
promise

(async, inner) downloadImgs(argImgList, argIsLocal) → {promise}

Description:
  • 下载图片到手机

Source:
Parameters:
Name Type Default Description
argImgList array

图片url,数组或字符串

argIsLocal boolean false

是否是本地临时文件路径或永久文件路径

Returns:

出错时无promise

Type
promise

(inner) getCurrentPage() → {object}

Description:
  • 获取当前页面数据obj

Source:
Returns:
Type
object

(inner) getCurrentPageUrl(argWithParams) → {string}

Description:
  • 获取当前页url

Source:
Parameters:
Name Type Default Description
argWithParams boolean true

是否附带参数

Returns:
Type
string

(inner) getDb()

Description:
  • 获取unicloud DB,返回实例

Source:

(async, inner) getDom(argThis:, argId, getAll, argOptions)

Source:
Parameters:
Name Type Description
argThis: object

当前this,

argId string

id/class

getAll Boolean

是否获取全部 true时,返回数组

argOptions object

修改默认返回具体参考:https://uniapp.dcloud.io/api/ui/nodes-info?id=nodesreffields

(inner) getLocation(argType, argAltitude) → {promise}

Description:
  • 获取地理位置 (类型,)

Source:
Parameters:
Name Type Default Description
argType string gcj02

类型

argAltitude boolean false

是否高精度

Returns:
Type
promise

(inner) getRichText(argData) → {string}

Description:
  • 富文本格式处理 for 小程序rich-text

Source:
Parameters:
Name Type Description
argData string

富文本

Returns:
Type
string

(async, inner) getStorage(argKey, argNoJson) → {promise}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Default Description
argKey string

要获取的key

argNoJson boolean false

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
promise

(inner) getStorageSync(argKey, argNoJson) → {any}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Default Description
argKey string

要获取的key

argNoJson boolean false

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
any

(inner) getSystemInfo() → {object}

Description:
  • 检测浏览器状态,系统状态 *

Source:
Returns:

{ ua: ua, platform: 平台, isMobile: 移动端, isWin: winPC端, isIphone: iphone, isIpad: ipad, isMac: mac, isAppleMobile: 苹果移动端webview isSafari: Safari浏览器, isIos: Ios平台, isAndroid: android平台, isIE: 显示8 9 10, true为11以上 ... }

Type
object

(async, inner) getUserInfo(argData) → {promise}

Description:
  • 获取用户信息

Source:
Parameters:
Name Type Description
argData object

用户数据(点按钮授权时传入)

Returns:
Type
promise

(inner) hideLoading()

Description:
  • 隐藏loading

Source:

(inner) init(argConfig)

Description:
  • 初始化配置(uniCloud/request拦截)

Source:
Parameters:
Name Type Description
argConfig any
Properties
Name Type Description
localEncrypt boolean

本地缓存是否加密

(inner) ljApiFn(argOption) → {argOption}

Description:
  • 使用ljapi

Source:
Parameters:
Name Type Description
argOption AnyObject

传入参数

Returns:

返回修改后的参数

Type
argOption

(inner) login() → {promise}

Description:
  • 获取微信登录code

Source:
Returns:
Type
promise

(inner) refresh()

Description:
  • 页面刷新

Source:

(async, inner) request(argOption, argIsMock) → {promise}

Description:
  • 封装小程序request

Source:
Parameters:
Name Type Default Description
argOption AnyObject

http配置

argIsMock Bool false

是否使用mock

Returns:
Type
promise

(async, inner) requestCloud(argOption)

Description:
  • 请求云函数

Source:
Parameters:
Name Type Description
argOption object
Properties
Name Type Description
name string

云函数名

params object

参数

config object

请求配置 }

(inner) scrollTop(scrollTop, duration) → {promise}

Description:
  • 回到顶部/某个位置

Source:
Parameters:
Name Type Default Description
scrollTop number 0

滚动距离

duration number 0

时间

...arg any

其他参数selector/offsetTop/success/fail/complete

Returns:
Type
promise

(inner) setRequest(argRequest, argResponse)

Description:
  • 修改设置拦截函数

Source:
Parameters:
Name Type Description
argRequest function

请求拦截

argResponse function

响应拦截

(async, inner) setStorage(argKey, argData) → {promise}

Description:
  • 设置storage的值,默认将obj转为json

Source:
Parameters:
Name Type Description
argKey string

要设置的key

argData string | AnyObject

要设置的值

Returns:

key对应的数据

Type
promise

(inner) setTitle(argTitle)

Description:
  • 设置标题

Source:
Parameters:
Name Type Description
argTitle string

标题

(inner) showLoading()

Description:
  • 显示loading

Source:

(inner) toPage(argPage, argParams, argType, argForce)

Description:
  • uniapp跳到特定页面

Source:
Parameters:
Name Type Default Description
argPage string

标题

argParams object

url参数

argType string | number

跳转类型 switchTab reload redirectTo reLaunch navigateTo

argForce boolean false

是否取消节流非H5生效

(async, inner) toast(argTitle, argOption) → {promise}

Description:
  • toast默认为文字提示,默认推迟320ms显示

Source:
Parameters:
Name Type Description
argTitle string

title

argOption object

配置 argOption.icon:'图标', argOption.delay: '延时显示ms' argOption.duration:"显示时间"

Returns:
Type
promise

(async, inner) uploadImg(argOption) → {promise}

Description:
  • 图片上传 单图/多图

Source:
Parameters:
Name Type Description
argOption object

参数配置

Returns:

上传回调

Type
promise

(async, inner) uploadImgs(argOptions, argMb, argQuality, argMaxSize) → {promise}

Description:
  • 上传图片,返回临时图片路径

Source:
Parameters:
Name Type Default Description
argOptions object

argOptions.count: 9,最多可以选择的图片张数 argOptions.sizeType: ['original', 'compressed'], 所选的图片的尺寸 argOptions.sourceType: ['album', 'camera'] album ,从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项 argOptions.disCompress: false 是否关闭图片压缩,默认开启 } 外加选择图片chooseImage配置

argMb number 1

超过多少M压缩,默认1M(仅支持jpg)

argQuality number 90

压缩质量默认80

argMaxSize number 1920

图片最长边默认1920

Returns:

返回临时图片路径[{tempFilePath:'临时路径',size: '不压缩时返回'}]

Type
promise

(inner) wxLog() → {AnyObject}

Description:
  • 微信实时日志记录

Source:
Returns:
Type
AnyObject