# -*- coding: utf-8 -*- import os import re import io directory = r'd:\WorkSpace\boying\boying-pda\src\views\modules' 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 # Ensure list-body wrapper exists in HTML if label-list is there if '
' in content and 'class="list-body"' not in content: # We need to wrap the items. This is a bit complex to do automatically safely. print('Needs list-body wrapper: ' + path) # Update CSS for label-list # Find .label-list { ... } label_list_pattern = r'(\.label-list\s*\{[^}]*?)\}' match = re.search(label_list_pattern, content) if match: inner_content = match.group(1) # Check if it has display: flex; if 'flex:' not in inner_content: new_inner = inner_content + ' flex: 1;\n display: flex;\n flex-direction: column;\n max-height: 300px;\n}' content = re.sub(label_list_pattern, new_inner.replace('\\', '\\\\'), content, count=1) changed = True # Find .list-body { ... } or add it if '.label-list .list-body {' not in content and '.list-body {' not in content and 'class="list-body"' in content: content = content.replace('.list-header {', '.label-list .list-body {\n flex: 1;\n overflow-y: auto;\n max-height: 250px;\n}\n\n.list-header {') changed = True if changed: with io.open(path, 'w', encoding='utf-8') as f: f.write(content) print('Updated flex ' + file)