New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

element-address

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

element-address

element address components

latest
Source
npmnpm
Version
0.3.3
Version published
Maintainers
1
Created
Source

element-address

基于 address-parse 通过 element-ui 实现的即开即用地址类组件库

📄组件效果 github gitee

Install

npm install element-address --save

使用

import ElementAddress from 'element-address';
import 'element-address/lib/index.css';

Vue.use(ElementAddress);

组件库依赖 element-ui
<el-dialog> <el-button> <el-form> <el-form-item> <el-row> <el-col> <el-input> <el-collapse> <el-collapse-item><el-radio-group> <el-radio> <el-cascader>
如按需加载,请确保以上组件已注册

提供组件

ElAreaCascader 地址地区级联选择器
ElAddressForm 通用地址解析表单组件
ElAddressDialog 弹层地址解析表单组件 【建议直接使用ElementAddress.$dialog】
ElAreaDialog 地区选择器

一个方法

ElementAddress.$dialog 弹出式地址解析编辑组件

ElAreaCascader

地址地区级联选择器 ElAreaCascader

Attributes

参数说明类型可选值默认值
size表单尺寸Stringmedium / small / mini--
value / v-model绑定值 6位地区编码String / Number--
clearable是否支持清空选项Boolean--true
filterable是否可搜索选项Boolean--true
radioHide是否隐藏el-cascader单选框Boolean--true
placeholder输入框占位文本String----
disabled是否禁用Boolean--false
separator选项分隔符String--斜杠' / '
props配置选项参见Object--{"checkStrictly":true,"expandTrigger":"hover"}

Events

事件名称说明回调参数
change当选中地区变化触发(code 地区地区编码, ary 选中地区数据列表 , codes 选中地区码表 )

ElAddressForm

带解析功能地址表单
ElAddressForm

Attributes

参数说明类型可选值默认值
size表单尺寸Stringmedium / small / mini--
label-width表单域标签的的宽度String--80px
labels标签文本配置项Object--{"name":"姓名","mobile":"手机","phone":"电话","code":"地区","details":"地址","company":"单位","zip_code":"邮编","parse":"解 析"}
area-props地区级联组件配置项Object----
placeholders占位文本配置项Object--{"name":"","mobile":"","phone":"","details":"请输入详细地址","company":"","zip_code":"","code":"省 市 区","parse":"此处地址执行解析后会被智能识别"}
data绑定表单对象Object--{"name":"","mobile":"","phone":"","code":"","details":"","company":"","zip_code":"","province":"","city":"","area":""}
rules表单验证对象Object----
rules-mobile-either是否启用mobile跟phone二选一规则Boolean--false
assigned-before表单解析值赋值回调Function----
parse-select是否允许解析多结果选择Boolean--true

Methods

方法名说明参数
validate对整个表单进行校验的方法Function(callback: Function(boolean, object))
clearValidate移除表单项的校验结果Function(props: array
clear清空数据内容并移除表单项的校验结果Function()

Events

事件名称说明回调参数
parse地址解析后触发(ary 解析结果列表 )

ElementAddress.$dialog(data, options)

弹层地址表单组件
ElAddressDialog

组件式调用使用唯一入口this.$refs.dialog.open(data, options)
与全局调用配置一致ElementAddress.$dialog(data, options)

data

表单对象

options

支持所有ElAddressFormAttributes

参数说明类型可选值默认值
title弹层标题String--'地址编辑'
cancelButtonText取消按钮文本String--'取 消'
confirmButtonText确定按钮文本String--'确 定'
resetButtonText清空按钮文本String--'清 空'
resetButton是否显示清空按钮Boolean--false
beforeResolve确认前回调Function--(data, done) 需要触发done才正式关闭 done(false) 终止
beforeClose关闭前回调Function--(data, done) 需要触发done才正式关闭
width弹层宽度String--'700px'
closeOnClickModal是否点击遮罩关闭Boolean--false
bindData是否直接绑定表单对象Boolean--false
####tips
可通过ElementAddress.$dialog.$vm访问到全局实例

ElAreaDialog

地区选择器
ElAddressForm

<el-area-dialog ref="area"/>
areaDialog() {
  this.$refs.area.open(this.areaValue).then(res => {
    this.areaValue = res;
  });
},

可以通过配置项level设置等级,默认是2
this.$refs.area.open(this.areaValue, {level: 1})
1省 2市 3区县【暂无】
参数及结果是一个数组

[
  {
    code: '320000',     // 选中的省份编码
    children: [],       // children是空数组表示当前省份全部选中 level: 2
  },
  {
    code: '350000',     // 选中的省份编码
    children: [         // children非空,值是选中的城市编码    level: 2
      {code: '350100'}, 
    ],
  },
],

此组件需要引入样式文件

import 'element-address/lib/index.css';

你可以参考下面这个函数展示选择的结果

import {AREA} from 'element-address';

/**
 * ElAreaDialog result to Label
 * @return {string}
 */
function AreasLabel(areas, defaultLabel = '') {
  const ary = [];
  for (const province of areas) {
    if (AREA.province_list[province.code]) {
      if (!province.children || !province.children.length) {
        ary.push(AREA.province_list[province.code]);
      } else {
        for (const city of province.children) {
          if (AREA.city_list[city.code]) {
            ary.push(AREA.city_list[city.code]);
          }
        }
      }
    }
  }
  return ary.length ?  ary.join('、') : defaultLabel;
}

LICENSE

MIT

Keywords

element address

FAQs

Package last updated on 13 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts