byInput.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <el-input
  3. v-model="value"
  4. :placeholder="placeholder"
  5. :maxlength="attrs.maxlength"
  6. :minlength="attrs.minlength"
  7. :show-word-limit="attrs.showWordLimit"
  8. :clearable="attrs.clearable"
  9. :show-password="attrs.showPassword"
  10. :disabled="attrs.disabled"
  11. :size="attrs.size"
  12. :type="attrs.type"
  13. :prefix-icon="attrs.prefixIcon"
  14. :suffix-icon="attrs.suffixIcon"
  15. :rows="attrs.rows"
  16. :readonly="attrs.readonly"
  17. @input="onChange"
  18. @clear="onChange"
  19. ></el-input>
  20. </template>
  21. <script lang="ts">
  22. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  23. import VueViews from '@/benyun/compVue/VueViews'
  24. @Component
  25. export default class ByInput extends VueViews {
  26. value:any=null;
  27. @Watch('propValue')
  28. propValueChange(v:any){
  29. if(v){
  30. this.value = (this as any).$lodash.cloneDeep(v);
  31. if(this.attrs.type == 'number'){
  32. this.value = Number(v);
  33. }
  34. }else{
  35. this.value = null;
  36. }
  37. }
  38. created(){
  39. if(this.propConfig){
  40. this.setConfig(this.propConfig)
  41. }
  42. if(this.propValue){
  43. this.setValue(this.propValue)
  44. }
  45. if(this.attrs.defaultValue && !this.value){
  46. this.setValue(this.attrs.defaultValue);
  47. this.onChange();
  48. }
  49. }
  50. get placeholder(){
  51. if(this.attrs.disabled){
  52. return ''
  53. }
  54. if(this.attrs.placeholder){
  55. return this.attrs.placeholder
  56. }
  57. return '请输入内容'
  58. }
  59. mounted(){
  60. }
  61. setValue(data:any){
  62. if(data){
  63. this.value = (this as any).$lodash.cloneDeep(data);
  64. if(this.attrs.type == 'number'){
  65. this.value = Number(data);
  66. }
  67. }else{
  68. this.value = null;
  69. }
  70. }
  71. getValue(){
  72. return (this as any).$lodash.cloneDeep(this.value);
  73. }
  74. // 清空数据
  75. clearValue(){
  76. this.value = ''
  77. }
  78. onChange(){
  79. this.$emit('onChange',this.value);
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. </style>