Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bde2d35756 | |||
| 4ac5adac3e | |||
| 8c2dcf49a8 | |||
| f400459497 | |||
| 64ac17d6b5 |
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.0.45] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复微信分享卡片标题仍显示"岩美"的问题(HTML 缩进导致字符串匹配失败)
|
||||
- 微信分享卡片描述去掉"扫码验真"后缀
|
||||
|
||||
## [1.0.44] - 2026-06-15
|
||||
|
||||
### 改进
|
||||
- 微信分享卡片标题改为商品名称(之前仍显示"岩美")
|
||||
- 微信分享卡片描述去掉"扫码验真"后缀
|
||||
|
||||
## [1.0.43] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复微信/飞书分享商品链接时卡片只显示"岩美"而不显示商品名称和图片的问题
|
||||
|
||||
## [1.0.42] - 2026-06-15
|
||||
|
||||
### 修复
|
||||
- 修复商品二维码扫码页报"index.html not found"的错误
|
||||
|
||||
## [1.0.41] - 2026-06-15
|
||||
|
||||
### 改进
|
||||
- 标签打印布局优化:编号字体与度数/日期统一大小,内容整体下移并填满标签底部,店名适当放大
|
||||
- 标签度数与规格之间加宽间距,两个字段更易区分
|
||||
|
||||
## [1.0.40] - 2026-06-15
|
||||
|
||||
### 新功能
|
||||
|
||||
@@ -80,7 +80,7 @@ func Load() {
|
||||
viper.SetDefault("storage.upload_dir", "./uploads/images")
|
||||
viper.SetDefault("storage.base_url", "http://localhost:8080/images")
|
||||
viper.SetDefault("storage.public_url", "http://localhost:8081")
|
||||
viper.SetDefault("storage.web_dir", "./client/build/web")
|
||||
viper.SetDefault("storage.web_dir", "./web")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Println("[config] no config file found, using defaults and env vars")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"html"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -313,15 +314,19 @@ func (h *PublicHandler) ProductPage(c *gin.Context) {
|
||||
|
||||
// 构造 OG 标签并注入 </head> 前
|
||||
ogTags := buildProductOG(product, shopName, config.C.Storage.PublicURL)
|
||||
out := strings.Replace(idxHTML, "</head>", ogTags+"</head>", 1)
|
||||
ogTitle := buildOGTitle(product)
|
||||
// 同时替换 <title> 标签,微信/飞书等平台有时优先读 <title> 而非 og:title
|
||||
// 用正则替换避免缩进空格导致字符串不匹配
|
||||
titleRe := regexp.MustCompile(`<title>[^<]*</title>`)
|
||||
out := titleRe.ReplaceAllString(idxHTML, "<title>"+html.EscapeString(ogTitle)+"</title>")
|
||||
out = strings.Replace(out, "</head>", ogTags+"</head>", 1)
|
||||
// 禁止缓存,确保爬虫每次都能拿到最新 OG 标签
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(out))
|
||||
}
|
||||
|
||||
// buildProductOG 构造基础 Open Graph meta 标签字符串。
|
||||
// 所有值经 html.EscapeString 转义,防止 XSS 或破坏 HTML 结构。
|
||||
// 无图片时不输出 og:image 行。
|
||||
func buildProductOG(product model.Product, shopName, publicURL string) string {
|
||||
// og:title:品牌 + 商品名(品牌已含在名字中时不重复)+ 系列
|
||||
// buildOGTitle 生成商品的分享标题:品牌 + 商品名(品牌已含在名字中时不重复)+ 系列。
|
||||
func buildOGTitle(product model.Product) string {
|
||||
title := product.Name
|
||||
if product.Brand != "" && !strings.Contains(product.Name, product.Brand) {
|
||||
title = product.Brand + title
|
||||
@@ -329,10 +334,18 @@ func buildProductOG(product model.Product, shopName, publicURL string) string {
|
||||
if product.Series != "" {
|
||||
title = title + "(" + product.Series + ")"
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
// og:description:规格(度数/香型/容量)| 门店名正品 · 扫码验真
|
||||
// buildProductOG 构造基础 Open Graph meta 标签字符串。
|
||||
// 所有值经 html.EscapeString 转义,防止 XSS 或破坏 HTML 结构。
|
||||
// 无图片时不输出 og:image 行。
|
||||
func buildProductOG(product model.Product, shopName, publicURL string) string {
|
||||
title := buildOGTitle(product)
|
||||
|
||||
// og:description:规格(度数/香型/容量)| 门店名正品
|
||||
desc := product.Spec
|
||||
suffix := "正品 · 扫码验真"
|
||||
suffix := "正品"
|
||||
if shopName != "" {
|
||||
suffix = shopName + suffix
|
||||
}
|
||||
|
||||
@@ -224,26 +224,38 @@ Future<ui.Image> _renderLabelBitmap({
|
||||
// 扫码溯源:居中于二维码正下方
|
||||
_drawText(canvas, '扫码溯源', qrLeft, qrTop + qrS + 2, 14, qrS, center: true);
|
||||
|
||||
// 左侧文字(无字段名标签):按行等比分配高度铺满,字号自适应填充
|
||||
// 左侧文字:固定字号 + 自适应行间距(与二维码上下对齐,行距均匀分配剩余空间)
|
||||
const lx = 22.0;
|
||||
const textMaxW = qrLeft - lx - 6; // 164
|
||||
|
||||
// 字号固定:只有商品名按宽度自适应,其余行均固定,杜绝自动放大
|
||||
const double kShopSize = 17.0; // 酒行名,粗体
|
||||
const double kSmallSize = 13.0; // 编号 / 度数 / 日期,统一小字
|
||||
// 商品名:仅按宽度适配,上限 26px,下限 14px
|
||||
final double nameSize = _fitFont(name, textMaxW, 1000, true, 26.0).clamp(14.0, 26.0);
|
||||
|
||||
final codeText = code.isNotEmpty ? '编号:$code' : '';
|
||||
final rows = <(String, double, bool)>[
|
||||
(shop, 0.9, true),
|
||||
(name, 1.5, true),
|
||||
if (codeText.isNotEmpty) (codeText, 1.0, false),
|
||||
if (degSpec.isNotEmpty) (degSpec, 1.05, false),
|
||||
if (date.isNotEmpty) (date, 1.0, false),
|
||||
if (shop.isNotEmpty) (shop, kShopSize, true),
|
||||
if (name.isNotEmpty) (name, nameSize, true),
|
||||
if (codeText.isNotEmpty) (codeText, kSmallSize, false),
|
||||
if (degSpec.isNotEmpty) (degSpec, kSmallSize, false),
|
||||
if (date.isNotEmpty) (date, kSmallSize, false),
|
||||
];
|
||||
const topY = 4.0, botY = 156.0;
|
||||
final totalWeight = rows.fold<double>(0, (a, r) => a + r.$2);
|
||||
double yy = topY;
|
||||
|
||||
// 文字区域:整体略低于二维码顶部,底部延伸至扫码溯源文字下方
|
||||
const double kTextTop = 16.0; // 比二维码顶部(8)低一些,整体下移
|
||||
const double kTextBot = 150.0; // 延伸至底部,减少留白
|
||||
const double kLineH = 1.35; // 行高倍数(字号 × 行高 = 该行占用高度)
|
||||
final double totalTextH = rows.fold(0.0, (s, r) => s + r.$2 * kLineH);
|
||||
final int n = rows.length;
|
||||
final double rawGap = n > 0 ? (kTextBot - kTextTop - totalTextH) / (n + 1) : 4.0;
|
||||
final double gap = rawGap < 1.5 ? 1.5 : rawGap;
|
||||
|
||||
double yy = kTextTop + gap;
|
||||
for (final r in rows) {
|
||||
final rowH = (botY - topY) * r.$2 / totalWeight;
|
||||
final fs = _fitFont(r.$1, textMaxW, rowH * 0.84, r.$3, 30);
|
||||
final ty = yy + (rowH - fs * 1.25) / 2;
|
||||
_drawText(canvas, r.$1, lx, ty < yy ? yy : ty, fs, textMaxW, bold: r.$3);
|
||||
yy += rowH;
|
||||
_drawText(canvas, r.$1, lx, yy, r.$2, textMaxW, bold: r.$3);
|
||||
yy += r.$2 * kLineH + gap;
|
||||
}
|
||||
|
||||
return recorder.endRecording().toImage(w, h);
|
||||
@@ -327,7 +339,7 @@ Future<void> printProductLabelImpl({
|
||||
final specVal = (spec ?? '').isNotEmpty ? spec! : '';
|
||||
final seriesVal = (series ?? '').isNotEmpty ? series! : '';
|
||||
// 度数(系列) + 规格 同一行
|
||||
final degSpecVal = [seriesVal, specVal].where((s) => s.isNotEmpty).join(' ');
|
||||
final degSpecVal = [seriesVal, specVal].where((s) => s.isNotEmpty).join(' ');
|
||||
final dateVal = (productionDate ?? '').isNotEmpty
|
||||
? (productionDate!.length > 10 ? productionDate.substring(0, 10) : productionDate)
|
||||
: '—';
|
||||
@@ -484,7 +496,7 @@ Future<void> printProductLabelImpl({
|
||||
Future<Uint8List> renderLabelPreviewImpl(LabelData label) async {
|
||||
final specVal = (label.spec ?? '').isNotEmpty ? label.spec! : '';
|
||||
final seriesVal = (label.series ?? '').isNotEmpty ? label.series! : '';
|
||||
final degSpecVal = [seriesVal, specVal].where((s) => s.isNotEmpty).join(' ');
|
||||
final degSpecVal = [seriesVal, specVal].where((s) => s.isNotEmpty).join(' ');
|
||||
final dateVal = (label.productionDate ?? '').isNotEmpty
|
||||
? (label.productionDate!.length > 10
|
||||
? label.productionDate!.substring(0, 10)
|
||||
|
||||
Reference in New Issue
Block a user