Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qcloud-iotexplorer-h5-panel-sdk

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qcloud-iotexplorer-h5-panel-sdk

腾讯连连小程序自定义H5面板SDK开发文档

  • 1.0.6
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

qcloud-iotexplorer-h5-panel-sdk

腾讯连连小程序自定义H5面板SDK开发文档

开始使用

npm i qcloud-iotexplorer-h5-panel-sdk

引入sdk

import sdk from 'qcloud-iotexplorer-h5-panel-sdk';

// or
const sdk = require('qcloud-iotexplorer-h5-panel-sdk');

API

sdk.controlDeviceData: (data) => Promise

控制设备属性,如:

sdk.controlDeviceData({ 
    power_switch: 1
});

sdk.getDeviceDataHistory

查询设备历史数据,具体用法参见: AppGetDeviceDataHistory 接口文档

sdk.getUserInfo

拉取用户信息,调用后会更新到 sdk.userInfo 中,具体用法参考 AppGetUser 接口文档

sdk.getProductInfo

拉取设备所属产品信息,调用后会更新 sdk.productInfo 和 sdk.dataTemplate,具体用法参考 AppGetProducts 接口文档

sdk.getDeviceData

拉取设备最新的属性,调用后会更新 sdk.deviceData,具体用法参考 AppGetDeviceData 接口文档

sdk.getDeviceStatus

拉取设备当前在线状态,调用后会更新 sdk.deviceStatus,具体用法参考 AppGetDeviceStatuses 接口文档

sdk.goDeviceDetailPage

跳转到腾讯连连通用的产品详情页(小程序页面)

sdk.tips

tips模块,样式和风格与连连小程序一致

sdk.tips.show: (message, options) => Promise
  • options.type?: 'info' | 'danger' | 'loading' | 'success';
  • options.waitForHide?: boolean; 若为true,则 show 方法返回一个Promise,并且当关闭后才会触发 resolve
  • options.duration?: number; 展示提示的时间,单位毫秒,默认 1500
  • options.delayDuration?: number; 默认0,单位毫秒,提示会在该延时后展示
  • options.canClickClose?: boolean; 默认true,点击mask是否能够关闭提示
  • options.canBeReplace?: boolean; 默认false,为false时上一个提示未关闭前,再次调用 tips.show会被忽略

展示tips

sdk.tips.hide: () => Promise

关闭tips

sdk.tips.showLoading: (message, options) => Promise

封装后的 tips.show 方法,等价于:

this.show(message, {
    type: 'loading',
    canBeReplace: true,
    duration: 0,
    delayDuration: 200,
    canClickClose: false,
    ...options,
})
sdk.tips.hideLoading: () => Promise

关闭loading tips

注意,showLoading后必须主动调用hideLoading,否则tips永远不会消失

sdk.tips.showSuccess: (message, options) => Promise

封装后的 tips.show 方法,等价于:

this.show(message, { type: 'success', ...opts });
sdk.tips.showInfo: (message, options) => Promise

封装后的 tips.show 方法,等价于:

this.show(message, { type: 'info', ...options });
sdk.tips.showError: (error, options) => Promise
  • error: any; 可以为一个原生Error对象,可以为标准的api响应 { code, msg },也可以为一个字符串。

会先标准化处理错误展示信息后展示tips,等价于:

return this.show(errMsg, { type: 'danger', mask, duration, ...options });

sdk.onWsClose: (callback) => void;

  • callback: ({ code, reason }) => void;

当 websocket close 事件触发后执行回调

sdk.onWsError: (callback) => void;

  • callback: (error) => void;

当 websocket 触发 error 事件后触发回调

sdk.onWsControl: (callback) => void;

  • callback: ({ deviceId, deviceData }) => void;

当 websocket 收到 control 指令后触发

sdk.onWsReport: (callback) => void;

  • callback: ({ deviceId, deviceData }) => void;

当 websocket 收到 report 指令后触发

sdk.onWsStatusChange: (callback) => void;

  • callback: ({ deviceId, deviceStatus }) => void;

当 websocket 收到设备状态改变推送后触发回调

sdk.requestTokenApi: (action, data, options) => Promise

  • action: string 具体api名称,如:AppGetUser
  • data: object 接口调用参数
  • options: 参数参考 appDevSdk.requestApi 文档

sdk.share: ({ title, imgUrl }) => Promise

  • title: string 分享的标题
  • imgUrl?: string 分享图片的地址,默认会取当前页面截图

设置当前页面的分享内容,通过 wx.miniProgram.postMessage 向小程序推送分享信息,具体参考 小程序页面分享文档

sdk.navBack: () => Promise

调用 wx.miniProgram.navigateBack 返回上一级页面

sdk.appDevSdk

应用开发 SDK 实例,H5面板sdk底层依赖 应用开发小程序端SDK,更多调用能力请参考应用开发SDK文档

sdk.wx

微信 JS-SDK 实例,具体用法参考官方文档,使用前必须保证已经调用 sdk.wxSdkReady 方法

sdk.wxSdkReady: () => Promise

确保微信 jssdk 已注册完成,完成后会触发 resolve,该方法多次调用,若成功会返回缓存的 Promise 对象,如:

sdk.wxSdkReady().then(() => wx.miniProgram.navigateBack());

属性

sdk.deviceId: string

设备id,由 {productId}/{deviceName} 组成

sdk.productId: string

产品id

sdk.deviceName: string

设备名称

sdk.deviceInfo

设备信息,如:

{
    AliasName: "设备别名",
    CreateTime: 1583739344,
    DeviceId: "{productId}/{deviceName}",
    DeviceName: "{deviceName}",
    DeviceType: 0,
    FamilyId: "家庭ID",
    IconUrl: "设备ICON",
    ProductId: "{productId}",
    RoomId: "房间id",
    UpdateTime: 1583739344,
    UserID: "用户Id"
}

sdk.dataTemplate

设备所在产品的物模型,如:

{
    "version": "1.0",
    "profile": {
        "ProductId": "xxxx",
        "CategoryId": "1"
    },
    "properties": [
        {
            "id": "int",
            "name": "int",
            "desc": "",
            "mode": "rw",
            "define": {
                "type": "int",
                "min": "0",
                "max": "100",
                "start": "0",
                "step": "1",
                "unit": ""
            },
            "required": false
        },
        {
            "id": "float",
            "name": "float",
            "desc": "",
            "mode": "rw",
            "define": {
                "type": "float",
                "min": "0",
                "max": "100",
                "start": "0",
                "step": "1",
                "unit": ""
            },
            "required": false
        },
        {
            "id": "bool",
            "name": "bool",
            "desc": "",
            "mode": "rw",
            "define": {
                "type": "bool",
                "mapping": {
                    "0": "关",
                    "1": "开"
                }
            },
            "required": false
        },
        {
            "id": "enum",
            "name": "enum",
            "desc": "",
            "mode": "rw",
            "define": {
                "type": "enum",
                "mapping": {
                    "1": "1",
                    "2": "2",
                    "3": "3",
                    "4": "4",
                    "5": "5"
                }
            },
            "required": false
        }
    ],
    "events": [],
    "actions": []
}

sdk.deviceStatus: number

设备在线状态,在线: 1,非在线: 0

sdk.deviceDisplayName: string

设备展示名称,会依次取:AliasName > productInfo.name > deviceName 来展示

sdk.isShareDevice: boolean

是否是分享设备

sdk.familyId: string

设备所在家庭id,如果是分享设备则无此值

sdk.roomId: string;

设备所在房间id,如果是分享设备则无此值

sdk.familyInfo

设备所在家庭详情,如果是分享设备则无此值

sdk.isFamilyOwner: boolean

用户是否是当前家庭的管理员

sdk.userInfo

用户信息,如:

{
    Avatar: "头像url",
    CountryCode: "国家代码",
    Email: "email",
    NickName: "昵称",
    PhoneNumber: "电话号码",
    UserID: "用户id"
}

FAQs

Package last updated on 31 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc