81 lines
3.6 KiB
Python
81 lines
3.6 KiB
Python
path = r'C:\Users\jsmbz\Documents\flutter-app-02\lib\features\home\presentation\widgets\map\testmap_pages.dart'
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
# Target: lines 915-954 (0-indexed: 914-953) are duplicate response blocks
|
|
# We want to replace them with a single clean response block
|
|
# Lines before 915 (0-914) = request params + _showPageToast (already good)
|
|
# Line 915-954 = duplicates to remove
|
|
# Lines 955+ = list refresh, _clearLocalData, setState (keep)
|
|
|
|
# New response block (same indentation as original, 6 spaces)
|
|
clean_resp = [
|
|
' debugPrint(\'\U0001f4e5 [保存地块] 响应状态码: ${response.statusCode}\');\n',
|
|
' debugPrint(\'\U0001f4e5 [保存地块] 响应体(完整): $responseBody\');\n',
|
|
'\n',
|
|
' if (response.statusCode == 200) {\n',
|
|
' // \U0001f525 解析响应体确认后端是否真的成功\n',
|
|
' Map<String, dynamic>? respJson;\n',
|
|
' try {\n',
|
|
' respJson = jsonDecode(responseBody) as Map<String, dynamic>;\n',
|
|
' } catch (_) {\n',
|
|
' debugPrint(\'\u274c [保存地块] 响应体非JSON: $responseBody\');\n',
|
|
' throw Exception(\'响应体非JSON: $responseBody\');\n',
|
|
' }\n',
|
|
'\n',
|
|
' final apiCode = respJson[\'code\'];\n',
|
|
' if (apiCode != null && apiCode.toString() != \'200\') {\n',
|
|
' final apiMsg = respJson[\'msg\'] ?? respJson[\'message\'] ?? \'未知错误\';\n',
|
|
' debugPrint(\'\u274c [保存地块] 后端返回失败, code=$apiCode, msg=$apiMsg\');\n',
|
|
' throw Exception(\'$apiMsg\');\n',
|
|
' }\n',
|
|
'\n',
|
|
' debugPrint(\'\u2705 [保存地块] 保存成功, plotName=$plotName, 响应: $respJson\');\n',
|
|
' // \U0001f525 刷新地块列表\n',
|
|
' debugPrint(\'\U0001f504 [保存地块] 刷新地块列表, siteId=$siteId\');\n',
|
|
' context.read<DevicesCubit>().loadWorkRecordsBySiteId(siteId);\n',
|
|
]
|
|
|
|
# We also need to remove the duplicate list refresh code that comes after line 954
|
|
# Line 955-957 is: debugPrint('🔄...'); context.read<DevicesCubit>().loadWorkRecordsBySiteId(siteId);
|
|
# We'll include these in the new block above and remove them
|
|
|
|
# Find the start of duplicate block
|
|
dup_start = None
|
|
dup_end = None
|
|
for i, line in enumerate(lines):
|
|
if 'debugPrint' in line and '响应状态码' in line and dup_start is None:
|
|
dup_start = i
|
|
if dup_start is not None and 'List<LatLng> _getPolygonPoints()' in line:
|
|
dup_end = i
|
|
break
|
|
|
|
print(f"Duplicate block: lines {dup_start+1} to {dup_end+1}")
|
|
|
|
if dup_start is not None and dup_end is not None:
|
|
# Keep: lines before dup_start + our clean block + lines after dup_end
|
|
before = lines[:dup_start]
|
|
after_dup_end = lines[dup_end:]
|
|
|
|
# Remove the duplicate '🔄 刷新' and context.read lines that appear right after our block
|
|
# Those are at the start of after_dup_end
|
|
cleaned_after = []
|
|
skip_dedup = False
|
|
for line in after_dup_end:
|
|
# Skip lines that duplicate what's already in our clean_resp block
|
|
if '🔄 [保存地块] 刷新地块列表' in line:
|
|
skip_dedup = True
|
|
continue
|
|
if skip_dedup and 'context.read<DevicesCubit>().loadWorkRecordsBySiteId(siteId)' in line:
|
|
skip_dedup = False
|
|
continue
|
|
skip_dedup = False
|
|
cleaned_after.append(line)
|
|
|
|
new_lines = before + clean_resp + cleaned_after
|
|
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|
f.writelines(new_lines)
|
|
print(f"OK: Replaced {len(lines) - len(new_lines)} lines")
|
|
else:
|
|
print(f"FAIL: dup_start={dup_start}, dup_end={dup_end}") |