v0.0.6
Chanjet-Mutants 作为Mutants框架的入口,提供以下功能:
- 不同平台(工作圈 , 微信 , 钉钉等)的统一预处理.
- 环境检测
- native能力
加载
目前还是使用 import
方式进行进入 , 在适当时候 , 我们会将 mutants
更新到cdn服务器 , 使用script
方式加载 . 目的是为了当工作圈native能力发生更新时 , mutants
提供的插件能力也能够同步更新 , 减少npm包管理导致的依赖复杂性.
我们会通过版本号来管理不同版本 , 这样可以兼容不同版本的工作圈.
安装
npm install chanjet-mutants
ready
mutants.ready
作为 mutants
整个框架的入口 , 会先检测不同平台 native 能力是否准备完成 . 当准备完成后 , 将会执行通过 ready
传入的回调函数
; mutants;
环境检测
在 mutants
提供环境检测之前 , 环境检测是有 chanjet-env-check
这个包来完成的. 现在 mutants
中已经整合了环境检测 , 也是使用 chanjet-env-check
, 挂载在 mutants.env
对象上.
/*mutants封装了chanjet-env-check对象,可以快速获取当前环境,无需在引入chanjet-env-check包,详见接口文档*/ //当前平台console;//当前系统或设备console;//当前浏览器console; //可以通过constant来判断 //判断是否是chanjet平台mutantsenvplatform == mutantsconstantplatformchanjet//判断是否是ios操作系统mutantsenvos == mutantsconstantosios//判断是否是chrome浏览器mutantsenvbrowser == mutantsconstantbrowserchrome
Native能力
目前提供的Native能力 , 都可以在 mutants.plugin
对象上找到.
具体能力见下表:
API | Native能力 | 文档 |
---|---|---|
mutants.plugin.auth | 企业信息及权限相关 | 去看看 |
mutants.plugin.choosePhoto | 读取相册选照片 | 去看看 |
mutants.plugin.takePhoto | 拍照 | 去看看 |
mutants.plugin.preview | 预览 | 去看看 |
mutants.plugin.upload | 上传 | 去看看 |
mutants.plugin.geo | 定位 | 去看看 |
mutants.plugin.phone | 电话 | 去看看 |
mutants.plugin.sms | 短信 | 去看看 |
mutants.plugin.share | 分享 | 去看看 |
mutants.plugin.speechReco | 语音识别 | 去看看 |
mutants.plugin.restoreStatus | 安卓restore状态查询(Private) |
所有插件的方法, 都可以在对应的 mutants.plugin[pluginName]
上直接使用.
为了兼容好会计之前的调用方式, 每一个插件的包依旧支持独立使用 , 等好会计调整过后. 将不再提供.
Mock
在开发过程中, 可以在浏览器环境中 , 使用 mock
数据来模拟Native能力的调用返回. 上表中 , 详细文档中会有每个插件的 mock
数据格式 .
通过 mutants.plugin.setMockData
可以进行 mock
数据的绑定.
以 choosePhoto
为例:
const mockData = //读取相册成功 ChoosePhotoPlugin: status: 'success' //替换成自己想显示的图片 data: 'http://www.example.com/example.png' ; //设置mock数据mutantsplugin; //详细文档参见ChoosePhotoPlugin文档const choosePhotoOptions = maxCount : 2 quality : 0;mutantspluginchoosePhoto;