Skip to content

前端联调 · 开机信息屏(splash.ts) ​

归属:前端联调 API 手册 → src/api/splash.ts 端点:2 个 · 路由前缀 /api/v1/splash-screen(模块名是 ad,路由名不是) 鉴权:两个都免登录(开屏在登录前展示) 错误码:本模块不定义自己的错误码段 —— 异常复用 user 域码(40301xxx),见下 取值语义:取值速查 · splash —— mediaType / linkType / notice.level 各自的 DB 缺省值与前端表现、event 仅两值的约束、forecast 降级是 [] 不是 null

本页 curl 变量 ​

bash
BASE_URL=https://api.qingmulife.cn   # 本地:http://localhost:3000
ENV=Prd                              # Dev | Prd —— 全程必须一致

端点一览 ​

#方法路径场景
1GET/api/v1/splash-screen冷启动开屏:广告 + 实时天气 + 运营提醒
2POST/api/v1/splash-screen/track广告曝光 / 点击埋点(fire-and-forget)

getSplashScreen ​

一句话:开屏聚合数据 —— 一次拿广告 + 天气 + 提醒三块(各块独立可 null)。

curl ​

bash
curl -s "$BASE_URL/api/v1/splash-screen" \
  -H 'X-Env: Prd'

请求 ​

字段类型必填说明
———无入参、免登录

响应 data ​

顶层三块,每块都可能是 null —— 前端必须逐块判空:

字段类型可空说明
adobject | null是广告块
ad.idnumber是广告 id —— track 要用
ad.imageUrlstring是图片 / 视频封面 URL
ad.mediaTypestring是'image' | 'video'(默认 'image')
ad.linkTypestring是'none' | 'webview'
ad.linkUrlstring | null是linkType='webview' 时才有意义
weatherobject | null是天气块
weather.city / .text / .iconstring是城市 / 天气文案 / 图标
weather.temperature / .feelsLike / .humiditynumber是int
weather.forecast[]object[]是[{date, textDay, tempMax, tempMin, icon}] —— 和风接口失败时降级为 [](空数组,不是 null)
weather.updatedAtstring ISO是前端 new Date 格式化用
noticeobject | null是运营提醒块
notice.title / .contentstring是
notice.levelstring是'info' | 'warn'

📌 信封:本接口手组信封({"code":"0","msg":"ok","data":…})—— 前端类型只声明了 {code, data},msg 未声明(不消费,无影响)。 📌 天气 stub:.env 未配 QWEATHER key 时走 stub(长沙数据),forecast 为空数组 —— 联调期看到长沙天气不是 bug。

错误码 ​

无业务错误码(公开只读、异常一律降级为 null / 空数组)。服务不可用 → HTTP 5xx。


trackSplashEvent ​

一句话:广告曝光 / 点击埋点 —— fire-and-forget,前端 .catch(() => {}) 静默。

curl ​

bash
# 曝光
curl -s "$BASE_URL/api/v1/splash-screen/track" \
  -H 'Content-Type: application/json' \
  -H 'X-Env: Prd' \
  -d '{"adId":1,"event":"exposure"}'

# 点击
curl -s "$BASE_URL/api/v1/splash-screen/track" \
  -H 'Content-Type: application/json' \
  -H 'X-Env: Prd' \
  -d '{"adId":1,"event":"click"}'

请求 ​

字段类型必填说明
adIdnumber✔来自 data.ad.id
eventstring✔值域仅 'exposure' | 'click' —— 其他值 → 400
X-Envheader✔埋点也按库落

无 Authorization(免登录)。服务端另取 IP 与 user-agent 记录。

响应 data ​

字段类型可空说明
datanull—恒 null(固定信封 {"code":"0","msg":"ok","data":null})—— 前端类型声明 void,忽略即可

错误码 ​

⚠️ 本模块不定义错误码段 —— 业务异常抛的是 UserError,因此业务码落在 user 段 40301xxx:

业务码HTTP触发条件前端建议处置
40301001400event 非 exposure/click,或 body 非法 JSON静默(埋点失败不影响 UI)
40301004404adId 对应的广告不存在静默