标签只属于长文:短文落库强制清空标签,编辑器切到短文隐藏并清空标签栏,存量短文标签关联已清理
This commit is contained in:
@@ -995,7 +995,12 @@ func (s *Store) Create(in model.PostInput) (model.Post, error) {
|
||||
}
|
||||
}
|
||||
p.ID = id
|
||||
if err := s.setTags(id, in.Tags); err != nil {
|
||||
// 标签是长文的组织方式;短文(类推微博)一律不打标签
|
||||
tags := in.Tags
|
||||
if p.Kind == model.KindShort {
|
||||
tags = nil
|
||||
}
|
||||
if err := s.setTags(id, tags); err != nil {
|
||||
return p, err
|
||||
}
|
||||
return s.Get(id)
|
||||
@@ -1054,8 +1059,13 @@ func (s *Store) Update(id int64, in model.PostInput) (model.Post, error) {
|
||||
p.PublishedAt, p.UpdatedAt, p.ReadingMinutes, encodeImages(p.Images), encodeLinkCard(p.LinkCard), id); err != nil {
|
||||
return p, err
|
||||
}
|
||||
if in.Tags != nil {
|
||||
if err := s.setTags(id, in.Tags); err != nil {
|
||||
// 短文一律无标签:切换类型或直接保存时都把旧标签清掉
|
||||
if in.Tags != nil || p.Kind == model.KindShort {
|
||||
tags := in.Tags
|
||||
if p.Kind == model.KindShort {
|
||||
tags = nil
|
||||
}
|
||||
if err := s.setTags(id, tags); err != nil {
|
||||
return p, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,6 +365,14 @@ onBeforeRouteLeave(() => {
|
||||
|
||||
// ---------- 标签 ----------
|
||||
|
||||
// 标签是长文的组织方式;切到短文时把已选的清掉(后端落库时也会强制丢弃)
|
||||
watch(
|
||||
() => form.kind,
|
||||
(k) => {
|
||||
if (k === 'short') form.tags = []
|
||||
}
|
||||
)
|
||||
|
||||
function addTag() {
|
||||
const v = tagInput.value.trim().replace(/[,,]$/, '')
|
||||
if (!v) return
|
||||
@@ -848,7 +856,7 @@ const tbGroups = computed(() => [
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<div v-if="form.kind !== 'short'" class="field">
|
||||
<label>标签</label>
|
||||
<div v-if="form.tags.length" style="display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;">
|
||||
<span v-for="t in form.tags" :key="t" class="chip">
|
||||
|
||||
Reference in New Issue
Block a user