修复管理端创建标签时字数限制为8个字

This commit is contained in:
王卓煜
2025-08-20 13:47:02 +08:00
parent 2c2f666c4a
commit 32cae2aee4

View File

@@ -13,6 +13,7 @@
:disabled="sysTypeList.length===0" :disabled="sysTypeList.length===0"
placeholder="按回车键Enter创建标签" placeholder="按回车键Enter创建标签"
@remove-tag="handleTagRemove" @remove-tag="handleTagRemove"
@change="handleSelectionChange"
@keyup.enter.native="handleEnterKey" @keyup.enter.native="handleEnterKey"
> >
<el-option <el-option
@@ -22,18 +23,6 @@
:value="item" :value="item"
/> />
</el-select> </el-select>
<!-- 预览 ---
<div class="tag-preview">
<el-tag
v-for="tag in displayTags"
:key="tag.id"
closable
@close="removeTag(tag.id)"
>
{{ tag.tagName }}
</el-tag>
</div>
-->
</div> </div>
</template> </template>
@@ -116,8 +105,17 @@ export default {
} }
}, },
// 新增:处理选择变化事件
handleSelectionChange() {
this.$emit('change', this.displayTags)
},
//创建新标签 //创建新标签
async createNewTag(tagName) { async createNewTag(tagName) {
// 标签不能超过八个字
if (tagName.length > 8) {
this.$message.error('标签不能超过8个字')
return;
}
this.loading = true this.loading = true
try { try {
this.params.courseId = this.courseId; this.params.courseId = this.courseId;
@@ -134,8 +132,10 @@ export default {
} }
const {result:newTag} = await apiCourseTag.createTag(this.params) const {result:newTag} = await apiCourseTag.createTag(this.params)
this.tagMap.set(newTag.id, newTag) this.tagMap.set(newTag.id, newTag)
this.selectedTags.push(newTag.tagName) // 修复:存储完整的标签对象,而不是名称
this.$emit('change', this.selectedTags.map(tag => tag.id)) this.selectedTags.push(newTag)
// 修复:正确传递标签对象数组
this.$emit('change', this.displayTags)
} finally { } finally {
this.loading = false this.loading = false
} }