Selaa lähdekoodia

fix: show all activity categories in list

Developer 2 viikkoa sitten
vanhempi
commit
b8e8e7e978
3 muutettua tiedostoa jossa 34 lisäystä ja 6 poistoa
  1. BIN
      dist.zip
  2. 18 6
      src/views/modules/activity/list.vue
  3. 16 0
      tests/activity-list-category.test.js

BIN
dist.zip


+ 18 - 6
src/views/modules/activity/list.vue

@@ -35,7 +35,9 @@
               <el-table-column prop="id" label="活动ID" width="200"></el-table-column>
               <el-table-column prop="activityName" label="活动名称" width="350"></el-table-column>
               <el-table-column prop="typeName" label="活动类型" width="120"></el-table-column>
-              <el-table-column prop="categoryName" label="活动分类" width="120"></el-table-column>
+              <el-table-column prop="categoryName" label="活动分类" width="180">
+                <template #default="scope">{{ getCategoryNames(scope.row) }}</template>
+              </el-table-column>
               <el-table-column prop="" label="报名时间" width="320">
                 <template #default="scope">{{ scope.row.signupStartTime }} - {{ scope.row.signupEndTime }}</template>
               </el-table-column>
@@ -194,11 +196,21 @@ export default {
         this.typeOptions = res.data.data.list || []
       })
     },
-    getCategoryOptions () {
-      this.$http.get('/core/activity/category/page', { params: { page: 1, limit: -1 } }).then(res => {
-        this.categoryOptions = res.data.data.list || []
-      })
-    },
+    getCategoryOptions () {
+      this.$http.get('/core/activity/category/page', { params: { page: 1, limit: -1 } }).then(res => {
+        this.categoryOptions = res.data.data.list || []
+      })
+    },
+    getCategoryNames (activity) {
+      const rawIds = activity.categoryIds || activity.categoryId
+      if (!rawIds) return activity.categoryName || ''
+      const ids = String(rawIds).split(',').map(id => id.trim()).filter(Boolean)
+      const names = ids.map(id => {
+        const category = this.categoryOptions.find(item => String(item.id) === id)
+        return category ? category.categoryName : ''
+      }).filter(Boolean)
+      return names.length > 0 ? names.join('、') : (activity.categoryName || '')
+    },
     handleAdd () {
       this.$router.push({ name: 'activityAdd' })
     },

+ 16 - 0
tests/activity-list-category.test.js

@@ -0,0 +1,16 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import fs from 'node:fs'
+import path from 'node:path'
+
+const listFile = path.resolve('src/views/modules/activity/list.vue')
+
+test('活动列表展示全部多选活动分类并兼容旧数据', () => {
+  const source = fs.readFileSync(listFile, 'utf8')
+
+  assert.match(source, /getCategoryNames\(scope\.row\)/)
+  assert.match(source, /categoryIds/)
+  assert.match(source, /getCategoryNames\s*\(activity\)/)
+  assert.match(source, /categoryId/)
+  assert.match(source, /join\(['"]、['"]\)/)
+})