fix(admin): 轮播底色对齐生态绿主题(含 color 列扩容与幂等升级)
- 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 老库升级步骤
这个提交包含在:
@@ -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],
|
||||
|
||||
在新工单中引用
屏蔽一个用户