主要功能: - 修改RequirementModal支持12个订单班选择 - 添加OrderClassIconMap图标映射组件 - Store中添加selectedOrderClass状态管理 - WorkflowPage支持传递orderClass参数 - web_result添加URL参数切换功能 - 创建order-class-handler.js动态处理页面主题 技术改进: - 创建软链接关联订单班数据目录 - 生成wenlu.json和food.json数据结构 - 删除重复的web_result目录 - 添加测试页面test-order-class.html 影响范围: - 展会策划系统现支持12个订单班 - 结果展示页面自动适配不同订单班主题 - 用户可选择不同行业生成对应方案 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
267 lines
9.4 KiB
Python
267 lines
9.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
图片整理脚本
|
|
功能:
|
|
1. 统一图片命名格式
|
|
2. 更新Markdown文件中的图片引用
|
|
3. 生成图片映射文件
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Dict, List, Tuple
|
|
|
|
class ImageOrganizer:
|
|
def __init__(self, base_path: str):
|
|
self.base_path = Path(base_path)
|
|
self.image_mapping = {} # 旧名称 -> 新名称的映射
|
|
|
|
def clean_filename(self, filename: str, prefix: str = "", index: int = 1) -> str:
|
|
"""
|
|
清理文件名,生成规范的命名
|
|
规则:
|
|
- Whisk_开头的文件 -> 设计图_01.jpg
|
|
- 数字开头的文件 -> 展示图_01.jpg
|
|
- 中文名保留但规范化
|
|
"""
|
|
name = Path(filename).stem
|
|
ext = Path(filename).suffix.lower()
|
|
|
|
# 统一扩展名
|
|
if ext == '.jpeg':
|
|
ext = '.jpg'
|
|
|
|
# 根据原始文件名特征分类
|
|
if name.startswith('Whisk_'):
|
|
# AI生成的设计图
|
|
new_name = f"设计图_{index:02d}{ext}"
|
|
elif name[0].isdigit():
|
|
# 数字开头的展示图
|
|
desc = name.split('.')[-1] if '.' in name else ""
|
|
new_name = f"展示图_{index:02d}_{desc}{ext}" if desc else f"展示图_{index:02d}{ext}"
|
|
elif name in ['博览会', '展会内部参观', '展馆布置图', '签到']:
|
|
# 保留有意义的中文名
|
|
new_name = f"{name}{ext}"
|
|
else:
|
|
# 其他情况
|
|
new_name = f"{prefix}_{index:02d}{ext}" if prefix else f"图片_{index:02d}{ext}"
|
|
|
|
return new_name
|
|
|
|
def organize_images(self, order_class: str):
|
|
"""整理指定订单班的图片"""
|
|
image_dir = self.base_path / order_class / "notion文稿" / "image"
|
|
|
|
if not image_dir.exists():
|
|
print(f"目录不存在: {image_dir}")
|
|
return
|
|
|
|
# 获取所有图片文件
|
|
images = list(image_dir.glob("*.[jJ][pP][gG]")) + \
|
|
list(image_dir.glob("*.[jJ][pP][eE][gG]")) + \
|
|
list(image_dir.glob("*.[pP][nN][gG]"))
|
|
|
|
if not images:
|
|
print(f"没有找到图片: {image_dir}")
|
|
return
|
|
|
|
print(f"\n处理 {order_class} 的 {len(images)} 张图片...")
|
|
|
|
# 分类计数器
|
|
design_count = 0
|
|
display_count = 0
|
|
other_count = 0
|
|
|
|
# 处理每张图片
|
|
for img_path in sorted(images):
|
|
old_name = img_path.name
|
|
|
|
# 判断类型并生成新名称
|
|
if 'Whisk' in old_name:
|
|
design_count += 1
|
|
new_name = self.clean_filename(old_name, "设计图", design_count)
|
|
elif old_name[0].isdigit():
|
|
display_count += 1
|
|
new_name = self.clean_filename(old_name, "展示图", display_count)
|
|
else:
|
|
# 保留原有的中文名称
|
|
new_name = self.clean_filename(old_name)
|
|
|
|
# 如果名称有变化,记录映射关系
|
|
if old_name != new_name:
|
|
self.image_mapping[old_name] = new_name
|
|
|
|
# 重命名文件
|
|
new_path = img_path.parent / new_name
|
|
if not new_path.exists():
|
|
shutil.move(str(img_path), str(new_path))
|
|
print(f" 重命名: {old_name} -> {new_name}")
|
|
|
|
def update_markdown_references(self, order_class: str):
|
|
"""更新Markdown文件中的图片引用"""
|
|
md_dir = self.base_path / order_class / "notion文稿"
|
|
|
|
# 查找所有Markdown文件
|
|
md_files = list(md_dir.glob("*.md"))
|
|
|
|
for md_file in md_files:
|
|
content = md_file.read_text(encoding='utf-8')
|
|
original_content = content
|
|
|
|
# 更新图片引用
|
|
for old_name, new_name in self.image_mapping.items():
|
|
# 匹配各种可能的图片引用格式
|
|
patterns = [
|
|
f"!\\[([^\\]]*)\\]\\({re.escape(old_name)}\\)", # 
|
|
f"!\\[([^\\]]*)\\]\\(\\./image/{re.escape(old_name)}\\)", # 
|
|
f"!\\[([^\\]]*)\\]\\(image/{re.escape(old_name)}\\)", # 
|
|
]
|
|
|
|
for pattern in patterns:
|
|
# 保持原有的路径结构,只替换文件名
|
|
if './image/' in pattern:
|
|
replacement = f""
|
|
elif 'image/' in pattern:
|
|
replacement = f""
|
|
else:
|
|
replacement = f""
|
|
|
|
content = re.sub(pattern, replacement, content)
|
|
|
|
# 如果内容有变化,保存文件
|
|
if content != original_content:
|
|
md_file.write_text(content, encoding='utf-8')
|
|
print(f" 更新Markdown: {md_file.name}")
|
|
|
|
def update_html_references(self):
|
|
"""更新HTML文件中的图片引用"""
|
|
# 更新web_result中的HTML文件
|
|
web_result_path = self.base_path.parent.parent / "web_frontend" / "web_result"
|
|
|
|
if not web_result_path.exists():
|
|
return
|
|
|
|
html_files = list(web_result_path.glob("*.html")) + \
|
|
list((web_result_path / "pages").glob("*.html"))
|
|
|
|
for html_file in html_files:
|
|
content = html_file.read_text(encoding='utf-8')
|
|
original_content = content
|
|
|
|
# 更新图片引用
|
|
for old_name, new_name in self.image_mapping.items():
|
|
# 匹配HTML中的图片引用
|
|
patterns = [
|
|
f'src="([^"]*)/image/{re.escape(old_name)}"',
|
|
f"src='([^']*)/image/{re.escape(old_name)}'",
|
|
f'url\\(([^)]*)/image/{re.escape(old_name)}\\)',
|
|
]
|
|
|
|
for pattern in patterns:
|
|
content = re.sub(
|
|
pattern,
|
|
lambda m: f'{pattern.split("(")[0].split("=")[0]}="{m.group(1)}/image/{new_name}"' if "src" in pattern else f'url({m.group(1)}/image/{new_name})',
|
|
content
|
|
)
|
|
|
|
if content != original_content:
|
|
html_file.write_text(content, encoding='utf-8')
|
|
print(f" 更新HTML: {html_file.name}")
|
|
|
|
def save_mapping(self, order_class: str):
|
|
"""保存图片映射关系"""
|
|
if not self.image_mapping:
|
|
return
|
|
|
|
mapping_file = self.base_path / order_class / "图片映射.json"
|
|
|
|
with open(mapping_file, 'w', encoding='utf-8') as f:
|
|
json.dump(self.image_mapping, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f" 保存映射文件: {mapping_file}")
|
|
|
|
def create_image_index(self, order_class: str):
|
|
"""创建图片索引文档"""
|
|
image_dir = self.base_path / order_class / "notion文稿" / "image"
|
|
|
|
if not image_dir.exists():
|
|
return
|
|
|
|
images = sorted(image_dir.glob("*.[jJ][pP][gG]")) + \
|
|
sorted(image_dir.glob("*.[pP][nN][gG]"))
|
|
|
|
if not images:
|
|
return
|
|
|
|
index_content = f"# {order_class} - 图片索引\n\n"
|
|
index_content += f"总计:{len(images)} 张图片\n\n"
|
|
|
|
# 按类别分组
|
|
design_images = [img for img in images if "设计图" in img.name]
|
|
display_images = [img for img in images if "展示图" in img.name]
|
|
other_images = [img for img in images if img not in design_images and img not in display_images]
|
|
|
|
if design_images:
|
|
index_content += "## 设计图\n"
|
|
for img in design_images:
|
|
index_content += f"- {img.name}\n"
|
|
index_content += "\n"
|
|
|
|
if display_images:
|
|
index_content += "## 展示图\n"
|
|
for img in display_images:
|
|
index_content += f"- {img.name}\n"
|
|
index_content += "\n"
|
|
|
|
if other_images:
|
|
index_content += "## 其他图片\n"
|
|
for img in other_images:
|
|
index_content += f"- {img.name}\n"
|
|
index_content += "\n"
|
|
|
|
# 保存索引文件
|
|
index_file = self.base_path / order_class / "notion文稿" / "图片索引.md"
|
|
index_file.write_text(index_content, encoding='utf-8')
|
|
print(f" 创建图片索引: {index_file}")
|
|
|
|
def main():
|
|
# 设置基础路径
|
|
base_path = "/Users/xiaoqi/Documents/Dev/Project/2025-09-08_n8nDEMO演示/doc/订单班文档资料"
|
|
|
|
# 订单班列表
|
|
order_classes = [
|
|
"文旅", "财经商贸", "食品", "智能开发", "智能制造",
|
|
"视觉设计", "交通物流", "土木", "大健康", "能源",
|
|
"化工", "环保"
|
|
]
|
|
|
|
organizer = ImageOrganizer(base_path)
|
|
|
|
# 处理每个订单班
|
|
for order_class in order_classes:
|
|
print(f"\n{'='*50}")
|
|
print(f"处理订单班: {order_class}")
|
|
print(f"{'='*50}")
|
|
|
|
organizer.image_mapping = {} # 重置映射
|
|
|
|
# 1. 整理图片
|
|
organizer.organize_images(order_class)
|
|
|
|
# 2. 更新Markdown引用
|
|
if organizer.image_mapping:
|
|
organizer.update_markdown_references(order_class)
|
|
|
|
# 3. 保存映射关系
|
|
organizer.save_mapping(order_class)
|
|
|
|
# 4. 创建图片索引
|
|
organizer.create_image_index(order_class)
|
|
|
|
print("\n✅ 所有订单班图片整理完成!")
|
|
|
|
if __name__ == "__main__":
|
|
main() |