From d5729e92b84e815201d769bd58917e85db2bdcb1 Mon Sep 17 00:00:00 2001 From: linda Date: Thu, 15 Oct 2026 19:29:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E8=BD=AE=E6=92=AD=E5=BA=95?= =?UTF-8?q?=E8=89=B2=E5=AF=B9=E9=BD=90=E7=94=9F=E6=80=81=E7=BB=BF=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=EF=BC=88=E5=90=AB=20color=20=E5=88=97=E6=89=A9?= =?UTF-8?q?=E5=AE=B9=E4=B8=8E=E5=B9=82=E7=AD=89=E5=8D=87=E7=BA=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FcInstall 抽出 BANNERS 常量(标题/跳转/生态绿渐变),种子与升级共用同一份定义 - 新增幂等 upgradeBanners():先把 fc_banner.color 由 varchar(16) 扩为 varchar(255) (渐变串约 70 字符,varchar(16) 会被截断成非法样式),再按标题精确覆盖内置 3 条 轮播的 color(已填 gradient(...) 的跳过),不动发布/订单/会员等业务数据 - 建表语句 color 同步扩容并补字段注释 - 后台轮播表单:image/color 改为非必填 + 渐变写法提示(纯色写成同色双色标) - tools/verify-api.mjs:H2 /home/banners 增加 title/image/color 类型断言(178 例全通过) - docs/05:补 color 取值约定与 §7.6 老库升级步骤 --- application/admin/command/FcInstall.php | 62 +++++++++++++++++++--- application/admin/view/fc/banner/add.html | 6 ++- application/admin/view/fc/banner/edit.html | 6 ++- docs/05-后端实现规范.md | 38 ++++++++++++- tools/verify-api.mjs | 4 +- 5 files changed, 102 insertions(+), 14 deletions(-) diff --git a/application/admin/command/FcInstall.php b/application/admin/command/FcInstall.php index 408765c..049ac95 100644 --- a/application/admin/command/FcInstall.php +++ b/application/admin/command/FcInstall.php @@ -12,13 +12,25 @@ use think\Db; * 同城分类信息 · 业务表安装器 * * 用法: - * php think fc:install 建表 + 首次注入种子数据(已存在则跳过种子) + * php think fc:install 建表 + 首次注入种子数据(已存在则跳过种子)+ 轮播底色与生态绿主题对齐 * php think fc:install --reset 建表 + 强制重置种子数据 * * 说明:全部使用 CREATE TABLE IF NOT EXISTS,幂等安全,不影响 FastAdmin 原有表。 + * 不加 --reset 时只补建表结构、对齐内置轮播底色,业务数据(发布/订单/会员)一律不动。 */ class FcInstall extends Command { + /** + * 内置轮播(标题 / 跳转 / 底色)——种子数据与「底色升级」共用同一份定义。 + * color 取前端 uni.scss 的生态绿渐变家族:绿 = 平台与内容; + * image 留空时小程序用「绿底 + 白色插画」内置配图渲染。 + */ + const BANNERS = [ + ['同城好物节 · 二手直降', '/pages/post/list?categoryId=3', 'linear-gradient(135deg, #18a587 0%, #0e7c66 55%, #0a5d4d 100%)'], + ['招聘旺季 · 免费发布', '/pages/post/create', 'linear-gradient(135deg, #0e7c66 0%, #0a5d4d 55%, #04302a 100%)'], + ['本地服务 · 上门更省心', '/pages/post/list?categoryId=5', 'linear-gradient(135deg, #16897f 0%, #0e6b62 55%, #07443e 100%)'], + ]; + protected function configure() { $this->setName('fc:install') @@ -51,12 +63,52 @@ class FcInstall extends Command $output->writeln('==> 已有数据,跳过种子(如需重置请加 --reset)'); } + $output->writeln('==> 轮播底色与生态绿主题对齐'); + $this->upgradeBanners($output); + $output->writeln('==> 初始化后台菜单'); $this->menu($output); $output->writeln('==> 完成'); } + /** + * 轮播底色升级(幂等,可重复执行) + * + * v1.2 起主题改为生态绿,旧版种子里的轮播底色是暖橙纯色(#FF8A5B / #FFB86B / #FF6F61)。 + * 线上库若还是旧值,这里按「标题」精确匹配把内置 3 条轮播的底色覆盖为生态绿渐变; + * 只动 color 字段,不新增/删除记录,也不影响发布、订单等业务数据。 + * 自定义过标题或已填渐变(linear-gradient(...))的轮播不会被改动。 + */ + private function upgradeBanners(Output $output) + { + // ① 先确保 color 列容得下 CSS 渐变字符串:旧库是 varchar(16),只够存 #RRGGBB, + // 直接写 linear-gradient(...) 会被截断(严格模式还会报 1406 Data too long)。 + $table = \think\Config::get('database.prefix') . 'fc_banner'; + $cols = Db::query("SHOW COLUMNS FROM `{$table}` LIKE 'color'"); + $row = isset($cols[0]) ? $cols[0] : []; + $type = isset($row['Type']) ? (string)$row['Type'] : (isset($row['type']) ? (string)$row['type'] : ''); + if (preg_match('/^varchar\((\d+)\)$/i', $type, $m) && (int)$m[1] < 255) { + Db::execute("ALTER TABLE `{$table}` MODIFY COLUMN `color` varchar(255) NOT NULL DEFAULT ''" + . " COMMENT '底色:CSS 渐变 linear-gradient(...),留空则用内置生态绿渐变'"); + $output->writeln(' - 轮播底色列 color 已由 ' . $type . ' 扩容为 varchar(255)(存 CSS 渐变)'); + } + + // ② 旧暖色纯色 → 生态绿渐变 + $upgraded = 0; + foreach (self::BANNERS as $b) { + $row = Db::name('fc_banner')->where('title', $b[0])->find(); + if ($row && strpos((string)$row['color'], 'gradient(') === false) { + Db::name('fc_banner')->where('id', $row['id']) + ->update(['color' => $b[2], 'updatetime' => time()]); + $upgraded++; + } + } + $output->writeln($upgraded + ? ' - 已把 ' . $upgraded . ' 条旧纯色轮播底色升级为生态绿渐变' + : ' - 轮播底色已是渐变或非内置轮播,无需处理'); + } + /** * 初始化 FastAdmin 后台菜单(幂等) * @@ -198,7 +250,7 @@ class FcInstall extends Command `title` varchar(64) NOT NULL DEFAULT '', `image` varchar(255) NOT NULL DEFAULT '' COMMENT '图片,空则用渐变占位', `link` varchar(255) NOT NULL DEFAULT '' COMMENT '跳转路径', - `color` varchar(16) NOT NULL DEFAULT '', + `color` varchar(255) NOT NULL DEFAULT '' COMMENT '底色:CSS 渐变 linear-gradient(...),留空则用内置生态绿渐变', `sort` int(10) NOT NULL DEFAULT '0', `enabled` tinyint(1) NOT NULL DEFAULT '1', `createtime` int(10) DEFAULT NULL, @@ -534,11 +586,7 @@ class FcInstall extends Command } /* ---------- 轮播 ---------- */ - $banners = [ - ['同城好物节 · 二手直降', '/pages/post/list?categoryId=3', '#FF8A5B'], - ['招聘旺季 · 免费发布', '/pages/post/create', '#FFB86B'], - ['本地服务 · 上门更省心', '/pages/post/list?categoryId=5', '#FF6F61'], - ]; + $banners = self::BANNERS; foreach ($banners as $i => $b) { Db::name('fc_banner')->insert([ 'title' => $b[0], 'image' => '', 'link' => $b[1], 'color' => $b[2], diff --git a/application/admin/view/fc/banner/add.html b/application/admin/view/fc/banner/add.html index 3c9196d..19f3914 100644 --- a/application/admin/view/fc/banner/add.html +++ b/application/admin/view/fc/banner/add.html @@ -9,7 +9,8 @@
- + + 留空时小程序用内置白色插画(生态绿渐变底 + 圆环大徽章)渲染;填了图则铺满整张卡面并隐藏装饰层。
@@ -21,7 +22,8 @@
- + + 填 CSS 渐变(生态绿家族,纯色请写成同色双色标,如 linear-gradient(135deg, #0E7C66 0%, #0E7C66 100%));留空或填纯色时小程序会回落到内置生态绿渐变。
diff --git a/application/admin/view/fc/banner/edit.html b/application/admin/view/fc/banner/edit.html index 6bed72d..7f555e1 100644 --- a/application/admin/view/fc/banner/edit.html +++ b/application/admin/view/fc/banner/edit.html @@ -9,7 +9,8 @@
- + + 留空时小程序用内置白色插画(生态绿渐变底 + 圆环大徽章)渲染;填了图则铺满整张卡面并隐藏装饰层。
@@ -21,7 +22,8 @@
- + + 填 CSS 渐变(生态绿家族,纯色请写成同色双色标,如 linear-gradient(135deg, #0E7C66 0%, #0E7C66 100%));留空或填纯色时小程序会回落到内置生态绿渐变。
diff --git a/docs/05-后端实现规范.md b/docs/05-后端实现规范.md index ebfd627..8c4242d 100644 --- a/docs/05-后端实现规范.md +++ b/docs/05-后端实现规范.md @@ -3,7 +3,7 @@ > 框架:FastAdmin / ThinkPHP **5.0.29** / PHP **7.4** / MySQL 5.7,表前缀 `fa_` > 控制器命名空间:`app\api\controller`;全部继承 `V1`(已完成,勿改) > 路由表:`application/route.php`(已完成,勿改) -> 建表+种子:`application/admin/command/FcInstall.php`(已完成,勿改) +> 建表+种子:`application/admin/command/FcInstall.php`(**已完成**;表结构/菜单 ID 勿改,种子文案与轮播底色可随主题演进) ## 一、响应契约(V1 基类已封装,禁止直接 echo/json) @@ -71,6 +71,13 @@ $this->fail('信息不存在', 404); // 自定义业务码 | `fc_message` | user_id(0=全体), type(system/interact), title, content, isread, readtime | | `fc_pay_view` | user_id, post_id, pay_type, amount, order_id | +> **`fc_banner.color` 取值约定(v1.2.1 生态绿主题)**:字段已由 `varchar(16)` **扩容为 `varchar(255)`** +> (渐变串约 70 字符,`varchar(16)` 会被截断成 `linear-gradient(` 这类非法样式 → 小程序卡片空白), +> 存 **CSS 渐变字符串**(`linear-gradient(135deg, #18a587 0%, …)`)。前端 `common/assets/banners.js` 的 `bannerBg()` +> **只认结构完整的渐变**(含 ≥2 个色标、以 `)` 收尾):若为历史暖色纯色(`#FF8A5B` 等)、空值或被截断的半截值, +> 小程序会回落内置生态绿渐变(不再出现旧配色/空白卡)。`image` 为空时前端按位置取内置白色插画渲染,无需后端出图。 +> 需要把线上老库对齐主题时执行 `php think fc:install`(幂等,见 §7.6)。 + 用户主表:`fa_user`(`Db::name('user')`):id, username, nickname, avatar, mobile, `money`(余额), score, status。 后台:`fa_admin`、`fa_auth_group`(角色)、`fa_admin_log`(日志)。 @@ -131,7 +138,8 @@ $this->fail('信息不存在', 404); // 自定义业务码 - 字符串用单引号;数组用 `[]`;不加 `declare(strict_types=1)` - 金额 `round($x, 2)`;时间统一 `time()` - 后台写入类动作需调用 `$this->adminLog('动作描述')` 留痕 -- **不要**修改 `V1.php` / `route.php` / `FcInstall.php` / `Auth.php` +- **不要**修改 `V1.php` / `route.php` / `Auth.php`;`FcInstall.php` 仅在「表结构、菜单 ID、种子文案」明确需要时改, + 且必须保持**幂等**(`CREATE TABLE IF NOT EXISTS` + 存在即跳过 + 升级步骤只覆盖已知种子行) --- @@ -211,6 +219,32 @@ curl -s -c /tmp/cj.txt -b /tmp/cj.txt -X POST 'http://127.0.0.1/s.php/index/logi curl -s -b /tmp/cj.txt 'http://127.0.0.1/s.php/fc/post/index?offset=0&limit=3&sort=id&order=desc' \ -H 'Host: 域名' -H 'X-Requested-With: XMLHttpRequest' ``` + +前端契约验证(本机跑,打线上 `/api/v1`,178 例): + +```bash +node tools/verify-api.mjs # 其中 H2 GET /home/banners 校验 id/title/image/link/color 字段齐备 +``` + +### 7.6 轮播底色与前端主题对齐(幂等升级) + +小程序 v1.2 起主题改为**生态绿**,而**旧版种子**里 `fc_banner.color` 是暖橙纯色(`#FF8A5B` / `#FFB86B` / `#FF6F61`), +老库已按旧值落库;前端虽已加 `bannerBg()` 护栏(旧纯色自动回落生态绿),但数据层面也建议一次性对齐: + +```bash +php think fc:install # 幂等:建表 + 存在则跳过种子 + 按标题覆盖内置 3 条轮播底色 + 补菜单 +``` + +- 覆盖范围:**仅**内置 3 条轮播(按 `title` 精确匹配:`同城好物节 · 二手直降` / `招聘旺季 · 免费发布` / `本地服务 · 上门更省心`), + 且**已填 `gradient(...)` 的行一律跳过**(不覆盖运营自己改过的配色)。 +- 同时把 `color` 列由 `varchar(16)` **扩容为 `varchar(255)`**(仅当仍是 < 255 的 varchar 时执行 `ALTER TABLE`; + 不写渐变就无法存下,老库直接写会被截断成 `linear-gradient(`)。 +- 只改 `color`(顺带 `updatetime`),**不新增/删除记录**,不动发布、订单、会员等业务数据;可重复执行。 +- 底色定义集中在 `FcInstall::BANNERS` 常量(与小程序 `common/mock/data.js` 逐字对齐),**改主题只改这一处**。 +- 后台表单(`view/fc/banner/add.html` / `edit.html`)里 `image` / `color` 均**非必填**:留空即用内置插画与内置绿渐变, + 并附有渐变写法提示(纯色请写成同色双色标,如 `linear-gradient(135deg, #0E7C66 0%, #0E7C66 100%)`)。 +- 非要加 `--reset` 才会清空业务表重灌种子,常规上线流程**不要**带该参数。 + ## 八、小程序账号凭据(AppID / AppSecret) `POST /api/v1/auth/wx-login` 会把前端 `wx.login()` 拿到的 `code` 交给微信 `sns/jscode2session` 换 `openid`, diff --git a/tools/verify-api.mjs b/tools/verify-api.mjs index 1410d53..e922a07 100644 --- a/tools/verify-api.mjs +++ b/tools/verify-api.mjs @@ -124,7 +124,9 @@ async function userAuth() { async function userHome() { await ok200('H2 GET /home/banners', 'GET', '/home/banners', null, false, - (d) => (Array.isArray(d) && d.length > 0 && 'title' in d[0] && 'link' in d[0] ? '' : '非数组或缺字段')) + (d) => (Array.isArray(d) && d.length > 0 && 'title' in d[0] && 'link' in d[0] + && typeof d[0].title === 'string' && typeof d[0].image === 'string' && typeof d[0].color === 'string' + ? '' : '非数组或缺 title/image/link/color 字段')) await ok200('H1 GET /home/categories', 'GET', '/home/categories', null, false, (d) => (Array.isArray(d) && d.length === 8 && 'iconKey' in d[0] && 'count' in d[0] && d[0].id === 1 ? '' : '应 8 项且含 iconKey/count,实际 ' + (Array.isArray(d) ? d.length + ' 项' : typeof d)))