Files
soul-yongping/next-project/scripts/fix-earnings-detail-styles.py

211 lines
5.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
收益明细样式修复脚本
功能清理冲突的旧样式注入新的重构样式
"""
import re
import sys
def fix_earnings_styles():
wxss_path = 'miniprogram/pages/referral/referral.wxss'
try:
# 读取原文件
with open(wxss_path, 'r', encoding='utf-8') as f:
content = f.read()
print("📖 读取原wxss文件...")
# 备份原文件
backup_path = wxss_path + '.before-fix-' + __import__('datetime').datetime.now().strftime('%Y%m%d%H%M%S')
with open(backup_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✅ 备份文件: {backup_path}")
# 删除旧的冲突样式(旧版收益明细)
patterns_to_remove = [
# 旧的 detail-item使用 justify-content: space-between
r'\.detail-item\s*\{\s*display:\s*flex;\s*align-items:\s*center;\s*justify-content:\s*space-between;[^}]+\}',
# 旧的 detail-left
r'\.detail-left\s*\{[^}]+\}',
# 旧的 detail-icon
r'\.detail-icon\s*\{[^}]+\}',
# 旧的 detail-info
r'\.detail-info\s*\{[^}]+\}',
# 旧的 detail-type
r'\.detail-type\s*\{[^}]+\}',
]
cleaned_content = content
for pattern in patterns_to_remove:
matches = re.findall(pattern, cleaned_content, re.DOTALL)
if matches:
print(f"🗑️ 删除旧样式: {pattern[:50]}... ({len(matches)}处)")
cleaned_content = re.sub(pattern, '', cleaned_content, flags=re.DOTALL)
# 删除重复的 loading 和 detail 样式(编码错误的部分)
# 查找并删除包含特殊字符的样式块
cleaned_content = re.sub(
r'/\s*\*\s*=\s*=\s*=\s*=\s*=.*?=\s*=\s*=\s*=\s*=\s*\*\s*/.*?(?=/\*|$)',
'',
cleaned_content,
flags=re.DOTALL
)
# 新的收益明细样式
new_styles = '''
/* ===================================
收益明细卡片样式 - 重构版 2026-02-04
=================================== */
/* 列表项容器 */
.earnings-detail-card .detail-item {
display: flex !important;
align-items: center !important;
gap: 24rpx !important;
padding: 24rpx 40rpx !important;
background: transparent !important;
border-bottom: 2rpx solid rgba(255,255,255,0.03) !important;
transition: background 0.3s !important;
}
.earnings-detail-card .detail-item:last-child {
border-bottom: none !important;
}
.earnings-detail-card .detail-item:active {
background: rgba(255, 255, 255, 0.05) !important;
}
/* 头像容器 */
.earnings-detail-card .detail-avatar-wrap {
width: 88rpx;
height: 88rpx;
flex-shrink: 0;
}
.earnings-detail-card .detail-avatar {
width: 100%;
height: 100%;
border-radius: 50%;
border: 2rpx solid rgba(56, 189, 172, 0.2);
display: block;
}
.earnings-detail-card .detail-avatar-text {
width: 100%;
height: 100%;
border-radius: 50%;
background: linear-gradient(135deg, #38bdac 0%, #2da396 100%);
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 700;
color: #ffffff;
}
/* 详细信息容器 */
.earnings-detail-card .detail-content {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8rpx;
}
/* 顶部行 */
.earnings-detail-card .detail-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
/* 买家昵称 */
.earnings-detail-card .detail-buyer {
font-size: 28rpx;
font-weight: 500;
color: #ffffff;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 佣金金额 */
.earnings-detail-card .detail-amount {
font-size: 32rpx;
font-weight: 700;
color: #38bdac;
flex-shrink: 0;
white-space: nowrap;
}
/* 商品信息 */
.earnings-detail-card .detail-product {
display: flex;
align-items: baseline;
gap: 4rpx;
font-size: 24rpx;
color: rgba(255, 255, 255, 0.6);
min-width: 0;
overflow: hidden;
}
/* 书名 */
.earnings-detail-card .detail-book {
color: rgba(255, 255, 255, 0.7);
font-weight: 500;
max-width: 50%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex-shrink: 1;
}
/* 章节 */
.earnings-detail-card .detail-chapter {
color: rgba(255, 255, 255, 0.5);
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 时间 */
.earnings-detail-card .detail-time {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.4);
}
'''
# 在文件末尾添加新样式
final_content = cleaned_content.rstrip() + '\n' + new_styles + '\n'
# 写入文件
with open(wxss_path, 'w', encoding='utf-8') as f:
f.write(final_content)
print("✅ 样式修复完成!")
print(f"📝 原文件大小: {len(content)} 字符")
print(f"📝 清理后大小: {len(cleaned_content)} 字符")
print(f"📝 最终大小: {len(final_content)} 字符")
print("\n🎉 收益明细样式已重构!")
return True
except Exception as e:
print(f"❌ 错误: {str(e)}")
import traceback
traceback.print_exc()
return False
if __name__ == '__main__':
success = fix_earnings_styles()
sys.exit(0 if success else 1)