byInput.vue 2.3 KB

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