ce5ba5a4d2d2e940ca8f36a668f4d1e8427688f1.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <a-input :placeholder="placeholder" :value="inputVal" @input="backValue"></a-input>
  3. </template>
  4. <script>
  5. const JINPUT_QUERY_LIKE = 'like';
  6. const JINPUT_QUERY_NE = 'ne';
  7. const JINPUT_QUERY_GE = 'ge'; //大于等于
  8. const JINPUT_QUERY_LE = 'le'; //小于等于
  9. export default {
  10. name: 'JInput',
  11. props:{
  12. value:{
  13. type:String,
  14. required:false
  15. },
  16. type:{
  17. type:String,
  18. required:false,
  19. default:JINPUT_QUERY_LIKE
  20. },
  21. placeholder:{
  22. type:String,
  23. required:false,
  24. default:''
  25. },
  26. trim:{
  27. type: Boolean,
  28. required: false,
  29. default:false
  30. }
  31. },
  32. watch:{
  33. value:{
  34. immediate:true,
  35. handler:function(){
  36. this.initVal();
  37. }
  38. },
  39. // update-begin author:sunjianlei date:20200225 for:当 type 变化的时候重新计算值 ------
  40. type() {
  41. this.backValue({ target: { value: this.inputVal } })
  42. },
  43. // update-end author:sunjianlei date:20200225 for:当 type 变化的时候重新计算值 ------
  44. },
  45. model: {
  46. prop: 'value',
  47. event: 'change'
  48. },
  49. data(){
  50. return {
  51. inputVal:''
  52. }
  53. },
  54. methods:{
  55. initVal(){
  56. if(!this.value){
  57. this.inputVal = ''
  58. }else{
  59. let text = this.value
  60. switch (this.type) {
  61. case JINPUT_QUERY_LIKE:
  62. //修复路由传参的值传送到jinput框被前后各截取了一位 #1336
  63. if(text.indexOf("*") != -1){
  64. text = text.substring(1,text.length-1);
  65. }
  66. break;
  67. case JINPUT_QUERY_NE:
  68. text = text.substring(1);
  69. break;
  70. case JINPUT_QUERY_GE:
  71. text = text.substring(2);
  72. break;
  73. case JINPUT_QUERY_LE:
  74. text = text.substring(2);
  75. break;
  76. default:
  77. }
  78. this.inputVal = text
  79. }
  80. },
  81. backValue(e){
  82. let text = e.target.value
  83. if(text && this.trim===true){
  84. text = text.trim()
  85. }
  86. switch (this.type) {
  87. case JINPUT_QUERY_LIKE:
  88. text = "*"+text+"*";
  89. break;
  90. case JINPUT_QUERY_NE:
  91. text = "!"+text;
  92. break;
  93. case JINPUT_QUERY_GE:
  94. text = ">="+text;
  95. break;
  96. case JINPUT_QUERY_LE:
  97. text = "<="+text;
  98. break;
  99. default:
  100. }
  101. this.$emit("change",text)
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. </style>