Просмотр исходного кода

feat: 运动类型统一标准+后台可配置(全局一套,sys_config.exercise_types)

- 后端:DatabaseInitializer 幂等种子 exercise_types(8项标准并集,ball_game 统一为 ball)
- 小程序:抽公共模块 utils/exerciseTypes.js(读 public config → 解析 → 缓存 → 回退 + 历史 value 映射),
  成长运动打卡/健康运动记录两页改造共用;老记录 ball_game 自动映射为球类不丢显示
- 后台:cfc-web 新增 ExerciseTypeConfig 页(增删改排序+校验),路由/菜单注册于系统配置→基础管理
- TDD:小程序 13 例 + cfc-web 7 例 + 后端种子契约 2 例全绿;三端构建/模板编译通过
Xiaogang Liao 1 час назад
Родитель
Сommit
f0e24df22f

+ 8 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -1181,6 +1181,14 @@ insertSysConfigSeed("gift_membership_original_threshold", "1000000", "送会员
 insertSysConfigSeed("gift_membership_pay_price", "198000", "送会员商品达标后一口实付价(分)");
             insertSysConfigSeed("health_dimension_weights", "{\"growth\":0.20,\"sleep\":0.15,\"vision\":0.10,\"immunity\":0.15,\"nutrition\":0.15,\"gut\":0.10,\"exercise\":0.15}", "7维健康→身能量权重配置");
             insertSysConfigSeed("health_dimension_sync_factor", "0.5", "7维健康同步至身能量系数");
+            // 运动类型统一+后台可配置:全局标准并集种子(小程序两页从 public config 读取,
+            // 后台 ExerciseTypeConfig 页可增删改;历史 value ball_game 已统一为 ball)
+            insertSysConfigSeed("exercise_types",
+                    "[{\"label\":\"跑步\",\"value\":\"running\"},{\"label\":\"游泳\",\"value\":\"swimming\"},"
+                            + "{\"label\":\"骑行\",\"value\":\"cycling\"},{\"label\":\"跳绳\",\"value\":\"jump_rope\"},"
+                            + "{\"label\":\"球类\",\"value\":\"ball\"},{\"label\":\"力量训练\",\"value\":\"strength\"},"
+                            + "{\"label\":\"体操\",\"value\":\"gymnastics\"},{\"label\":\"其他\",\"value\":\"other\"}]",
+                    "运动类型配置(全局统一一套,小程序成长运动打卡/健康运动记录共用;后台可增删改排序)");
             log.info("SysConfig 种子数据已加载");
         } catch (Exception e) {
             log.warn("SysConfig 种子数据初始化失败: {}", e.getMessage());

+ 54 - 0
cfc-backend/src/test/java/com/etotem/cfc/unit/ExerciseTypeConfigSeedTest.java

@@ -0,0 +1,54 @@
+package com.etotem.cfc.unit;
+
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * 契约级单测(纯源码文本断言,无 Spring 上下文 / 无 DB):
+ * 运动类型统一 + 后台可配置 —— 后端种子必须幂等插入 sys_config.exercise_types,
+ * 且默认 JSON 为全局标准并集(8 项,ball_game 统一为 ball)。
+ *
+ * <p>RED:DatabaseInitializer 尚无 exercise_types 种子 → 断言失败。
+ * GREEN:在该文件种子区加 insertSysConfigSeed("exercise_types", ...) 后转绿。</p>
+ */
+class ExerciseTypeConfigSeedTest {
+
+    private static final String INIT_PATH =
+            "src/main/java/com/etotem/cfc/config/DatabaseInitializer.java";
+
+    private String source() throws Exception {
+        Path p = Paths.get(INIT_PATH);
+        if (!Files.exists(p)) {
+            // 兼容从 cfc-backend 子目录或仓库根运行
+            p = Paths.get("../cfc-backend/" + INIT_PATH);
+        }
+        return new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
+    }
+
+    @Test
+    void seed_exists_and_is_idempotent() throws Exception {
+        String src = source();
+        assertTrue(src.contains("insertSysConfigSeed(\"exercise_types\""),
+                "[exercise.types.config] DatabaseInitializer 必须幂等插入 sys_config.exercise_types 种子");
+    }
+
+    @Test
+    void seed_default_has_standard_union_values() throws Exception {
+        String src = source();
+        int idx = src.indexOf("insertSysConfigSeed(\"exercise_types\"");
+        assertTrue(idx >= 0, "种子必须存在才能校验默认值");
+        String tail = src.substring(idx, Math.min(src.length(), idx + 1200));
+        for (String value : new String[]{"running", "swimming", "cycling", "jump_rope", "ball", "strength", "gymnastics", "other"}) {
+            assertTrue(tail.contains("\\\"" + value + "\\\""),
+                    "[exercise.types.config] 默认 JSON 应包含标准值 " + value + "(全局并集)");
+        }
+        assertTrue(!tail.contains("ball_game") || tail.contains("ball"),
+                "[exercise.types.config] ball_game 不应作为独立标准值(统一为 ball)");
+    }
+}

+ 127 - 0
cfc-frontend/__tests__/utils/exerciseTypes.test.js

@@ -0,0 +1,127 @@
+/**
+ * 运动类型统一 + 后台可配置:utils/exerciseTypes.js 契约测试
+ *
+ * 背景:growth/exercise-checkin.vue 与 health/exercise-index.vue 各自写死一套
+ * exerciseTypes,value 分歧(ball vs ball_game),且后台无法配置。
+ * 本测试规定公共模块行为:
+ *   1) 标准并集默认值(全局一套)
+ *   2) 解析后台 sys_config 的 JSON 字符串响应
+ *   3) 历史 value 映射(ball_game → ball),保证老记录 label 不丢
+ *   4) 拉取失败/空值时回退默认(离线可用)
+ *   5) 加载后写入缓存复用
+ */
+describe('exerciseTypes 公共模块', () => {
+  let mod
+
+  beforeAll(() => {
+    mod = require('@/utils/exerciseTypes')
+  })
+
+  test('默认值为标准并集(8 项,含 ball/strength/gymnastics,不含 ball_game)', () => {
+    const defs = mod.DEFAULT_EXERCISE_TYPES
+    const values = defs.map((x) => x.value)
+    expect(values).toEqual([
+      'running', 'swimming', 'cycling', 'jump_rope',
+      'ball', 'strength', 'gymnastics', 'other'
+    ])
+    expect(values).not.toContain('ball_game')
+    defs.forEach((x) => expect(x.label).toBeTruthy())
+  })
+
+  test('normalizeExerciseTypes 解析 JSON 数组字符串(后台 sys_config 的 data 字段)', () => {
+    const raw = JSON.stringify([
+      { label: '跑步', value: 'running' },
+      { label: '瑜伽', value: 'yoga' }
+    ])
+    expect(mod.normalizeExerciseTypes(raw).map((x) => x.value)).toEqual(['running', 'yoga'])
+  })
+
+  test('normalizeExerciseTypes 接受已解析的数组', () => {
+    expect(mod.normalizeExerciseTypes([{ label: '骑行', value: 'cycling' }])[0].label).toBe('骑行')
+  })
+
+  test('normalizeExerciseTypes 空值 / 非法 JSON / 空数组 → 回退默认', () => {
+    expect(mod.normalizeExerciseTypes(null).length).toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+    expect(mod.normalizeExerciseTypes('').length).toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+    expect(mod.normalizeExerciseTypes('{bad json').length).toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+    expect(mod.normalizeExerciseTypes('[]').length).toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+    expect(mod.normalizeExerciseTypes([{ label: 'x' }]).length).toBe(mod.DEFAULT_EXERCISE_TYPES.length) // 缺 value
+  })
+
+  test('normalizeExerciseTypes 过滤 item.value 为空的脏数据', () => {
+    const raw = JSON.stringify([
+      { label: '跑步', value: 'running' },
+      { label: '', value: '  ' }
+    ])
+    expect(mod.normalizeExerciseTypes(raw).map((x) => x.value)).toEqual(['running'])
+  })
+
+  test('历史 value 映射:ball_game 归一为 ball', () => {
+    expect(mod.normalizeExerciseValue('ball_game')).toBe('ball')
+    expect(mod.normalizeExerciseValue('ball')).toBe('ball')
+    expect(mod.normalizeExerciseValue('running')).toBe('running')
+  })
+
+  test('resolveExerciseTypeLabel 用历史 value 也能取到 label', () => {
+    const types = mod.DEFAULT_EXERCISE_TYPES
+    expect(mod.resolveExerciseTypeLabel('ball_game', types)).toBe('球类')
+    expect(mod.resolveExerciseTypeLabel('ball', types)).toBe('球类')
+    expect(mod.resolveExerciseTypeLabel('strength', types)).toBe('力量训练')
+    expect(mod.resolveExerciseTypeLabel('unknown_x', types)).toBe('其他')
+  })
+
+  test('extractFromPublicConfigResp:解包 {code:200,data:"<json>"}', () => {
+    const resp = { code: 200, data: JSON.stringify([{ label: '瑜伽', value: 'yoga' }]) }
+    expect(mod.extractFromPublicConfigResp(resp).map((x) => x.value)).toEqual(['yoga'])
+  })
+
+  test('extractFromPublicConfigResp:code != 200 / 无 data → 默认', () => {
+    expect(mod.extractFromPublicConfigResp({ code: 500, data: '[]' }).length)
+      .toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+    expect(mod.extractFromPublicConfigResp(null).length)
+      .toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+  })
+
+  test('loadExerciseTypes:fetcher 成功 → 返回解析结果并写缓存', async () => {
+    const fetcher = jest.fn().mockResolvedValue({
+      code: 200,
+      data: JSON.stringify([{ label: '瑜伽', value: 'yoga' }])
+    })
+    const store = {}
+    const result = await mod.loadExerciseTypes(fetcher, store)
+    expect(result.map((x) => x.value)).toEqual(['yoga'])
+    expect(fetcher).toHaveBeenCalledWith('exercise_types')
+    expect(store[mod.CACHE_KEY]).toBeTruthy()
+  })
+
+  test('loadExerciseTypes:fetcher 失败 → 回退缓存/默认,不抛错', async () => {
+    const fetcher = jest.fn().mockRejectedValue(new Error('network'))
+    const result = await mod.loadExerciseTypes(fetcher, {})
+    expect(result.length).toBe(mod.DEFAULT_EXERCISE_TYPES.length)
+  })
+
+  test('loadExerciseTypes:已有缓存且 fetcher 失败 → 用缓存', async () => {
+    const cached = JSON.stringify([{ label: '旧配置', value: 'legacy_cached' }])
+    const fetcher = jest.fn().mockRejectedValue(new Error('network'))
+    const result = await mod.loadExerciseTypes(fetcher, { [mod.CACHE_KEY]: cached })
+    expect(result.map((x) => x.value)).toEqual(['legacy_cached'])
+  })
+
+  test('loadExerciseTypes:store 支持 getItem/setItem 适配器(uni storage)', async () => {
+    const mem = {}
+    const store = {
+      getItem: (k) => mem[k],
+      setItem: (k, v) => { mem[k] = v }
+    }
+    const fetcher = jest.fn().mockResolvedValue({
+      code: 200, data: JSON.stringify([{ label: '瑜伽', value: 'yoga' }])
+    })
+    const result = await mod.loadExerciseTypes(fetcher, store)
+    expect(result[0].value).toBe('yoga')
+    expect(mem[mod.CACHE_KEY]).toBeTruthy()
+    // 第二次 fetcher 失败 → 从 getItem 缓存读回
+    const failFetcher = jest.fn().mockRejectedValue(new Error('offline'))
+    const result2 = await mod.loadExerciseTypes(failFetcher, store)
+    expect(result2[0].value).toBe('yoga')
+  })
+})

+ 15 - 11
cfc-frontend/pages/growth/exercise-checkin.vue

@@ -154,6 +154,8 @@ import { resolveCheckinMemberId } from '../../utils/memberNormalize.js'
 import { parseDate } from '../../utils/format.js'
 import { sttTranscribe } from '../../utils/api.js'
 import { pickImage } from '../../utils/image-picker.js'
+import { getPublicConfig } from '../../utils/api.js'
+import { DEFAULT_EXERCISE_TYPES, loadExerciseTypes, resolveExerciseTypeLabel } from '../../utils/exerciseTypes.js'
 import TagChip from '../../components/TagChip.vue'
 import fontScaleMixin from '@/mixins/font-scale.js'
 
@@ -175,15 +177,8 @@ export default {
       recorderManager: null,
       history: [],
       todayText: '',
-      exerciseTypes: [
-        { label: '跑步', value: 'running' },
-        { label: '游泳', value: 'swimming' },
-        { label: '跳绳', value: 'jump_rope' },
-        { label: '球类', value: 'ball' },
-        { label: '骑行', value: 'cycling' },
-        { label: '体操', value: 'gymnastics' },
-        { label: '其他', value: 'other' }
-      ],
+      // 运动类型:首屏用统一默认(离线可用),onLoad 拉取后台配置覆盖
+      exerciseTypes: DEFAULT_EXERCISE_TYPES.slice(),
       intensityOptions: [
         { label: '低', value: 'low' },
         { label: '中', value: 'medium' },
@@ -249,6 +244,7 @@ export default {
       uni.showToast({ title: '录音失败', icon: 'none' })
     })
     this.loadHistory()
+    this.loadExerciseTypes()
   },
   onUnload: function() {
     if (this.recordTimer) clearInterval(this.recordTimer)
@@ -260,9 +256,17 @@ export default {
       return d.getFullYear() + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日 周' + weekdays[d.getDay()]
     },
     goBack: function() { uni.navigateBack() },
+    // 拉取后台配置(sys_config.exercise_types),失败回退默认;缓存到 uni storage 供离线复用
+    loadExerciseTypes: function() {
+      var self = this
+      loadExerciseTypes(function(key) { return getPublicConfig(key) }, {
+        getItem: function(k) { return uni.getStorageSync(k) },
+        setItem: function(k, v) { uni.setStorageSync(k, v) }
+      }).then(function(types) { self.exerciseTypes = types })
+    },
     exerciseTypeLabel: function(type) {
-      var m = { running: '跑步', swimming: '游泳', jump_rope: '跳绳', ball: '球类', cycling: '骑行', gymnastics: '体操', other: '其他' }
-      return m[type] || type || '运动'
+      // 历史 value(ball_game 等)经公共函数归一/映射,老记录 label 不丢
+      return resolveExerciseTypeLabel(type, this.exerciseTypes)
     },
     formatDate: function(dateStr) {
       if (!dateStr) return ''

+ 18 - 10
cfc-frontend/pages/health/exercise-index.vue

@@ -110,7 +110,7 @@
           <view class="history-list" v-if="history.length > 0">
             <view class="history-item" v-for="item in history" :key="item.id">
               <view class="history-left">
-                <text class="history-type">{{ item.exerciseType }}</text>
+                <text class="history-type">{{ exerciseTypeLabel(item.exerciseType) }}</text>
                 <text class="history-duration">{{ item.durationMinutes }}分钟</text>
               </view>
               <view class="history-right">
@@ -129,6 +129,8 @@
 <script>
 import config from '@/config.js'
 import { parseDate } from '@/utils/format.js'
+import { getPublicConfig } from '@/utils/api.js'
+import { DEFAULT_EXERCISE_TYPES, loadExerciseTypes, resolveExerciseTypeLabel } from '@/utils/exerciseTypes.js'
 import TagChip from '@/components/TagChip.vue'
 import fontScaleMixin from '@/mixins/font-scale.js'
 
@@ -140,15 +142,8 @@ export default {
       memberId: null,
       submitting: false,
       history: [],
-      exerciseTypes: [
-        { label: '跑步', value: 'running' },
-        { label: '游泳', value: 'swimming' },
-        { label: '骑行', value: 'cycling' },
-        { label: '跳绳', value: 'jump_rope' },
-        { label: '球类', value: 'ball_game' },
-        { label: '力量训练', value: 'strength' },
-        { label: '其他', value: 'other' }
-      ],
+      // 运动类型:首屏用统一默认(离线可用),onLoad 拉取后台配置覆盖
+      exerciseTypes: DEFAULT_EXERCISE_TYPES.slice(),
       intensityOptions: [
         { label: '低强度', value: 'low' },
         { label: '中等', value: 'medium' },
@@ -170,8 +165,21 @@ export default {
       this.memberId = uni.getStorageSync('currentChildId') || null
     }
     this.loadHistory()
+    this.loadExerciseTypes()
   },
   methods: {
+    // 拉取后台配置(sys_config.exercise_types),失败回退默认;缓存到 uni storage 供离线复用
+    loadExerciseTypes: function() {
+      var self = this
+      loadExerciseTypes(function(key) { return getPublicConfig(key) }, {
+        getItem: function(k) { return uni.getStorageSync(k) },
+        setItem: function(k, v) { uni.setStorageSync(k, v) }
+      }).then(function(types) { self.exerciseTypes = types })
+    },
+    // 历史 value(ball_game 等)经公共函数归一/映射,老记录 label 不丢
+    exerciseTypeLabel: function(type) {
+      return resolveExerciseTypeLabel(type, this.exerciseTypes)
+    },
     goBack: function() {
       uni.navigateBack()
     },

+ 129 - 0
cfc-frontend/utils/exerciseTypes.js

@@ -0,0 +1,129 @@
+/**
+ * 运动类型公共模块(全局统一一套 · 后台可配置)
+ *
+ * 背景:growth/exercise-checkin.vue 与 health/exercise-index.vue 各自写死一套
+ * exerciseTypes,value 分歧(ball vs ball_game)、成员不齐(一个缺 strength、
+ * 一个缺 gymnastics),后台无法配置。本模块统一为一套标准并集,并提供:
+ *   - DEFAULT_EXERCISE_TYPES:标准默认值(并集),离线/首屏/失败回退使用
+ *   - normalizeExerciseTypes(raw):把后台 sys_config 的 JSON 字符串/数组归一为有效列表
+ *   - normalizeExerciseValue(v):历史 value 映射(ball_game → ball),保证老记录 label 不丢
+ *   - resolveExerciseTypeLabel(v, types):value → label(兼容历史 value)
+ *   - extractFromPublicConfigResp(resp):解包 /api/config/public/value 的响应
+ *   - loadExerciseTypes(fetcher, store):拉取 + 缓存 + 回退(离线可用)
+ *
+ * 配置源:sys_config.config_key = 'exercise_types',值为 [{label,value}] JSON 数组。
+ * 读取走公开接口 getPublicConfig('exercise_types');写由后台 ExerciseTypeConfig 页负责。
+ */
+
+// 全局统一一套:并集 + 去重后的标准 value(ball_game 废弃 → ball)
+export const DEFAULT_EXERCISE_TYPES = [
+  { label: '跑步', value: 'running' },
+  { label: '游泳', value: 'swimming' },
+  { label: '骑行', value: 'cycling' },
+  { label: '跳绳', value: 'jump_rope' },
+  { label: '球类', value: 'ball' },
+  { label: '力量训练', value: 'strength' },
+  { label: '体操', value: 'gymnastics' },
+  { label: '其他', value: 'other' }
+]
+
+// 历史 value 兼容映射:旧 health 页用 ball_game,统一后归一为 ball
+const LEGACY_VALUE_MAP = {
+  ball_game: 'ball'
+}
+
+export const CACHE_KEY = 'exercise_types'
+
+const FALLBACK_LABEL = '其他'
+
+export function normalizeExerciseValue(value) {
+  if (value == null) return value
+  const v = String(value).trim()
+  return Object.prototype.hasOwnProperty.call(LEGACY_VALUE_MAP, v) ? LEGACY_VALUE_MAP[v] : v
+}
+
+export function normalizeExerciseTypes(raw) {
+  let arr = raw
+  if (typeof raw === 'string') {
+    try {
+      arr = JSON.parse(raw)
+    } catch (e) {
+      return DEFAULT_EXERCISE_TYPES.slice()
+    }
+  }
+  if (!Array.isArray(arr)) return DEFAULT_EXERCISE_TYPES.slice()
+
+  const seen = {}
+  const result = []
+  arr.forEach((item) => {
+    if (!item || typeof item !== 'object') return
+    const value = item.value == null ? '' : String(item.value).trim()
+    const label = item.label == null ? '' : String(item.label).trim()
+    if (!value || !label) return
+    const normalized = normalizeExerciseValue(value)
+    if (seen[normalized]) return
+    seen[normalized] = true
+    result.push({ label, value: normalized })
+  })
+  return result.length ? result : DEFAULT_EXERCISE_TYPES.slice()
+}
+
+export function resolveExerciseTypeLabel(value, types) {
+  const list = Array.isArray(types) && types.length ? types : DEFAULT_EXERCISE_TYPES
+  const normalized = normalizeExerciseValue(value)
+  const found = list.find((x) => x.value === normalized)
+  if (found) return found.label
+  // 老数据里若后台配置把 label 也配成历史词,再按原 value 找一次
+  const rawFound = list.find((x) => x.value === value)
+  return rawFound ? rawFound.label : FALLBACK_LABEL
+}
+
+export function extractFromPublicConfigResp(resp) {
+  if (!resp || resp.code !== 200 || resp.data == null || resp.data === '') {
+    return DEFAULT_EXERCISE_TYPES.slice()
+  }
+  return normalizeExerciseTypes(resp.data)
+}
+
+/**
+ * 拉取 + 缓存 + 回退。
+ * @param fetcher async (key) => resp(形如 {code:200,data:"<json>"});不传则用 getPublicConfig
+ * @param store  简单 KV(小程序里可传 uni 缓存适配器);失败时读缓存,再失败回退默认
+ */
+export async function loadExerciseTypes(fetcher, store) {
+  const readCache = () => {
+    if (!store) return null
+    if (typeof store.getItem === 'function') return store.getItem(CACHE_KEY)
+    return store[CACHE_KEY]
+  }
+  const writeCache = (val) => {
+    if (!store) return
+    if (typeof store.setItem === 'function') store.setItem(CACHE_KEY, val)
+    else store[CACHE_KEY] = val
+  }
+
+  let data = null
+  if (fetcher) {
+    try {
+      const resp = await fetcher(CACHE_KEY)
+      const parsed = extractFromPublicConfigResp(resp)
+      // parsed 为默认(说明响应无效或空)——不当作后台配置缓存,避免污染
+      if (JSON.stringify(parsed) !== JSON.stringify(DEFAULT_EXERCISE_TYPES)) {
+        data = parsed
+      }
+    } catch (e) {
+      data = null
+    }
+  }
+  if (!data) {
+    const cached = readCache()
+    if (cached) {
+      data = normalizeExerciseTypes(cached)
+      // 缓存里是默认值时不算有效配置
+      if (JSON.stringify(data) === JSON.stringify(DEFAULT_EXERCISE_TYPES)) data = null
+    }
+  }
+  if (!data) data = DEFAULT_EXERCISE_TYPES.slice()
+  writeCache(JSON.stringify(data))
+  return data
+}

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-d773da94f605a249f054af5d4bca76ee83c80252
+12f4bd507e9f128c2e337fe5956bbeff0eec4c50

+ 1 - 1
cfc-web/package.json

@@ -1,6 +1,6 @@
 {
   "name": "cfc-web",
-  "version": "1.0.2661",
+  "version": "1.0.2662",
   "private": true,
   "scripts": {
     "dev": "vue-cli-service serve",

+ 17 - 0
cfc-web/public/CHANGELOG-v1.0.md

@@ -4,6 +4,23 @@
 
 ---
 
+## v1.0.2662 (2026-11-19)
+
+### 测试
+- 定时闭环测试汇报 — 三节点派发189admin5/5+204fe6/6+251lg46/6/1(6红全429环境型扩面,B-142-2 0/2) + 窗口2处src变更零回归(completeTask时间窗守卫契约4/4全绿+任务页UI遮挡修复) — 后端定向115逐类零漂移 + 双端Jest840零漂移(G13第104次) + 本机live22/9/2 + web覆盖率11.54%零下降 — 门禁不通过(有条件·承袭)零新增产品代码缺陷 — 分支cfclub/起始234c04b29/结束e36e28089
+
+### 新功能
+- completeTask 时间窗守卫 — earliest_start/latest_end 窗口外拒绝提交
+
+### 其他
+- 提示用户。未到 earliest_start → 「未到开始时间,HH:mm 后可提交」;
+- 已过 latest_end → 「已过截止时间 HH:mm,无法提交」。窗口为闭区间,
+- 边界时刻(等于 earliest/latest)可提交;deadline 逾期零奖励机制独立
+- 不受影响。TDD:TaskTimeWindowGuardContractTest RED 3 失败 → GREEN 4/4,
+- Task* 回归 175 条仅存 flaky/存量 1 失败(基线对比确认)。
+- 
+
+
 ## v1.0.2661 (2026-11-19)
 
 ### Bug 修复

+ 18 - 1
cfc-web/public/CHANGELOG.md

@@ -1,6 +1,6 @@
 # 更新日志
 
-> 当前版本: v1.0.2661
+> 当前版本: v1.0.2662
 
 ## 历史版本
 
@@ -8,6 +8,23 @@
 
 ---
 
+## v1.0.2662 (2026-11-19)
+
+### 测试
+- 定时闭环测试汇报 — 三节点派发189admin5/5+204fe6/6+251lg46/6/1(6红全429环境型扩面,B-142-2 0/2) + 窗口2处src变更零回归(completeTask时间窗守卫契约4/4全绿+任务页UI遮挡修复) — 后端定向115逐类零漂移 + 双端Jest840零漂移(G13第104次) + 本机live22/9/2 + web覆盖率11.54%零下降 — 门禁不通过(有条件·承袭)零新增产品代码缺陷 — 分支cfclub/起始234c04b29/结束e36e28089
+
+### 新功能
+- completeTask 时间窗守卫 — earliest_start/latest_end 窗口外拒绝提交
+
+### 其他
+- 提示用户。未到 earliest_start → 「未到开始时间,HH:mm 后可提交」;
+- 已过 latest_end → 「已过截止时间 HH:mm,无法提交」。窗口为闭区间,
+- 边界时刻(等于 earliest/latest)可提交;deadline 逾期零奖励机制独立
+- 不受影响。TDD:TaskTimeWindowGuardContractTest RED 3 失败 → GREEN 4/4,
+- Task* 回归 175 条仅存 flaky/存量 1 失败(基线对比确认)。
+- 
+
+
 ## v1.0.2661 (2026-11-19)
 
 ### Bug 修复

+ 47 - 0
cfc-web/src/__tests__/views/ExerciseTypeConfig.contract.spec.js

@@ -0,0 +1,47 @@
+import { readFileSync } from 'fs'
+import { resolve } from 'path'
+
+// 契约:admin.exercise.types.config(运动类型统一+后台可配置)
+// 页面通过 sys_config.exercise_types 读写 [{label,value}],增删改排序后保存
+const VUE_PATH = resolve(__dirname, '../../views/admin/ExerciseTypeConfig.vue')
+const ROUTER_PATH = resolve(__dirname, '../../router/index.js')
+const LAYOUT_PATH = resolve(__dirname, '../../views/Layout.vue')
+const source = readFileSync(VUE_PATH, 'utf8')
+const router = readFileSync(ROUTER_PATH, 'utf8')
+const layout = readFileSync(LAYOUT_PATH, 'utf8')
+
+describe('ExerciseTypeConfig.vue 运动类型配置页', () => {
+  test('读写 sys_config.exercise_types(通过 getSysConfigList/updateSysConfig)', () => {
+    expect(source).toMatch(/getSysConfigList/)
+    expect(source).toMatch(/updateSysConfig/)
+    expect(source).toMatch(/exercise_types/)
+  })
+
+  test('支持增删改:删除/新增行方法存在', () => {
+    expect(source).toMatch(/addRow|handleAdd|addType/)
+    expect(source).toMatch(/removeRow|handleDelete|removeType/)
+  })
+
+  test('支持排序:上移/下移方法存在', () => {
+    expect(source).toMatch(/moveUp|moveDown/)
+  })
+
+  test('保存前校验 label/value 必填、value 唯一', () => {
+    expect(source).toMatch(/必填|不能为空|required/)
+    expect(source).toMatch(/重复|唯一|duplicate/)
+  })
+
+  test('保存写入 JSON 数组字符串(JSON.stringify types)', () => {
+    expect(source).toMatch(/JSON\.stringify/)
+  })
+
+  test('路由注册 exercise-type-config', () => {
+    expect(router).toMatch(/exercise-type-config/)
+    expect(router).toMatch(/ExerciseTypeConfig/)
+  })
+
+  test('侧边栏菜单注册运动类型配置入口(系统配置→基础管理)', () => {
+    expect(layout).toMatch(/path: '\/exercise-type-config'/)
+    expect(layout).toMatch(/运动类型配置/)
+  })
+})

+ 6 - 0
cfc-web/src/router/index.js

@@ -361,6 +361,12 @@ const routes = [
       component: () => import('@/views/admin/SysConfig.vue'),
       meta: { title: '系统配置', perm: 'system:base' }
     },
+    {
+      path: 'exercise-type-config',
+      name: 'ExerciseTypeConfig',
+      component: () => import('@/views/admin/ExerciseTypeConfig.vue'),
+      meta: { title: '运动类型配置', perm: 'system:base' }
+    },
     {
       path: 'guide-config',
       name: 'GuideConfig',

+ 1 - 0
cfc-web/src/views/Layout.vue

@@ -317,6 +317,7 @@ export default {
             { title: '基础管理', icon: 'el-icon-s-tools', perm: 'system:base',
               children: [
                 { path: '/sys-config', label: '系统配置', icon: 'el-icon-s-tools', perm: 'system:base' },
+                { path: '/exercise-type-config', label: '运动类型配置', icon: 'el-icon-s-grid', perm: 'system:base' },
                 { path: '/guide-config', label: '引导配置', icon: 'el-icon-setting', perm: 'system:base' },
                 { path: '/users', label: '用户管理', icon: 'el-icon-user', perm: 'system:users' },
                 { path: '/menu-manage', label: '菜单管理', icon: 'el-icon-menu', perm: 'system:menu' },

+ 163 - 0
cfc-web/src/views/admin/ExerciseTypeConfig.vue

@@ -0,0 +1,163 @@
+<template>
+  <div class="exercise-type-config admin-page">
+    <PageHeader title="运动类型配置"
+      subtitle="全局统一一套运动类型:小程序「成长运动打卡」与「健康运动记录」共用此处配置。改动保存后小程序下次进入打卡页自动生效(无需发版)。" />
+
+    <div class="config-body" v-loading="loading">
+      <el-card shadow="never" class="config-block">
+        <div slot="header">
+          <SectionTitle title="运动类型列表" />
+          <div class="config-tip">按顺序展示;上移/下移可调整小程序里的排列。value 保存后作为constants标识,老数据 value(如 ball_game)会自动映射为球类。</div>
+        </div>
+
+        <el-table :data="rows" border size="small" row-key="_id">
+          <el-table-column label="顺序" width="70" align="center">
+            <template slot-scope="{ $index }">{{ $index + 1 }}</template>
+          </el-table-column>
+          <el-table-column label="显示名称(label)" min-width="180">
+            <template slot-scope="{ row }">
+              <el-input v-model="row.label" size="small" placeholder="如:跑步" />
+            </template>
+          </el-table-column>
+          <el-table-column label="标识(value)" min-width="180">
+            <template slot-scope="{ row }">
+              <el-input v-model="row.value" size="small" placeholder="如:running" />
+            </template>
+          </el-table-column>
+          <el-table-column label="操作" width="200" fixed="right">
+            <template slot-scope="{ $index }">
+              <el-button size="mini" :disabled="$index === 0" @click="moveUp($index)">上移</el-button>
+              <el-button size="mini" :disabled="$index === rows.length - 1" @click="moveDown($index)">下移</el-button>
+              <el-button size="mini" type="danger" @click="removeRow($index)">删除</el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+
+        <div class="config-actions">
+          <el-button size="small" icon="el-icon-plus" @click="addRow">新增运动类型</el-button>
+          <el-button size="small" @click="load">重新加载</el-button>
+          <el-button size="small" @click="resetDefault">恢复默认</el-button>
+          <el-button size="small" type="primary" :loading="saving" @click="save">保存</el-button>
+        </div>
+      </el-card>
+    </div>
+  </div>
+</template>
+
+<script>
+import { getSysConfigList, updateSysConfig } from '@/api/admin'
+
+const CONFIG_KEY = 'exercise_types'
+const DEFAULT_ROWS = [
+  { label: '跑步', value: 'running' },
+  { label: '游泳', value: 'swimming' },
+  { label: '骑行', value: 'cycling' },
+  { label: '跳绳', value: 'jump_rope' },
+  { label: '球类', value: 'ball' },
+  { label: '力量训练', value: 'strength' },
+  { label: '体操', value: 'gymnastics' },
+  { label: '其他', value: 'other' }
+]
+
+let seq = 0
+const withId = () => ({ _id: ++seq, label: '', value: '' })
+
+export default {
+  name: 'ExerciseTypeConfig',
+  data() {
+    return {
+      loading: false,
+      saving: false,
+      rows: []
+    }
+  },
+  created() {
+    this.load()
+  },
+  methods: {
+    async load() {
+      this.loading = true
+      try {
+        const res = await getSysConfigList({})
+        const list = (res && res.data) || []
+        const found = list.find((c) => c.configKey === CONFIG_KEY || c.config_key === CONFIG_KEY)
+        const raw = found ? (found.configValue != null ? found.configValue : found.config_value) : null
+        let parsed = null
+        if (raw) {
+          try { parsed = typeof raw === 'string' ? JSON.parse(raw) : raw } catch (e) { parsed = null }
+        }
+        this.rows = Array.isArray(parsed) && parsed.length
+          ? parsed.map((r) => ({ _id: ++seq, label: String(r.label || ''), value: String(r.value || '') }))
+          : DEFAULT_ROWS.map((r) => ({ ...r, _id: ++seq }))
+      } catch (e) {
+        this.rows = DEFAULT_ROWS.map((r) => ({ ...r, _id: ++seq }))
+        this.$message && this.$message.error && this.$message.error('加载配置失败,已显示默认值')
+      } finally {
+        this.loading = false
+      }
+    },
+    addRow() {
+      this.rows.push(withId())
+    },
+    removeRow(index) {
+      this.rows.splice(index, 1)
+    },
+    moveUp(index) {
+      if (index <= 0) return
+      const tmp = this.rows[index - 1]
+      this.$set(this.rows, index - 1, this.rows[index])
+      this.$set(this.rows, index, tmp)
+    },
+    moveDown(index) {
+      if (index >= this.rows.length - 1) return
+      const tmp = this.rows[index + 1]
+      this.$set(this.rows, index + 1, this.rows[index])
+      this.$set(this.rows, index, tmp)
+    },
+    resetDefault() {
+      this.rows = DEFAULT_ROWS.map((r) => ({ ...r, _id: ++seq }))
+    },
+    validate() {
+      if (!this.rows.length) return '至少保留一个运动类型'
+      const values = []
+      for (let i = 0; i < this.rows.length; i++) {
+        const r = this.rows[i]
+        if (!r.label || !String(r.label).trim()) return `第 ${i + 1} 行显示名称不能为空`
+        if (!r.value || !String(r.value).trim()) return `第 ${i + 1} 行标识(value)不能为空`
+        const v = String(r.value).trim()
+        if (values.indexOf(v) >= 0) return `标识 "${v}" 重复,value 必须唯一`
+        values.push(v)
+      }
+      return null
+    },
+    async save() {
+      const err = this.validate()
+      if (err) {
+        this.$message && this.$message.warning && this.$message.warning(err)
+        return
+      }
+      this.saving = true
+      try {
+        const payload = this.rows.map((r) => ({ label: String(r.label).trim(), value: String(r.value).trim() }))
+        await updateSysConfig(null, {
+          configKey: CONFIG_KEY,
+          configValue: JSON.stringify(payload),
+          description: '运动类型配置(全局统一一套,小程序成长运动打卡/健康运动记录共用;后台可增删改排序)'
+        })
+        this.$message && this.$message.success && this.$message.success('保存成功,小程序下次进入打卡页生效')
+      } catch (e) {
+        this.$message && this.$message.error && this.$message.error('保存失败')
+      } finally {
+        this.saving = false
+      }
+    }
+  }
+}
+</script>
+
+<style scoped>
+.config-body { padding: 0; }
+.config-block { margin-bottom: 16px; }
+.config-tip, .config-actions { font-size: 12px; color: #909399; margin: 8px 0; }
+.config-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
+</style>