InputNumber.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script lang="tsx">
  2. import { defineComponent, unref } from 'vue'
  3. import { useI18n } from 'vue-i18n'
  4. import { useFormSize } from 'element-plus'
  5. const Props = {
  6. modelValue: {},
  7. params: {
  8. type: Object
  9. }
  10. // 扩展
  11. // 1. prefix -> prefixIcon (prefix 已被vue 拦截)
  12. // prefixIcon: String, // eg: '测试Prefix'
  13. // 2. suffix -> suffixIcon (prefix 已被vue 拦截 与 suffix 对应做处理)
  14. // suffixIcon: String, // eg: '测试suffix'
  15. // 3. v-slot: { prefix, suffix } or slots: { prefix: render, suffix: render, }
  16. }
  17. const Component = defineComponent({
  18. name: 'LeInputNumber',
  19. props: Props,
  20. emits: [
  21. 'change',
  22. // "update:modelValue"
  23. ],
  24. setup(props, ctx) {
  25. const { t } = useI18n()
  26. return () => {
  27. const { prefixIcon, suffixIcon, prop, controlsPosition, t_placeholder, size, placeholder, max = 999999999999999, ...local_props } = ctx.attrs
  28. const inputNumberSize = size || unref(useFormSize())
  29. const _prefix = prefixIcon ? <span class="le-addon le-input-number__prefix">{prefixIcon}</span> : ''
  30. const _suffix = suffixIcon ? <span class="le-addon le-input-number__suffix">{suffixIcon}</span> : ''
  31. const _placeholder = (t_placeholder ? t(t_placeholder) : placeholder) ?? t('le.el.input.placeholder')
  32. const slots = Object.keys(ctx.slots).length ? ctx.slots : local_props.slots || {}
  33. const onChange = (...v) => {
  34. ctx.emit('change', ...v)
  35. }
  36. return (
  37. <div
  38. class={`le-input-number le-input-number--${inputNumberSize} el-input el-input-group
  39. ${_prefix || slots.prefix ? 'el-input-group--prepend le-input-number--prefix' : ''}
  40. ${_suffix || slots.suffix ? 'el-input-group--append le-input-number--suffix' : ''}
  41. `}
  42. >
  43. {slots.prefix ? slots.prefix() : _prefix}
  44. <el-input-number
  45. max={max}
  46. {...local_props}
  47. onChange={onChange}
  48. size={inputNumberSize}
  49. controlsPosition={controlsPosition ?? 'right'}
  50. placeholder={_placeholder}
  51. model-value={props.modelValue}
  52. />
  53. {slots.suffix ? slots.suffix() : _suffix}
  54. </div>
  55. )
  56. }
  57. }
  58. /*render() {
  59. const { t } = useI18n()
  60. const { prefix, suffix, prop, controlsPosition, placeholder, max = 999999999999999, ...props } = this.$attrs
  61. const { inputNumberSize, value } = this
  62. const $slots = this.$slots
  63. // const onEvents = this.$listeners
  64. const _prefix = prefix ? <span class="le-addon le-input-number__prefix">{prefix}</span> : ''
  65. const _suffix = suffix ? <span class="le-addon le-input-number__suffix">{suffix}</span> : ''
  66. return (
  67. <div
  68. class={`le-input-number le-input-number--${inputNumberSize} el-input el-input-group
  69. ${_prefix || $slots.prefix ? 'le-input-number--prefix' : ''}
  70. ${_suffix || $slots.suffix ? 'le-input-number--suffix' : ''}
  71. `}
  72. >
  73. {$slots.prefix || _prefix}
  74. <el-input-number
  75. max={max}
  76. {...props}
  77. size={inputNumberSize}
  78. controlsPosition={controlsPosition || 'right'}
  79. placeholder={placeholder || t('le.el.input.placeholder')}
  80. // value={this.localValue}
  81. value={value}
  82. />
  83. {$slots.suffix || _suffix}
  84. </div>
  85. )
  86. },*/
  87. })
  88. export default Component
  89. </script>