npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@quec-wx-mp/api-scene

v1.0.0

Published

小程序插件 智能场景

Readme

智能场景

智能场景模块,提供场景查询、创建、编辑、执行、测试和日志管理等 API。

安装

npm install @quec-wx-mp/api-scene
import scene from '@quec-wx-mp/api-scene'
const plugin = requirePlugin('quecPlugin')

plugin.use(scene)

API 列表

| 方法 | 说明 | | ---------------------- | ---------------- | | selectCommonSceneList | 查询常用场景列表 | | selectSceneDetail | 查询场景详情 | | selectSceneList | 查询场景列表 | | batchAddCommonScene | 批量添加常用场景 | | batchDeleteCommonScene | 批量移除常用场景 | | deleteSceneLog | 删除场景日志 | | sceneCreate | 创建场景 | | sceneDelete | 删除场景 | | sceneEdit | 编辑场景 | | sceneExecute | 执行场景 | | sceneTest | 测试场景 | | selectSceneLogDetail | 查询场景日志详情 | | selectSceneLogList | 查询场景日志列表 |


API 详细说明

1) 查询常用场景列表

接口名称

selectCommonSceneList

功能描述

查询常用场景列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | page | number | - | 是 | 当前页 | | pageSize | string | - | 是 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.code 为状态码,res.data 为常用场景列表数据。

示例代码

plugin.scene.selectCommonSceneList({
  fid: 'family_id',
  page: 1,
  pageSize: '10',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

2) 查询场景详情

接口名称

selectSceneDetail

功能描述

根据场景 id 查询场景详情。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为场景详情。

示例代码

plugin.scene.selectSceneDetail({
  fid: 'family_id',
  sceneId: 'scene_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

3) 查询场景列表

接口名称

selectSceneList

功能描述

分页查询场景列表,支持按场景名称筛选。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | page | number | - | 是 | 当前页 | | pageSize | string | - | 是 | 页大小 | | sceneName | string | - | 否 | 场景名称 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为场景分页列表。

示例代码

plugin.scene.selectSceneList({
  fid: 'family_id',
  page: 1,
  pageSize: '10',
  sceneName: '回家模式',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

4) 批量添加常用场景

接口名称

batchAddCommonScene

功能描述

将多个场景批量添加到常用场景。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ------------ | | fid | string | - | 是 | 家庭 id | | sceneIdList | string[] | - | 是 | 场景 id 列表 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.scene.batchAddCommonScene({
  fid: 'family_id',
  sceneIdList: ['scene_1', 'scene_2'],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

5) 批量移除常用场景

接口名称

batchDeleteCommonScene

功能描述

将多个场景从常用场景中批量移除。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ------------ | | fid | string | - | 是 | 家庭 id | | sceneIdList | string[] | - | 是 | 场景 id 列表 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.scene.batchDeleteCommonScene({
  fid: 'family_id',
  sceneIdList: ['scene_1', 'scene_2'],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

6) 删除场景日志

接口名称

deleteSceneLog

功能描述

删除当前用户下的场景日志。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 是 | 家庭 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.scene.deleteSceneLog({
  fid: 'family_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

7) 创建场景

接口名称

sceneCreate

功能描述

创建场景。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为创建结果。

示例代码

plugin.scene.sceneCreate({
  arr: [
    {
      fid: 'family_id',
      isCommon: false,
      sceneInfo: {
        icon: 'scene_icon',
        id: 1,
        name: '回家模式',
        sceneId: '',
        metaDataList: [
          {
            deviceKey: 'device_key',
            deviceName: '客厅灯',
            logoImage: 'logo.png',
            productKey: 'product_key',
            actionList: [
              {
                actionId: 1,
                code: 'switch',
                dataType: 'BOOL',
                id: 1,
                name: '开关',
                subName: '',
                subType: '',
                type: 'WRITE-ATTR',
                unit: '',
                value: true
              }
            ]
          }
        ]
      }
    }
  ],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

8) 删除场景

接口名称

sceneDelete

功能描述

根据场景 id 删除场景。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.scene.sceneDelete({
  fid: 'family_id',
  sceneId: 'scene_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

9) 编辑场景

接口名称

sceneEdit

功能描述

编辑场景,入参结构与创建场景一致。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为编辑结果。

示例代码

plugin.scene.sceneEdit({
  arr: [
    {
      fid: 'family_id',
      isCommon: true,
      sceneInfo: {
        icon: 'scene_icon',
        id: 1,
        name: '离家模式',
        sceneId: 'scene_id',
        metaDataList: [
          {
            deviceKey: 'device_key',
            deviceName: '空调',
            logoImage: 'logo.png',
            productKey: 'product_key',
            actionList: [
              {
                actionId: 2,
                code: 'power',
                dataType: 'BOOL',
                id: 2,
                name: '电源',
                subName: '',
                subType: '',
                type: 'WRITE-ATTR',
                unit: '',
                value: false
              }
            ]
          }
        ]
      }
    }
  ],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

10) 执行场景

接口名称

sceneExecute

功能描述

执行指定场景。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为执行结果。

示例代码

plugin.scene.sceneExecute({
  fid: 'family_id',
  sceneId: 'scene_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

11) 测试场景

接口名称

sceneTest

功能描述

测试场景配置,入参结构与创建场景一致。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为测试结果。

示例代码

plugin.scene.sceneTest({
  arr: [
    {
      fid: 'family_id',
      isCommon: false,
      sceneInfo: {
        icon: 'scene_icon',
        id: 1,
        name: '测试场景',
        sceneId: '',
        metaDataList: [
          {
            deviceKey: 'device_key',
            deviceName: '插座',
            logoImage: 'logo.png',
            productKey: 'product_key',
            actionList: [
              {
                actionId: 3,
                code: 'switch',
                dataType: 'BOOL',
                id: 3,
                name: '开关',
                subName: '',
                subType: '',
                type: 'WRITE-ATTR',
                unit: '',
                value: true
              }
            ]
          }
        ]
      }
    }
  ],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

12) 查询场景日志详情

接口名称

selectSceneLogDetail

功能描述

根据 executionId 查询场景日志详情。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ----------- | | executionId | number | - | 否 | 执行日志 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为日志详情。

示例代码

plugin.scene.selectSceneLogDetail({
  executionId: 1001,
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

13) 查询场景日志列表

接口名称

selectSceneLogList

功能描述

查询当前用户下的场景日志列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------------- | -------- | ------ | ---- | ---------------------------- | | fid | string | - | 否 | 家庭 id | | lastExecutionId | number | - | 否 | 上一次 executionId,用于翻页 | | limit | number | - | 否 | 限制返回数量 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为日志列表。

示例代码

plugin.scene.selectSceneLogList({
  fid: 'family_id',
  lastExecutionId: 1001,
  limit: 10,
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})