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

bdmp-common-js

v1.1.5

Published

Encapsulate the front-end public package

Downloads

27

Readme

bdmp-common-js

前端js公共服务库

安装

npm install bdmp-common-js -S

安装完毕之后

1. 使用埋点工具(biSensors)

import {biSensors} from 'bdmp-common-js'

// 初始化埋点
// 参数可选:project用于判断存储埋点数据是存在测试环境还是线上环境,默认是'production'(线上环境)。可选值:'production'(线上环境) || 'default'(测试环境)
biSensors.init({
    project: 'production' || 'default'
})
// 设置用户信息
biSensors.setProfile({
    user_no: '工号',
    user_name: '用户名称'
})
// 登录
biSensors.login('工号')
// 首页埋点-全局埋点
biSensors.registerPage({
    platform_type: 'H5',
    app_code: '指定的属性code',
    app_name: '指定的属性名称'
})
// 自定义监控埋点
biSensors.track({
    event: '事件名称',
    parameter: {...'事件属性'}
})

2. 使用websocket工具(biSocket)

import {biSocket} from 'bdmp-common-js'

// 初始化websocket链接
biSocket.initWebSocket('url').then(res => {})

// 发送消息,任意参数
biSocket.sendMsg('msg')

// 初始化模块接收消息实例

// 第一种场景:使用模块id,独立模块不互相影响时
biSocket.receiveMsg('moduleId', function(res){
    // 接收成功的回调函数,判断数据,渲染数据
    console.log(res)
}, function(error) {
    // 接收发生错误时的回调函数,需要你手动调用https请求
    console.log(error)
}, function(errCatch) {
    // 彻底不接收消息时的回调函数,需要你设置定时器轮询请求https
    console.log(errCatch)
})
// 第二种场景:使用后台特定的主题类似时,比如推送弹幕、推送特殊消息时
biSocket.receiveMsg('与后台约定好的event_type', function(res){
    // 接收成功的回调函数,判断数据,渲染数据
    console.log(res)
}, function(error) {
    // 接收发生错误时的回调函数,需要你手动调用https请求
    console.log(error)
}, function(errCatch) {
    // 彻底不接收消息时的回调函数,需要你设置定时器轮询请求https
    console.log(errCatch)
})
// 第三种场景:当使用模块id时,页面出现两个模块共用一个id时,则使用这种方法
biSocket.receiveMsg({
    id: 'moduleId'
}, function(res){
    // 接收成功的回调函数,判断数据,渲染数据
    console.log(res)
}, function(error) {
    // 接收发生错误时的回调函数,需要你手动调用https请求
    console.log(error)
}, function(errCatch) {
    // 彻底不接收消息时的回调函数,需要你设置定时器轮询请求https
    console.log(errCatch)
})

// 关闭websocket连接
biSocket.clearTimer()

3. 使用前端页面监控工具(biWebErrorLog)

import { biWebErrorLog } from 'bdmp-common-js'
/**
 * 第一个参数 systemId 系统id/系统标识
 * 第二个参数 fetchInfo 请求信息, 格式: {url: 'xxxx/xxx', headers: {}, method: 'POST'}
 * 第三个参数 Vue 若需要监控vue页面的话,则需要传递Vue实例
 */
biWebErrorLog('systemId', {
    url: 'xxxx/xxx', 
    headers: {}, 
    method: 'POST'
}, 'Vue实例')

4. 加密(biSignatureStr)

import { biSignatureStr } from 'bdmp-common-js'
/**
    作用:该方法用于将某个对象进行加密,当前用于与后台接口交互过程中参数进行加密
 * 第一个参数 参数对象。必传
 * 第二个参数 加密规则密钥。必传
 * 第三个参数 md5实例,可以通过cnpm install [email protected] -S。必传
 */
biSignatureStr({
    name: 'xxx',
    ...
}, 'SignatureStr', 'md5实例')

5. 请求头统一封装且加密(biRequestHeader)

import { biSignatureStr } from 'bdmp-common-js'
/**
    作用:该方法用于axios统一处理请求头的方法,且包含加密功能
 * 第一个参数 aixos拦截config对象。必传
 * 第二个参数 加密规则密钥。必传
 * 第三个参数 md5实例,可以通过cnpm install [email protected] -S。必传
 */
// 使用案例
axios.interceptors.request.use(
  (config) => {
    biRequestHeader(config, 'SignatureStr', 'md5实例')
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)