Files
akmon/fix_uts_android.sh
2026-01-20 08:04:15 +08:00

60 lines
2.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# UTS Android 兼容性批量修复脚本
# 此脚本用于修复 pages/ec/ 下所有 .uvue 文件的 UTS Android 兼容性问题
echo "🚀 开始批量修复 UTS Android 兼容性问题..."
# 找到所有 .uvue 文件
find ./pages/ec -name "*.uvue" -type f | while read -r file; do
echo "📝 处理文件: $file"
# 1. 将 Type[] 替换为 Array<Type>
sed -i 's/ref<\([A-Za-z_][A-Za-z0-9_]*\)\[\]>/ref<Array<\1>>/g' "$file"
sed -i 's/computed<\([A-Za-z_][A-Za-z0-9_]*\)\[\]>/computed<Array<\1>>/g' "$file"
sed -i 's/: \([A-Za-z_][A-Za-z0-9_]*\)\[\]/: Array<\1>/g' "$file"
# 2. 将可选属性 ? 替换为 | null
sed -i 's/\([A-Za-z_][A-Za-z0-9_]*\)\?\:\s*\([A-Za-z_][A-Za-z0-9_]*\)/\1: \2 | null/g' "$file"
# 3. 修正空值判断
sed -i 's/== null/=== null/g' "$file"
sed -i 's/!= null/!== null/g' "$file"
# 4. for 循环的 i 添加类型(只处理简单情况)
sed -i 's/for (let i =/for (let i: Int =/g' "$file"
sed -i 's/for(let i =/for(let i: Int =/g' "$file"
# 5. 修复 CSS 中的不兼容属性
sed -i 's/min-height: 100vh/min-height: 600px/g' "$file"
sed -i 's/height: 100vh/height: 600px/g' "$file"
sed -i '/gap:/d' "$file" # 删除 gap 属性行
sed -i 's/display: grid/display: flex/g' "$file"
# 6. 修复 findIndex 为 for 循环(需要手动处理复杂情况)
if grep -q "findIndex" "$file"; then
echo "⚠️ $file 包含 findIndex需要手动修复为 for 循环"
fi
# 7. 检查 forEach 和 map
if grep -q "forEach\|\.map(" "$file"; then
echo "⚠️ $file 包含 forEach 或 map需要手动修复为 for 循环"
fi
# 8. 检查 interface 使用
if grep -q "interface " "$file"; then
echo "⚠️ $file 包含 interface建议改为 type"
fi
echo "✅ 完成: $file"
done
echo ""
echo "📊 批量修复完成!"
echo "⚠️ 请注意:某些复杂情况需要手动修复:"
echo " 1. findIndex/indexOf 需要改为 for 循环"
echo " 2. forEach/map 需要改为 for 循环"
echo " 3. interface 建议改为 type"
echo " 4. 复杂的条件判断可能需要手动调整"
echo ""
echo "🎉 UTS Android 兼容性修复脚本执行完成!"