byInput.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. created(){
  28. if(this.propConfig){
  29. this.setConfig(this.propConfig)
  30. }
  31. if(this.propValue){
  32. this.setValue(this.propValue)
  33. }
  34. if(this.attrs.defaultValue && !this.value){
  35. this.setValue(this.attrs.defaultValue);
  36. this.onChange();
  37. }
  38. }
  39. get placeholder(){
  40. if(this.attrs.disabled){
  41. return ''
  42. }
  43. if(this.attrs.placeholder){
  44. return this.attrs.placeholder
  45. }
  46. return '请输入内容'
  47. }
  48. mounted(){
  49. }
  50. setValue(data:any){
  51. if(data){
  52. this.value = (this as any).$lodash.cloneDeep(data);
  53. if(this.attrs.type == 'number'){
  54. this.value = Number(this.value);
  55. }
  56. }else{
  57. this.value = null;
  58. }
  59. }
  60. getValue(){
  61. return (this as any).$lodash.cloneDeep(this.value);
  62. }
  63. // 清空数据
  64. clearValue(){
  65. this.value = ''
  66. }
  67. onChange(){
  68. this.$emit('onChange',this.value);
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. </style>