AIGC/fix_credits.py
2026-02-27 14:37:19 +08:00

46 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
修复 App.vue 文件,在所有生成功能成功后添加积分扣除
"""
import re
# 读取文件
with open(r'e:\Github\AIGC\aigc-ui\src\App.vue', 'r', encoding='utf-8') as f:
content = f.read()
# 定义需要添加积分扣除的位置(在 handleGenerate 函数中,不是 executeGenerate
# 我们需要在第一次出现这些模式时添加而不是第二次executeGenerate 函数中)
# 1. 答辩PPT生成 - 在第263行后添加
pattern1 = r"(extra: defenseExtra \|\| '',\s*\}\)\s*previewContent\.value = res\.content \|\| ''\s*)(// 尝试解析 JSON 格式的 PPT 数据)"
replacement1 = r"\1\n // 扣除积分\n deductCredits(1)\n\n \2"
# 2. 降重功能 - 在第296行后添加
pattern2 = r"(const res = await api\(\{ text: formModel\.value\.title \}\)\s*previewContent\.value = res\.content \|\| ''\s*)(} catch \(e: any\) \{\s*ElMessage\.error\(e\?\.message \|\| '降重处理失败)"
replacement2 = r"\1\n // 扣除积分\n deductCredits(1)\n \2"
# 3. 实习报告生成 - 在第354行后添加
pattern3 = r"(console\.log\('API response:', res\)\s*previewContent\.value = res\.content \|\| ''\s*)(ElMessage\.success\('实习报告生成成功'\))"
replacement3 = r"\1\n // 扣除积分\n deductCredits(1)\n \n \2"
# 应用替换(只替换第一次出现)
content = re.sub(pattern1, replacement1, content, count=1)
content = re.sub(pattern2, replacement2, content, count=1)
content = re.sub(pattern3, replacement3, content, count=1)
# 写回文件
with open(r'e:\Github\AIGC\aigc-ui\src\App.vue', 'w', encoding='utf-8') as f:
f.write(content)
print("✅ 修复完成!已在以下位置添加积分扣除:")
print(" 1. 答辩PPT生成")
print(" 2. 降重功能")
print(" 3. 实习报告生成")
print("\n已完成的位置:")
print(" ✅ 查重功能第218行")
print(" ✅ 任务书生成第324行")
print(" ✅ 论文生成第385行")
print(" ✅ 开题报告生成第416行")