zhaoxiaoqiang
2022-08-05 6d01c9373f912f46fc10b25a5096152d2794ade5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!--
 * @Author: 小明丶
 * @Date: 2020-05-08 19:04:22
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-06-24 11:27:18
 * @Description: 登录也输入框组件
 -->
<template>
  <div class="h-ipt-box">
    <div class="ipt-div">
      <i class="left iconfont" :class="icon" v-if="icon"></i>
      <input
        :type="type"
        class="ipt"
        v-model="newValue"
        :maxlength="maxlength"
        :placeholder="placeholder"
        @focus="showClose"
        @blur="noClose"
      />
      <div class="right-slot">
        <slot name="right">
        </slot>
      </div>
      
      <i class="right iconfont iconreeor-fill" v-if="close && newValue && getClose" @click="deleteMsg"></i>
    </div>
  </div>
</template>
<script>
export default {
  name:'h-ipt',
  model: {
    prop: "value",
    event: "input"
  },
  props: {
    getClose:{
      type:Boolean,
      default:false
    },
    icon: {
      type: String
    },
    maxlength: {
      type: Number
    },
    placeholder: {
      type: String,
      default: "请输入"
    },
    value: {
      type: [String, Number]
    },
    type: {
      type: String,
      default: "text"
    },
    
  },
  data() {
    return {
        close:false,
    };
  },
  computed: {
    newValue: {
      get: function() {
        return this.value;
      },
      set: function(value) {
        this.$emit("input", value);
      }
    }
  },
  methods:{ 
      showClose(){
          this.close = true
      },
      noClose(){
          this.close = false
      },
      deleteMsg(){
        this.newValue = ''
      }
  }
};
</script>
<style lang="less" scoped>
.h-ipt-box {
  width: 100%;
  text-align: center;
  .ipt-div {
    display: inline-block;
    width: 80%;
    height: 40px;
    border-radius: 20px;
    border: 1px solid rgb(234, 234, 234);
    //line-height: 40px;
    position: relative;
    .left {
      font-size: 24px;
      color: @c-default;
      position: absolute;
      left: 10px;
      top: 6px;
    }
    .right{
        font-size: 18px;
        color: @c-default;
        position: absolute;
        right: 10px;
        top: 10px;
    }
    .ipt {
      position: absolute;
      right: 100px;
      top: 10px;
      width: 50%;
      border: 0; // 去除未选中状态边框
      outline: none; // 去除选中状态边框
      background-color: rgba(0, 0, 0, 0); // 透明背景
    }
    .right-slot{
      position: absolute;
      right: 10px;
      top: 6px;
    }
  }
 
  input::-webkit-input-placeholder {
    color: rgb(163, 163, 163);
  }
 
  input::-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: rgb(163, 163, 163);
  }
 
  input:-moz-placeholder {
    /* Mozilla Firefox 4 to 18 */
    color: rgb(163, 163, 163);
  }
 
  input:-ms-input-placeholder {
    /* Internet Explorer 10-11 */
    color: rgb(163, 163, 163);
  }
  input:-internal-autofill-previewed,
  input:-internal-autofill-selected {
    -webkit-text-fill-color: #333;
    transition: background-color 5000s ease-out 0.5s;
  }
}
</style>