uniapp-ZHSQ/doc/首页Banner跳转现状梳理.md

85 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 首页 Banner / 广告位 跳转现状梳理
> 状态现状分析仅梳理代码未改。日期2026-06-03
> 范围:小程序 `pages/index/index.vue` 首页各广告位的点击跳转逻辑,对照后端配置。
---
## 一、后端是怎么配置跳转的
每条 banner/广告(表 `home_banner_region`)、金刚位(表 `home_button_region`)都有统一的跳转配置字段,核心是 **`promotion_type`(推广类型)**
| promotion_type | 含义 | 配套字段 |
|---|---|---|
| 1 | 无跳转 | — |
| 2 | 选择活动 | 关联 `advertisement_goods`(按 banner id |
| 3 | 跳转本程序页面 | `link_url` |
| 4 | 跳转其他小程序 | `appid` + `link_url` |
| 5 | 选择商品 | `advertisement_goods[].goods_id` |
- 后台创建/编辑接口(`api/admin/v2/crud_home_banner_region.go`)用 `promotion_type` + `required-if` 校验对应字段,例如 type=4 必填 appid、type=3/4 必填 link_url。
- `home_button_region`(金刚位)字段相同,也有 `promotion_type` / `link_url` / `appid`
- type=2/5 的落地:`/packages/advertising/index/index?id=<banner.id>` 是“广告聚合落地页”,传 banner 自身 id 进去,页面内部拉该 banner 关联的 `advertisement_goods` 商品列表展示,并可进入 `goodsDetail`
---
## 二、前端实际怎么跳的(问题所在)
首页有 4 个不同的点击处理函数各管一片,**几乎都没读 `promotion_type`**
### 1. `headerServerClick`(金刚位 tabList、homeLeftList 用)
- 文件:`pages/index/index.vue`(搜 `headerServerClick(e)`
- 只看 `link_url``appid`**完全忽略 `promotion_type`**。
- 逻辑:无 `link_url` → 弹“此功能暂未开通”;有 `appid` → 跳小程序;否则当本程序路径 `NavgateTo`
- **后果**type=2活动、type=5商品的配置它不认 → 落到“没 link_url”分支 → 弹“暂未开通”。
### 2. `toAdvertisingView`(广告横幅 serverLeft、serverRight[0] 用)
- 文件:`pages/index/index.vue:357` 附近
- **写死**跳 `/packages/advertising/index/index?id=xxx`,不看 `promotion_type`,一律进广告落地页。
### 3. `goToPurify`serverRight 非首个用,模板 `index.vue:101`
- 文件:`pages/index/index.vue:363` 附近
- **彻底写死**:固定跳净水小程序 `appId=wx77b22c0a0018e580`path/appId 全硬编码,传入的 `item` 没用到,与后台配置零关系。
- 模板:`@tap="index === 0 ? toAdvertisingView(serverRightList) : goToPurify(item)"` —— serverRight 第一个跳广告页,其余全跳净水小程序。
### 4. `headerServerClick2`(中部 serverItem / homeRightList1,2 用)
- 文件:`pages/index/index.vue`(搜 `headerServerClick2(e)`
- 不跳外链,只按 `title` 匹配商家分类做筛选,或固定跳本地生活页。**注意:这一处可能是“按分类筛选”的有意设计,不一定算 bug。**
### 5. 顶部轮播 Banner位置 1模板 `index.vue:68`
- 点击事件被**注释掉了**`<!-- <swiper-item ... @click="headerServerClick(item)"> -->`),顶部 banner 现在点击无反应。
---
## 三、根因
后台用统一的 `promotion_type` 模型配跳转,前端却是早期“按位置分别写死”的处理函数拼起来的:既没统一读 `promotion_type`,部分位置还硬编码了目标(广告页、净水小程序)。所以出现“很多跳转和后台配置不符”——不是数据错,是前端没按配置解析。
---
## 四、建议修法(未实施,待决策)
做一个统一跳转函数 `handleAdJump(item)`,严格按 `promotion_type` 分发:
```
switch promotion_type:
1: 不跳
2: NavgateTo('/packages/advertising/index/index?id=' + item.id) // 活动
3: link_url 跳本程序页面(兼容 shopEnter 特例 / H5 / APP webview
4: navigateToMiniProgram(appid, link_url) // 其他小程序
5: NavgateTo('/packages/advertising/index/index?id=' + item.id) // 商品(同活动,落地页内展示)
其他: 弹“暂未开通”
```
然后把首页所有广告位的 `@click`/`@tap` 都换成 `handleAdJump(item)`
- 顶部轮播 banner取消注释`handleAdJump`
- 金刚位 tabList、homeLeftList`headerServerClick``handleAdJump`
- serverLeft、serverRight`toAdvertisingView` / `goToPurify``handleAdJump`
### 实施前需确认的点
1. `headerServerClick2`(中部 serverItem 按 title 筛分类)是否要保留分类筛选语义?还是也改成按 `promotion_type` 跳?
2. 净水小程序跳转:是想**保留写死**,还是改由后台某条 banner 配 `type=4 + 该 appid` 来控制(更灵活,去掉硬编码)?
3. type=2/5 是否都统一进广告落地页 `/packages/advertising/index/index?id=banner.id`(当前分析结论是“是”)。
> 相关:`promotion_type` 字段定义见 `huichang-server/internal/model/entity/home_banner_region.go`、`home_button_region.go`;广告落地页 `uniapp-ZHSQ/packages/advertising/index/index.vue`。