Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datepicker's value type customized #2076

Closed
Uther opened this issue Dec 30, 2021 · 1 comment
Closed

datepicker's value type customized #2076

Uther opened this issue Dec 30, 2021 · 1 comment
Labels
feature request New feature or request

Comments

@Uther
Copy link

Uther commented Dec 30, 2021

This function solves the problem (这个功能解决的问题)

now the value is timestamp only , if i need a value format like 'YYYY-MM-DD', i need to import a lib like moment and then trans the value to post to backend,u can add a prop allow me to customize it

Expected API (期望的 API)

const renderFormat = computed(() => {
      const { type, format } = attrs
      const defaultM = isDateTimeType(type) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'
      const defaultN = isDateTimeType(type) ? 'yyyy-MM-dd HH:mm:ss' : 'yyyy-MM-dd'
      if (format) {
        return {m: format.m || defaultM, n: format.n || defaultN}
      } else {
        return {m: defaultM, n: defaultN}
      }
    })
    const getTrueValue = (val) => {
      const props = {...val}
      const { endProp, startProp, type = 'date'  } = props
      if (props.value) {
        if (['datetimerange', 'daterange'].includes(type) && startProp && endProp) { 
          props._value = [moment(props.value[0]).format('x') * 1, moment(props.value[1]).format('x') * 1]
          props.value = [moment(props.value[0]).format(renderFormat.m), moment(props.value[1]).format(renderFormat.m)]
        } else {
          props._value = moment(props.value).format('x') * 1
          props.value = moment(props._value).format(renderFormat.m)
        }
      } else {
        props._value = props.value
      }
      return props
    }
const onUpdate = (v) => {
      const { needTrans = true, type, startProp, endProp } = attrs
      let nv = null
      if (v) {
        if (['datetimerange', 'daterange'].includes(type) && startProp && endProp) {
          nv = needTrans ? [moment(v[0]).format(renderFormat.value.m), moment(v[1]).format(renderFormat.value.m)] : [moment(v[0]).format('x'), moment(v[1]).format('x')]
        } else {
          nv = needTrans ? moment(v).format(renderFormat.value.m) : moment(v).format('x')
        }
      } else {
        nv = v
      }
      attrs.onInput(nv)
    }
@github-actions github-actions bot added the feature request New feature or request label Dec 30, 2021
@07akioni
Copy link
Collaborator

Will fix soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants