mirror of
https://github.com/jumpserver/lina.git
synced 2025-08-18 14:57:26 +00:00
perf: 新增按键 t 使得 Search 组件自动 focus
This commit is contained in:
parent
f7ab833cb8
commit
080565bea6
@ -29,13 +29,14 @@
|
|||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:validate-event="false"
|
:validate-event="false"
|
||||||
class="search-input"
|
class="search-input"
|
||||||
suffix-icon="el-icon-search"
|
:suffix-icon="suffixIcon"
|
||||||
@blur="handleBlur"
|
@blur="handleBlur"
|
||||||
@change="handleConfirm"
|
@change="handleConfirm"
|
||||||
@focus="focus = true"
|
@focus="handleFocus"
|
||||||
@keyup.enter.native="handleConfirm"
|
@keyup.enter.native="handleConfirm"
|
||||||
@keyup.delete.native="handleDelete"
|
@keyup.delete.native="handleDelete"
|
||||||
/>
|
/>
|
||||||
|
<span class="keydown-focus" :class="isFocus ? 'is-focus ' : ''">t</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@ -67,10 +68,12 @@ export default {
|
|||||||
filterKey: '',
|
filterKey: '',
|
||||||
filterValue: '',
|
filterValue: '',
|
||||||
valueLabel: '',
|
valueLabel: '',
|
||||||
|
suffixIcon: '',
|
||||||
emptyCount: 0,
|
emptyCount: 0,
|
||||||
filterTags: this.default || {},
|
filterTags: this.default || {},
|
||||||
focus: false,
|
focus: false,
|
||||||
showCascade: true
|
showCascade: true,
|
||||||
|
isFocus: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -134,9 +137,22 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
document.addEventListener('keyup', this.handleKeyUp)
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
document.removeEventListener('keyup', this.handleKeyUp)
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleFocus() {
|
||||||
|
this.focus = true
|
||||||
|
this.isFocus = true
|
||||||
|
this.suffixIcon = 'el-icon-search'
|
||||||
|
},
|
||||||
handleBlur() {
|
handleBlur() {
|
||||||
this.focus = false
|
this.focus = false
|
||||||
|
this.isFocus = false
|
||||||
|
this.suffixIcon = ''
|
||||||
this.$emit('blur')
|
this.$emit('blur')
|
||||||
},
|
},
|
||||||
// 获取url中的查询条件,判断是不是包含在当前查询条件里
|
// 获取url中的查询条件,判断是不是包含在当前查询条件里
|
||||||
@ -329,6 +345,14 @@ export default {
|
|||||||
this.filterValue = v.value
|
this.filterValue = v.value
|
||||||
this.$refs.SearchInput.focus()
|
this.$refs.SearchInput.focus()
|
||||||
},
|
},
|
||||||
|
handleKeyUp(event) {
|
||||||
|
// 检查按下的键是否是"T"键
|
||||||
|
if (event.key === 'T' || event.key === 't') {
|
||||||
|
this.$refs.SearchInput.focus()
|
||||||
|
this.suffixIcon = 'el-icon-search'
|
||||||
|
this.isFocus = true
|
||||||
|
}
|
||||||
|
},
|
||||||
// 删除查询条件时改变url
|
// 删除查询条件时改变url
|
||||||
checkUrlFields(evt) {
|
checkUrlFields(evt) {
|
||||||
let newQuery = _.omit(this.$route.query, evt)
|
let newQuery = _.omit(this.$route.query, evt)
|
||||||
@ -347,11 +371,16 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
$borderColor-neutral-muted: #afb8c133;
|
||||||
|
$bgColor-muted: #f6f8fa;
|
||||||
|
$origin-white-color: #ffffff;
|
||||||
|
|
||||||
.filter-field {
|
.filter-field {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-width: 198px;
|
min-width: 210px;
|
||||||
background-color: #fff;
|
background-color: $origin-white-color;
|
||||||
|
|
||||||
.el-cascader {
|
.el-cascader {
|
||||||
height: 28px;
|
height: 28px;
|
||||||
@ -413,6 +442,25 @@ export default {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keydown-focus {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 3px 5px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
border: solid 1px $borderColor-neutral-muted;
|
||||||
|
border-radius: 6px;
|
||||||
|
line-height: 10px;
|
||||||
|
background-color: var(--bgColor-muted);
|
||||||
|
box-shadow: inset 0 -1px 0 $borderColor-neutral-muted;
|
||||||
|
|
||||||
|
&.is-focus {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-input2 >>> .el-input__inner {
|
.search-input2 >>> .el-input__inner {
|
||||||
|
Loading…
Reference in New Issue
Block a user