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

@hema-npm/js-bridge

v1.1.18

Published

河马混合开发原生h5交互js-bridge库

Downloads

80

Readme

@hema-npm/js-bridge

河马混合开发原生 h5 交互 js-bridge 库

use

npm install @hema-npm/js-bridge

在 vue 项目中 main.js 文件中直接引入 window 下注入 HmJsBridge 方法

import '@hema-npm/js-bridge';

用法

方法名就是 src 文件夹下 callHandler 里的方法

testEvent 方法名 window.HmJsBridge.callHandler(方法名,参数,回调函数接收结果,是否需要进度回溯)

window.HmJsBridge.callHandler(
  'testEvent',
  {
    message: '这是js调用testEvent方法传递的参数',
    params: {
      id: 1,
    },
  },
  res => {
    console.log('这是testEvent方法的回调', res);
  },
  true
);

如果不需要支持进度回溯,方法已转换成 promise 可通过 promise 方式调用 window.HmJsBridge.callHandler(方法名,参数)

const getAppInfo = async () => {
  const result = await window.HmJsBridge.callHandler('getAppInfo');
};

返回结果

{
  code: 0|1, // 0调用成功 1调用中
  data: '返回数据',
  msg: 'msg信息'
}

详细使用方式

get-app-info 方法

获取 app 设备信息以及 token 等

用法

const getAppInfo = async () => {
  const result = await window.HmJsBridge.callHandler('getAppInfo');
};

返回结果

get-app-status-height 方法

获取 app 通知栏高度

用法

const getAppStatusHeight = async () => {
  const result = await window.HmJsBridge.callHandler('getAppStatusHeight');
};

返回结果

{
  code: 0,
  data: 40, // 高度值
  msg: ''
}

go-router 方法

h5 跳转原生页面 调用立即生效

用法

window.HmJsBridge.callHandler('goRouter', params);

传参

interface params {
  router: string; // 跳转路径
  params?: {[key: string]: any}; // 传参
}

close-webview 方法

h5 关闭当前 webview

用法

window.HmJsBridge.callHandler('closeWebview');

download-file 方法

下载文件到本地

用法

window.HmJsBridge.callHandler(
  'downloadFile',
  params,
  res => {
    console.log('这是downloadFile方法的回调', res);
  },
  true
);

传参

interface params {
  url: string; // 需要保存文件路径
  filesType: 'img' | 'pdf'; // 文件类型  图片文件、pdf文件
}

返回结果

{
  code: 1,// 0调用完成 1调用中 3调用失败
  data: {
    progress: 10, // 下载进度0-100
    status: 0|1|3 // 0 下载完成 1 下载中 3 下载失败 失败可在msg返回失败提示原因
  },
  msg: ''
}

upload 方法

上传文件

用法 upload 方法限制文件大小范围 image 类型 2.5M 以内 application/pdf 10M 以内

window.HmJsBridge.callHandler(
  'upload',
  params,
  res => {
    console.log('这是upload方法的回调', res);
  },
  true
);

传参

interface params {
  type: 0|1|2|3  // 0 直接拍照 1 弹窗 (拍照 相册 文件上传) 2 弹窗 (拍照 相册) 3 直接文件上传
  privatization: boolean // 是否是私有化上传
  filesNumber: number // 文件个数
  MIMETypes?: Array<'image/jpeg'|'image/png'|'application/pdf'> // 文件MIME类型 数组 可以多种类型 ['image/jpeg','image/png','application/pdf'] 传空代表不限制文件MIME类型
}

返回结果

{
  code: 1,// 0调用完成 1调用中 3调用失败
  data: {
    progress: 10, // 上传进度0-100
    url: [], // 上传文件完成的网络链接
    status: 0|1|2|3 // 0 上传完成 1 上传中 2 取消上传 3 上传失败 失败可在msg返回失败提示原因
  },
  msg: ''
}

pay方法

=======


微信/支付宝支付

```js
window.HmJsBridge.callHandler('pay', params, (res) => {
  console.log('这是pay方法的回调', res)
}, true)

传参

interface params {
  payMethod: "ALIPAY" | "WECHAT"; // ALIPAY 支付宝支付 WECHAT 微信支付
  transactionNo: string; // 订单编号
}

返回结果

{
  code: 1,// 0支付失败 1支付成功
  msg: ''
}

open-modal 方法

h5 页面掉原生弹框 调用立即生效

用法

window.HmJsBridge.callHandler('openModal', params);

传参

interface params {
  modalName: string; // 弹框类型
  type?: string; // 可选动态传参
}

联系客服 方法

用法

window.HmJsBridge.callHandler('jumpToCustomer', params);

传参

interface params {
  type: string; // 客服类型
}

安卓前往应用市场下载app 方法

用法

window.HmJsBridge.callHandler('downloadApp', params);

传参

interface params {
  id: string; // app应用对应包名
}