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

@gdjiami/gzb-jssdk

v1.10.13

Published

MyGZB Webview JSSDK

Downloads

12

Readme

GZB JSSDK(v1)

注意:新项目使用 jssdk ,请直接使用 @gzbapp/sdk,@gdjiami/gzb-jssdk 只在老项目中使用,如有更新,则同步更新 @gzbapp/sdk 库。该库将不再维护。

工作宝JSSDK, 是工作宝APP面向web应用提供的开发工具包, 用于在工作宝应用的webview内调用APP 服务. 目前支持PC, Android, IOS平台。

通过这些接口可以实现选择图片,获取当前位置,分享,拨打电话, 发送短信,打开工作宝应用对话框等功能, 提升工作宝嵌入应用的网页体验

安装

yarn add @gdjiami/gzb-jssdk

或者

npm install @gdjiami/gzb-jssdk --save

接口协议

GZB-JSSDK-SPECS

文档和DEMO

GZB-JSSDK-DEMO

使用

基本使用

import Api, { BridgeResponseError } from '@gdjiami/gzb-jssdk'
const api = api()

// 简单接口
api.setTitle('hello gzb')

UMD版本

<script src="path/to/gzb-jssdk.umd.js"></script>
<script>
  var api = GZB.api()
  api.setTitle('hello gzb')
</script>

异步回调接口

async function chooseImage() {
  try {
    // 接口返回Promise, 所有可以配合使用async/await 编写更加简洁的异步代码
    const { width, height, name, quality, dataUrl } = await api.chooseImage({
      quality: 80
    })
    preview(dataUrl)
  } catch(error: BridgeResponseError) {
    console.log(error.errCode, error.message)
  }
}

事件接口, 工作宝JSSDK, 目前支持两种类型的事件, beforeunloadbeforegoback, 分别对应原生窗口中的关闭和返回按钮.

beforeunload: beforeunload 事件类似于浏览器端的beforeunload 事件,你可以通过返回字符串来弹出一个确认框, 如果用户点击确认就会退出应用。

api.addListener('beforeunload', event => {
  return 'Are Sure to exit?'
})

你也可以通过返回false,会调用event.preventDefault() 来阻止默认行为。 需要注意的是返回 false 还会阻止后续订阅者的调用.

api.addListener('beforeunload', event => {
  event.preventDefault()
  myCustomConfirm('确认退出', () => {
    saveSomething()
    api.exit()
  })
})

事件接口目前有较为严重的问题,当你开发的是单页应用, 可以考虑使用这些接口。如果是多页应用, 由于原生Bridge绑定原有的回调,当切换页面后,会导致绑定事件的按钮失效。详见已知问题 解决这个问题的暂时方法是使用api.locationTo 来进行网站导航

用户代理检测

import { Device } from '@gdjiami/gzb-jssdk'

if (Device.mobile()) {
  // is mobile
} else if (Device.tablet()) {
  // is tablet
} else {
  // is desktop
}

兼容性

1.0 版本使用Typescript重写,依然兼容旧的接口,只不过只在umd压缩版本中提供,文件为dist/gzb-jssdk.umd.js, 可以 通过script标签进行导入 :

<script src="path/to/gzb-jssdk.umd.js"></script>
<script>
// 接口调用
var api = customApi.init()
api.setTitle('hello')
api.chooseImg({
  quality: 80,
  targetType: 'width',
  target: 700,
}, function(res) {
  if (res.result === 'true') {
    // 调用成功
    // 预览图片
    preview(res.imgData)
  } else {
    console.log(res.errCode, errMsg)
  }
})

// 用户代理检测
var detector =  window.JH.Detector
detector.Android()
detector.isMobile()
detector.IOS()
// ...
</script>

注意:旧版接口将在下一大版本中移除,不要将他们用在新项目中。详见CHANGELOG

JSSDK 依赖于Promise,你需要确保你的环境支持Promise

  • setBar 不能应用于多页应用,如果在当前页面绑定了close和goback事件, 当跳转到其他页面时,close,goback按钮将会失效, 因为没办法找到原来的回调,所以目前只建议在单页应用只使用api.addListener('beforeunload')api.addListener('beforegoback')