1+ def replace_colors_in_vue (input_file , output_file ):
2+ """
3+ 将Vue文件中的蓝色系配色替换为紫色系
4+ """
5+
6+ # 定义所有需要替换的颜色映射
7+ color_replacements = [
8+ # 主要颜色替换
9+ ('#1a237e' , '#4a148c' ), # 深紫色,用于标题
10+
11+ # 链接和强调色
12+ ('#1976d2' , '#7b1fa2' ), # 主紫色
13+ ('#1565c0' , '#6a1b9a' ), # 深一点的紫色,hover状态
14+ ('#0d47a1' , '#4a148c' ), # 更深的紫色,hover状态
15+
16+ # 浅色背景和边框
17+ ('#90caf9' , '#ce93d8' ), # 浅紫色,用于边框
18+ ('#64b5f6' , '#ba68c8' ), # 渐变色的浅端
19+ ('#42a5f5' , '#ab47bc' ), # hover渐变的浅端
20+
21+ # 背景色调整
22+ ('#e3f0fc' , '#f3e5f5' ), # 很浅的紫色背景
23+ ('#e3f2fd' , '#f3e5f5' ), # 图标颜色
24+ ('#e3eaf2' , '#e1bee7' ), # 边框色
25+
26+ # 阴影颜色调整
27+ ('rgba(25, 118, 210, 0.04)' , 'rgba(123, 31, 162, 0.04)' ),
28+ ('rgba(25, 118, 210, 0.06)' , 'rgba(123, 31, 162, 0.06)' ),
29+ ('rgba(25, 118, 210, 0.08)' , 'rgba(123, 31, 162, 0.08)' ),
30+ ('rgba(25, 118, 210, 0.13)' , 'rgba(123, 31, 162, 0.13)' ),
31+ ('rgba(25, 118, 210, 0.18)' , 'rgba(123, 31, 162, 0.18)' ),
32+
33+ # 渐变调整
34+ ('linear-gradient(90deg, #1976d2 0%, #64b5f6 100%)' ,
35+ 'linear-gradient(90deg, #7b1fa2 0%, #ba68c8 100%)' ),
36+ ('linear-gradient(90deg, #1565c0 0%, #42a5f5 100%)' ,
37+ 'linear-gradient(90deg, #6a1b9a 0%, #ab47bc 100%)' ),
38+ ]
39+
40+ # 读取输入文件
41+ try :
42+ with open (input_file , 'r' , encoding = 'utf-8' ) as f :
43+ content = f .read ()
44+ except FileNotFoundError :
45+ print (f"错误:找不到输入文件 { input_file } " )
46+ return
47+ except Exception as e :
48+ print (f"读取文件时出错:{ e } " )
49+ return
50+
51+ # 执行所有替换
52+ replaced_count = 0
53+ for old_color , new_color in color_replacements :
54+ count = content .count (old_color )
55+ if count > 0 :
56+ content = content .replace (old_color , new_color )
57+ replaced_count += count
58+ print (f"替换 { old_color } -> { new_color } ({ count } 处)" )
59+
60+ # 写入输出文件
61+ try :
62+ with open (output_file , 'w' , encoding = 'utf-8' ) as f :
63+ f .write (content )
64+ print (f"\n ✅ 成功!总共替换了 { replaced_count } 处颜色" )
65+ print (f"新文件已保存到:{ output_file } " )
66+ except Exception as e :
67+ print (f"写入文件时出错:{ e } " )
68+ return
69+
70+ # 使用示例
71+ if __name__ == "__main__" :
72+ # 设置输入和输出文件路径
73+ input_vue_file = "D:\科研\ICLR2026\dart\src\components\Main.vue" # 替换为你的原始Vue文件路径
74+ output_vue_file = "D:\科研\ICLR2026\dart\src\components\Main_alt.vue" # 输出的紫色主题Vue文件
75+
76+ # 执行颜色替换
77+ replace_colors_in_vue (input_vue_file , output_vue_file )
78+
79+ print ("\n 提示:请将你的Vue代码保存为 'original.vue' 文件," )
80+ print ("然后运行这个脚本,会生成 'purple_theme.vue' 文件" )
0 commit comments