Files
akmon/doc_zhipao/fix_css_restrictions.ps1
2026-01-20 08:04:15 +08:00

53 lines
2.3 KiB
PowerShell

# PowerShell script to fix CSS property restrictions in uni-app-x
Write-Host "Starting CSS property restrictions fix process..." -ForegroundColor Cyan
# Get all .uvue files in the pages directory
$uvueFiles = Get-ChildItem -Path "pages" -Filter "*.uvue" -Recurse
$fixedCount = 0
$totalFiles = 0
Write-Host "Found $($uvueFiles.Count) .uvue files to process."
foreach ($file in $uvueFiles) {
$totalFiles++
Write-Host "Processing: $($file.FullName)"
try {
$content = Get-Content $file.FullName -Raw -Encoding UTF8
$originalContent = $content
# Fix text-align on view elements (remove or convert to flex)
# Replace text-align: center with display: flex + align-items: center + justify-content: center
$content = $content -replace '(\s+)text-align:\s*center;', '$1display: flex;$1flex-direction: column;$1align-items: center;$1justify-content: center;'
# Fix font-size on view elements by adding comment for manual review
if ($content -match 'view.*?{[^}]*font-size:') {
$content = $content -replace '(\s+)(font-size:\s*[^;]+;)(\s*)(.*?view)', '$1/* TODO: Move font-size to text element */ $2$3$4'
Write-Host "Found font-size on view element in: $($file.FullName)" -ForegroundColor Yellow
}
if ($content -ne $originalContent) {
Write-Host "Fixing file: $($file.FullName)" -ForegroundColor Yellow
# Write the updated content back to the file
Set-Content -Path $file.FullName -Value $content -NoNewline -Encoding UTF8
$fixedCount++
Write-Host "Fixed: $($file.FullName)" -ForegroundColor Green
}
} catch {
Write-Host "Error processing $($file.FullName): $($_.Exception.Message)" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "=== Summary ===" -ForegroundColor Cyan
Write-Host "Total .uvue files processed: $totalFiles" -ForegroundColor Cyan
Write-Host "Files fixed: $fixedCount" -ForegroundColor Green
Write-Host "Fix completed!" -ForegroundColor Green
Write-Host ""
Write-Host "Note: Files with font-size on view elements have been marked with TODO comments." -ForegroundColor Yellow
Write-Host "Please manually review and move font-size properties to text elements." -ForegroundColor Yellow