1.3.8 • Published 5 years ago

chanjet-mutants v1.3.8

Weekly downloads
84
License
MIT
Repository
-
Last release
5 years ago

Chanjet-Mutants v0.0.6

作为Mutants框架的入口,提供以下功能:

  • 不同平台(工作圈 , 微信 , 钉钉等)的统一预处理.
  • 环境检测
  • native能力

加载

目前还是使用 import 方式进行进入 , 在适当时候 , 我们会将 mutants 更新到cdn服务器 , 使用script方式加载 . 目的是为了当工作圈native能力发生更新时 , mutants 提供的插件能力也能够同步更新 , 减少npm包管理导致的依赖复杂性.

我们会通过版本号来管理不同版本 , 这样可以兼容不同版本的工作圈.

安装

npm install chanjet-mutants

ready

mutants.ready 作为 mutants 整个框架的入口 , 会先检测不同平台 native 能力是否准备完成 . 当准备完成后 , 将会执行通过 ready 传入的回调函数

import mutants from 'chanjet-mutants';

mutants.ready( () => {
  //启动应用
});

环境检测

mutants 提供环境检测之前 , 环境检测是有 chanjet-env-check 这个包来完成的. 现在 mutants 中已经整合了环境检测 , 也是使用 chanjet-env-check , 挂载在 mutants.env 对象上.

import mutants from 'chanjet-mutants'

/*
mutants封装了chanjet-env-check对象,可以快速获取当前环境,无需在引入chanjet-env-check包,详见接口文档
*/

//当前平台
console.log(mutants.env.platform);
//当前系统或设备
console.log(mutants.env.os);
//当前浏览器
console.log(mutants.env.browser);

//可以通过constant来判断

//判断是否是chanjet平台
mutants.env.platform == mutants.constant.platform.chanjet
//判断是否是ios操作系统
mutants.env.os == mutants.constant.os.ios
//判断是否是chrome浏览器
mutants.env.browser == mutants.constant.browser.chrome

Native能力

目前提供的Native能力 , 都可以在 mutants.plugin 对象上找到.

具体能力见下表:

APINative能力文档
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 为例:

import mutants from 'chanjet-mutants'

const mockData = {
  //读取相册成功
  ChoosePhotoPlugin: {
    status: 'success',
    //替换成自己想显示的图片
    data: ['http://www.example.com/example.png']
  },
};

//设置mock数据
mutants.plugin.setMockData(mockData);


//详细文档参见ChoosePhotoPlugin文档
const choosePhotoOptions = {
  maxCount : 2,
  quality : 0
};
mutants.plugin.choosePhoto.choosePhoto(choosePhotoOpitons , (rs) => {
  //rs.body.data 中得数据 应该是mockData中所设置的
  console.log(rs);
});