From cbe7981abd6e51cc44ad3ddd18442fff58d7b3d8 Mon Sep 17 00:00:00 2001 From: 670788339 <670788339@qq.com> Date: Fri, 31 Oct 2025 19:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Course/courseForm.vue | 6 ++--- src/components/Course/courseTag.vue | 38 +++++++++++++++++++++++----- src/views/portal/course/Index.vue | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/components/Course/courseForm.vue b/src/components/Course/courseForm.vue index b473899d..80369172 100644 --- a/src/components/Course/courseForm.vue +++ b/src/components/Course/courseForm.vue @@ -607,6 +607,8 @@ export default { // 限制最多5个标签 if (tags.length > 5) { this.$message.warning('最多只能选择5个标签') + // 强制限制为5个 + tags = tags.slice(0, 5); return } let ids = ""; @@ -615,9 +617,7 @@ export default { ids += tag.id + ','; }) this.courseInfo.tags = ids; - console.log("父组件ids : ",this.courseInfo.tags) - // 同时更新showTags,确保显示与实际数据一致 - this.showTags = tags.map(tag => tag.tagName); + this.$emit('change', tags.slice(0, 5)); // 确保传出数据也不超过5个 }, showChooseOrg(){ this.$refs.refChooseOrg.dlgShow = true; diff --git a/src/components/Course/courseTag.vue b/src/components/Course/courseTag.vue index 21b601aa..2a126745 100644 --- a/src/components/Course/courseTag.vue +++ b/src/components/Course/courseTag.vue @@ -23,6 +23,7 @@ :key="item.id" :label="item.tagName" :value="item" + :disabled="isTagDisabled(item)" /> @@ -66,7 +67,9 @@ export default { tagMap: new Map(), inputBuffer: '', params: {}, - tag: {} + tag: {}, + // 添加临时存储用于回滚 + previousTags: [] } }, computed: { @@ -121,9 +124,19 @@ export default { } }, methods: { + // 新增:检查标签是否应该被禁用 + isTagDisabled(tag) { + // 如果标签已经被选中,不应该禁用(允许取消选择) + const isSelected = this.selectedTags.some(selectedTag => selectedTag.id === tag.id); + if (isSelected) { + return false; + } + // 如果标签未被选中且已达到最大数量,则禁用 + return this.selectedTags.length >= this.maxTags; + }, // 新增:处理输入框获得焦点事件 async handleFocus() { - console.log("-- handleFocus --- " + this.sysTypeList.length) + this.previousTags = [...this.selectedTags]; // 当输入框获得焦点时,加载默认的搜索结果 if (this.sysTypeList.length > 0) { await this.doSearch(''); @@ -172,16 +185,27 @@ export default { }, // 新增:处理选择变化事件 - handleSelectionChange() { - this.$emit('change', this.displayTags) - // 选择标签后清空输入框 + handleSelectionChange(newValues) { + // 检查数量限制 + if (newValues.length > this.maxTags) { + this.$message.warning(`最多只能选择${this.maxTags}个标签`); + // 回滚到之前的状态 + this.selectedTags = [...this.previousTags]; + return; + } + + // 更新前保存当前状态 + this.previousTags = [...newValues]; + this.$emit('change', this.displayTags); + if (this.$refs.tagSelect) { - const input = this.$refs.tagSelect.$refs.input + const input = this.$refs.tagSelect.$refs.input; if (input) { - input.value = '' + input.value = ''; } } }, + //创建新标签 async createNewTag(tagName) { // 标签不能超过八个字 diff --git a/src/views/portal/course/Index.vue b/src/views/portal/course/Index.vue index 954c7d62..1b0f3083 100644 --- a/src/views/portal/course/Index.vue +++ b/src/views/portal/course/Index.vue @@ -2694,7 +2694,7 @@ a.custom2 { gap: 15px; align-items: center; padding-top: 2px; - margin-left: 90px; /* 为"热点标签:"文本留出空间 */ + //margin-left: 90px; /* 为"热点标签:"文本留出空间 */ } /* 调整option-item样式以适应换行布局 */