文件
huaqiapp/utils/request.js
linda 5ea1b461f3 feat: 花期 V1.0 纵向切片(暖色调设计系统 + 周期/情绪/会员全链路)
前端(uni-app · Vue3)
- 设计系统:uni.scss 品牌令牌(花红 #E8604C / 蜜橙 #F5A65B / 暖米白 #FFF9F5),
  App.vue 全局原子类(卡片/按钮/胶囊/单元格/空态/进度)
- 页面:登录、首页(聚合)、周期(花瓣日历+当日记录+预测+概览)、情绪(记录+趋势+日记+疗愈)、
  我的(资料/会员/隐私/提醒)、健康报告、会员套餐、内容详情
- 组件:hq-tabbar(自定义底栏)、bloom-calendar(阶段日历)
- 基础层:utils/{config,request,store,api,date}.js(统一 token、401 处理、接口集中定义)

后端(FastAdmin / ThinkPHP 5.0)
- 新增 api 控制器:Home / Cycle / Mood / Content / Member / Setting,User 增补 detail、updateprofile
- 新增服务层:CycleService(四阶段计算、预测、月历、汇总)、MemberService(权益判定)
- 新增表:fa_cycle / fa_cycle_log / fa_symptom_tag / fa_mood_log / fa_content /
  fa_content_category / fa_member_plan / fa_member_order / fa_user_setting
- 初始化数据:20 个症状标签、28 条内容(心语/科普/知识/食谱/运动/睡眠/痛经/冥想)、3 档会员

验证(全部通过)
- 接口全链路 48 项断言(登录→周期→首页→情绪→内容→会员→设置→资料)
- 前后端契约静态校验 24 个接口 0 偏差
- Vue SFC 编译 11/11、SCSS 编译 10/10
- 验证脚本见 scripts/verify/,报告见 docs/04-前端设计系统与联调验证.md
2026-11-05 22:54:02 +08:00

78 行
1.7 KiB
JavaScript

import { BASE_URL, REQUEST_TIMEOUT } from './config.js'
import store from './store.js'
let redirecting = false
/**
* 统一请求封装
* - 自动携带 token
* - code=1 视为成功,直接返回 data
* - 401 清理登录态并跳转登录页
* - 其它错误统一 toast,返回 rejected Promise 供页面自行处理
*/
export function request(path, options = {}) {
const { method = 'GET', data = {}, auth = true, silent = false, loading = false } = options
return new Promise((resolve, reject) => {
if (loading) {
uni.showLoading({ title: '加载中', mask: true })
}
const header = {
'Content-Type': 'application/x-www-form-urlencoded'
}
if (auth && store.token) {
header.token = store.token
}
uni.request({
url: BASE_URL + path,
method,
data,
header,
timeout: REQUEST_TIMEOUT,
success: (res) => {
const body = res.data || {}
// FastAdmin 业务错误
if (body.code === 1) {
resolve(body.data || {})
return
}
if (res.statusCode === 401 || body.code === 401) {
handleUnauthorized()
reject(body)
return
}
if (!silent) {
uni.showToast({ title: body.msg || '请求失败', icon: 'none' })
}
reject(body)
},
fail: (err) => {
if (!silent) {
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' })
}
reject(err)
},
complete: () => {
if (loading) {
uni.hideLoading()
}
}
})
})
}
function handleUnauthorized() {
if (redirecting) return
redirecting = true
store.clear()
uni.showToast({ title: '登录已过期,请重新登录', icon: 'none' })
setTimeout(() => {
uni.reLaunch({ url: '/pages/login/index' })
redirecting = false
}, 600)
}
export default request