Bladeren bron

chore: auto bump version and changelog [skip ci]

iwt 2 weken geleden
bovenliggende
commit
71278e26c1

+ 16 - 0
cfc-frontend/__tests__/api/api.test.js

@@ -25,6 +25,22 @@ function mockFail(err) {
   })
 }
 
+/** Helper: make uni.request return a sequence of responses (one per call) */
+function mockSequence(responses) {
+  var i = 0
+  global.uni.request.mockImplementation((opts) => {
+    var resp = responses[Math.min(i, responses.length - 1)]
+    i++
+    process.nextTick(() => {
+      if (resp.err) {
+        if (opts.fail) opts.fail(resp.err)
+      } else {
+        if (opts.success) opts.success({ data: resp.data })
+      }
+    })
+  })
+}
+
 // --------------- global beforeEach ---------------
 
 beforeEach(() => {

+ 72 - 2
cfc-frontend/utils/api.js

@@ -3,6 +3,7 @@ import config from '@/config.js'
 const BASE_URL = config.API_BASE_URL
 
 var _redirectingToLogin = false
+var _reloginLock = false
 
 function _clearAuthAndRedirect() {
   if (_redirectingToLogin) return
@@ -21,6 +22,76 @@ function _clearAuthAndRedirect() {
   }, 1500)
 }
 
+// 静默续期成功后回写登录态(token/角色/familyId/openid),保持与 App.vue saveLoginInfo 一致
+function _applyLoginData(data) {
+  uni.setStorageSync('token', data.token)
+  uni.setStorageSync('userId', data.userId)
+  uni.setStorageSync('role', data.role)
+  uni.setStorageSync('currentRole', data.role)
+  uni.setStorageSync('isSwitchedChild', false)
+  uni.setStorageSync('isSwitchedTeacher', false)
+  if (data.openid) {
+    uni.setStorageSync('openid', data.openid)
+  }
+  uni.setStorageSync('userInfo', {
+    nickname: data.nickname,
+    userId: data.userId,
+    familyId: data.familyId
+  })
+  try {
+    var app = typeof getApp === 'function' ? getApp() : null
+    if (app && app.$store) {
+      app.$store.commit('setToken', data.token)
+      app.$store.commit('setUserInfo', {
+        userId: data.userId,
+        role: data.role,
+        familyId: data.familyId,
+        nickname: data.nickname
+      })
+      app.$store.commit('setFamilyId', data.familyId)
+    }
+  } catch (e) { /* 非页面环境无 Vuex,静默忽略 */ }
+}
+
+// 401 处理:优先用缓存 openid 静默续期并重放原请求;续期失败或无 openid 时回退跳登录页
+function _handle401(url, method, data, options, resolve, reject, resData) {
+  // 续期接口自身 401 / 重试仍 401 时,避免递归续期死循环
+  if (_reloginLock) {
+    _clearAuthAndRedirect()
+    reject(resData)
+    return
+  }
+  var openid = uni.getStorageSync('openid')
+  if (!openid) {
+    _clearAuthAndRedirect()
+    reject(resData)
+    return
+  }
+  _reloginLock = true
+  autoLogin(openid).then(function(res) {
+    if (res && res.data && res.data.token) {
+      console.warn('[API] 401 静默续期成功,重放原请求 ' + url)
+      _applyLoginData(res.data)
+      // 重放原请求;重试期间保持锁,防止重试仍 401 时再次触发续期
+      request(url, method, data, options).then(function(r) {
+        _reloginLock = false
+        resolve(r)
+      }, function(e) {
+        _reloginLock = false
+        reject(e)
+      })
+    } else {
+      _reloginLock = false
+      _clearAuthAndRedirect()
+      reject(resData)
+    }
+  }).catch(function() {
+    _reloginLock = false
+    _clearAuthAndRedirect()
+    reject(resData)
+  })
+}
+
 const request = (url, method = 'POST', data = {}, options = {}) => {
   // Append query params from options to URL if provided (e.g., { guideId } for GET requests)
   if (options && Object.keys(options).length > 0) {
@@ -63,8 +134,7 @@ const request = (url, method = 'POST', data = {}, options = {}) => {
       success: (res) => {
         if (res.statusCode === 401 || res.data.code === 401) {
           console.warn('[API] 401 ' + method + ' ' + fullUrl)
-          _clearAuthAndRedirect()
-          reject(res.data)
+          _handle401(url, method, data, options, resolve, reject, res.data)
           return
         }
         // 5001: 用户无家庭 — resolve 带标记,不 reject;由组件层各自渲染 FamilyEmptyState

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-4b921f8e660e1ac6d8989586604ffe3cfb729f40
+767c29ce9c79fbcf1ea0a074f781fc563cbab279

+ 2 - 2
cfc-web/package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "cfc-web",
-  "version": "1.0.1277",
+  "version": "1.0.1278",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "cfc-web",
-      "version": "1.0.1277",
+      "version": "1.0.1278",
       "dependencies": {
         "@wangeditor/editor": "^5.1.23",
         "@wangeditor/editor-for-vue": "^1.0.2",

+ 1 - 1
cfc-web/package.json

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

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

@@ -4,6 +4,12 @@
 
 ---
 
+## v1.0.1279 (2026-09-02)
+
+### 新功能
+- 美化菌群报告疾病风险页并补充疾病知识库,手风琴标题去掉有效保留异常/共
+
+
 ## v1.0.1278 (2026-09-01)
 
 ### 文档

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

@@ -1,6 +1,6 @@
 # 更新日志
 
-> 当前版本: v1.0.1278
+> 当前版本: v1.0.1279
 
 ## 历史版本
 
@@ -8,6 +8,12 @@
 
 ---
 
+## v1.0.1279 (2026-09-02)
+
+### 新功能
+- 美化菌群报告疾病风险页并补充疾病知识库,手风琴标题去掉有效保留异常/共
+
+
 ## v1.0.1278 (2026-09-01)
 
 ### 文档