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

cpm-consent-sdk-for-wx

v0.0.6

Published

cpm-consent-sdk-for-wx

Downloads

10

Readme

cpm-consent for 微信小程序

CPM 用户同意授权 Dialog 组件 、授权详情中心 Center 组件 SDK。

引入

原生组件使用

  • 点击下载SDK,将该项目复制到 components 小程序组件目录下
  • 在需要引入的page对应 json 中,配置组件
"usingComponents": {
    "dialog": "/components/cpm-consent-sdk-for-wx/components/dialog",
    "center": "/components/cpm-consent-sdk-for-wx/components/center"
  }

npm 使用

  • npm安装组件
npm install --save cpm-consent-sdk-for-wx
  • 进入小程序开发工具 工具 -> 构建npm,点击构建

使用

Dialog 组件

  • json 文件中引入组件
"usingComponents": {
    "dialog": "/components/cpm-consent-sdk-for-wx/components/dialog", 
  }

引入地址根据实际引入路径为主,组件路径注意是在:sdk目录/components/dialog 下

  • wxml 文件中引入组件

Dialog 组件wxml文件引入


  <dialog id="cl_dialog"  bindconfirm="onDialogConfirm" bindrefuse ="onDialogRefuse" bindopenurl="onOpenUrl"></center>

注意组件使用需要设置id,在后面控制器中需要传入该id

  • js引入组件控制器
// 引入控制器,控制器位于SDK根路径/dialog.js
const Dialog = require("../../components/consents/dialog.js");

// 在需要显示的地方创建对应的控制

onLoad: function(options) {
  // Dialog 组件使用方式
  ...
       // 初始化组件控制器
       const dialog = Dialog(this, // 传入 Page 上下文对象
              '#cl_dialog', // css选择器,需要指定Page wxml中需要绑定的 dialog 组件
              {
                  tenantId: 1, // [必须] 租户id, 可在cpm后台中c查看当前租户信息
                  identityId: '微信小程序用户openid', // [必须]用户身份标识openId,该信息需要用户自身获得用户授权信息
                  appId: '微信小程序id', // [可选]初始化appId,如未提供控制器将尝试使用wxid 
                  baseUrl: 'https://cpm-api.convertlab.com', // [可选]如果需要指定私服链接,可覆盖改参数,默认 cpm-api.convertlab.com
              }
      )
  ...
      // 显示组件
      dialog.show(this, //[可选] 传入 Page 上下文对象,可再次对目标控件进行选择定位,如果未提供,则默认使用构造时传入的Page上下文
       {
            onConfirm() {
               // 弹框选择确认,如返回值为true,则阻止弹框关闭
            },
            onRefuse() {
              // 弹框选择拒绝,如返回值为true,则阻止弹框关闭
            }
        });
      // 关闭组件
      dialog.close()
}

Center 组件

  • json 文件中引入组件
"usingComponents": {
    "center": "/components/cpm-consent-sdk-for-wx/components/center", 
  }

引入地址根据实际引入路径为主,组件路径注意是在:sdk目录/components/center 下

  • Center 组件wxml文件引入
 <center id="cl_center"  bindconfirm="onCenteronfirm" bindopenurl="onCenterOpenUrl"></center>

注意组件使用需要设置id,在后面控制器中需要传入该id

  • js引入组件控制器
// 引入控制,控制器位于SDK根路径/center.js
const Center = require("../../components/consents/center.js");

// 在需要显示的地方创建对应的控制

onLoad: function(options) {
  // Center 组件使用方式
  ...
       // 初始化组件控制器
       const center = Center(this, // 传入 Page 上下文对象
                '#cl_center',// css选择器,需要指定Page wxml中需要绑定的 Center 组件
                {
                 tenantId: 1, // [必须] 租户id, 可在cpm后台中查看当前租户信息
                  identityId: '微信小程序用户openid', // [必须]用户身份标识openId,该信息需要用户自身获得用户授权信息
                  appId: '微信小程序id', // [可选]初始化appId,如未提供控制器将尝试使用wxid 
                  baseUrl: 'https://cpm-api.convertlab.com', // [可选]如果需要指定私服链接,可覆盖改参数,默认 cpm-api.convertlab.com
                }
      )
  ...
      // 显示组件
      center.show(this,  //[可选] 传入 Page 上下文对象,可再次对目标控件进行选择定位,如果未提供,则要求在构造时进行选择器绑定过
            {
            onConfirm(cosents) {
               // 发生保存时响应,cosents 返回保存信息, 如返回值为true,则阻止中心关闭
            }
          
        });
       // 关闭组件
      center.close()  
}

API说明

Dialog

事件

| 事件 | 说明 | | --- | --- | | confirm |确认事件| | refuse |拒绝事件| | load | 组件配置加载完成 | | openurl | 如果展示组件中存在超链接请求,需要用户实现事件响应,否则将无法打开 |

例子:

 <dialog id="cl_dialog"  bindconfirm="onDialogConfirm" 
 bindrefuse="onDialogRefuse" bindload="onDialogLoad" bindopenurl="onDialogOpenUrl" ></center>

控件属性

| 属性名 | 说明 | | --- | --- | | closeOnClickModal |模态模式控制,默认为true,设置点击弹框外阴影是否关闭弹框|

例子: 模态弹框,不允许弹框未响应按钮前关闭

 <dialog id="cl_dialog"  closeOnClickModal="{{false}}" ></center>

控制器初始化属性

控制获取时需要绑定对应控制组件以及上下文 | 事件 | 说明 | | --- | --- | | tenantId |必须属性,当前租户信息,可以从cpm后台中获取| | identityId |必须属性,当前用户微信openid,用于识别用户身份信息| | appId | 可选,默认会读取当前小程序微信id| | baseUrl |可选,默认 https://cpm-api.convertlab.com,如果为私部环境则需要设置,目前url需要咨询相关人员| | onConfirm |可选,同 confirm 事件,确定按钮发生响应触发| | onRefuse |可选,同 refuse 事件,拒绝按钮发生响应触发| | onLoad |可选,同 load 事件,组件完成配置初始时回调|

控制器方法

|方法|说明| |---|---| |show|显示组件| |close|关闭组件| |setData|设置属性|

Center

事件

| 事件 | 说明 | | --- | --- | | confirm |确认事件| | load | 组件配置加载完成 | | openurl | 如果展示组件中存在超链接请求,需要用户实现事件响应,否则将无法打开 |

例子:

 <center id="cl_center"  bindconfirm="onCenterConfirm"  bindload="onCenterLoad" bindopenurl="onCenterOpenUrl" ></center>

控制器初始化属性

控制获取时需要绑定对应控制组件以及上下文 | 事件 | 说明 | | --- | --- | | tenantId |必须属性,当前租户信息,可以从cpm后台中获取| | identityId |必须属性,当前用户微信openid,用于识别用户身份信息| | appId | 可选,默认会读取当前小程序微信id | | baseUrl |可选,默认 https://cpm-api.convertlab.com,如果为私部环境则需要设置,目前url需要咨询相关人员| | onConfirm| 可选,同confirm事件,保存按钮响应时回调 | | onLoad |可选,同 load 事件,组件完成配置初始时回调|

控制器方法

|方法|说明| |---|---| |show|显示组件| |close|关闭组件| |setData|设置属性|

QA

  • 用户openid获取是否是必须? 用户身份标识是sdk必须的信息,如果没有该标识SDK将无法稳定记录用户授权状态。