feat: 分销码
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 2m22s

This commit is contained in:
luo
2026-10-08 11:00:51 +08:00
parent 65d4c7bcf8
commit 2b4fd6fff8
12 changed files with 255 additions and 11 deletions

View File

@@ -0,0 +1,21 @@
## Context
The Uni-app frontend already obtains the authenticated user through `GET /api/auth/me`. That user includes `user_type` and `shop_id`; `GET /api/admin/shops/{shop_id}` returns the shop's `distribution_code`. The home page currently has an agent-only “提现管理” shortcut, and `src/static/icons/分销码.png` is present as an untracked user-supplied asset.
## Goals / Non-Goals
- Goals: expose a role-restricted shortcut after withdrawal management and show the current shop's distribution code as a scannable QR code.
- Non-Goals: change backend contracts, generate or rotate distribution codes, or expose another shop's code.
## Decisions
- Use the current authenticated user's `shop_id` from `/api/auth/me`; do not hardcode a shop ID or accept one from the page URL.
- Fetch the shop record through a typed shop-detail API method and encode the returned `distribution_code` value itself in the QR code.
- Generate/render the QR code locally with a Uni-app-compatible solution. Do not send distribution codes to a remote QR-generation service.
- Add a dedicated page, use the supplied icon for the home shortcut, and re-check the current user type on the page so direct navigation does not bypass the agent-only UI.
- Show a clear unavailable/error state when the account has no `shop_id`, the shop response has no distribution code, or the request fails.
## Risks / Trade-offs
- QR rendering APIs differ across Uni-app targets. Select a local renderer compatible with the project's supported H5 and mini-program builds and verify it in the target runtime.
- The supplied icon is currently untracked; implementation must preserve and use it without replacing or deleting it.

View File

@@ -0,0 +1,16 @@
# Change: Add agent distribution code viewing
## Why
Agent accounts need a quick way to share their shop's distribution code. The authenticated user response already provides `shop_id`, and the shop detail endpoint returns `distribution_code`, but the agent home page does not expose or display it.
## What Changes
- Add a “查看我的分销码” shortcut immediately after “提现管理” on the agent home page, visible only when `user_type` is `3`.
- Add a distribution-code page that uses the current authenticated user's `shop_id` to fetch `/api/admin/shops/{shop_id}` and renders the returned `distribution_code` as a QR code.
- Reuse the existing `src/static/icons/分销码.png` shortcut icon.
## Impact
- Affected specs: `agent-distribution-code` (new capability)
- Affected code: `src/pages/agent-system/home/index.vue`, `src/pages/agent-system/distribution-code/index.vue`, `src/pages.json`, and the shop API module; a Uni-app-compatible local QR renderer may require a dependency.

View File

@@ -0,0 +1,23 @@
## ADDED Requirements
### Requirement: Agent users can view their shop distribution code
The authenticated home page SHALL show a “查看我的分销码” shortcut immediately after “提现管理” only when the current user's `user_type` is `3`. The shortcut SHALL use `src/static/icons/分销码.png`. Opening it SHALL use the current user's `shop_id` to retrieve that shop's `distribution_code` from `/api/admin/shops/{shop_id}` and display a QR code encoding that exact value. The code SHALL be generated locally and SHALL NOT be sent to a third-party QR service.
#### Scenario: Agent sees and opens the shortcut
- **GIVEN** `/api/auth/me` returns a user with `user_type` `3` and a valid `shop_id`
- **WHEN** the home page displays its quick actions
- **THEN** “查看我的分销码” appears immediately after “提现管理” with the supplied distribution-code icon
- **AND** opening it displays the current shop's distribution code as a QR code
#### Scenario: Non-agent does not see the shortcut
- **GIVEN** `/api/auth/me` returns a user whose `user_type` is not `3`
- **WHEN** the home page displays its quick actions
- **THEN** the distribution-code shortcut is not shown
- **AND** direct navigation to the distribution-code page does not reveal a code
#### Scenario: Shop or distribution code is unavailable
- **GIVEN** an agent opens the distribution-code page
- **WHEN** the current account has no `shop_id`, the shop request fails, or the shop has no `distribution_code`
- **THEN** no QR code is rendered
- **AND** the page explains that the distribution code is currently unavailable

View File

@@ -0,0 +1,12 @@
## 1. Proposal Review
- [x] 1.1 Review and approve this proposal before implementation
## 2. Implementation
- [x] 2.1 Add a typed shop-detail API method for `/api/admin/shops/{shop_id}` and its `distribution_code` field
- [x] 2.2 Add a distribution-code page that checks the current user type, fetches the current shop, and renders the code locally as a QR
- [x] 2.3 Register the page and add the agent-only home shortcut immediately after withdrawal management using the supplied icon
- [x] 2.4 Handle missing shop/code and request failure states
## 3. Verification
- [x] 3.1 Run targeted ESLint and type-check; record unrelated existing type-check failures
- [x] 3.2 Verify role gating, `shop_id` lookup, and QR content mapping, and build H5 and WeChat mini-program targets