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

miniprogram-pca-picker

v1.0.2

Published

小程序省市区三级联动组件

Downloads

5

Readme

pca-picker

微信虽然提供了省市区的三级联动picker,但是他的区块代码code 却是微信已经写好的。项目中我们可能需要使用自己的省市区code 以做到和其他端效果一致

本组件需要微信基础版本库大于1.1.0 github项目地址

效果演示

省市区演示 省市演示 省演示

使用方法

1.安装pca-picker

开启微信的npm构建 文档 然后安装

npm install --save miniprogram-pca-picker

2.在需要使用 sms-code 的页面 .json 中添加 sms-code 自定义组件配置

{
  "usingComponents": {
    "pca-picker": "miniprogram-pca-picker"
  }
}

3.在需要使用 pca-picker 的页面 .wxml 中引用 pca-picker

  <!--基本用法-->
  <pca-picker
      pca-arr="{{ pcaArr }}"
      visible="{{isShow}}"
      bindclose="close"
      bindconfirm="confirm">
  </pca-picker>

4.在需要使用 pca-picker 的页面 .js 中

  import {addressArr} from './pca'
  
  Page({
    data: {
      isShow: false,
      pcaArr: addressArr,
      col: 1
    },
    clickPCA() {
      this.setData({
        isShow: !this.data.isShow
      })
    },
    close() {
      this.setData({
        isShow: false
      })
    },
    confirm(e) {
      this.setData({
        isShow: false
      })
      console.log(e)
    }
  })

组件属性

1.属性

| 属性名 | 类型 | 默认值 | 是否必须 | 说明 | |-------------------------|--------------|-----------------------------------------------------|------------|---------------------------------------------| | pcaArr | Array | [] | 是 | 省市区的数据数组,格式请参考下方示例| | | props | Object | {label: 'name',value: 'code',children: 'children'} | 否 | 设置省市区组件选择的数组字段,label表示组件显示的字段key,value表示组件选中的值key,children表示子项的key | | visible | Boolean | false | 是 | 组件是否显示 | | pickerHeight | Number | 200 | 否 | 组件滚动区域的高度,单位(px)| | row | Number | 5 | 否 | 组件滚动区域可见行数,设置后每一行的行高等于 pickerHeight / row| | col | Number | 3 | 否 | 显示列数,1:只显示省, 2:显示省、市,3:显示省、市、区| | indicatorStyle | String | 无 (微信默认样式) | 否 | 自定义选中框的样式| | pickerMaskStyle | String | 无 (微信默认样式) | 否 | 滚动部分蒙层样式| | top-class | String | 无 | 否 | 组件顶部按钮区域的class名,用于自定义样式| | cancel-class | String | 无 | 否 | 组件顶部取消按钮的class名,用于自定义样式| | confirm-class | String | 无 | 否 | 组件顶部确认按钮的class名,用于自定义样式|

indicatorStyle 中不能设置line-height属性,否则每一行高度显示会有问题

pcaArr格式示例:

[
    {
      code: '33',
      name: '浙江',
      children: [
          {
            code: '3301',
            name: '杭州市',
            children: [
                {
                  code: '330102',
                  name: '上城区'
                }
                ...
            ]
          }
          ...
      ],
    }
    ...
]

2.方法

| 方法名 | 是否必须 | 返回值 | 说明 | |------------------------|------------- |--------------------------------------------------|---------------------------------------------| | bindclose | 是 |无 | 省市区组件被关闭时的回调函数 | | bindconfirm | 是 |e,输入框的值 e.detail.label,e.detail.code | 省市区组件点击确定按钮时的回调函数 |

栗子

覆盖默认样式

1.在引用组件的页面.wxml中,设置top-class 、confirm-class和 cancel-class

<view class="pca-test">
  <view bindtap="clickPCA" class="clickBtn">点击</view>
  <pca-picker
      pca-arr="{{ pcaArr }}"
      visible="{{isShow}}"
      bindclose="close"
      bindconfirm="confirm"
      top-class="topClass"
      cancel-class="cancelClass"
      confirm-class="confirmClass"></pca-picker>
</view>

2.在引用组件的页面.wxss中,编写自己的样式代码

/*自定义组件样式*/
.pca-test .topClass{
  border-color: red;
}
.pca-test .cancelClass{
  color: green;
}
.pca-test .confirmClass{
  color: red;
}

3.效果

覆盖默认样式

修改滚动区域显示行数

1.在引用组件的页面.wxml中,设置row属性

  <pca-picker
      pca-arr="{{ pcaArr }}"
      visible="{{isShow}}"
      row="3"
      bindclose="close"
      bindconfirm="confirm">
  </pca-picker>

2.效果

修改显示行数

修改选中行的样式

1.在引用组件的页面.wxml中,设置indicatorStyle

  <pca-picker
      pca-arr="{{ pcaArr }}"
      visible="{{isShow}}"
      bindclose="close"
      bindconfirm="confirm"
      indicatorStyle="background: rgba(32,178,170,.2)"
  ></pca-picker>

2.效果

修改显示行数