Commit 891057941243780bac97d0441418fe2d27c31445

Authored by 刘汉宸
1 parent 60dc37a2

fix: 修复SchemaSelect清空及placeholder逻辑

Showing 1 changed file with 25 additions and 14 deletions   Show diff stats
packages/schema-select/index.vue
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 <el-popover class="z-schema-select" popper-class="z-schema-select__popper" v-model="visible" trigger="manual" placement="bottom-start" transition="el-zoom-in-top" @show="onTriggerShow"> 15 <el-popover class="z-schema-select" popper-class="z-schema-select__popper" v-model="visible" trigger="manual" placement="bottom-start" transition="el-zoom-in-top" @show="onTriggerShow">
16 <template #reference> 16 <template #reference>
17 <el-input 17 <el-input
  18 + ref="input"
18 v-model="model" 19 v-model="model"
19 :size="selectSize" 20 :size="selectSize"
20 :disabled="selectDisabled" 21 :disabled="selectDisabled"
@@ -27,7 +28,7 @@ @@ -27,7 +28,7 @@
27 @mouseleave.native="inputHovering = false" 28 @mouseleave.native="inputHovering = false"
28 > 29 >
29 <template #suffix> 30 <template #suffix>
30 - <i v-if="showClose" class="el-input__icon el-icon-circle-close" @click="onClear"></i> 31 + <i v-if="showClose" class="el-input__icon el-icon-circle-close" @click="onClear" @mouseenter="clearHovering = true" @mouseleave="clearHovering = false"></i>
31 <i v-else class="el-input__icon"></i> 32 <i v-else class="el-input__icon"></i>
32 </template> 33 </template>
33 </el-input> 34 </el-input>
@@ -156,6 +157,7 @@ export default { @@ -156,6 +157,7 @@ export default {
156 loading: false, 157 loading: false,
157 loaded: false, 158 loaded: false,
158 inFocus: false, 159 inFocus: false,
  160 + clearHovering: false,
159 }; 161 };
160 }, 162 },
161 created() { 163 created() {
@@ -289,40 +291,49 @@ export default { @@ -289,40 +291,49 @@ export default {
289 } 291 }
290 }, 292 },
291 onInputFocus() { 293 onInputFocus() {
292 - this.visible = true;  
293 - this.inFocus = true;  
294 - if (!this.allowCreate) {  
295 - this.model = ''; 294 + if (!this.clearHovering) {
  295 + this.visible = true;
  296 + this.inFocus = true;
  297 + this.query = this.model;
  298 + if (!this.allowCreate) {
  299 + this.model = '';
  300 + }
296 } 301 }
297 }, 302 },
298 onInputBlur() { 303 onInputBlur() {
299 this.inFocus = false; 304 this.inFocus = false;
300 - if (!this.visible) {  
301 - this.model = this.selectedLabel;  
302 - } 305 + this.$nextTick(() => {
  306 + if (!this.visible) {
  307 + this.query = '';
  308 + if (!this.allowCreate) {
  309 + this.model = this.selectedLabel;
  310 + }
  311 + }
  312 + });
303 }, 313 },
304 onClickoutside() { 314 onClickoutside() {
305 if (!this.inFocus) { 315 if (!this.inFocus) {
306 this.visible = false; 316 this.visible = false;
307 - }  
308 - if (this.visible) {  
309 this.model = this.selectedLabel; 317 this.model = this.selectedLabel;
310 - this.query = ''; 318 + this.query = this.selectedLabel;
311 } 319 }
312 }, 320 },
313 // 点击表格行 321 // 点击表格行
314 onTableRowClick(row) { 322 onTableRowClick(row) {
315 - this.query = '';  
316 this.model = this.selectedLabel; 323 this.model = this.selectedLabel;
  324 + this.$nextTick(() => {
  325 + this.query = this.selectedLabel;
  326 + });
317 this.visible = false; 327 this.visible = false;
318 this.$emit('input', row[this.valueKey]); 328 this.$emit('input', row[this.valueKey]);
319 this.$emit('change', row); 329 this.$emit('change', row);
320 }, 330 },
321 // 清空 331 // 清空
322 - onClear(event) {  
323 - event.stopPropagation(); 332 + onClear() {
324 this.query = ''; 333 this.query = '';
325 this.model = ''; 334 this.model = '';
  335 + this.clearHovering = false;
  336 + this.$refs.input.blur();
326 this.$emit('input', ''); 337 this.$emit('input', '');
327 this.$emit('clear'); 338 this.$emit('clear');
328 this.$emit('change', ''); 339 this.$emit('change', '');