mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 11:56:44 +08:00
调整
This commit is contained in:
@@ -168,13 +168,8 @@ export default {
|
||||
},
|
||||
|
||||
//按回车键,创建新标签
|
||||
handleEnterKey(event) {
|
||||
console.log('开始回车创建 = ' + event.target.value)
|
||||
async handleEnterKey(event) {
|
||||
const inputVal = event.target.value?.trim()
|
||||
console.log('回车创建 inputVal= ' + inputVal)
|
||||
this.clearInput();
|
||||
console.log('回车创建中 先清文字 inputVal = ' + inputVal)
|
||||
|
||||
if (!inputVal) return;
|
||||
// 检查是否与已选择的标签重复
|
||||
const isDuplicate = this.selectedTags.some(tag => tag.tagName === inputVal);
|
||||
@@ -184,7 +179,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
if (!this.searchResults.length && inputVal && this.selectedTags.length < this.maxTags) {
|
||||
this.createNewTag(inputVal)
|
||||
await this.createNewTag(inputVal)
|
||||
this.clearInput();
|
||||
} else if (this.selectedTags.length >= this.maxTags) {
|
||||
this.$message.warning('最多只能添加5个标签')
|
||||
@@ -196,7 +191,6 @@ export default {
|
||||
|
||||
// 新增:处理选择变化事件
|
||||
handleSelectionChange(newValues) {
|
||||
console.log('handleSelectionChange = ' + newValues)
|
||||
// 检查数量限制
|
||||
if (newValues.length > this.maxTags) {
|
||||
this.$message.warning(`最多只能选择${this.maxTags}个标签`);
|
||||
@@ -208,21 +202,13 @@ export default {
|
||||
// 更新前保存当前状态
|
||||
this.previousTags = [...newValues];
|
||||
this.$emit('change', this.displayTags);
|
||||
console.log('-- handleSelectionChange clearInput --- this.$refs.tagSelect = ' + this.$refs.tagSelect )
|
||||
|
||||
this.clearInput();
|
||||
console.log('-- handleSelectionChange clearInput --- input.value = ' + this.$refs.tagSelect.$refs.input )
|
||||
},
|
||||
|
||||
clearInput() {
|
||||
/*if (this.$refs.tagSelect) {
|
||||
const input = this.$refs.tagSelect.$refs.input;
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
}*/
|
||||
// 方案1:通过 ref 直接操作 el-select 的输入框
|
||||
if (this.$refs.tagSelect) {
|
||||
const input = this.$refs.tagSelect.$el.querySelector('input');
|
||||
const input = this.$refs.tagSelect.$refs.input;
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
@@ -269,9 +255,17 @@ export default {
|
||||
}
|
||||
const {result:newTag} = await apiCourseTag.createTag(this.params)
|
||||
this.$message.success('标签创建成功',newTag);
|
||||
|
||||
console.log("----------创建前---------->",this.searchResults)
|
||||
console.log("----------创建前---------->",this.selectedTags)
|
||||
|
||||
this.searchResults.push(newTag)
|
||||
console.log("----------newTag---------->",this.searchResults)
|
||||
this.tagMap.set(newTag.id, newTag)
|
||||
|
||||
this.selectedTags.push(newTag);
|
||||
console.log("----------创建后---------->",this.searchResults)
|
||||
console.log("----------创建后---------->",this.selectedTags)
|
||||
|
||||
this.$emit('change', this.displayTags)
|
||||
} finally {
|
||||
this.loading = false
|
||||
|
||||
Reference in New Issue
Block a user