98 lines
3.6 KiB
PowerShell
98 lines
3.6 KiB
PowerShell
# UTS Android calc() 兼容性修复脚本
|
|
# UTS Android 不支持 calc() 函数,需要用固定值替代
|
|
|
|
Write-Host "开始修复 UTS Android calc() 兼容性问题..." -ForegroundColor Green
|
|
|
|
# 定义替换规则
|
|
$replacements = @{
|
|
# 50% 相关的计算
|
|
'calc\(50% - 10rpx\)' = '46%'
|
|
'calc\(50% - 15rpx\)' = '45%'
|
|
'calc\(50% - 20rpx\)' = '44%'
|
|
'calc\(50% - 7\.5rpx\)' = '47%'
|
|
'calc\(50% - 12px\)' = '46%'
|
|
'calc\(50% - 15px\)' = '45%'
|
|
'calc\(50% - 16px\)' = '44%'
|
|
'calc\(50% - 10px\)' = '46%'
|
|
'calc\(50% -15px\)' = '45%' # 注意这个没有空格的版本
|
|
'calc\(50% - 6px\)' = '47%'
|
|
|
|
# 33.333% 相关的计算 (3列布局)
|
|
'calc\(33\.333% - 12px\)' = '30%'
|
|
'calc\(33\.333% - 10px\)' = '31%'
|
|
|
|
# 25% 相关的计算 (4列布局)
|
|
'calc\(25% - 15px\)' = '22%'
|
|
'calc\(25% - 12px\)' = '23%'
|
|
|
|
# 高度相关的计算
|
|
'calc\(100vh - 300rpx\)' = '70vh'
|
|
'calc\(100vh - 200rpx\)' = '80vh'
|
|
'calc\(100vh - 160rpx\)' = '82vh'
|
|
'calc\(100vh - 120rpx\)' = '85vh'
|
|
'calc\(100vh - 300px\)' = '70vh'
|
|
'calc\(90vh - 140px\)' = '75vh'
|
|
'calc\(80vh - 80px\)' = '70vh'
|
|
|
|
# 位置相关的计算
|
|
'calc\(50% - 90rpx\)' = '42%'
|
|
}
|
|
|
|
# 获取所有 .uvue 文件
|
|
$files = Get-ChildItem -Path "." -Recurse -Filter "*.uvue" | Where-Object { $_.FullName -notlike "*node_modules*" }
|
|
|
|
$totalReplacements = 0
|
|
$affectedFiles = @()
|
|
|
|
foreach ($file in $files) {
|
|
$content = Get-Content $file.FullName -Raw -Encoding UTF8
|
|
$originalContent = $content
|
|
$fileReplacements = 0
|
|
|
|
foreach ($pattern in $replacements.Keys) {
|
|
$replacement = $replacements[$pattern]
|
|
$matches = [regex]::Matches($content, $pattern, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
|
|
|
|
if ($matches.Count -gt 0) {
|
|
$content = [regex]::Replace($content, $pattern, $replacement, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
|
|
$fileReplacements += $matches.Count
|
|
Write-Host " 修复 $($file.Name): $($matches.Count) 个 '$pattern' -> '$replacement'" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
|
|
if ($fileReplacements -gt 0) {
|
|
Set-Content -Path $file.FullName -Value $content -Encoding UTF8
|
|
$affectedFiles += $file.Name
|
|
$totalReplacements += $fileReplacements
|
|
Write-Host " ✅ 修复文件: $($file.Name) ($fileReplacements 个替换)" -ForegroundColor Green
|
|
}
|
|
}
|
|
|
|
Write-Host "`n修复完成!" -ForegroundColor Green
|
|
Write-Host "影响文件数: $($affectedFiles.Count)" -ForegroundColor Cyan
|
|
Write-Host "总替换数: $totalReplacements" -ForegroundColor Cyan
|
|
Write-Host "`n修复文件列表:" -ForegroundColor Yellow
|
|
$affectedFiles | ForEach-Object { Write-Host " - $_" -ForegroundColor White }
|
|
|
|
# 验证是否还有遗漏的 calc()
|
|
Write-Host "`n检查是否还有遗漏的 calc() 函数..." -ForegroundColor Yellow
|
|
$remainingCalcs = @()
|
|
|
|
foreach ($file in $files) {
|
|
$content = Get-Content $file.FullName -Raw -Encoding UTF8
|
|
$matches = [regex]::Matches($content, 'calc\(', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
|
|
|
|
if ($matches.Count -gt 0) {
|
|
$remainingCalcs += "$($file.Name): $($matches.Count) 个"
|
|
}
|
|
}
|
|
|
|
if ($remainingCalcs.Count -gt 0) {
|
|
Write-Host "`n⚠️ 还有以下文件包含 calc() 函数需要手动处理:" -ForegroundColor Red
|
|
$remainingCalcs | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
|
|
} else {
|
|
Write-Host "`n🎉 所有 calc() 函数都已修复完成!" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host "`n🚀 UTS Android calc() 兼容性修复完成!" -ForegroundColor Green
|