| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import re
- path = r'd:\Users\chenjun\kyj-yanglao-web-new\src\views\elderly\apply\check-in\ContractForm.vue'
- with open(path, 'r', encoding='utf-8') as f:
- content = f.read()
- # 修复有 class="fill" 的双重嵌套:
- # <template v-if="isTextMode"><span class="fill"><template v-if="isTextMode">{{ contractForm.field || '___' }}</template><input v-else v-model="contractForm.field" class="text-input" placeholder="请输入" style="max-width: 180px;" /></span></template><input v-else v-model="contractForm.field" class="text-input" placeholder="请输入" style="max-width: 180px;" />
- # ->
- # <template v-if="isTextMode"><span class="fill">{{ contractForm.field || '___' }}</span></template><input v-else v-model="contractForm.field" class="text-input" placeholder="请输入" style="max-width: 180px;" />
- pattern_nested = r'<template v-if="isTextMode"><span class="fill"><template v-if="isTextMode">(\{\{\s*contractForm\.(\w+)\s*\|\|\s*\'[^\']*\'\s*\}\})</template><input v-else v-model="contractForm\.\w+" class="text-input" placeholder="请输入" style="max-width: 180px;" /></span></template><input v-else v-model="contractForm\.\w+" class="text-input" placeholder="请输入" style="max-width: 180px;" />'
- matches = re.findall(pattern_nested, content)
- print(f"Found nested fill patterns: {len(matches)}")
- def repl_nested(m):
- inner_expr = m.group(1) # {{ contractForm.field || '___' }}
- field = m.group(2) # field
- return f'<template v-if="isTextMode"><span class="fill">{inner_expr}</span></template><input v-else v-model="contractForm.{field}" class="text-input" placeholder="请输入" style="max-width: 180px;" />'
- content_new = re.sub(pattern_nested, repl_nested, content)
- # 检查是否还有残余的双重嵌套问题
- remaining = re.findall(r'<template v-if="isTextMode"><span class="fill"><template', content_new)
- print(f"Remaining nested after fix: {len(remaining)}")
- # 检查是否还有未被正确替换的原始模式
- remaining_orig = re.findall(r"<span class=\"fill\">{{\s*contractForm", content_new)
- print(f"Remaining original fill patterns: {len(remaining_orig)}")
- # 检查未被正确替换的直接变量
- remaining_var = re.findall(r"[^>]\{\{\s*contractForm\.\w+\s*\|\|\s*'", content_new)
- print(f"Remaining raw variable patterns: {len(remaining_var)}")
- # 保存
- with open(path, 'w', encoding='utf-8') as f:
- f.write(content_new)
- print("Done!")
|