Blame view

ant-design-vue-jeecg/src/components/jeecg/JInput.vue 2.43 KB
肖超群 authored
1
2
3
4
5
<template>
  <a-input :placeholder="placeholder" :value="inputVal" @input="backValue"></a-input>
</template>

<script>
肖超群 authored
6
7
8
9
10
11
12
13
14
15
16
const JINPUT_QUERY_LIKE = 'like';
const JINPUT_QUERY_NE = 'ne';
const JINPUT_QUERY_GE = 'ge'; //大于等于
const JINPUT_QUERY_LE = 'le'; //小于等于

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

<style scoped>

</style>