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 🙏

© 2024 – Pkg Stats / Ryan Hefner

open-bridge

v1.0.10

Published

舟港通开放对接SDK

Downloads

5

Readme

open-bridge

📖简介

舟港通H5子应用舟港通本体桥接的开放SDK,该包具备typescript支持。

👌快速上手

[TOC]

🪛安装

  # shell
  npm i open-bridge -S
  # 或
  yarn add open-bridge
  # 或
  pnpm add open-bridge

💻使用

API说明

代码示例

这里以ts文件为例

系统操作 topSys
关闭当前子应用 topSys.close
  import { OpenBridge } from "open-bridge";

  const handleClick = () => {
    /**
     * 一些用户提示及延时
     */

    // 仅关闭当前应用
    OpenBridge.create().topSys.close();
    // or
    // 关闭当前应用并显示消息
    OpenBridge.create().topSys.close({
      message: "系统出错啦",
      type: "error",
    });
  }
获取当前登录用户的OTP topSys.getOTP
  import { OpenBridge } from "open-bridge";

  // 回调形式
  const handleClick = () => {
    OpenBridge.create().topSys.getOTP(({isSuccess,otp,error})=>{
      if(isSuccess){
        console.log(otp);
      }else{
        console.error(error);
      }
    });
  }

  // Promise形式
  const handleGetOTPWithPromise = async () => {
    try {
      const otp = await ob.topSys.getOTP()
      console.log(otp)
    } catch (error) {
      console.error(error)
    }
  }
扫码 codeScan
完全使用 codeScan.start

  import { OpenBridge, CodeScan } from "open-bridge";

  const handleClick = () => {
    OpenBridge.create().codeScan.start({
      // 扫码页标题
      title: "二维码扫描",
      // 扫码类型过滤,默认值为[QR],即只扫描二维码
      filters: [CodeScan.barcodeType.QR],
      // 扫码成功的回调,扫码成功后会主动关闭并且返回扫描信息
      onSuccess(params) {
        console.log(params);
      },
      // 扫码主动关闭的回调
      onClose() {
        console.log("关闭了");
      },
      // 扫码启动失败的错误回调
      onError(e) {
        console.log(e);
      },
    });
  }
简单使用
  import { OpenBridge } from "open-bridge";

  const handleClick = () => {
    OpenBridge.create().codeScan.start({
      // 扫码成功返回的参数
      onSuccess(params) {
        console.log(params);
      },
    });
  }

类型与参数

OpenBridge
  • class
create
  • static function
  • params 不接受参数
  • return 返回一个 OpenBridge 实例属性
  • description 多次调用返回同一个实例
destroy
  • static function
  • params 不接受参数
  • return 无返回值
  • description 调用后类与原实例取消关联,原实例仍能使用,但是无法响应父应用的反馈,且再次使用create会创建一个新的实例
topSys
  • instance data
  • description 系统API实例,通过它进行一些关键性系统操作
  • TopSys原型类
codeScan
isZgt
  • instance data
  • description 实例属性,布尔值,是否舟港通环境,若需要区分环境可以使用这个
isReady
  • instance function
  • return Promise<boolean>
  • description 实例方法,返回布尔值Pormise,SDK通常于子应用共同就绪,无需使用此方法
call
  • instance function
  • params
    • cmd String
    • params Object
  • return 无返回值
  • description 实例方法,用于调用一些扩展API

Class TopSys
  • class
close
TopSysCloseOption
  • type

  • attrs

  • | 属性名 | 必要性 | 类型 | 默认值 | 描述 | | ------- | ------ | -------- | ------ | ------------------ | | message | 可选 | string | 无 | 关闭后提示消息内容 | | type | 可选 | string | 无 | 关闭后提示消息类型 |

interface TopSysCloseOption {
  message?: string
  type?: "text" | "loading" | "success" | "fail" | "html"
}
getOTP
GetOTPCallback
  • type
  • callback
  • description getOTP的回调函数类型
type GetOTPCallback = (p: {
  isSuccess: boolean
  otp?: string
  error?: unknown
}) => void

Class CodeScan
  • class
barcodeType
  • static data
  • description 条码类型常量
  • | 属性 | 值 | 描述 | | ----------- | --- | --------------------- | | QR | 0 | QR二维码 | | EAN13 | 1 | EAN一维条形码码标准版 | | EAN8 | 2 | ENA一维条形码简版 | | AZTEC | 3 | Aztec二维码 | | DATAMATRIX | 4 | Data Matrix二维码 | | UPCA | 5 | UPC码标准版 | | UPCE | 6 | UPC码缩短版 | | CODABAR | 7 | Codabar码 | | CODE39 | 8 | Code39一维条形码 | | CODE93 | 9 | Code93码 | | CODE128 | 10 | Code128码 | | ITF | 11 | ITF码 | | MAXICODE | 12 | MaxiCode二维码 | | PDF417 | 13 | PDF 417码 | | RSS14 | 14 | RSS 14组合码 | | RSSEXPANDED | 15 | 扩展式RSS组合码 |
start
BarcodeComposeOption
  • type
  • attrs
  • | 属性名 | 必要性 | 类型 | 默认值 | 描述 | | --------- | ------ | ---------- | --------------------------- | ---------------- | | onSuccess | 可选 | function | (params:ScanDTO)=>{} | 扫码成功回调 | | onClose | 可选 | function | ()=>{} | 扫码取消回调 | | onError | 可选 | function | (error:ErrorDTO)=>{} | 扫码启用错误回调 | | filters | 可选 | number[] | [CodeScan.barcodeType.QR] | 可扫条码类型 | | title | 可选 | string | "" | 扫码界面标题 |
interface BarcodeComposeOption {
  onSuccess?: (p: ScanDTO) => void
  onClose?: () => void
  onError?: (p: ErrorDTO) => void
  filters?: number[]
  title?: string
}
ScanDTO
  • type
  • attrs
  • | 属性名 | 必要性 | 类型 | 默认值 | 描述 | | -------- | ------ | -------- | ------ | --------------------- | | codeType | 必要 | string | "" | 码类型,如二维码则为QR | | result | 必要 | string | "" | 码内容 |
interface ScanDTO {
  codeType: string
  result: string
}
ErrorDTO
  • type
  • attrs
  • | 属性名 | 必要性 | 类型 | 默认值 | 描述 | | ------- | ------ | --------- | ------ | ------------------------------------- | | error | 必要 | unknown | {} | 错误堆栈信息,因传输克隆大部分情况为{} | | message | 必要 | string | "" | 主要错误信息 |
interface ErrorDTO {
  error: unknown
  message: string
}