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

hardware-api

v1.11.3

Published

硬件控制中心API访问库

Readme

硬件控制中心 API 访问库

安装

yarn

引用

1.在 vue 项目的 plugins 目录下新建一个 hardware.js 文件,将以下代码复制到文件中

/*
 * @Descripttion:
 * @version: 1.0
 * @Author: ZaccheoW
 * @Date: 2023-10-13 17:08:58
 * @LastEditors: ZaccheoW
 * @LastEditTime: 2023-11-10 16:35:16
 */
// 硬件控制中心插件封装
import {
  Host,
  Terminal,
  Document,
  Downloader,
  Drive,
  FileSystem,
  IDCardReader,
  Indicator,
  Printer,
  Scanner,
  SerialBarcodeReader,
  StorageCabinet,
  ThermalPrinter
} from '@zaccheo/hardware-api'
import PubSub from 'pubsub-js'

class Hardware {
  // 重连间隔
  _reconnectInterval = 30000

  _protocolType = ''

  // // 构造函数
  // constructor() {
  //   // 初始化

  // }

  // vue插件安装入口函数
  install (Vue, options) {
    Vue.prototype.$hardware = this
    // 初始化所有插件
    this.initial(Vue)
    // 根据插件启用情况与插件建立实时连接
    this.connect(Vue)
  }

  /**
   * @name: 初始化
   * @return {void}
   */
  initial (Vue) {
    // 引入硬件控制中心插件
    Vue.use(Host)
    Vue.use(Terminal)
    Vue.use(Document)
    Vue.use(Downloader)
    Vue.use(Drive)
    Vue.use(FileSystem)
    Vue.use(IDCardReader)
    Vue.use(Indicator)
    Vue.use(Printer)
    Vue.use(Scanner)
    Vue.use(SerialBarcodeReader)
    Vue.use(StorageCabinet)
    Vue.use(ThermalPrinter)
  }

  /**
   * @name: 建立各插件的hub连接
   * @return {void}
   */
  connect (Vue) {
    // 根据启用的插件进行初始化
    Host.getVersion()
      .then(res => {
        this._protocolType = res.data.hubProtocol
        return Host.getPlugins()
      })
      .then(res => {
        // 遍历所有插件,根据插件启用情况进行连接
        if (res.data) {
          debugger
          res.data.forEach(p => {
            if (p.enabled) {
              // 建立hub连接
              if (!Vue[p.code]) {
                console.warn(`[hardware]${p.code} 插件不存在。请检查。`)
                return
              }
              if (Vue[p.code].connect) {
                Vue[p.code].connect({ protocolType: this._protocolType.toUpperCase() })
              }
            }
          })
        }
      })
      .catch(err => {
        // 连接失败重连
        setTimeout(() => {
          this.connect(Vue)
        }, this._reconnectInterval)

        const msg = `请求硬件控制中心插件列表失败!${err.message}`
        //发布设备状态变更消息
        PubSub.publish('OnTerminalStateChanged', {
          isReadly: false,
          level: 'Error',
          title: '与硬件控制中心连接失败',
          message: msg,
          detail: ''
        })
        console.error(`[hardware]${msg}`, err)
      })
  }
}

export default new Hardware()

2.将以下代码添加到 main.js 中

import Hardware from "@/plugins/hardware"

// 引入硬件控制中心插件
Vue.use(Hardware, { baseUrl: "http://localhost:5000" })