Procházet zdrojové kódy

refactor(admin): 文章编辑移除知识标签(tagIds)字段,标签改为可输入控件

- 移除「知识标签」多选下拉(tagIds 后端不持久化,属死字段;AI 自动打标会同步写入 tags 与 article_tags)
- 「标签」由逗号分隔文本框改为 el-select multiple+filterable+allow-create:回车添加、点标签删除
- 新增 tagList computed 在数组与逗号分隔字符串之间双向转换(兼容存量中文逗号/顿号/空格)
- 移除已无引用的 getTagList 导入与 loadTagOptions 方法
- tags 字段保持逗号分隔字符串契约,相关文章推荐(FIND_IN_SET)与关键词搜索不受影响
Xiaogang Liao před 6 dny
rodič
revize
3e28dc682d
1 změnil soubory, kde provedl 14 přidání a 24 odebrání
  1. 14 24
      cfc-web/src/views/admin/ArticleEdit.vue

+ 14 - 24
cfc-web/src/views/admin/ArticleEdit.vue

@@ -57,12 +57,6 @@
           <el-rate v-model="form.difficultyLevel" :max="5" :disabled="readonly" show-text :texts="['入门', '简单', '中等', '较难', '深入']" style="margin-top: 6px;" />
         </el-form-item>
 
-        <el-form-item label="知识标签">
-          <el-select v-model="form.tagIds" multiple placeholder="选择知识标签" class="form-select form-select--wide" :disabled="readonly" clearable>
-            <el-option v-for="tag in tagOptions" :key="tag.id" :label="tag.name" :value="tag.id" />
-          </el-select>
-        </el-form-item>
-
         <el-form-item label="摘要">
           <el-input v-model="form.summary" type="textarea" :rows="3" placeholder="请输入文章摘要" maxlength="500" show-word-limit :disabled="readonly" />
         </el-form-item>
@@ -112,7 +106,11 @@
         </el-form-item>
 
         <el-form-item label="标签">
-          <el-input v-model="form.tags" placeholder="逗号分隔,如: 育儿,亲子,心理" :disabled="readonly" />
+          <el-select v-model="tagList" multiple filterable allow-create default-first-option
+                     placeholder="输入标签后回车添加,如:育儿、亲子、心理"
+                     class="form-select form-select--wide" :disabled="readonly">
+          </el-select>
+          <span class="form-hint">回车添加标签,点标签可删除;用于关键词搜索与「相关文章」推荐</span>
         </el-form-item>
 
         <el-row :gutter="20" class="form-row">
@@ -161,7 +159,6 @@ import {
   adminArticleReDraft
 } from '@/api/article.js'
 import { saveDimensionWeights, getDimensionWeights } from '@/api/dimension-weight.js'
-import { getTagList } from '@/api/dimension.js'
 import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
 import { DomEditor, SlateTransforms, SlatePath } from '@wangeditor/editor'
 import '@wangeditor/editor/dist/css/style.css'
@@ -182,7 +179,6 @@ export default {
       articleStatus: '',
       rejectReason: '',
       categories: [],
-      tagOptions: [],
       editorConfig: null,
       toolbarConfig: {},
       editorMode: 'default',
@@ -198,7 +194,6 @@ export default {
         tags: '',
         contentType: 'article',
         difficultyLevel: 0,
-        tagIds: [],
         author: '',
         readTime: 3,
         sortOrder: 0,
@@ -210,6 +205,15 @@ export default {
     }
   },
   computed: {
+    tagList: {
+      get() {
+        if (!this.form.tags) return []
+        return this.form.tags.split(/[,,、\s]+/).map(t => t.trim()).filter(t => t.length > 0)
+      },
+      set(val) {
+        this.form.tags = (val || []).join(',')
+      }
+    },
     statusLabel() {
       const map = { draft: '当前状态:草稿箱', pending: '当前状态:待审核(等待管理员审核)', rejected: '当前状态:已驳回', published: '当前状态:发布中', withdrawn: '当前状态:已撤回' }
       return map[this.articleStatus] || ''
@@ -234,7 +238,6 @@ export default {
   created() {
     this.initEditorConfig()
     this.loadCategories()
-    this.loadTagOptions()
     const id = this.$route.query.id
     const copyId = this.$route.query.copyId
     this.readonly = this.$route.query.readonly === '1'
@@ -586,16 +589,6 @@ onError: (file, err, res) => {
         console.error('加载分类失败', e)
       }
     },
-    async loadTagOptions() {
-      try {
-        const res = await getTagList()
-        if (res.data) {
-          this.tagOptions = res.data
-        }
-      } catch (e) {
-        console.error('加载标签失败', e)
-      }
-    },
     async loadDetail(id) {
       this.loading = true
       try {
@@ -625,7 +618,6 @@ onError: (file, err, res) => {
             tags: d.tags || '',
             contentType: d.contentType || 'article',
             difficultyLevel: d.difficultyLevel || 0,
-            tagIds: d.tagIds || [],
             author: d.author || '',
             readTime: d.readTime || 3,
             sortOrder: d.sortOrder || 0,
@@ -665,7 +657,6 @@ onError: (file, err, res) => {
             tags: d.tags || '',
             contentType: d.contentType || 'article',
             difficultyLevel: d.difficultyLevel || 0,
-            tagIds: [],
             author: d.author || '',
             readTime: d.readTime || 3,
             sortOrder: 0,
@@ -725,7 +716,6 @@ onError: (file, err, res) => {
         tags: this.form.tags,
         contentType: this.form.contentType,
         difficultyLevel: this.form.difficultyLevel || 0,
-        tagIds: this.form.tagIds,
         author: this.form.author,
         readTime: this.form.readTime,
         sortOrder: this.form.sortOrder,