You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
2.0 KiB

  1. <template>
  2. <l-label @click="click" :class="className" :style="style" :arrow="!disabled" :required="required" :title="title">
  3. <!-- #ifndef MP-DINGTALK -->
  4. <picker
  5. @change="change"
  6. :value="value"
  7. :start="start"
  8. :end="end"
  9. :disabled="disabled"
  10. :class="[disabled ? '' : 'picker-arrow']"
  11. mode="time"
  12. >
  13. <view class="picker">{{ value || displayPlaceholder }}</view>
  14. </picker>
  15. <!-- #endif -->
  16. <!-- #ifdef MP-DINGTALK -->
  17. <text @click="click">{{ value || displayPlaceholder }}</text>
  18. <!-- #endif -->
  19. </l-label>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'l-time-picker',
  24. props: {
  25. title: {},
  26. start: { default: '00:00' },
  27. end: { default: '23:59' },
  28. disabled: {},
  29. placeholder: {},
  30. value: {}
  31. },
  32. methods: {
  33. click(e) {
  34. if (this.disabled) {
  35. return
  36. }
  37. this.$emit('click', e)
  38. // #ifdef MP-DINGTALK
  39. const getCurrent = () => {
  40. const now = new Date()
  41. const hours = now
  42. .getHours()
  43. .toString()
  44. .padStart(2, '0')
  45. const minutes = now
  46. .getMinutes()
  47. .toString()
  48. .padStart(2, '0')
  49. return hours + ':' + minutes
  50. }
  51. const currentDate = this.value ? this.value : getCurrent()
  52. this.$emit('open')
  53. dd.datePicker({
  54. currentDate,
  55. format: 'HH:mm',
  56. success: ({ date }) => {
  57. if (date) {
  58. this.$emit('input', date + ':00')
  59. this.$emit('change', date + ':00')
  60. }
  61. },
  62. complete: () => {
  63. this.$emit('close')
  64. }
  65. })
  66. // #endif
  67. },
  68. change(e) {
  69. this.$emit('input', e.detail.value)
  70. this.$emit('change', e.detail.value)
  71. }
  72. },
  73. computed: {
  74. displayPlaceholder() {
  75. if (this.disabled) {
  76. return ''
  77. }
  78. if (this.placeholder) {
  79. return this.placeholder
  80. }
  81. return this.title ? `请选择${this.title}` : '请选择…'
  82. }
  83. }
  84. }
  85. </script>