base-jssdk-iot
v0.1.46
Published
Bladex Frontend SDK
Downloads
17
Readme
base-jssdk
此版本封版, 无特殊情况不进行更新
包含 BladeX Auth, Storage, Fetch 的 JavaScript SDK。
安装
yarn add base-jssdk
设置
/src/plugins/bladex.js
import BDTD from 'base-jssdk'
const config = {
endpoint: '/api',
storage: localStorage
}
BDTD.initializeApp(config)
const auth = BDTD.auth()
const fetch = BDTD.fetch()
const storage = BDTD.storage()
export {
auth,
fetch,
storage
}
使用说明
import { auth, fetch, storage } from './plugins/bladex.js'
Auth
登录
await auth.login(username, password)
注销
await auth.logout()
获取 Token
const jwt = auth.getJWTToken()
onAuthStateChanged
auth.onAuthStateChanged(data => {
console.log('auth state changed!')
console.log({data})
})
Fetch
请求
try {
const res = await fetch.post('/interface', data)
} catch (e) {
// handle error
}
Storage
上传文件
metadata
是可选项
onUploadProgress
是可选项
try {
await storage.put(path, file, metadata, onUploadProgress);
} catch (e) {
// handle error
}
获取可下载的文件地址
storage.getDownloadURL(path);