更新金属机箱3.5寸小SKU:按最新标准重新生成,数据盘组合到各SKU;配件清单新增HDD-1T/3T/4T/6T
This commit is contained in:
@@ -1,71 +1,81 @@
|
||||
---
|
||||
name: image-tools
|
||||
description: 图片处理工具集,用于检查图片信息、HTML转PNG、裁剪水印等操作。当用户需要处理产品图片、转换HTML为图片、或去除图片水印时使用此技能。
|
||||
description: 阿里云万相2.7图生图工具,用于AI生成产品主图、场景图、电商素材。Invoke when user needs to generate product images, e-commerce visuals, or AI image editing.
|
||||
---
|
||||
|
||||
# Image Tools
|
||||
# Image Tools - 万相2.7 AI图生图
|
||||
|
||||
## Overview
|
||||
使用阿里云百炼 **wan2.7-image-pro** 模型进行 AI 图生图处理,支持文生图、图生图、图片编辑。
|
||||
|
||||
提供产品图片处理相关功能,包括检查图片元信息、HTML页面截图、裁剪水印等操作。适用于产品文档和图片批量处理场景。
|
||||
## 前提条件
|
||||
|
||||
## Quick Start
|
||||
环境变量 `DASHSCOPE_API_KEY` 已配置(默认使用内置Key)
|
||||
|
||||
使用前需安装依赖:
|
||||
## 基本用法
|
||||
|
||||
```bash
|
||||
cd tools/image-tools/scripts
|
||||
npm install
|
||||
python wan_image_edit.py <提示词> <输入图片> [输出路径] [尺寸]
|
||||
```
|
||||
|
||||
## Tasks
|
||||
**参数说明**:
|
||||
- `提示词`: 描述想要的效果,支持中英文
|
||||
- `输入图片`: 产品图片路径(PNG/JPG),留空则为文生图
|
||||
- `输出路径`: 输出文件名(可选,默认 wan_output.png)
|
||||
- `尺寸`: 1K 或 2K(可选,默认 2K)
|
||||
|
||||
### 检查图片信息
|
||||
|
||||
查看图片的宽度、高度、格式等元信息:
|
||||
## 示例
|
||||
|
||||
```bash
|
||||
cd tools/image-tools/scripts
|
||||
node check-image-info.js
|
||||
# 白底产品图
|
||||
python wan_image_edit.py "keep the product, pure white background, professional e-commerce photo" "product.png" "output.png"
|
||||
|
||||
# 场景图
|
||||
python wan_image_edit.py "place product on modern desk, cozy home office" "product.png" "scene.png"
|
||||
|
||||
# 高性能风格
|
||||
python wan_image_edit.py "cyberpunk gaming setup with RGB lights, benchmark scores" "product.png" "gaming.png" "2K"
|
||||
|
||||
# 文生图(无输入图片)
|
||||
python wan_image_edit.py "futuristic NAS server in data center" "" "t2i.png"
|
||||
|
||||
# 直接在图上添加文字
|
||||
python wan_image_edit.py "keep product, add bold text: 千兆高速传输, professional tech background" "product.png" "with_text.png"
|
||||
```
|
||||
|
||||
**用途**:批量检查产品图片尺寸,确保符合规格要求。
|
||||
## 可用尺寸
|
||||
|
||||
### HTML 转 PNG
|
||||
| 尺寸 | 分辨率 | 适用场景 |
|
||||
|-----|-------|---------|
|
||||
| 1K | 1024x1024 | 快速预览、轮播图 |
|
||||
| 2K | 2048x2048 | 主图、海报(推荐)|
|
||||
|
||||
将HTML文件转换为PNG图片截图:
|
||||
## 代码调用
|
||||
|
||||
```bash
|
||||
cd tools/image-tools/scripts
|
||||
node convert-html-to-png.js
|
||||
```python
|
||||
from wan_image_edit import wan_image_edit
|
||||
|
||||
# 基础调用
|
||||
wan_image_edit(
|
||||
prompt="keep the product, white background",
|
||||
image_path="product.png",
|
||||
output_path="output.png",
|
||||
size="2K"
|
||||
)
|
||||
|
||||
# 批量生成多张
|
||||
styles = [
|
||||
("white bg", "product.png", "white.png"),
|
||||
("cyberpunk", "product.png", "cyber.png"),
|
||||
("data center", "product.png", "datacenter.png"),
|
||||
]
|
||||
for prompt, img, out in styles:
|
||||
wan_image_edit(prompt, img, out)
|
||||
```
|
||||
|
||||
**用途**:将产品配置清单HTML转换为PNG图片,用于产品展示。
|
||||
## 提示词技巧
|
||||
|
||||
### 裁剪水印
|
||||
|
||||
裁剪图片底部水印区域(默认裁剪底部300px):
|
||||
|
||||
```bash
|
||||
cd tools/image-tools/scripts
|
||||
node remove-watermark.js
|
||||
```
|
||||
|
||||
**用途**:批量处理产品图片,去除底部水印。
|
||||
|
||||
## Configuration
|
||||
|
||||
脚本默认处理路径为 `产品/飞牛 NAS/fyd-亚克力机箱 - 单/详情` 目录。如需修改:
|
||||
|
||||
- **check-image-info.js**: 修改 `imageDir` 变量
|
||||
- **convert-html-to-png.js**: 修改 `detailDir` 变量及文件过滤条件
|
||||
- **remove-watermark.js**: 修改 `imageDir` 和 `CROP_BOTTOM_HEIGHT` 常量
|
||||
|
||||
## Resources
|
||||
|
||||
### scripts/
|
||||
|
||||
- `check-image-info.js` - 图片信息检查脚本
|
||||
- `convert-html-to-png.js` - HTML转PNG截图脚本
|
||||
- `remove-watermark.js` - 水印裁剪脚本
|
||||
- `package.json` - Node.js 依赖配置
|
||||
- **保持产品**: "keep the product", "retain the original product"
|
||||
- **背景**: "white background", "modern office", "data center"
|
||||
- **风格**: "cyberpunk", "minimalist", "professional"
|
||||
- **氛围**: "dramatic lighting", "warm tones", "neon lights"
|
||||
- **添加文字**: "add bold text: 千兆高速传输"
|
||||
@@ -1,27 +0,0 @@
|
||||
const sharp = require('sharp');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
async function checkImageInfo() {
|
||||
const imageDir = path.join(__dirname, '产品', '飞牛 NAS', 'fyd-亚克力机箱 - 单', '详情', 'image');
|
||||
|
||||
const imageFiles = fs.readdirSync(imageDir).filter(file => file.endsWith('.jpg'));
|
||||
|
||||
console.log('📸 图片信息检查\n');
|
||||
|
||||
for (const imageFile of imageFiles) {
|
||||
const imagePath = path.join(imageDir, imageFile);
|
||||
const metadata = await sharp(imagePath).metadata();
|
||||
|
||||
console.log(`${imageFile}:`);
|
||||
console.log(` 宽度: ${metadata.width}px`);
|
||||
console.log(` 高度: ${metadata.height}px`);
|
||||
console.log(` 格式: ${metadata.format}`);
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
|
||||
checkImageInfo().catch(error => {
|
||||
console.error('💥 检查过程出错:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
async function convertHtmlToPng() {
|
||||
console.log('🚀 启动 HTML 转 PNG 转换工具...\n');
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.setViewport({ width: 1000, height: 1000 });
|
||||
|
||||
const detailDir = 'G:\\stonelan-workspace\\membank\\产品\\Linux主机\\详情';
|
||||
|
||||
const htmlFiles = fs.readdirSync(detailDir)
|
||||
.filter(file => file.endsWith('.html'));
|
||||
|
||||
console.log(`📁 找到 ${htmlFiles.length} 个 HTML 文件需要转换\n`);
|
||||
|
||||
for (const htmlFile of htmlFiles) {
|
||||
try {
|
||||
const htmlPath = path.join(detailDir, htmlFile);
|
||||
const pngFile = htmlFile.replace('.html', '.png');
|
||||
const pngPath = path.join(detailDir, pngFile);
|
||||
|
||||
console.log(`📄 正在转换: ${htmlFile}`);
|
||||
|
||||
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
|
||||
await page.goto(fileUrl, {
|
||||
waitUntil: 'networkidle0',
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
await page.screenshot({
|
||||
path: pngPath,
|
||||
fullPage: true,
|
||||
type: 'png'
|
||||
});
|
||||
|
||||
console.log(`✅ 已生成: ${pngFile}\n`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 转换失败 ${htmlFile}: ${error.message}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
console.log('✨ 所有转换任务已完成!');
|
||||
}
|
||||
|
||||
convertHtmlToPng().catch(error => {
|
||||
console.error('💥 转换过程出错:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,60 +0,0 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
async function convertHtmlToPng() {
|
||||
console.log('🚀 启动主图 HTML 转 PNG 转换工具...\n');
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
// 主图尺寸 800x800
|
||||
await page.setViewport({ width: 1000, height: 1000 });
|
||||
|
||||
const mainImageDir = 'G:\\stonelan-workspace\\membank\\产品\\飞牛 NAS\\fyd-亚克力机箱 - 单\\主图';
|
||||
|
||||
const htmlFiles = fs.readdirSync(mainImageDir)
|
||||
.filter(file => file.endsWith('.html') && file.includes('主图'));
|
||||
|
||||
console.log(`📁 找到 ${htmlFiles.length} 个主图 HTML 文件需要转换\n`);
|
||||
|
||||
for (const htmlFile of htmlFiles) {
|
||||
try {
|
||||
const htmlPath = path.join(mainImageDir, htmlFile);
|
||||
const pngFile = htmlFile.replace('.html', '.png');
|
||||
const pngPath = path.join(mainImageDir, pngFile);
|
||||
|
||||
console.log(`📄 正在转换: ${htmlFile}`);
|
||||
|
||||
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
|
||||
await page.goto(fileUrl, {
|
||||
waitUntil: 'networkidle0',
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
await page.screenshot({
|
||||
path: pngPath,
|
||||
fullPage: false,
|
||||
type: 'png',
|
||||
clip: { x: 0, y: 0, width: 1000, height: 1000 }
|
||||
});
|
||||
|
||||
console.log(`✅ 已生成: ${pngFile}\n`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 转换失败 ${htmlFile}: ${error.message}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
console.log('✨ 所有主图转换任务已完成!');
|
||||
}
|
||||
|
||||
convertHtmlToPng().catch(error => {
|
||||
console.error('💥 转换过程出错:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
1666
.trae/skills/image-tools/scripts/package-lock.json
generated
1666
.trae/skills/image-tools/scripts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "membank",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@gitee.com:xiongmaojames/membank.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"puppeteer": "^24.40.0",
|
||||
"sharp": "^0.34.5"
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
产品图片抠图工具
|
||||
使用rembg库自动去除图片背景
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
from rembg import remove
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
print("Missing dependencies, installing...")
|
||||
os.system("pip install rembg pillow")
|
||||
from rembg import remove
|
||||
from PIL import Image
|
||||
|
||||
def remove_background(input_path, output_path):
|
||||
"""
|
||||
去除图片背景
|
||||
"""
|
||||
try:
|
||||
print(f"Processing: {input_path}")
|
||||
|
||||
# 打开原始图片
|
||||
with open(input_path, 'rb') as input_file:
|
||||
input_data = input_file.read()
|
||||
|
||||
# 去除背景
|
||||
output_data = remove(input_data)
|
||||
|
||||
# 保存结果
|
||||
with open(output_path, 'wb') as output_file:
|
||||
output_file.write(output_data)
|
||||
|
||||
print(f"Saved: {output_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 产品图片路径
|
||||
image_dir = r"g:\stonelan-workspace\membank\产品\飞牛 NAS\fyd-亚克力机箱 - 单\image"
|
||||
|
||||
# 要处理的图片
|
||||
input_image = os.path.join(image_dir, "正面.jpg")
|
||||
output_image = os.path.join(image_dir, "正面_抠图.png")
|
||||
|
||||
# 检查文件是否存在
|
||||
if not os.path.exists(input_image):
|
||||
print(f"File not found: {input_image}")
|
||||
sys.exit(1)
|
||||
|
||||
# 执行抠图
|
||||
success = remove_background(input_image, output_image)
|
||||
|
||||
if success:
|
||||
print(f"\nBackground removal completed!")
|
||||
print(f"Original: {input_image}")
|
||||
print(f"Result: {output_image}")
|
||||
else:
|
||||
print("\nBackground removal failed!")
|
||||
sys.exit(1)
|
||||
@@ -1,51 +0,0 @@
|
||||
const sharp = require('sharp');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const CROP_BOTTOM_HEIGHT = 300;
|
||||
|
||||
async function removeWatermark() {
|
||||
console.log('🖼️ 开始裁剪图片水印...\n');
|
||||
|
||||
const imageDir = path.join(__dirname, '产品', '飞牛 NAS', 'fyd-亚克力机箱 - 单', '详情', 'image');
|
||||
|
||||
const backupDir = path.join(imageDir, 'backup');
|
||||
|
||||
const imageFiles = fs.readdirSync(backupDir).filter(file => file.endsWith('.jpg'));
|
||||
|
||||
console.log(`📸 找到 ${imageFiles.length} 张图片需要处理\n`);
|
||||
console.log(`✂️ 裁剪设置: 从底部裁剪 ${CROP_BOTTOM_HEIGHT}px\n`);
|
||||
|
||||
for (const imageFile of imageFiles) {
|
||||
try {
|
||||
const backupPath = path.join(backupDir, imageFile);
|
||||
const imagePath = path.join(imageDir, imageFile);
|
||||
|
||||
console.log(`📄 正在处理: ${imageFile}`);
|
||||
|
||||
const metadata = await sharp(backupPath).metadata();
|
||||
|
||||
const newHeight = metadata.height - CROP_BOTTOM_HEIGHT;
|
||||
|
||||
await sharp(backupPath)
|
||||
.extract({
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: metadata.width,
|
||||
height: newHeight
|
||||
})
|
||||
.toFile(imagePath);
|
||||
|
||||
console.log(` ✅ 已裁剪: ${metadata.width}x${metadata.height} -> ${metadata.width}x${newHeight}\n`);
|
||||
} catch (error) {
|
||||
console.error(` ❌ 处理失败 ${imageFile}: ${error.message}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✨ 所有图片处理完成!');
|
||||
}
|
||||
|
||||
removeWatermark().catch(error => {
|
||||
console.error('💥 处理过程出错:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
async function convertMainImageToPng() {
|
||||
console.log('🎨 启动主图渲染工具...\n');
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.setViewport({ width: 800, height: 800 });
|
||||
|
||||
const mainImageDir = 'G:\\stonelan-workspace\\membank\\产品\\飞牛 NAS\\fyd-亚克力机箱 - 单\\主图';
|
||||
|
||||
const htmlFiles = fs.readdirSync(mainImageDir)
|
||||
.filter(file => file.endsWith('.html'));
|
||||
|
||||
console.log(`📁 找到 ${htmlFiles.length} 个主图HTML文件需要渲染\n`);
|
||||
|
||||
for (const htmlFile of htmlFiles) {
|
||||
try {
|
||||
const htmlPath = path.join(mainImageDir, htmlFile);
|
||||
const pngFile = htmlFile.replace('.html', '.png');
|
||||
const pngPath = path.join(mainImageDir, pngFile);
|
||||
|
||||
console.log(`📄 正在渲染: ${htmlFile}`);
|
||||
|
||||
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
|
||||
await page.goto(fileUrl, {
|
||||
waitUntil: 'networkidle0',
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
await page.screenshot({
|
||||
path: pngPath,
|
||||
fullPage: true,
|
||||
type: 'png'
|
||||
});
|
||||
|
||||
console.log(`✅ 已生成: ${pngFile}\n`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 渲染失败 ${htmlFile}: ${error.message}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
console.log('✨ 所有主图渲染完成!');
|
||||
}
|
||||
|
||||
convertMainImageToPng().catch(error => {
|
||||
console.error('💥 渲染过程出错:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
123
.trae/skills/image-tools/scripts/wan_image_edit.py
Normal file
123
.trae/skills/image-tools/scripts/wan_image_edit.py
Normal file
@@ -0,0 +1,123 @@
|
||||
import os
|
||||
import sys
|
||||
import base64
|
||||
import mimetypes
|
||||
import requests
|
||||
from urllib.request import urlretrieve
|
||||
|
||||
API_KEY = os.getenv("DASHSCOPE_API_KEY", "")
|
||||
DEFAULT_API_KEY = "sk-ef591b52e48840c6a63899c8901a9428"
|
||||
if not API_KEY:
|
||||
API_KEY = DEFAULT_API_KEY
|
||||
print(f"使用默认API Key (前8位): {DEFAULT_API_KEY[:8]}...")
|
||||
|
||||
def encode_image(file_path):
|
||||
mime_type, _ = mimetypes.guess_type(file_path)
|
||||
if not mime_type:
|
||||
mime_type = "image/png"
|
||||
with open(file_path, "rb") as f:
|
||||
return f"data:{mime_type};base64,{base64.b64encode(f.read()).decode('utf-8')}"
|
||||
|
||||
def wan_image_edit(
|
||||
prompt,
|
||||
image_path,
|
||||
output_path="wan_output.png",
|
||||
size="2K",
|
||||
negative_prompt="",
|
||||
n=1,
|
||||
prompt_extend=True
|
||||
):
|
||||
"""
|
||||
万相2.7图生图 - 基于输入图片和提示词生成新图
|
||||
|
||||
参数:
|
||||
prompt: 提示词,描述想要的效果
|
||||
image_path: 输入图片路径
|
||||
output_path: 输出图片路径
|
||||
size: 输出尺寸 ("2K" 或 "1K")
|
||||
negative_prompt: 反向提示词
|
||||
n: 生成数量 (1-4)
|
||||
prompt_extend: 是否启用提示词扩展
|
||||
|
||||
示例:
|
||||
python wan_image_edit.py "keep the product, white background" "product.png" "output.png"
|
||||
"""
|
||||
print(f"提示词: {prompt}")
|
||||
print(f"输入图片: {image_path}")
|
||||
print(f"输出路径: {output_path}")
|
||||
print(f"尺寸: {size}")
|
||||
|
||||
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {API_KEY}"
|
||||
}
|
||||
|
||||
content = [{"text": prompt}]
|
||||
if image_path:
|
||||
content.append({"image": encode_image(image_path)})
|
||||
|
||||
payload = {
|
||||
"model": "wan2.7-image-pro",
|
||||
"input": {
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": content
|
||||
}]
|
||||
},
|
||||
"parameters": {
|
||||
"size": size,
|
||||
"n": n,
|
||||
"prompt_extend": prompt_extend,
|
||||
"watermark": False
|
||||
}
|
||||
}
|
||||
|
||||
if negative_prompt:
|
||||
payload["parameters"]["negative_prompt"] = negative_prompt
|
||||
|
||||
try:
|
||||
resp = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
result = resp.json()
|
||||
|
||||
if resp.status_code == 200 and "output" in result:
|
||||
choices = result["output"].get("choices", [])
|
||||
if choices:
|
||||
for idx, choice in enumerate(choices):
|
||||
content_list = choice.get("message", {}).get("content", [])
|
||||
for item in content_list:
|
||||
if item.get("type") == "image":
|
||||
image_url = item["image"]
|
||||
out_path = output_path if n == 1 else output_path.replace(".png", f"_{idx}.png").replace(".jpg", f"_{idx}.jpg")
|
||||
urlretrieve(image_url, out_path)
|
||||
print(f"成功: {out_path}")
|
||||
return True
|
||||
else:
|
||||
msg = result.get("message", str(result))
|
||||
print(f"失败: {msg}")
|
||||
return False
|
||||
|
||||
except requests.exceptions.Timeout:
|
||||
print("请求超时,请重试")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"错误: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print("用法: python wan_image_edit.py <提示词> <输入图片> [输出路径] [尺寸]")
|
||||
print("")
|
||||
print("示例:")
|
||||
print(' python wan_image_edit.py "keep the product, white background" "product.png" "output.png"')
|
||||
print(' python wan_image_edit.py "cyberpunk style" "product.png" "output.png" "2K"')
|
||||
print("")
|
||||
print("尺寸选项: 1K (1024x1024), 2K (2048x2048)")
|
||||
sys.exit(1)
|
||||
|
||||
prompt = sys.argv[1]
|
||||
image_path = sys.argv[2]
|
||||
output_path = sys.argv[3] if len(sys.argv) > 3 else "wan_output.png"
|
||||
size = sys.argv[4] if len(sys.argv) > 4 else "2K"
|
||||
|
||||
wan_image_edit(prompt, image_path, output_path, size)
|
||||
@@ -1,88 +0,0 @@
|
||||
---
|
||||
name: product-detail-designer
|
||||
description: 设计电商产品的详情页。当用户需要为产品生成详情页HTML、批量渲染SKU页面、或处理产品图片时使用此技能。
|
||||
---
|
||||
|
||||
# Product Detail Designer
|
||||
|
||||
## 概述
|
||||
|
||||
根据产品的 SKU 和配置规范,生成对应的产品详情页 HTML,并转换为 PNG 图片。自动化处理从配置数据到最终展示页面的完整流程。
|
||||
|
||||
## 使用场景
|
||||
|
||||
- 有产品种类或 SKU 变化,需要重新生成详情页
|
||||
- 有产品图片变化,需要更新详情页
|
||||
- 需要批量为多个 SKU 生成对应的详情页
|
||||
|
||||
## 工作流程
|
||||
|
||||
### 步骤 1: 读取 SKU 配置
|
||||
|
||||
从 `产品` 目录下找到对应的产品目录
|
||||
|
||||
|
||||
### 步骤 2: 生成 HTML 文件
|
||||
|
||||
#### 详情页组成部分
|
||||
- 购买须知 (不需要二级标题)
|
||||
- 亚克力机箱需要自己组装,店铺会提供安装视频
|
||||
- 受成本限制,产品无法做到十全十美,完美主义者慎拍
|
||||
- 配置清单
|
||||
1. 以表格的形式展示
|
||||
2. cpu 内存 系统盘,网口,
|
||||
3. 内存体现容量和ddr3,内存插槽数量
|
||||
4. 支持硬盘数量,尺寸, 容量
|
||||
- 使用场景
|
||||
1. 手机扩容
|
||||
照片视频备份,自动同步,远程同步
|
||||
2. 小型办公/团队协作
|
||||
远程文件访问,多人协作,权限分级,文件共享,文件归档,在线编辑
|
||||
3. 监控视频存储
|
||||
小米摄像头存储,onvif协议支持
|
||||
4. 家庭影院打造
|
||||
流畅播放4k视频,硬解4k
|
||||
5. 微信聊天记录备份
|
||||
支持微信聊天记录备份
|
||||
6. 远程访问
|
||||
远程访问照片,视频,文件等内容
|
||||
- 产品特点
|
||||
1. 体积小,容量大,功能强
|
||||
2. 低耗静音
|
||||
3. 支持远程访问
|
||||
4. 支持wifi联网
|
||||
5. 来电自启
|
||||
6. 远程开关机
|
||||
- 产品实拍图
|
||||
- 飞牛系统截图
|
||||
- 配件清单
|
||||
- 包装展示
|
||||
- 常见问题
|
||||
|
||||
|
||||
- 严格按照详情页组成生成详情页,多余的删除掉
|
||||
- 需要用的产品图片,都放在对应产品目录的image目录下
|
||||
- html 按照宽1500的分辨率生成
|
||||
- 一个产品有多个sku,但一个产品只需要一个详情页,不需要为每个sku生成详情页
|
||||
- 详情页放到每个产品对应的`详情`目录下
|
||||
- 配色采用绿色清晰的风格
|
||||
|
||||
|
||||
|
||||
|
||||
### 步骤 3: HTML 转 PNG 图片
|
||||
|
||||
使用 `image-tools` 技能的 `convert-html-to-png.js` 脚本:
|
||||
|
||||
```bash
|
||||
cd ../image-tools/scripts
|
||||
node convert-html-to-png.js
|
||||
```
|
||||
|
||||
### 步骤 4: 裁剪图片水印
|
||||
|
||||
使用 `image-tools` 技能的 `remove-watermark.js` 脚本:
|
||||
|
||||
```bash
|
||||
node remove-watermark.js
|
||||
```
|
||||
@@ -1,133 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// SKU 字段映射表
|
||||
const FIELD_MAP = {
|
||||
'{{PRODUCT_NAME}}': 'productName',
|
||||
'{{PRODUCT_SUBTITLE}}': 'productSubtitle',
|
||||
'{{SKU_CODE}}': 'skuCode',
|
||||
'{{CPU}}': 'cpu',
|
||||
'{{MEMORY}}': 'memory',
|
||||
'{{STORAGE}}': 'storage',
|
||||
'{{CASE}}': 'case',
|
||||
'{{POWER}}': 'power',
|
||||
'{{CABLE}}': 'cable',
|
||||
'{{BATTERY}}': 'battery',
|
||||
'{{ETHERNET_CABLE}}': 'ethernetCable',
|
||||
'{{SHIPPING_FEE}}': 'shippingFee',
|
||||
'{{PACKAGING_FEE}}': 'packagingFee',
|
||||
'{{ASSEMBLY_FEE}}': 'assemblyFee',
|
||||
'{{TOTAL_COST}}': 'totalCost',
|
||||
'{{RETAIL_PRICE}}': 'retailPrice',
|
||||
'{{NOTE}}': 'note'
|
||||
};
|
||||
|
||||
// 从 SKU markdown 文件解析字段
|
||||
function parseSkuFile(skuPath) {
|
||||
const content = fs.readFileSync(skuPath, 'utf-8');
|
||||
const data = {};
|
||||
|
||||
content.split('\n').forEach(line => {
|
||||
// 匹配格式: | **字段名** | 值 | 价格 |
|
||||
const match = line.match(/\|\s*\*\*(.+?)\*\*\s*\|\s*(.+?)\s*\|/);
|
||||
if (match) {
|
||||
const [, fieldName, value] = match;
|
||||
data[fieldName.trim()] = value.trim();
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// 将 SKU 数据映射为模板变量
|
||||
function mapSkuToVariables(skuData) {
|
||||
const cpu = skuData['CPU'] || '';
|
||||
const memory = skuData['内存'] || '';
|
||||
const storage = skuData['系统盘'] || '';
|
||||
const caseType = skuData['机箱'] || '';
|
||||
|
||||
return {
|
||||
'{{PRODUCT_NAME}}': `飞牛NAS ${caseType}`,
|
||||
'{{PRODUCT_SUBTITLE}}': '亚克力机箱 透明系列',
|
||||
'{{SKU_CODE}}': skuData['产品型号'] || '',
|
||||
'{{CPU}}': cpu,
|
||||
'{{MEMORY}}': memory,
|
||||
'{{STORAGE}}': storage,
|
||||
'{{CASE}}': caseType,
|
||||
'{{POWER}}': skuData['电源'] || '电源-60W',
|
||||
'{{CABLE}}': skuData['硬盘线'] || '硬盘线-单',
|
||||
'{{BATTERY}}': skuData['电池'] || '电池',
|
||||
'{{ETHERNET_CABLE}}': skuData['网线'] || '网线',
|
||||
'{{SHIPPING_FEE}}': skuData['运费']?.replace('¥', '') || '10',
|
||||
'{{PACKAGING_FEE}}': skuData['包装费']?.replace('¥', '') || '5',
|
||||
'{{ASSEMBLY_FEE}}': skuData['装机费']?.replace('¥', '') || '10',
|
||||
'{{TOTAL_COST}}': skuData['总成本']?.replace('¥', '') || '0',
|
||||
'{{RETAIL_PRICE}}': skuData['建议零售价']?.replace('¥', '') || '0',
|
||||
'{{NOTE}}': skuData['备注'] || ''
|
||||
};
|
||||
}
|
||||
|
||||
// 渲染 HTML 模板
|
||||
function renderTemplate(templatePath, variables) {
|
||||
let html = fs.readFileSync(templatePath, 'utf-8');
|
||||
|
||||
Object.entries(variables).forEach(([placeholder, value]) => {
|
||||
html = html.split(placeholder).join(value);
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
// 主函数:生成亚克力单详情页
|
||||
function generateDetailPages(skuFilePath, outputDir) {
|
||||
const skuData = parseSkuFile(skuFilePath);
|
||||
const variables = mapSkuToVariables(skuData);
|
||||
|
||||
const skuCode = variables['{{SKU_CODE}}'];
|
||||
const productType = '亚克力单';
|
||||
const templateDir = path.join(__dirname, '..', 'assets', 'templates', productType);
|
||||
|
||||
// 创建输出目录
|
||||
const productOutputDir = path.join(outputDir, skuCode);
|
||||
if (!fs.existsSync(productOutputDir)) {
|
||||
fs.mkdirSync(productOutputDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 模板列表
|
||||
const templates = [
|
||||
'配置清单-1.html',
|
||||
'配置清单-2.html',
|
||||
'商品卖点.html',
|
||||
'功能描述.html',
|
||||
'使用场景.html',
|
||||
'配件清单.html',
|
||||
'包装展示.html'
|
||||
];
|
||||
|
||||
templates.forEach(template => {
|
||||
const templatePath = path.join(templateDir, template);
|
||||
if (!fs.existsSync(templatePath)) {
|
||||
console.log(`跳过(模板不存在): ${template}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const html = renderTemplate(templatePath, variables);
|
||||
const outputPath = path.join(productOutputDir, template);
|
||||
fs.writeFileSync(outputPath, html, 'utf-8');
|
||||
console.log(`已生成: ${outputPath}`);
|
||||
});
|
||||
|
||||
console.log(`\n完成!共生成 ${templates.length} 个 HTML 文件到: ${productOutputDir}`);
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
const skuFile = process.argv[2];
|
||||
const outputDir = process.argv[3] || path.join(__dirname, '..', '..', '..', '产品', '飞牛 NAS', 'fyd-亚克力机箱 - 单', '详情');
|
||||
|
||||
if (!skuFile) {
|
||||
console.log('用法: node render.js <sku文件路径> [输出目录]');
|
||||
console.log('示例: node render.js ../产品/飞牛NAS/fyd-亚克力机箱 - 单/sku/亚克力-单-AMD-A4-2G-16G.md');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
generateDetailPages(skuFile, outputDir);
|
||||
@@ -1,49 +0,0 @@
|
||||
---
|
||||
name: product-main-image
|
||||
description: 设计电商产品的主图。当用户需要为产品生成主图图片或海报时使用此技能。
|
||||
---
|
||||
|
||||
# 商品主图设计
|
||||
|
||||
## 概述
|
||||
|
||||
-为每个产品生成主图图片
|
||||
-主图图片放到每个产品对应的`主图`目录下
|
||||
## 使用场景
|
||||
|
||||
- 有产品主图需要更新
|
||||
|
||||
## 工作流程
|
||||
|
||||
### 步骤 1: 准备素材
|
||||
- 根据产品详情页,归纳出主图要展示的信息
|
||||
|
||||
- 可以使用产品目录下`image`目录中的图片作为素材
|
||||
|
||||
|
||||
|
||||
### 步骤 2: 设计主图html
|
||||
- 主图尺寸:1000*1000
|
||||
- 一个主图一个html
|
||||
|
||||
|
||||
### 步骤 3: 导出图片
|
||||
|
||||
使用 `image-tools` 技能的 `convert-html-to-png.js` 脚本:
|
||||
|
||||
## 主图规范
|
||||
|
||||
|
||||
|
||||
## 配色参考
|
||||
|
||||
|
||||
|
||||
## 字体规范
|
||||
|
||||
|
||||
|
||||
## 示例模板
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,68 @@ description: 设计电商产品的 SKU 配置。当用户需要为产品生成 S
|
||||
## Overview
|
||||
|
||||
- 为每个产品生成 SKU 配置
|
||||
- 将 SKU 配置放到每个产品对应的 `SKU` 目录下
|
||||
- 将 SKU 配置放到每个产品对应的 `sku` 目录下(小写)
|
||||
|
||||
## 产品目录组织原则
|
||||
|
||||
每个产品目录必须遵循以下标准结构:
|
||||
|
||||
```
|
||||
产品名称/
|
||||
├── 商品标题.md # 电商商品标题关键词,一行文本
|
||||
├── sku/ # SKU配置目录(小写),每个SKU一个独立.md文件
|
||||
│ ├── [机箱]-[单/双]-[CPU]-[内存]-[硬盘].md
|
||||
│ └── ...
|
||||
├── image/ # 产品实拍图片(原图)
|
||||
├── 主图/ # 电商主图(html + png)
|
||||
│ ├── 主图1-xxx.html
|
||||
│ ├── 主图1-xxx.png
|
||||
│ └── ...
|
||||
└── 详情/ # 商品详情页(html + png)
|
||||
├── xxx_详情页.html
|
||||
└── xxx_详情页.png
|
||||
```
|
||||
|
||||
### SKU 文件命名规则
|
||||
- 文件名格式:`[机箱简称]-[单/双]-[CPU型号]-[内存容量]-[硬盘容量].md`
|
||||
- "单/双"指该机箱版本对应的SATA口数(单=单SATA口,双=双SATA口)
|
||||
- 示例:`2.5金-单-N2840-4G-32G.md`、`3.5大-双-1037U-4G-32G.md`、`3.5小-单-N2930-4G-32G.md`、`3.5小-双-1037U-4G-32G.md`
|
||||
|
||||
### 机箱与CPU匹配原则
|
||||
- 机箱标注"单"(单SATA口)只能配单SATA口CPU:N2840, N2930, AMD-A4, J1800, J1900, J3160, 3855U
|
||||
- 机箱标注"双"(双SATA口)只能配双SATA口CPU:1037U, 3217U, 5005U
|
||||
- 机箱标注"单/双"(如3.5寸小)支持两种SATA口,需分别生成单/双版本SKU
|
||||
|
||||
### SKU 文件内容格式
|
||||
每个SKU文件包含一个产品信息表格,字段如下:
|
||||
|
||||
```markdown
|
||||
# 产品信息
|
||||
|
||||
| 字段 | 配件名称 | 价格 |
|
||||
|------|---------|------|
|
||||
| **产品编号** | - | - |
|
||||
| **产品名称** | 飞牛NAS [产品线] [机箱] [CPU] | - |
|
||||
| **产品型号** | [机箱]-[盘位]-[CPU]-[内存]-[硬盘] | - |
|
||||
| **用途分类** | NAS | - |
|
||||
| **CPU** | [CPU型号] | ¥[价格] |
|
||||
| **内存** | D3-[容量] | ¥[价格] |
|
||||
| **系统盘** | mSATA-[容量] | ¥[价格] |
|
||||
| **机箱** | [机箱名称] | ¥[价格] |
|
||||
| **电源** | 电源-60W | ¥12 |
|
||||
| **硬盘线** | 硬盘线-单/双 | ¥4/5 |
|
||||
| **双SATA转换器** | 双SATA转换器 | ¥28 | (如需要)
|
||||
| **电池** | 电池 | ¥1 |
|
||||
| **网线** | 网线 | ¥1 |
|
||||
| **运费** | 运费 | ¥10 |
|
||||
| **包装费** | 包装费 | ¥5 |
|
||||
| **装机费** | 装机费 | ¥10 |
|
||||
| **总成本** | - | ¥[总计] |
|
||||
| **建议零售价** | - | ¥[售价] |
|
||||
| **备注** | [描述] | - |
|
||||
```
|
||||
|
||||
> 注意:双SATA转换器仅在单SATA口主板需要扩展盘位时添加
|
||||
|
||||
## SKU 编码规则
|
||||
|
||||
@@ -21,7 +82,10 @@ description: 设计电商产品的 SKU 配置。当用户需要为产品生成 S
|
||||
### 步骤1. 更新对应产品的sku,根据设计原则添加或者删除sku
|
||||
- 根据对应机箱设计原则,选择cpu,内存,硬盘
|
||||
- 按照SKU编码规则生成SKU名称
|
||||
- 将SKU配置保存到对应产品目录下的`SKU`文件夹
|
||||
- 按照产品目录组织原则,确保目录结构完整(商品标题.md、sku/、image/、主图/、详情/)
|
||||
- 每个SKU生成一个独立的.md文件,放到`sku/`目录下
|
||||
- SKU文件命名:`[机箱简称]-[单/双]-[CPU型号]-[内存容量]-[硬盘容量].md`
|
||||
- SKU文件内容按照标准产品信息表格格式填写
|
||||
|
||||
### 步骤2 计算与核对产品价格
|
||||
- 根据配件清单,计算产品价格
|
||||
@@ -32,28 +96,70 @@ description: 设计电商产品的 SKU 配置。当用户需要为产品生成 S
|
||||
- 更新产品信息到产品信息汇总表
|
||||
|
||||
|
||||
## 飞牛 NAS产设计原则
|
||||
### 3.5金属大配置原则
|
||||
- 3.5金属大,用于3盘位和4盘位,通过双sata转化器,主板单sata口就是3盘位,主板双sata口就是4盘位
|
||||
- 3.5金属大可安装cpu:j1900,j3160,i3-3217u,i3-5005u,3855u,1037u
|
||||
- 3.5金属大可安装内存和系统盘: 4G-32G,4G-64G,8G-64G,8G-128G
|
||||
### 3.5金属小配置原则
|
||||
- 3.5金属小可安装cpu:j1900,j3160,i3-3217u,i3-5005u,3855u,1037u
|
||||
- 3.5金属小,可安装一个2.5和一个3.5,配单sata口主板就是单3.5 ,双sata口主板就是 3.5+2.5
|
||||
- 3.5金属小可安装内存和系统盘: 4G-32G,4G-64G,8G-64G,8G-128G
|
||||
## 飞牛 NAS产品设计原则
|
||||
|
||||
### 基础版-金
|
||||
- 机箱与CPU对应:
|
||||
- 2.5金-单(单SATA口):amd-a4, n2840, n2930, j1800
|
||||
- 3.5金属大-双(双SATA口):1037u
|
||||
- 3.5金属小-单(单SATA口):amd-a4, n2840, n2930, j1800
|
||||
- 3.5金属小-双(双SATA口):1037u
|
||||
- 内存-硬盘: 4G-32G
|
||||
- 建议零售价: 成本+30
|
||||
|
||||
### 基础版-亚
|
||||
- 机箱与CPU对应:
|
||||
- 亚克力-双(双SATA口):1037u
|
||||
- 亚克力-单(单SATA口):amd-a4, n2840, n2930, j1800
|
||||
- 内存-硬盘: 4G-32G
|
||||
- 建议零售价: 成本+30
|
||||
|
||||
### 金属机箱3.5寸大
|
||||
- 3盘版(单SATA口CPU):3855U, J1900, J3160
|
||||
- 4盘版(双SATA口CPU):1037U, 3217U, 5005U
|
||||
- 内存硬盘可用:4G-32G, 4G-64G, 8G-64G, 8G-128G
|
||||
- 建议零售价:成本+50
|
||||
|
||||
### 金属机箱3.5寸小
|
||||
- 3.5+2.5盘位(双SATA口):1037U
|
||||
- 内存硬盘可用:4G-32G
|
||||
- 数据盘可选 500G ,1T ,3T ,4T 6T
|
||||
- 建议零售价:成本+50
|
||||
|
||||
### 亚克力机箱-单 配置原则
|
||||
- 可安装单SATA口主板
|
||||
- 可用CPU:N2840,N2930,AMD-A4,J1900,J3160
|
||||
- 可用内存:2G-16G,2G-32G,4G-64G,4G-128G
|
||||
####
|
||||
推荐价格:
|
||||
- 可用CPU:AMD-A4,J1900,J3160
|
||||
- 可用内存:D3-2G,D3-4G
|
||||
- 可用系统盘:mSATA-16G,mSATA-32G,mSATA-64G,mSATA-128G
|
||||
#### 推荐价格:
|
||||
- 配2G内存的成本加20作为推荐售价
|
||||
- 配4G内存的成本加30作为推荐售价
|
||||
|
||||
### 亚克力机箱-双 配置原则
|
||||
- 可安装双SATA口主板
|
||||
- 可用CPU:1037U,i3-3217U,i3-5005U
|
||||
- 可用CPU:1037U,3217U,5005U
|
||||
- 可用内存:2G-16G,2G-32G,4G-64G,4G-128G,8G-128G
|
||||
|
||||
### 高性能版-亚-双-j1900
|
||||
- 使用亚克力-双机箱
|
||||
- CPU J1900(单SATA口,需双SATA转换器)
|
||||
- 内存硬盘可用:4G-32G, 4G-64G, 8G-64G, 8G-128G
|
||||
- 建议零售价:成本+50
|
||||
|
||||
### 高性能版-亚-双-j3160
|
||||
- 使用亚克力-双机箱
|
||||
- CPU J3160(单SATA口,需双SATA转换器)
|
||||
- 内存硬盘可用:4G-32G, 4G-64G, 8G-64G, 8G-128G
|
||||
- 建议零售价:成本+70
|
||||
|
||||
### 高性能-i5-i7
|
||||
- 可使用机箱:亚克力机箱-双、金属机箱3.5寸大
|
||||
- CPU i5可用:i5-2代,i5-3代,i5-4代
|
||||
- CPU i7可用:i7-2代,i7-3代,i7-4代
|
||||
- i5内存硬盘可用:4G-128G,8G-128G
|
||||
- i7内存硬盘统一:8G-128G
|
||||
- 建议零售价:成本+80
|
||||
|
||||
## win 小主机产设计原则
|
||||
- win小主机全部使用2.5存机箱
|
||||
### 龙虾盒子
|
||||
|
||||
158
.trae/skills/sku-designer/scripts/sync-prices-to-summary.js
Normal file
158
.trae/skills/sku-designer/scripts/sync-prices-to-summary.js
Normal file
@@ -0,0 +1,158 @@
|
||||
// 价格同步工具 - 将SKU文件中的价格信息同步到产品价格汇总表
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 产品目录路径
|
||||
const PRODUCTS_DIR = path.join(__dirname, '../../../../产品');
|
||||
const PRICE_SUMMARY_FILE = path.join(PRODUCTS_DIR, '产品价格汇总表.md');
|
||||
|
||||
// 读取价格汇总表内容
|
||||
function readPriceSummary() {
|
||||
return fs.readFileSync(PRICE_SUMMARY_FILE, 'utf8');
|
||||
}
|
||||
|
||||
// 写入价格汇总表内容
|
||||
function writePriceSummary(content) {
|
||||
fs.writeFileSync(PRICE_SUMMARY_FILE, content, 'utf8');
|
||||
}
|
||||
|
||||
// 递归读取所有SKU文件
|
||||
function findSkuFiles(dir) {
|
||||
const skuFiles = [];
|
||||
|
||||
function traverse(currentDir) {
|
||||
const files = fs.readdirSync(currentDir);
|
||||
|
||||
for (const file of files) {
|
||||
const fullPath = path.join(currentDir, file);
|
||||
const stat = fs.statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
traverse(fullPath);
|
||||
} else if (file.endsWith('.md') && (file.includes('-') || file.includes('openclaw'))) {
|
||||
skuFiles.push(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverse(dir);
|
||||
return skuFiles;
|
||||
}
|
||||
|
||||
// 解析SKU文件内容
|
||||
function parseSkuFile(filePath) {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
const skuData = {
|
||||
model: '',
|
||||
cost: 0,
|
||||
price: 0
|
||||
};
|
||||
|
||||
// 解析产品型号
|
||||
const modelMatch = content.match(/\*\*产品型号\*\*\s*\|\s*([^|]+)\s*\|/);
|
||||
if (modelMatch) {
|
||||
skuData.model = modelMatch[1].trim();
|
||||
} else {
|
||||
console.log(`未找到产品型号: ${filePath}`);
|
||||
}
|
||||
|
||||
// 解析总成本
|
||||
const costMatch = content.match(/\*\*总成本\*\*\s*\|\s*-\s*\|\s*¥(\d+)\s*\|/);
|
||||
if (costMatch) {
|
||||
skuData.cost = parseInt(costMatch[1]);
|
||||
} else {
|
||||
console.log(`未找到总成本: ${filePath}`);
|
||||
}
|
||||
|
||||
// 解析建议零售价
|
||||
const priceMatch = content.match(/\*\*建议零售价\*\*\s*\|\s*-\s*\|\s*¥(\d+)\s*\|/);
|
||||
if (priceMatch) {
|
||||
skuData.price = parseInt(priceMatch[1]);
|
||||
} else {
|
||||
console.log(`未找到建议零售价: ${filePath}`);
|
||||
}
|
||||
|
||||
if (skuData.model && skuData.cost && skuData.price) {
|
||||
console.log(`解析成功: ${skuData.model} - 成本: ¥${skuData.cost}, 售价: ¥${skuData.price}`);
|
||||
}
|
||||
|
||||
return skuData;
|
||||
} catch (error) {
|
||||
console.log(`解析文件失败: ${filePath}, 错误: ${error.message}`);
|
||||
return { model: '', cost: 0, price: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// 同步价格信息到汇总表
|
||||
function syncPrices() {
|
||||
console.log('开始同步SKU价格到汇总表...');
|
||||
|
||||
// 读取所有SKU文件
|
||||
const skuFiles = findSkuFiles(PRODUCTS_DIR);
|
||||
console.log(`找到 ${skuFiles.length} 个SKU文件`);
|
||||
|
||||
// 解析所有SKU文件
|
||||
const skuDataMap = new Map();
|
||||
let parsedCount = 0;
|
||||
|
||||
for (const file of skuFiles) {
|
||||
const skuData = parseSkuFile(file);
|
||||
if (skuData.model && skuData.cost && skuData.price) {
|
||||
skuDataMap.set(skuData.model, skuData);
|
||||
parsedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`解析完成 ${parsedCount} 个SKU数据`);
|
||||
|
||||
// 读取汇总表内容
|
||||
let summaryContent = readPriceSummary();
|
||||
|
||||
// 更新日期
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
summaryContent = summaryContent.replace(/更新日期:\d{4}-\d{2}-\d{2}/, `更新日期:${today}`);
|
||||
|
||||
// 逐行处理汇总表,避免一次性处理大文件
|
||||
const lines = summaryContent.split('\n');
|
||||
const updatedLines = [];
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
let updatedLine = line;
|
||||
|
||||
// 检查是否是产品行
|
||||
const modelMatch = line.match(/\|\s*\d+\s*\|\s*([^|]+)\s*\|\s*¥\d+\s*\|\s*¥\d+\s*\|\s*¥\d+\s*\|\s*\d+%\s*\|/);
|
||||
if (modelMatch) {
|
||||
const model = modelMatch[1].trim();
|
||||
const skuData = skuDataMap.get(model);
|
||||
|
||||
if (skuData) {
|
||||
const profit = skuData.price - skuData.cost;
|
||||
const profitRate = Math.round((profit / skuData.cost) * 100);
|
||||
|
||||
// 找到行中的序号
|
||||
const indexMatch = line.match(/\|\s*(\d+)\s*\|/);
|
||||
const index = indexMatch ? indexMatch[1] : '1';
|
||||
|
||||
updatedLine = `| ${index} | ${model} | ¥${skuData.cost} | ¥${skuData.price} | ¥${profit} | ${profitRate}% |`;
|
||||
updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
updatedLines.push(updatedLine);
|
||||
}
|
||||
|
||||
// 重新组合内容
|
||||
const updatedContent = updatedLines.join('\n');
|
||||
|
||||
// 写入更新后的汇总表
|
||||
writePriceSummary(updatedContent);
|
||||
|
||||
console.log(`同步完成!更新了 ${updatedCount} 个产品的价格信息`);
|
||||
console.log(`价格汇总表已更新,更新日期:${today}`);
|
||||
}
|
||||
|
||||
// 执行同步
|
||||
syncPrices();
|
||||
Reference in New Issue
Block a user