byInput.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. @Watch('propValue')
  48. propValueChange(v:any){
  49. this.setValue(v);
  50. }
  51. created(){
  52. if(this.propConfig){
  53. this.setConfig(this.propConfig)
  54. }
  55. if(this.propValue){
  56. this.setValue(this.propValue)
  57. }
  58. if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
  59. this.setValue(this.attrs.defaultValue);
  60. this.onChange();
  61. }
  62. }
  63. get disabledValue(){
  64. let n = false;
  65. if(this.attrs.disabled){
  66. n = true
  67. }
  68. if(this.attrs.onceEdit && this.parentValue && this.parentValue.id){
  69. return n = true
  70. }
  71. return n;
  72. }
  73. get placeholder(){
  74. if(this.disabledValue){
  75. return ''
  76. }
  77. if(this.attrs.placeholder){
  78. return this.attrs.placeholder
  79. }
  80. return ''
  81. }
  82. mounted(){
  83. }
  84. setValue(data:any){
  85. if(data || data === 0){
  86. this.value = (this as any).$lodash.cloneDeep(data);
  87. if(this.attrs.type == 'number'){
  88. if(data !== '-') {
  89. this.value = Number(data);
  90. }
  91. }
  92. }else{
  93. this.value = null;
  94. }
  95. }
  96. getValue(){
  97. return (this as any).$lodash.cloneDeep(this.value);
  98. }
  99. // 清空数据
  100. clearValue(){
  101. this.value = '';
  102. if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
  103. this.setValue(this.attrs.defaultValue);
  104. this.onChange();
  105. }
  106. }
  107. onChange(){
  108. this.$emit('onChange',this.value);
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. </style>
  114. <style lang="scss">
  115. .el-input--small{
  116. font-size: 14px !important;
  117. }
  118. .vxe-input--inner[disabled]{
  119. background-color: #F5F7FA;
  120. border-color: #dfe4ed;
  121. color: #C0C4CC;
  122. cursor: not-allowed;
  123. }
  124. </style>