mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-06 17:36:42 +08:00
标签输入框下拉调整
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
:remote-method="debouncedSearch"
|
||||
:loading="loading"
|
||||
:disabled="sysTypeList.length===0"
|
||||
:placeholder="sysTypeList.length === 0 ? '请先选择课程分类' : '请输入标签名称'"
|
||||
:placeholder="'请输入标签名称'"
|
||||
@remove-tag="handleTagRemove"
|
||||
@change="handleSelectionChange"
|
||||
@keyup.enter.native="handleEnterKey"
|
||||
@keyup.delete.native="handleDeleteKey"
|
||||
@focus="handleFocus"
|
||||
ref="tagSelect"
|
||||
>
|
||||
<el-option
|
||||
@@ -108,9 +109,26 @@ export default {
|
||||
newVal.forEach(tag => {
|
||||
if (tag.id) this.tagMap.set(tag.id, tag);
|
||||
});
|
||||
},
|
||||
// 监听分类变化,重新加载搜索结果
|
||||
sysTypeList: {
|
||||
handler() {
|
||||
// 只有在已选择分类且有焦点时才重新加载
|
||||
if (this.sysTypeList.length > 0 && this.$refs.tagSelect && this.$refs.tagSelect.visible) {
|
||||
this.doSearch('');
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 新增:处理输入框获得焦点事件
|
||||
async handleFocus() {
|
||||
// 当输入框获得焦点时,加载默认的搜索结果
|
||||
if (this.sysTypeList.length > 0) {
|
||||
await this.doSearch('');
|
||||
}
|
||||
},
|
||||
// 新增:重置标签状态的方法
|
||||
resetTagState() {
|
||||
this.selectedTags = [];
|
||||
@@ -202,10 +220,11 @@ export default {
|
||||
},
|
||||
// 修改doSearch方法,添加搜索结果为空时的提示
|
||||
async doSearch(query) {
|
||||
if (!query.trim()) {
|
||||
this.searchResults = []
|
||||
return
|
||||
}
|
||||
// 不再在空查询时清空搜索结果
|
||||
// if (!query.trim()) {
|
||||
// this.searchResults = []
|
||||
// return
|
||||
// }
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user