index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <el-input ref="inputRef"
  3. v-model="proxyValue"
  4. :placeholder="placeholder"
  5. :clearable="clearable"
  6. :disabled="disabled"
  7. :maxlength="limit"
  8. :show-word-limit="!!limit"
  9. type="textarea"
  10. :autosize="autosize"
  11. resize="none"
  12. :style="{...inputStyle,width}"></el-input>
  13. </template>
  14. <script>
  15. import { ElInput } from 'element-plus'
  16. import { computed, watch, ref, nextTick, onMounted } from 'vue'
  17. import { useFormInput } from '@cip/components/hooks/form-input'
  18. import { formInputProps, fromInputEmits } from '../../form-input-props'
  19. import { useCipConfig } from '@cip/components/hooks/use-cip-config'
  20. import { getUsingConfig } from '@cip/utils/util'
  21. export default {
  22. components: { ElInput },
  23. props: formInputProps,
  24. emits: [...fromInputEmits],
  25. setup (props, context) {
  26. const cipConfig = useCipConfig()
  27. const { width, clearable, securityConfig, proxyValue, inputStyle, ...formInput } = useFormInput(props, context)
  28. const inputRef = ref()
  29. const limit = computed(() => {
  30. return getUsingConfig(securityConfig.value.limit, cipConfig.limit.textarea) // props.config?.limit ?? cipConfig?.limit?.textarea ?? ''
  31. })
  32. const autosize = computed(() => {
  33. return Object.assign({}, { minRows: 2, maxRows: 6 }, securityConfig.value.autosize) // props.config?.autosize || { minRows: 2, maxRows: 6 }
  34. })
  35. onMounted(() => {
  36. watch(() => securityConfig.value.autosize, () => {
  37. nextTick(() => {
  38. // 必须在nextTick中触发否则无效
  39. inputRef.value.resizeTextarea()
  40. })
  41. }, { deep: true }) // 需要深度监听才可以正常触发
  42. })
  43. return {
  44. ...formInput,
  45. inputRef,
  46. clearable,
  47. proxyValue,
  48. autosize,
  49. width,
  50. inputStyle,
  51. limit
  52. }
  53. }
  54. }
  55. </script>