1 Star 0 Fork 0

赛里木湖 / uni-date-selector

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

简介

一个日期选择组件,可以按照日、周、月、年、总的方式来选择时间,选择一种日期类型之后,支持前后查询,比如选择的是日类型,前后查询的切换单位是天,选择的是月,则前后查询额切换的单位是月 界面截图

项目依赖

API说明

属性

  • dateTypes,日期类型,支持 day, week, month, year, total 五种类型,默认是 ['month', 'year', 'total']
<!-- 下面代码初始化了一个支持日和周两种日期类型的组件 -->
<date-selector :dateTypes="['day', 'week']"></date-selector>
  • defaultDateType,默认选中的日期类型,支持 day, week, month, year, total 五种类型,如果不传入,则默认选中dateTypes的第一个类型

  • defaultDateValue,默认的日期值,比如 defaultDateType设置的是 'month',然后 defaultDateValue可以传入 2021-6-1,则初始显示未 2021年6月

<date-selector :dateTypes="['day', 'week', 'month']" defaultType='month' defaultDateValue="2021-6-1" ></date-selector>

事件

  • change,日期值改变时触发,比如在dateType的tab切换时会触发,比如前后查询时会触发,比如直接更改日期时也会触发,
<date-selector @change="onDateChange"></date-selector>
import {dateSelector} from 'uni-date-selector'

{
	methods:{
		onDateChange(val){
			console.log('onDateChange', val)
		}	
	}
}

工具

组件提供了datePickerHelper组件,包含一些工具方法,其中最常用的是getTheDateValue方法,这个一般用于初始化返回值

	import {datePickerHelper} from 'uni-date-selector'
	{
		date(){			
			selectedDate: datePickerHelper.getTheDateValue('month')
		}
	}

change参数格式如下

{
	"dateType": "day",
	"value": "2021-09-23T16:00:00.000Z",
	"startTime": "2021-09-24 00:00:00",
	"endTime": "2021-09-25 00:00:00",
	"chartFormat": "HH:mm",
	"tableFormat": "YYYY-MM-DD HH:mm",
	"year": 2021,
	"month": 9,
	"day": 24
}

这个返回参数提供了当前选择日期的3种格式的值:

  • 格式1:
    • value,这个是moment格式数值
  • 格式2:startTime, endTime,这是一个范围,可以用于某些需要提供范围的查询api中
  • 格式3:year, month, day,如果dateType='year',则只有year有值,month, day字段都是空的,这可以用于某些只接受year, month, day作为查询条件的api
  • 其他参数说明
    • dateType,当前选择的日期类型
    • chartFormat,比如如果当前查询的是
MIT License Copyright (c) 2021 小拿视界 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个日期选择组件,可以按照日、周、月、年、总的方式来选择时间 展开 收起
JavaScript 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/sailimuhu/uni-date-selector.git
git@gitee.com:sailimuhu/uni-date-selector.git
sailimuhu
uni-date-selector
uni-date-selector
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891