byInput.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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" :autosize="attrs.autosize"></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>
  90. <style lang="scss">
  91. .el-input--small{
  92. font-size: 14px !important;
  93. }
  94. .vxe-input--inner[disabled]{
  95. background-color: #F5F7FA;
  96. border-color: #dfe4ed;
  97. color: #C0C4CC;
  98. cursor: not-allowed;
  99. }
  100. </style>