DayPicker 星期选择器 - 图1

参数

参数 说明 类型 可选值 默认值
title string ‘’ 标题
show boolean false 弹窗显示状态
initValue number[] [] 初始化已选中的值,0-6分别表示周日至周六
confirmBtn string ‘确定’ 确定操作文案
cancelBtn string ‘取消’ 取消操作文案

Events

事件名称 说明 回调参数
update:show (show: boolean) 更新弹窗显示状态
confirm (days: number[]) 确认
cancel - 取消

使用示例

  1. <template>
  2. <div class="day-picker">
  3. <span @click="onShow">开始选择日期(星期日)</span>
  4. <p >{{daysText}}</p>
  5. <day-picker
  6. title="选择日期"
  7. :show.sync="show"
  8. :initValue="days"
  9. @confirm="onConfirm"
  10. @cancel="onCancel"
  11. >
  12. </day-picker>
  13. </div>
  14. </template>
  15. <script>
  16. import Vue from "vue";
  17. import { DayPicker } from "genie-ui";
  18. export default {
  19. components: {
  20. DayPicker,
  21. },
  22. data() {
  23. return {
  24. // 是否显示选择器
  25. show: false,
  26. // 初始默认选中日期
  27. days: [1],
  28. }
  29. },
  30. computed: {
  31. daysText() {
  32. const defaultDays = [
  33. { key: 0, name: '周日' },
  34. { key: 1, name: '周一' },
  35. { key: 2, name: '周二' },
  36. { key: 3, name: '周三' },
  37. { key: 4, name: '周四' },
  38. { key: 5, name: '周五' },
  39. { key: 6, name: '周六' },
  40. ]
  41. return this.days.map(key => {
  42. const day = defaultDays.find(item => item.key === key)
  43. return day ? day.name : ''
  44. })
  45. }
  46. },
  47. methods: {
  48. onShow() {
  49. console.log('show day picker')
  50. this.show = true
  51. },
  52. onConfirm(selectedDays) {
  53. console.log('on confirm pick day', selectedDays)
  54. this.days = selectedDays
  55. },
  56. onCancel() {
  57. console.log('on cancel pick day')
  58. },
  59. }
  60. };
  61. </script>
  62. <style scoped>
  63. .del {
  64. height: 100%;
  65. width: 50px;
  66. background: #f00;
  67. color: #fff;
  68. display: flex;
  69. justify-content: center;
  70. align-items: center;
  71. }
  72. </style>