diff --git a/README.md b/README.md
index 8e9757c..bb30f5d 100644
--- a/README.md
+++ b/README.md
@@ -38,15 +38,15 @@ App + Nvue + H5 + 各平台小程序(快应用及 360 未测试)
## 功能
-- 单选
-- 多级联动,非多级联动,理论支持任意级数
-- 省市区选择,基于多级联动
+- 单选
+- 多级联动,非多级联动,理论支持任意级数
+- 省市区选择,基于多级联动
- 日期选择器,年月日时分秒可自由组合选择(引入了`dayjs`方便处理日期)
-- 自定义选择器头部确定取消按钮颜色及插槽支持
-- 选择器可视区自定义滚动个数
-- 自定义数据字段,满足不同人的需求
-- 自定义选择器样式
-- formatter 格式化自定义显示
+- 自定义选择器头部确定取消按钮颜色及插槽支持
+- 选择器可视区自定义滚动个数
+- 自定义数据字段,满足不同人的需求
+- 自定义选择器样式
+- formatter 格式化自定义显示
- 单选及非联动选择支持扁平化的简单数据,如下形式:
```javascript
@@ -321,7 +321,7 @@ data () {
### Props
-#### 通用Props
+#### 通用 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------- | :---------------------------------------------------------------------------------------------------- | :----------------- |
@@ -353,7 +353,7 @@ data () {
| press-time | `(v1.1.6 新增)`长按触发时间,单位毫秒 ms | Number | - | 500 |
| formatter | `(v1.1.7 新增)`格式化自定义选择器文字内容,`Function`类型,`return`一个字符串(日期选择器`百度、支付宝、头条小程序`不支持,其他选择器仅`app` `nvue` `h5`支持),`item`当前项信息,`rowIndex`当前数据所在行数,`columnIndex`当前数据所在列数,写法参考[demo14](https://github.com/liub1934/uni-lb-picker/blob/master/pages/demos/demo14/demo14.vue#L206),日期选择器可参考[demo16](https://github.com/liub1934/uni-lb-picker/blob/master/pages/demos/demo16/demo16.vue#L245) | Function({ item, rowIndex, columnIndex }) | - |
-#### 单选、多级联动、非联动选择Props
+#### 单选、多级联动、非联动选择 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :---- | :-------------------------------------------------------------------- | :----- | :----- | :------------------------------------------------ |
@@ -361,7 +361,7 @@ data () {
| level | 多列联动层级,仅 mode 为 multiSelector 有效 | Number | - | 1 |
| props | 自定义数据字段 | Object | - | {label:'label',value:'value',children:'children'} |
-#### 日期选择Props
+#### 日期选择 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :----------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------ | :--------- | :--------------------------------------------------------------------------- |
@@ -369,29 +369,28 @@ data () {
| format | 选择器返回的日期格式,见下方`displayFormat、format说明`,如配置`YYYY年MM月DD日`选择器确定后返回显示的值为`2021年01月05号`或者`YYYY-MM-DD`返回的就是`2021-01-05`,可以自由组合,需要和`display-format`参数配合使用。 | String | - | YYYY-MM-DD |
| start-date | 开始日期,可精确到秒,如`2018-08-08 08:08:08` | String | - | - |
| end-date | 结束日期,可精确到秒,如`2021-08-08 08:08:08` | String | - | - |
-| default-time-limit | 默认显示的日期选择范围,默认当前日期前20年和后20年,配置`start-date`或`end-date`后失效 | Number | - | 20 |
+| default-time-limit | 默认显示的日期选择范围,默认当前日期前 20 年和后 20 年,配置`start-date`或`end-date`后失效 | Number | - | 20 |
| is-show-chinese | 是否显示日期选择器年月日时分秒中文文字,默认显示 | Boolean | true/false | true |
| ch-config | 显示的日期选择器年月日时分秒文字配置 | Object | - | {year: '年', month: '月', day: '日', hour: '时', minute: '分', second: '秒'} |
-
-### displayFormat、format说明
-
-| 标识 | 示例 | 描述 |
-| :--- | :---- | :------------- |
-| YY | 18 | 年,两位数 |
-| YYYY | 2018 | 年,四位数 |
-| M | 1-12 | 月,从1开始 |
-| MM | 01-12 | 月,两位数字 |
-| D | 1-31 | 日 |
-| DD | 01-31 | 日,两位数 |
-| H | 0-23 | 24小时 |
-| HH | 00-23 | 24小时,两位数 |
-| h | 1-12 | 12小时 |
-| hh | 01-12 | 12小时,两位数 |
-| m | 0-59 | 分钟 |
-| mm | 00-59 | 分钟,两位数 |
-| s | 0-59 | 秒 |
-| ss | 00-59 | 秒,两位数 |
+### displayFormat、format 说明
+
+| 标识 | 示例 | 描述 |
+| :--- | :---- | :-------------- |
+| YY | 18 | 年,两位数 |
+| YYYY | 2018 | 年,四位数 |
+| M | 1-12 | 月,从 1 开始 |
+| MM | 01-12 | 月,两位数字 |
+| D | 1-31 | 日 |
+| DD | 01-31 | 日,两位数 |
+| H | 0-23 | 24 小时 |
+| HH | 00-23 | 24 小时,两位数 |
+| h | 1-12 | 12 小时 |
+| hh | 01-12 | 12 小时,两位数 |
+| m | 0-59 | 分钟 |
+| mm | 00-59 | 分钟,两位数 |
+| s | 0-59 | 秒 |
+| ss | 00-59 | 秒,两位数 |
### 方法
@@ -401,6 +400,21 @@ data () {
| hide | 关闭选择器 | - | |
| getColumnsInfo | (v1.1.0 新增)根据 value 获取选择器信息 | 绑定值的`value` | 同`change` `confirm`回调参数,如果传入的`value`获取不到信息则只返回一个含有`dataset`的对象,具体自行打印查看 |
+`getColumnsInfo`注意事项:
+
+- 需要组件加载完成后调用才有效,即`console.log(this.$refs.picker)`打印有内容,否则会报错,可在`onReady`中进行调用。
+- 如果动态设置`list`后马上调用`getColumnsInfo`会无法取到相关信息,可以加个`setTimeout`解决,如下形式:
+
+```javascript
+onReady () {
+ this.list = [{ label: '测试', value: 1 }] // 动态设置一个list
+ setTimeout(() => {
+ const info = that.$refs.picker.getColumnsInfo(xx)
+ console.log(info)
+ }, 0)
+}
+```
+
### Events
| 事件名称 | 说明 | 回调参数 |
diff --git a/components/lb-picker/README.md b/components/lb-picker/README.md
index 8e9757c..bb30f5d 100644
--- a/components/lb-picker/README.md
+++ b/components/lb-picker/README.md
@@ -38,15 +38,15 @@ App + Nvue + H5 + 各平台小程序(快应用及 360 未测试)
## 功能
-- 单选
-- 多级联动,非多级联动,理论支持任意级数
-- 省市区选择,基于多级联动
+- 单选
+- 多级联动,非多级联动,理论支持任意级数
+- 省市区选择,基于多级联动
- 日期选择器,年月日时分秒可自由组合选择(引入了`dayjs`方便处理日期)
-- 自定义选择器头部确定取消按钮颜色及插槽支持
-- 选择器可视区自定义滚动个数
-- 自定义数据字段,满足不同人的需求
-- 自定义选择器样式
-- formatter 格式化自定义显示
+- 自定义选择器头部确定取消按钮颜色及插槽支持
+- 选择器可视区自定义滚动个数
+- 自定义数据字段,满足不同人的需求
+- 自定义选择器样式
+- formatter 格式化自定义显示
- 单选及非联动选择支持扁平化的简单数据,如下形式:
```javascript
@@ -321,7 +321,7 @@ data () {
### Props
-#### 通用Props
+#### 通用 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------- | :---------------------------------------------------------------------------------------------------- | :----------------- |
@@ -353,7 +353,7 @@ data () {
| press-time | `(v1.1.6 新增)`长按触发时间,单位毫秒 ms | Number | - | 500 |
| formatter | `(v1.1.7 新增)`格式化自定义选择器文字内容,`Function`类型,`return`一个字符串(日期选择器`百度、支付宝、头条小程序`不支持,其他选择器仅`app` `nvue` `h5`支持),`item`当前项信息,`rowIndex`当前数据所在行数,`columnIndex`当前数据所在列数,写法参考[demo14](https://github.com/liub1934/uni-lb-picker/blob/master/pages/demos/demo14/demo14.vue#L206),日期选择器可参考[demo16](https://github.com/liub1934/uni-lb-picker/blob/master/pages/demos/demo16/demo16.vue#L245) | Function({ item, rowIndex, columnIndex }) | - |
-#### 单选、多级联动、非联动选择Props
+#### 单选、多级联动、非联动选择 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :---- | :-------------------------------------------------------------------- | :----- | :----- | :------------------------------------------------ |
@@ -361,7 +361,7 @@ data () {
| level | 多列联动层级,仅 mode 为 multiSelector 有效 | Number | - | 1 |
| props | 自定义数据字段 | Object | - | {label:'label',value:'value',children:'children'} |
-#### 日期选择Props
+#### 日期选择 Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| :----------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------ | :--------- | :--------------------------------------------------------------------------- |
@@ -369,29 +369,28 @@ data () {
| format | 选择器返回的日期格式,见下方`displayFormat、format说明`,如配置`YYYY年MM月DD日`选择器确定后返回显示的值为`2021年01月05号`或者`YYYY-MM-DD`返回的就是`2021-01-05`,可以自由组合,需要和`display-format`参数配合使用。 | String | - | YYYY-MM-DD |
| start-date | 开始日期,可精确到秒,如`2018-08-08 08:08:08` | String | - | - |
| end-date | 结束日期,可精确到秒,如`2021-08-08 08:08:08` | String | - | - |
-| default-time-limit | 默认显示的日期选择范围,默认当前日期前20年和后20年,配置`start-date`或`end-date`后失效 | Number | - | 20 |
+| default-time-limit | 默认显示的日期选择范围,默认当前日期前 20 年和后 20 年,配置`start-date`或`end-date`后失效 | Number | - | 20 |
| is-show-chinese | 是否显示日期选择器年月日时分秒中文文字,默认显示 | Boolean | true/false | true |
| ch-config | 显示的日期选择器年月日时分秒文字配置 | Object | - | {year: '年', month: '月', day: '日', hour: '时', minute: '分', second: '秒'} |
-
-### displayFormat、format说明
-
-| 标识 | 示例 | 描述 |
-| :--- | :---- | :------------- |
-| YY | 18 | 年,两位数 |
-| YYYY | 2018 | 年,四位数 |
-| M | 1-12 | 月,从1开始 |
-| MM | 01-12 | 月,两位数字 |
-| D | 1-31 | 日 |
-| DD | 01-31 | 日,两位数 |
-| H | 0-23 | 24小时 |
-| HH | 00-23 | 24小时,两位数 |
-| h | 1-12 | 12小时 |
-| hh | 01-12 | 12小时,两位数 |
-| m | 0-59 | 分钟 |
-| mm | 00-59 | 分钟,两位数 |
-| s | 0-59 | 秒 |
-| ss | 00-59 | 秒,两位数 |
+### displayFormat、format 说明
+
+| 标识 | 示例 | 描述 |
+| :--- | :---- | :-------------- |
+| YY | 18 | 年,两位数 |
+| YYYY | 2018 | 年,四位数 |
+| M | 1-12 | 月,从 1 开始 |
+| MM | 01-12 | 月,两位数字 |
+| D | 1-31 | 日 |
+| DD | 01-31 | 日,两位数 |
+| H | 0-23 | 24 小时 |
+| HH | 00-23 | 24 小时,两位数 |
+| h | 1-12 | 12 小时 |
+| hh | 01-12 | 12 小时,两位数 |
+| m | 0-59 | 分钟 |
+| mm | 00-59 | 分钟,两位数 |
+| s | 0-59 | 秒 |
+| ss | 00-59 | 秒,两位数 |
### 方法
@@ -401,6 +400,21 @@ data () {
| hide | 关闭选择器 | - | |
| getColumnsInfo | (v1.1.0 新增)根据 value 获取选择器信息 | 绑定值的`value` | 同`change` `confirm`回调参数,如果传入的`value`获取不到信息则只返回一个含有`dataset`的对象,具体自行打印查看 |
+`getColumnsInfo`注意事项:
+
+- 需要组件加载完成后调用才有效,即`console.log(this.$refs.picker)`打印有内容,否则会报错,可在`onReady`中进行调用。
+- 如果动态设置`list`后马上调用`getColumnsInfo`会无法取到相关信息,可以加个`setTimeout`解决,如下形式:
+
+```javascript
+onReady () {
+ this.list = [{ label: '测试', value: 1 }] // 动态设置一个list
+ setTimeout(() => {
+ const info = that.$refs.picker.getColumnsInfo(xx)
+ console.log(info)
+ }, 0)
+}
+```
+
### Events
| 事件名称 | 说明 | 回调参数 |
diff --git a/components/lb-picker/index.vue b/components/lb-picker/index.vue
index c6396c1..4b9c3e7 100644
--- a/components/lb-picker/index.vue
+++ b/components/lb-picker/index.vue
@@ -20,6 +20,7 @@
@@ -200,6 +202,9 @@ const defaultChConfig = {
minute: '分',
second: '秒'
}
+// #ifdef APP-NVUE
+const animation = weex.requireModule('animation')
+// #endif
import { getColumns } from './utils'
import SelectorPicker from './pickers/selector-picker'
import MultiSelectorPicker from './pickers/multi-selector-picker'
@@ -306,7 +311,6 @@ export default {
format: {
type: String,
default: 'YYYY-MM-DD'
- // default: 'YYYY-MM-DD HH:mm:ss'
},
displayFormat: {
type: String,
@@ -322,7 +326,8 @@ export default {
type: Boolean,
default: true
},
- chConfig: Object
+ chConfig: Object,
+ filter: Function
},
data () {
return {
@@ -353,15 +358,21 @@ export default {
setTimeout(() => {
this.maskBgColor = this.maskColor
this.containerVisible = true
+ // #ifdef APP-NVUE
+ this.wxAnimation(0)
+ // #endif
}, 20)
},
hide () {
if (this.inline) return
this.maskBgColor = defaultMaskBgColor
this.containerVisible = false
+ // #ifdef APP-NVUE
+ this.wxAnimation('100%')
+ // #endif
setTimeout(() => {
this.visible = false
- }, 200)
+ }, 300)
},
handleCancel () {
this.$emit('cancel', this.picker)
@@ -401,6 +412,17 @@ export default {
}
},
moveHandle () {},
+ // #ifdef APP-NVUE
+ wxAnimation (num) {
+ const $container = this.$refs.container
+ animation.transition($container, {
+ styles: {
+ transform: `translateY(${num})`
+ },
+ duration: 300
+ })
+ },
+ // #endif
getColumnsInfo (value, type = 1) {
let columnsInfo = getColumns(
{
@@ -448,5 +470,5 @@ export default {
diff --git a/components/lb-picker/pickers/date-selector-picker.vue b/components/lb-picker/pickers/date-selector-picker.vue
index 466bfd2..be7f75b 100644
--- a/components/lb-picker/pickers/date-selector-picker.vue
+++ b/components/lb-picker/pickers/date-selector-picker.vue
@@ -63,7 +63,8 @@ export default {
endDate: String,
defaultTimeLimit: Number,
isShowChinese: Boolean,
- chConfig: Object
+ chConfig: Object,
+ filter: Function
},
data () {
return {
@@ -106,13 +107,10 @@ export default {
throw new Error('开始结束日期异常,startDate不得大于endDate')
}
this.selectItem = this.toObject(this.selectDate)
- let selectItem = {
- ...this.selectItem
- }
- selectItem.month = selectItem.month - 1
this.setColumnData()
+ const value = this.getValueDate()
this.$emit('change', {
- value: this.dayjs(selectItem).format(this.format),
+ value: value.format(this.format),
valueArr: this.selectValue,
item: this.selectItem,
index: this.pickerValue,
@@ -132,13 +130,10 @@ export default {
this.pickerValue = pickerValue
this.$set(this.selectValue, columnIndex, valueItem.value)
this.$set(this.selectItem, columnName, valueItem.value)
- this.setColumnData()
- let selectItem = {
- ...this.selectItem
- }
- selectItem.month = selectItem.month - 1
+ this.setColumnData(columnIndex)
+ const value = this.getValueDate()
this.$emit('change', {
- value: this.dayjs(selectItem).format(this.format),
+ value: value.format(this.format),
valueArr: this.selectValue,
item: this.selectItem,
index: this.pickerValue,
@@ -146,17 +141,26 @@ export default {
})
}
},
- getLabel (value, name, format, rowIndex, columnIndex) {
+ getLabel (value, name, format, $d, rowIndex, columnIndex) {
+ const ch = this.isShowChinese ? this.chConfig[name] || '' : ''
+ let label =
+ value < 10 && format.length > 1 ? `0${value}${ch}` : value + ch
if (this.formatter && isFunction(this.formatter)) {
- const item = { name, format, value }
- return this.formatter({ item, rowIndex, columnIndex })
- } else {
- const ch = this.isShowChinese ? this.chConfig[name] || '' : ''
- return value < 10 && format.length > 1 ? `0${value}${ch}` : value + ch
+ const item = { name, format, value, $d }
+ label = this.formatter({ item, rowIndex, columnIndex }) || label
}
+ return label
},
- setColumnData () {
- let list = []
+ getValueDate (dateObj = {}) {
+ let selectItem = {
+ ...this.selectItem,
+ ...dateObj
+ }
+ selectItem.month = selectItem.month - 1
+ return this.dayjs(selectItem)
+ },
+ setColumnData (n = 0) {
+ let list = [...this.pickerColumns]
const formatArr = this.displayFormat.split('-')
const formatObj = {
YY: 'year',
@@ -175,64 +179,74 @@ export default {
ss: 'second'
}
formatArr.forEach((item, index) => {
- const name = formatObj[item]
- let value = this.selectItem[name]
- const obj = {
- name: name,
- list: this.getColumnData(name, item, index)
- }
- list.push(obj)
- let n = obj.list.findIndex(l => l.value === value)
- if (n < 0) {
- const l = obj.list.length - 1
- const firstValue = obj.list[0].value
- const lastValue = obj.list[l].value
- if (value < firstValue) {
- n = 0
- value = firstValue
+ if (index >= n) {
+ const name = formatObj[item]
+ const obj = {
+ name: name,
+ list: this.getColumnData(name, item, index)
}
- if (value > lastValue) {
- n = l
- value = lastValue
+ let value = this.selectItem[name]
+ if (index !== n) {
+ list[index] = obj
}
+ // list.push(obj)
+ let n = obj.list.findIndex(l => l.value === value)
+ if (n < 0) {
+ const l = obj.list.length - 1
+ const firstValue = obj.list[0].value
+ const lastValue = obj.list[l].value
+ if (value < firstValue) {
+ n = 0
+ value = firstValue
+ }
+ if (value > lastValue) {
+ n = l
+ value = lastValue
+ }
+ if (n < 0) {
+ n = 0
+ value = firstValue
+ }
+ }
+ this.$set(this.pickerValue, index, n)
+ this.$set(this.selectValue, index, value)
+ this.$set(this.selectItem, name, value)
}
- this.$set(this.pickerValue, index, n)
- this.$set(this.selectValue, index, value)
- this.$set(this.selectItem, name, value)
})
this.pickerColumns = list
},
+ isSame (name, type = 'startInfo') {
+ let same = true
+ const arr = ['year', 'month', 'day', 'hour', 'minute', 'second']
+ const index = arr.findIndex(item => item === name)
+ if (index > -1) {
+ const slice = arr.slice(0, index + 1)
+ for (let i = 0; i < slice.length; i++) {
+ same = same && this.selectItem[slice[i]] === this[type][slice[i]]
+ }
+ }
+ return same
+ },
getColumnData (name, format, index) {
let list = []
let start = 0
let end = 0
let n = 0
+ const obj = {
+ month: 'year',
+ day: 'month',
+ hour: 'day',
+ minute: 'hour',
+ second: 'minute'
+ }
switch (name) {
case 'year':
- for (let i = this.startInfo[name]; i <= this.endInfo[name]; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
+ start = this.startInfo[name]
+ end = this.endInfo[name]
break
case 'month':
start = 1
end = 12
- if (this.selectItem.year === this.startInfo.year) {
- start = this.startInfo[name]
- }
- if (this.selectItem.year === this.endInfo.year) {
- end = this.endInfo[name]
- }
- for (let i = start; i <= end; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
break
case 'day':
start = 1
@@ -241,108 +255,43 @@ export default {
this.selectItem.month,
0
).getDate()
- if (
- this.selectItem.year === this.startInfo.year &&
- this.selectItem.month === this.startInfo.month
- ) {
- start = this.startInfo[name]
- }
- if (
- this.selectItem.year === this.endInfo.year &&
- this.selectItem.month === this.endInfo.month
- ) {
- end = this.endInfo[name]
- }
- for (let i = start; i <= end; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
break
case 'hour':
start = 0
end = 23
- if (
- this.selectItem.year === this.startInfo.year &&
- this.selectItem.month === this.startInfo.month &&
- this.selectItem.day === this.startInfo.day
- ) {
- start = this.startInfo[name]
- }
- if (
- this.selectItem.year === this.endInfo.year &&
- this.selectItem.month === this.endInfo.month &&
- this.selectItem.day === this.endInfo.day
- ) {
- end = this.endInfo[name]
- }
- for (let i = start; i <= end; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
break
case 'minute':
start = 0
end = 59
- if (
- this.selectItem.year === this.startInfo.year &&
- this.selectItem.month === this.startInfo.month &&
- this.selectItem.day === this.startInfo.day &&
- this.selectItem.hour === this.startInfo.hour
- ) {
- start = this.startInfo[name]
- }
- if (
- this.selectItem.year === this.endInfo.year &&
- this.selectItem.month === this.endInfo.month &&
- this.selectItem.day === this.endInfo.day &&
- this.selectItem.hour === this.endInfo.hour
- ) {
- end = this.endInfo[name]
- }
- for (let i = start; i <= end; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
break
case 'second':
start = 0
end = 59
- if (
- this.selectItem.year === this.startInfo.year &&
- this.selectItem.month === this.startInfo.month &&
- this.selectItem.day === this.startInfo.day &&
- this.selectItem.hour === this.startInfo.hour &&
- this.selectItem.minute === this.startInfo.minute
- ) {
- start = this.startInfo[name]
- }
- if (
- this.selectItem.year === this.endInfo.year &&
- this.selectItem.month === this.endInfo.month &&
- this.selectItem.day === this.endInfo.day &&
- this.selectItem.hour === this.endInfo.hour &&
- this.selectItem.minute === this.endInfo.minute
- ) {
- end = this.endInfo[name]
- }
- for (let i = start; i <= end; i++) {
- n++
- list.push({
- label: this.getLabel(i, name, format, n, index),
- value: i
- })
- }
break
}
+ if (this.isSame(obj[name], 'startInfo')) {
+ start = this.startInfo[name]
+ }
+ if (this.isSame(obj[name], 'endInfo')) {
+ end = this.endInfo[name]
+ }
+ for (let i = start; i <= end; i++) {
+ n++
+ list.push({
+ label: this.getLabel(
+ i,
+ name,
+ format,
+ this.getValueDate({ [name]: i }),
+ n,
+ index
+ ),
+ value: i
+ })
+ }
+ if (this.filter && isFunction(this.filter)) {
+ list = this.filter(name, list) || list
+ }
return list
},
validate (type) {
@@ -394,7 +343,8 @@ export default {
hour: d.$H,
minute: d.$m,
second: d.$s,
- timestamp: d.valueOf()
+ timestamp: d.valueOf(),
+ $d: d
}
}
},
@@ -403,11 +353,29 @@ export default {
if (!this.isConfirmChange) {
this.init('value')
}
+ },
+ displayFormat () {
+ this.init('displayFormat')
+ },
+ startDate () {
+ this.init('startDate')
+ },
+ endDate () {
+ this.init('endDate')
+ },
+ defaultTimeLimit () {
+ this.init('defaultTimeLimit')
+ },
+ isShowChinese () {
+ this.init('isShowChinese')
+ },
+ chConfig () {
+ this.init('chConfig')
}
}
}
diff --git a/components/lb-picker/style/picker.scss b/components/lb-picker/style/picker.scss
index 425bd99..f72943b 100644
--- a/components/lb-picker/style/picker.scss
+++ b/components/lb-picker/style/picker.scss
@@ -31,6 +31,7 @@
/* #endif */
}
+/* #ifndef APP-NVUE */
.lb-picker-container-animation {
transition-property: transform;
transition-duration: 0.3s;
@@ -40,6 +41,8 @@
transform: translateY(0);
}
+/* #endif */
+
.lb-picker-header {
position: relative;
background-color: #fff;
@@ -110,7 +113,7 @@
background-color: #fff;
}
-/* #ifndef APP-PLUS */
+/* #ifndef APP-NVUE */
.lb-picker-content-safe-buttom {
padding-bottom: 0;
padding-bottom: constant(safe-area-inset-bottom);
diff --git a/package.json b/package.json
index 0c4e875..82eb503 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "uni-lb-picker",
- "version": "1.1.9",
+ "version": "1.1.10",
"description": "uniapp picker选择器,可自定义,扩展性高,支持单选、理论任意级数多级联动、非联动及日期选择。",
"main": "components/lb-picker/index.vue",
"scripts": {
diff --git a/pages/demos/demo1/demo1.nvue b/pages/demos/demo1/demo1.nvue
index a05f6fc..f94253c 100644
--- a/pages/demos/demo1/demo1.nvue
+++ b/pages/demos/demo1/demo1.nvue
@@ -1,10 +1,10 @@
-
+
默认单选
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -23,10 +23,10 @@
-
+
单选绑定默认值
-
+
绑定值:{{ value2 }}
{{ label2 }}
@@ -45,10 +45,10 @@
-
+
默认扁平化单选
-
+
绑定值:{{ value3 }}
{{ value3 }}
@@ -66,10 +66,10 @@
-
+
扁平化单选绑定默认值
-
+
绑定值:{{ value4 }}
{{ value4 }}
@@ -87,10 +87,10 @@
-
+
无数据
-
+
绑定值:{{ value5 }}
{{ value5 }}
diff --git a/pages/demos/demo1/demo1.vue b/pages/demos/demo1/demo1.vue
index a05f6fc..f94253c 100644
--- a/pages/demos/demo1/demo1.vue
+++ b/pages/demos/demo1/demo1.vue
@@ -1,10 +1,10 @@
-
+
默认单选
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -23,10 +23,10 @@
-
+
单选绑定默认值
-
+
绑定值:{{ value2 }}
{{ label2 }}
@@ -45,10 +45,10 @@
-
+
默认扁平化单选
-
+
绑定值:{{ value3 }}
{{ value3 }}
@@ -66,10 +66,10 @@
-
+
扁平化单选绑定默认值
-
+
绑定值:{{ value4 }}
{{ value4 }}
@@ -87,10 +87,10 @@
-
+
无数据
-
+
绑定值:{{ value5 }}
{{ value5 }}
diff --git a/pages/demos/demo10/demo10.nvue b/pages/demos/demo10/demo10.nvue
index 342e3ad..26e7129 100644
--- a/pages/demos/demo10/demo10.nvue
+++ b/pages/demos/demo10/demo10.nvue
@@ -1,10 +1,10 @@
-
+
相关事件触发
-
+
绑定值:{{ value }}
{{ label }}
diff --git a/pages/demos/demo10/demo10.vue b/pages/demos/demo10/demo10.vue
index 342e3ad..26e7129 100644
--- a/pages/demos/demo10/demo10.vue
+++ b/pages/demos/demo10/demo10.vue
@@ -1,10 +1,10 @@
-
+
相关事件触发
-
+
绑定值:{{ value }}
{{ label }}
diff --git a/pages/demos/demo11/demo11.nvue b/pages/demos/demo11/demo11.nvue
index 061337a..b614f4c 100644
--- a/pages/demos/demo11/demo11.nvue
+++ b/pages/demos/demo11/demo11.nvue
@@ -1,10 +1,10 @@
-
+
默认异步加载整体数据
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -25,10 +25,10 @@
-
+
插槽自定义loading
-
+
绑定值:{{ value2 }}
{{ label2 }}
diff --git a/pages/demos/demo11/demo11.vue b/pages/demos/demo11/demo11.vue
index 061337a..b614f4c 100644
--- a/pages/demos/demo11/demo11.vue
+++ b/pages/demos/demo11/demo11.vue
@@ -1,10 +1,10 @@
-
+
默认异步加载整体数据
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -25,10 +25,10 @@
-
+
插槽自定义loading
-
+
绑定值:{{ value2 }}
{{ label2 }}
diff --git a/pages/demos/demo12/demo12.nvue b/pages/demos/demo12/demo12.nvue
index f6f4637..acc087d 100644
--- a/pages/demos/demo12/demo12.nvue
+++ b/pages/demos/demo12/demo12.nvue
@@ -1,10 +1,10 @@
-
+
非联动选择
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -23,10 +23,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -45,10 +45,10 @@
-
+
扁平化数据非联动选择
-
+
绑定值:{{ JSON.stringify(value4) }}
点我打开选择器
@@ -64,10 +64,10 @@
-
+
扁平化绑定默认值
-
+
绑定值:{{ JSON.stringify(value5) }}
点我打开选择器
@@ -83,10 +83,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value6) }}
点我打开选择器
diff --git a/pages/demos/demo12/demo12.vue b/pages/demos/demo12/demo12.vue
index f6f4637..acc087d 100644
--- a/pages/demos/demo12/demo12.vue
+++ b/pages/demos/demo12/demo12.vue
@@ -1,10 +1,10 @@
-
+
非联动选择
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -23,10 +23,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -45,10 +45,10 @@
-
+
扁平化数据非联动选择
-
+
绑定值:{{ JSON.stringify(value4) }}
点我打开选择器
@@ -64,10 +64,10 @@
-
+
扁平化绑定默认值
-
+
绑定值:{{ JSON.stringify(value5) }}
点我打开选择器
@@ -83,10 +83,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value6) }}
点我打开选择器
diff --git a/pages/demos/demo14/demo14.nvue b/pages/demos/demo14/demo14.nvue
index 8bf2c1c..626bfb9 100644
--- a/pages/demos/demo14/demo14.nvue
+++ b/pages/demos/demo14/demo14.nvue
@@ -1,10 +1,10 @@
-
+
单选formatter自定义显示
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
多级联动formatter自定义显示
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -48,10 +48,10 @@
-
+
非联动formatter自定义显示
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
diff --git a/pages/demos/demo14/demo14.vue b/pages/demos/demo14/demo14.vue
index 8bf2c1c..626bfb9 100644
--- a/pages/demos/demo14/demo14.vue
+++ b/pages/demos/demo14/demo14.vue
@@ -1,10 +1,10 @@
-
+
单选formatter自定义显示
-
+
绑定值:{{ value1 }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
多级联动formatter自定义显示
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -48,10 +48,10 @@
-
+
非联动formatter自定义显示
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
diff --git a/pages/demos/demo15/demo15.nvue b/pages/demos/demo15/demo15.nvue
index f966683..f18e651 100644
--- a/pages/demos/demo15/demo15.nvue
+++ b/pages/demos/demo15/demo15.nvue
@@ -1,10 +1,10 @@
-
+
点击弹出选择器后长按选择器文字
-
+
点我打开选择器
diff --git a/pages/demos/demo15/demo15.vue b/pages/demos/demo15/demo15.vue
index f966683..f18e651 100644
--- a/pages/demos/demo15/demo15.vue
+++ b/pages/demos/demo15/demo15.vue
@@ -1,10 +1,10 @@
-
+
点击弹出选择器后长按选择器文字
-
+
点我打开选择器
diff --git a/pages/demos/demo16/demo16.nvue b/pages/demos/demo16/demo16.nvue
index a28ad2d..33558e2 100644
--- a/pages/demos/demo16/demo16.nvue
+++ b/pages/demos/demo16/demo16.nvue
@@ -1,10 +1,10 @@
-
+
年月日选择
-
+
绑定值:{{ value1 }}
点我打开选择器
@@ -20,10 +20,10 @@
-
+
年月日默认值
-
+
绑定值:{{ value2 }}
点我打开选择器
@@ -39,10 +39,10 @@
-
+
开始结束日期限制(可精确到秒)
-
+
绑定值:{{ value3 }}
点我打开选择器
@@ -63,10 +63,10 @@
-
+
不显示年月日等日期文字
-
+
绑定值:{{ value4 }}
点我打开选择器
@@ -83,10 +83,10 @@
-
+
自定义显示年月日等文字
-
+
绑定值:{{ value5 }}
点我打开选择器
@@ -107,10 +107,10 @@
-
- 高级formatter自定义显示
-
+
+ formatter自定义显示(百度、支付宝、头条小程序不支持)
+
绑定值:{{ value6 }}
点我打开选择器
@@ -127,10 +127,10 @@
-
+
format格式化日期
-
+
绑定值:{{ value7 }}
点我打开选择器
@@ -160,11 +160,10 @@
-
+
自定义显示日期颗粒,可自由组合
-
-
+
绑定值:{{ value8 }}
点我打开选择器
@@ -181,6 +180,60 @@
+
+
+ filter过滤列表,例:过滤排除年月日为奇数项,仅保留偶数项
+
+ 绑定值:{{ value9 }}
+
+ 点我打开选择器
+
+
+
+
+
+
+
+
+ 插槽自定义日期范围选择
+
+ 绑定值:{{ JSON.stringify(value10) }}
+
+ 点我打开选择器
+
+
+
+
+
+ {{ value10[0] || '点击选择开始日期' }}
+
+
+ {{ value10[1] || '点击选择结束日期' }}
+
+
+
+
+
@@ -196,6 +249,10 @@ export default {
value6: '',
value7: '天朝2021年第01月第01日',
value8: '',
+ value9: '',
+ value10: [],
+ value10Active: 0,
+ value10Start: '',
startDate: '2018-08-08 08:08:08',
endDate: '2021-08-08 08:08:08',
curFormat: 'YYYY',
@@ -221,23 +278,19 @@ export default {
}
}
},
- onReady () {
- // this.$nextTick(() => {
- // // 此处可以调用getColumnsInfo方法获取默认值的选项信息
- // const info = this.$refs.picker2.getColumnsInfo(this.value2)
- // console.log('根据value获取的信息:', info)
- // this.label2 = info.item.label
- // })
- },
methods: {
handleTap (name) {
this.$refs[name].show()
},
handleChange (e) {
console.log('change::', e)
+ if (e.dataset.name === 'picker10') {
+ this.$set(this.value10, this.value10Active, e.value)
+ }
},
handleConfirm (e) {
console.log('confirm::', e)
+
},
handleCancel (e) {
console.log('cancel::', e)
@@ -249,17 +302,41 @@ export default {
const arr = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
return `${arr[item.value - 1]}月`
} else if (item.name === 'day') {
- return `第${item.value}日`
+ const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
+ return `${item.value}号-${week[item.$d.day()]}`
}
},
radioChange (e) {
this.value8 = ''
this.curFormat = e.detail.value
+ },
+ filter (name, list) {
+ list = list.filter(item => item.value%2 === 0)
+ return list
+ },
+ handleStartEnd (active) {
+ this.value10Active = active
+ this.value10Start = active === 1 ? this.value10[0] : ''
}
}
}
\ No newline at end of file
diff --git a/pages/demos/demo16/demo16.vue b/pages/demos/demo16/demo16.vue
index a28ad2d..33558e2 100644
--- a/pages/demos/demo16/demo16.vue
+++ b/pages/demos/demo16/demo16.vue
@@ -1,10 +1,10 @@
-
+
年月日选择
-
+
绑定值:{{ value1 }}
点我打开选择器
@@ -20,10 +20,10 @@
-
+
年月日默认值
-
+
绑定值:{{ value2 }}
点我打开选择器
@@ -39,10 +39,10 @@
-
+
开始结束日期限制(可精确到秒)
-
+
绑定值:{{ value3 }}
点我打开选择器
@@ -63,10 +63,10 @@
-
+
不显示年月日等日期文字
-
+
绑定值:{{ value4 }}
点我打开选择器
@@ -83,10 +83,10 @@
-
+
自定义显示年月日等文字
-
+
绑定值:{{ value5 }}
点我打开选择器
@@ -107,10 +107,10 @@
-
- 高级formatter自定义显示
-
+
+ formatter自定义显示(百度、支付宝、头条小程序不支持)
+
绑定值:{{ value6 }}
点我打开选择器
@@ -127,10 +127,10 @@
-
+
format格式化日期
-
+
绑定值:{{ value7 }}
点我打开选择器
@@ -160,11 +160,10 @@
-
+
自定义显示日期颗粒,可自由组合
-
-
+
绑定值:{{ value8 }}
点我打开选择器
@@ -181,6 +180,60 @@
+
+
+ filter过滤列表,例:过滤排除年月日为奇数项,仅保留偶数项
+
+ 绑定值:{{ value9 }}
+
+ 点我打开选择器
+
+
+
+
+
+
+
+
+ 插槽自定义日期范围选择
+
+ 绑定值:{{ JSON.stringify(value10) }}
+
+ 点我打开选择器
+
+
+
+
+
+ {{ value10[0] || '点击选择开始日期' }}
+
+
+ {{ value10[1] || '点击选择结束日期' }}
+
+
+
+
+
@@ -196,6 +249,10 @@ export default {
value6: '',
value7: '天朝2021年第01月第01日',
value8: '',
+ value9: '',
+ value10: [],
+ value10Active: 0,
+ value10Start: '',
startDate: '2018-08-08 08:08:08',
endDate: '2021-08-08 08:08:08',
curFormat: 'YYYY',
@@ -221,23 +278,19 @@ export default {
}
}
},
- onReady () {
- // this.$nextTick(() => {
- // // 此处可以调用getColumnsInfo方法获取默认值的选项信息
- // const info = this.$refs.picker2.getColumnsInfo(this.value2)
- // console.log('根据value获取的信息:', info)
- // this.label2 = info.item.label
- // })
- },
methods: {
handleTap (name) {
this.$refs[name].show()
},
handleChange (e) {
console.log('change::', e)
+ if (e.dataset.name === 'picker10') {
+ this.$set(this.value10, this.value10Active, e.value)
+ }
},
handleConfirm (e) {
console.log('confirm::', e)
+
},
handleCancel (e) {
console.log('cancel::', e)
@@ -249,17 +302,41 @@ export default {
const arr = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
return `${arr[item.value - 1]}月`
} else if (item.name === 'day') {
- return `第${item.value}日`
+ const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
+ return `${item.value}号-${week[item.$d.day()]}`
}
},
radioChange (e) {
this.value8 = ''
this.curFormat = e.detail.value
+ },
+ filter (name, list) {
+ list = list.filter(item => item.value%2 === 0)
+ return list
+ },
+ handleStartEnd (active) {
+ this.value10Active = active
+ this.value10Start = active === 1 ? this.value10[0] : ''
}
}
}
\ No newline at end of file
diff --git a/pages/demos/demo2/demo2.nvue b/pages/demos/demo2/demo2.nvue
index 4e41013..8c66f5c 100644
--- a/pages/demos/demo2/demo2.nvue
+++ b/pages/demos/demo2/demo2.nvue
@@ -1,10 +1,10 @@
-
+
二级联动
-
+
绑定值:{{ JSON.stringify(value1) }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
三级联动
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -47,10 +47,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -70,10 +70,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value4) }}
点我打开选择器
@@ -94,238 +94,238 @@
+
\ No newline at end of file
diff --git a/pages/demos/demo2/demo2.vue b/pages/demos/demo2/demo2.vue
index 4e41013..b8d5fff 100644
--- a/pages/demos/demo2/demo2.vue
+++ b/pages/demos/demo2/demo2.vue
@@ -1,10 +1,10 @@
-
+
二级联动
-
+
绑定值:{{ JSON.stringify(value1) }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
三级联动
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -47,10 +47,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -70,10 +70,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value4) }}
点我打开选择器
diff --git a/pages/demos/demo3/demo3.nvue b/pages/demos/demo3/demo3.nvue
index 7092b6f..c6ed3eb 100644
--- a/pages/demos/demo3/demo3.nvue
+++ b/pages/demos/demo3/demo3.nvue
@@ -1,10 +1,10 @@
-
+
省一级选择
-
+
绑定值:{{ JSON.stringify(value1) }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
省市二级选择
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -47,10 +47,10 @@
-
+
省市区三级选择
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -70,10 +70,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value4) }}
{{ label4 }}
@@ -93,10 +93,10 @@
-
+
默认值有缺省
-
+
绑定值:{{ JSON.stringify(value5) }}
{{ label5 }}
@@ -116,10 +116,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value6) }}
点我打开选择器
diff --git a/pages/demos/demo3/demo3.vue b/pages/demos/demo3/demo3.vue
index 7092b6f..c6ed3eb 100644
--- a/pages/demos/demo3/demo3.vue
+++ b/pages/demos/demo3/demo3.vue
@@ -1,10 +1,10 @@
-
+
省一级选择
-
+
绑定值:{{ JSON.stringify(value1) }}
{{ label1 }}
@@ -24,10 +24,10 @@
-
+
省市二级选择
-
+
绑定值:{{ JSON.stringify(value2) }}
{{ label2 }}
@@ -47,10 +47,10 @@
-
+
省市区三级选择
-
+
绑定值:{{ JSON.stringify(value3) }}
{{ label3 }}
@@ -70,10 +70,10 @@
-
+
绑定默认值
-
+
绑定值:{{ JSON.stringify(value4) }}
{{ label4 }}
@@ -93,10 +93,10 @@
-
+
默认值有缺省
-
+
绑定值:{{ JSON.stringify(value5) }}
{{ label5 }}
@@ -116,10 +116,10 @@
-
+
无数据
-
+
绑定值:{{ JSON.stringify(value6) }}
点我打开选择器
diff --git a/pages/demos/demo4/demo4.nvue b/pages/demos/demo4/demo4.nvue
index f44732b..7ed0a75 100644
--- a/pages/demos/demo4/demo4.nvue
+++ b/pages/demos/demo4/demo4.nvue
@@ -1,10 +1,10 @@
-
+
自定义确定取消文字及颜色,点击打开选择器
-
+
绑定值:{{ value }}
{{ label }}
diff --git a/pages/demos/demo4/demo4.vue b/pages/demos/demo4/demo4.vue
index f44732b..7ed0a75 100644
--- a/pages/demos/demo4/demo4.vue
+++ b/pages/demos/demo4/demo4.vue
@@ -1,10 +1,10 @@
-
+