sws-micro-app-adapter-mobile
v0.0.19
Published
SWS移动端微应用适配器
Downloads
8
Readme
SWS微应用适配器
用于快速接入SWS TIME APP的微应用适配器
API
1. 获取微应用运行环境
import {getRuntimeEnvironment} from "sws-micro-app-adapter-mobile";
// h5 or cordova
const runtimeEnvironment = getRuntimeEnvironment();
2. 挂载微应用
支持独立运行在浏览器中,但需要提前调用login方法,进行用户信息初始化
import {mountApp} from "sws-micro-app-adapter-mobile";
mountApp(() => {
// initial app
});
3. 卸载微应用
import {unmountApp} from "sws-micro-app-adapter-mobile";
unmountApp(() => {
// destroy app
});
4. 获取用户信息
import {getUserInfo} from "sws-micro-app-adapter-mobile";
const userInfo = getUserInfo();
5. 获取访问Token
import {getAccessToken} from "sws-micro-app-adapter-mobile";
const accessToken = getAccessToken();
6. 获取APP配置数据
import {getAppConfig} from "sws-micro-app-adapter-mobile";
getAppConfig("appId").then(configData => {
console.log(configData);
})
7. 登录
用于开发时让微应用独立在浏览器中运行,不建议在生产中使用
import {login} from "sws-micro-app-adapter-mobile";
login("工号", "密码").then(userInfo => {
console.log(userInfo);
})
8. 扫码
import {scanCode} from "sws-micro-app-adapter-mobile";
scanCode().then(data => {
console.log(data);
})
9. 获取当前的地理位置
import {getLocation} from "sws-micro-app-adapter-mobile";
getLocation().then(data => {
console.log(data);
})
10. 获取设备语言
import {getLocale} from "sws-micro-app-adapter-mobile";
getLocale().then(data => {
console.log(data);
})
11. 获取设备颜色模式
import {getColorMode} from "sws-micro-app-adapter-mobile";
getColorMode().then(data => {
console.log(data); // light or dark
})
12.监听设备颜色模式的改变
import {onColorModeChange} from "sws-micro-app-adapter-mobile";
onColorModeChange((colorMode) => {
console.log(colorMode); // light or dark
})
12. 获取设备的生物认证方式
import {getSupportBiometricAuthentication} from "sws-micro-app-adapter-mobile";
getSupportBiometricAuthentication().then(data => {
console.log(data); // facial or fingerPrint
})
13. 调用设备进行生物认证
import {startBiometricAuthentication} from "sws-micro-app-adapter-mobile";
startBiometricAuthentication().then(data => {
// 生物认证成功
})
14. 从文件系统中读取指定路径的文件
import {readFile} from "sws-micro-app-adapter-mobile";
readFile("filePath").then(file => {
console.log(file);
})
15. 拍摄照片
import {takePhoto} from "sws-micro-app-adapter-mobile";
takePhoto().then(image => {
// 将File对象转换成DataURL
const fileReader = new FileReader();
fileReader.readAsDataURL(image);
fileReader.onload = function(e) {
console.log(e.target.result);
};
})
16. 录制视频
import {recordVideo} from "sws-micro-app-adapter-mobile";
recordVideo().then(video => {
// 将File对象转换成DataURL
const fileReader = new FileReader();
fileReader.readAsDataURL(video);
fileReader.onload = function(e) {
console.log(e.target.result);
};
})