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

dh-jsbridge

v1.0.11

Published

基础平台app javascript 调用app功能

Downloads

4

Readme

基础平台app javascript 调用app功能

调佣全部api 需要基础平台app版本>= 1.0.17

引入

Demo: https://e.coding.net/sjtech/h5-demo/H5Demo.git

使用:

// main.js 引入
import 'dh-jsbridge'

js 调用原生功能均通过全局对象dh来调用,所以尽可能避免其他同名的全局对象的污染。

打开新的窗口

dh.openNewWindow({
  url: 'http://...',
  title: '导航栏标题'
})

判断是否在app内打开

版本>=1.0.9

   const isInApp = dh.isDHApp()

获取app版本

版本>=1.0.9

    const version = dh.getAppVersion()

判断app版本是否大于某版本

版本>=1.0.9

 const res = dh.isVersionHigherThan('1.0.30')

打开在线附件

版本>=1.0.9 注意:该api 需要app 版本大于等于1.0.30,使用前因判断app版本

dh.openDocument({
  url: 'http://...'
})

用户信息

    dh.getUserInfo({
      success: data => {  // 返回的数据为json字符串
        this.userInfo = JSON.parse(data)
      }
     })

项目信息

    dh.getProjectInfo({
      success: (data = '') => { // 返回的数据为json字符串
        this.projectInfo = JSON.parse(data.replace(/\r|\n|\t/g, ''))
      }
    })

Token

token在网页打开时 已写入到cookie中,key为“Access-Token”

import Cookies from 'js-cookie'

const TOKEN_NAME = 'Access-Token'

export const getToken = () => {
  return Cookies.get(TOKEN_NAME)
}

导航

后退

dh.back()

退出

dh.finish()

修改导航栏标题

 dh.setNavigationBarTitle('修改后的标题')

文件下载

文件下载后可在app 个人》我的下载 查看

dh.downloadFile({
     src: this.url
})    

地图定位

获取定位(一次):

dh.getLocation()

持续定位

dh.startLocation(),

定位成功后会持续进行定位,定位更新时会触发以下回调:

window.onLocationChanged = (longitude, latitude) => {
     this.locationDesc = `${longitude},${latitude}`
}

全屏切换

显示或隐藏app 导航栏

dh.toggleFullScreen()

横竖屏切换

dh.lockLandscape(true) // true为切换横屏,false 竖屏

截屏

type 不能为空,为“full” 时是截取整个网页,其他值只截取当前屏幕。

dh.screenshot({ type : 'default' })

导出pdf

dh.printWeb()

扫一扫

dh.scanCode()

扫码回调

dh.scanForResult({
  success: res => {
    // res 为扫码结果
  }
})

录音

开始录音

dh.startRecord()

停止录音

dh.stopRecord()

停止录音后回调

window.onRecordFinish = path => {
      console.log(path) // path为原生app本地缓存路径
}

播放本地录音 src 必传,值为停止录音后回调获取的路径

dh.playVoice({ src: path })

分享

link必传 android 只支持单文本和单图片分享,所以android 分享时只会分享链接 iOS 图片如果不传可以在body最上方添加img,content 不传微信会读网页标题

dh.shareLink({
        content: '分享的文字!',
        image: 'http://81.70.223.108:9293/app/images/logo.png',
        link: window.location.href,
        success: () => {
          console.log('success')
        },
        error: () => {
          console.log('error')
        }
      })

用于iOS分享

<body>
  <div style="display:none;"><img src="http://81.70.223.108:9293/app/images/logo.png"></div>

快捷相机

快捷相机拍照后发起业务,用一下api获取上传后的图片

dh.getCameraImages({
        success: dataStr => {
          try {
            const Json = JSON.parse(dataStr)
            const images = Json.map(item => {
              return {
                id: item.id,
                name: item.fileName,
                previewUrl: `${item.url}onlinePreview?url=${encodeURIComponent(window.btoa(item.filePath))}&sourceFileUrl=${encodeURIComponent(item.sourceFileUrl)}`

              }
            })
            if (images && images.length) {
              this.$refs.form.setFormFieldValue({
                edit_pict_before: JSON.stringify(images)
              })
            }
          } catch (e) {
            console.error(e)
          }
        }
      })