index.vue
4.05 KB
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
<template>
<el-form-item
class="fedexFormItem"
:label="itemLabel"
:prop="prop"
:required="required"
:error="error"
:id="'inputOuter-' + type + '-' + prop"
>
<slot name="title" slot="label"></slot>
<slot></slot>
<template v-slot:error="scoped">
<div class="formError">{{ scoped.error }}</div>
</template>
</el-form-item>
</template>
<script>
export default {
props: {
label: {
type: String,
default: "",
},
prop: {
type: String,
default: "",
},
type: {
type: String,
default: "",
},
activeType: {
type: Boolean,
default: false,
},
required: {
type: Boolean,
default: false,
},
error: {
type: String,
default: "",
},
},
data() {
return {
itemLabel: this.label,
inputFocusType: false,
};
},
watch: {
label(val) {
this.itemLabel = val;
},
},
mounted() {
this.getDateEditorNode();
let inputInner = document.querySelector(
"#inputInner-" + this.type + "-" + this.prop
); //获取input
let outInput = document.querySelector(
"#inputOuter-" + this.type + "-" + this.prop
); //获取formitem
if (inputInner) {
//通过input得id是否存在判断效果是否激活
inputInner.addEventListener("focus", (e) => {
this.inputFocusType = true;
inputInner.classList.add("inputFocus");
outInput.classList.add("activeBorder");
});
inputInner.addEventListener("blur", (e) => {
if (!e.target.value && !e.target.placeholder) {
// input失焦时如果无内容则移除active class
if (this.labelInput) {
this.itemLabel = this.label;
// labelInputInner_parentNode.style.display = 'inline-block'
} else {
!this.activeType ? inputInner.classList.remove("inputFocus") : "";
}
} else {
inputInner.classList.add("inputFocus");
}
this.inputFocusType = false;
outInput.classList.remove("activeBorder");
});
inputInner.addEventListener("change", (e) => {
if (!e.target.value && !e.target.placeholder) {
// input失焦时如果无内容则移除active class
if (this.labelInput) {
this.itemLabel = this.label;
// labelInputInner_parentNode.style.display = 'inline-block'
} else {
!this.activeType ? inputInner.classList.remove("inputFocus") : "";
}
} else {
inputInner.classList.add("inputFocus");
}
this.inputFocusType = false;
outInput.classList.remove("activeBorder");
});
if (inputInner.attributes.disabled) {
if (inputInner.value) {
inputInner.classList.add("inputFocus");
} else {
!this.activeType ? inputInner.classList.remove("inputFocus") : "";
}
}
this.$nextTick(() => {
if (inputInner.value) {
inputInner.classList.add("inputFocus");
}
});
}
},
updated() {
let inputInner = document.querySelector(
"#inputInner-" + this.type + "-" + this.prop
); //获取input
let outInput = document.querySelector(
"#inputOuter-" + this.type + "-" + this.prop
); //获取formitem
this.$nextTick(() => {
if (inputInner && inputInner.value) {
inputInner.classList.add("inputFocus");
} else {
!this.inputFocusType ? inputInner?.classList.remove("inputFocus") : "";
}
});
},
methods: {
getDateEditorNode() {
let dateInput = document.getElementsByClassName("el-date-editor");
dateInput.forEach((item) => {
item
.querySelector(".el-input__suffix")
.children[0].children[0].classList.add("el-icon-date");
});
let selectInput = document.getElementsByClassName("el-select");
selectInput.forEach((item) => {
// item.querySelector('.el-input__suffix').children[0].children[0].style.display = 'none'
});
},
},
};
</script>
<style lang="scss" scoped></style>