byInput.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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="disabledValue" :prefix-icon="attrs.prefixIcon"
  4. :suffix-icon="attrs.suffixIcon" :readonly="attrs.readonly" :autosize="attrs.autosize"></el-input>
  5. <vxe-input
  6. v-else
  7. ref="input"
  8. v-model="value"
  9. :placeholder="placeholder"
  10. :maxlength="attrs.maxlength"
  11. :minlength="attrs.minlength"
  12. :clearable="attrs.clearable"
  13. :disabled="disabledValue"
  14. :size="attrs.size?attrs.size:'medium'"
  15. :type="attrs.type"
  16. :min="attrs.min"
  17. :max="attrs.max"
  18. :step="attrs.step"
  19. :align="attrs.align"
  20. :prefix-icon="attrs.prefixIcon"
  21. :suffix-icon="attrs.suffixIcon"
  22. :readonly="attrs.readonly"
  23. @input="onChange"
  24. @clear="onChange"
  25. ></vxe-input>
  26. </template>
  27. <script lang="ts">
  28. /*
  29. config:{
  30. attr:{
  31. type:'text, number(数字), integer(整数),textarea,float(小数),password(密码),positiveNumber(正数),positiveInteger(正整数)',
  32. align:'left, center, right'
  33. min:0 //最小值
  34. max:'' //最大值
  35. step:'' //间隔
  36. onceEdit: true/false //保存后不能修改
  37. prefixIcon:'' //头部图标
  38. suffixIcon:'' //尾部图标
  39. }
  40. }
  41. */
  42. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  43. import VueViews from '@/benyun/compVue/VueViews'
  44. @Component
  45. export default class ByInput extends VueViews {
  46. value:any=null;
  47. typeArr:Array<any>=['number','integer','float','positiveNumber','positiveInteger']
  48. @Watch('propValue')
  49. propValueChange(v:any){
  50. this.setValue(v);
  51. }
  52. created(){
  53. if(this.propConfig){
  54. this.setConfig(this.propConfig)
  55. }
  56. if(this.propValue){
  57. this.setValue(this.propValue)
  58. }
  59. if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
  60. this.setValue(this.attrs.defaultValue);
  61. this.onChange();
  62. }
  63. }
  64. get disabledValue(){
  65. let n = false;
  66. if(this.attrs.disabled){
  67. n = true
  68. }
  69. if(this.attrs.onceEdit && this.parentValue && this.parentValue.id){
  70. return n = true
  71. }
  72. return n;
  73. }
  74. get placeholder(){
  75. if(this.disabledValue){
  76. return ''
  77. }
  78. if(this.attrs.placeholder){
  79. return this.attrs.placeholder
  80. }
  81. return ''
  82. }
  83. mounted(){
  84. }
  85. setValue(data:any){
  86. if(data || data === 0){
  87. this.value = (this as any).$lodash.cloneDeep(data);
  88. if(this.attrs.type == 'number'){
  89. if(data !== '-') {
  90. this.value = Number(data);
  91. }
  92. }
  93. }else{
  94. this.value = null;
  95. }
  96. }
  97. getValue(){
  98. return (this as any).$lodash.cloneDeep(this.value);
  99. }
  100. // 清空数据
  101. clearValue(){
  102. this.value = '';
  103. if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
  104. this.setValue(this.attrs.defaultValue);
  105. this.onChange();
  106. }
  107. }
  108. onChange(){
  109. if(this.typeArr.indexOf(this.attrs.type) >= 0 && this.value){
  110. this.value = Number(this.value)
  111. }
  112. this.$emit('onChange',this.value);
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. </style>
  118. <style lang="scss">
  119. .el-input--small{
  120. font-size: 14px !important;
  121. }
  122. .vxe-input--inner[disabled]{
  123. background-color: #F5F7FA;
  124. border-color: #dfe4ed;
  125. color: #C0C4CC;
  126. cursor: not-allowed;
  127. }
  128. </style>