mobile.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { ref, computed } from 'vue'
  2. import { Field as VantField, Popup as VanPopup, Picker as VanPicker } from 'vant'
  3. import { useFormInput } from '../../../hooks/form-input'
  4. import { formInputProps, fromInputEmits } from '../../form-input-props'
  5. import { nextTime, compareTime } from './utils'
  6. export default {
  7. props: formInputProps,
  8. emits: [...fromInputEmits],
  9. setup (props, context) {
  10. const { proxyValue, placeholder, width } = useFormInput(props, context)
  11. const start = computed(() => {
  12. return props.config?.start ?? '00:00'
  13. })
  14. const end = computed(() => {
  15. return props.config?.end ?? '24:00'
  16. })
  17. const step = computed(() => {
  18. return props.config?.step ?? '00:30'
  19. })
  20. // picker中的列表值
  21. const columns = computed(() => {
  22. const result = []
  23. if (start.value && end.value && step.value) {
  24. let current = start.value
  25. while (!compareTime(current, end.value)) {
  26. result.push(current)
  27. current = nextTime(current, step.value)
  28. }
  29. }
  30. return result
  31. })
  32. const show = ref(false)
  33. const openPopup = () => {
  34. show.value = true
  35. }
  36. const confirm = (val) => {
  37. proxyValue.value = val
  38. show.value = false
  39. }
  40. const cancel = () => {
  41. show.value = false
  42. }
  43. return () => <div style={{ width: width.value }}>
  44. <VantField modelValue={proxyValue.value}
  45. placeholder={placeholder.value}
  46. readonly
  47. is-link
  48. onclick={openPopup}></VantField>
  49. <VanPopup show={show.value} position="bottom" style="height: 40%">
  50. <VanPicker title='选择时间'
  51. modelValue={proxyValue.value}
  52. columns={columns.value}
  53. onConfirm={confirm}
  54. onCancel={cancel} />
  55. </VanPopup>
  56. </div>
  57. }
  58. }