# -*- coding: utf-8 -*- import os import re import io directory = r'd:\WorkSpace\boying\boying-pda\src\views\modules' css_to_add = u''' /* 滚动条样式优化 */ .label-list .list-body::-webkit-scrollbar { width: 4px; } .label-list .list-body::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 2px; } .label-list .list-body::-webkit-scrollbar-thumb { background: #17B3A3; border-radius: 2px; } .label-list .list-body::-webkit-scrollbar-thumb:hover { background: #0d8f7f; } ''' for root, _, files in os.walk(directory): for file in files: if file.endswith('.vue'): path = os.path.join(root, file) with io.open(path, 'r', encoding='utf-8') as f: content = f.read() changed = False # 1. Update text-align for numeric columns num_cols = ['col-qty', 'col-required-qty', 'col-picked-qty', 'col-available-qty', 'col-inbound-qty', 'col-scans-qty', 'col-roll-qty'] for col in num_cols: # Find .col-xyz { ... text-align: center; ... } # The pattern matches \.col-xyz \s* \{ [^}]*? text-align:\s*center; pattern_center = r'(\.' + col + r'\s*\{[^}]*?)text-align:\s*center;' if re.search(pattern_center, content): content = re.sub(pattern_center, r'\1text-align: right;\n padding-right: 12px;', content) changed = True # The pattern matches \.col-xyz \s* \{ [^}]*? text-align:\s*left; pattern_left = r'(\.' + col + r'\s*\{[^}]*?)text-align:\s*left;' if re.search(pattern_left, content): content = re.sub(pattern_left, r'\1text-align: right;\n padding-right: 12px;', content) changed = True # Also check .material-table inside material dialog # 2. Add scrollbar CSS if list-body is present and scrollbar is missing if 'class="list-body"' in content and '::-webkit-scrollbar' not in content: content = content.replace('', css_to_add + '\n') changed = True if changed: with io.open(path, 'w', encoding='utf-8') as f: f.write(content) print('Updated ' + file)