|
| 1 | +<template> |
| 2 | + <div class="space-y-6"> |
| 3 | + <div class="space-y-4"> |
| 4 | + <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">缓存管理</h3> |
| 5 | + <p class="text-sm text-gray-600 dark:text-gray-400"> |
| 6 | + 管理应用缓存,包括代码执行临时文件等 |
| 7 | + </p> |
| 8 | + </div> |
| 9 | + |
| 10 | + <!-- 缓存统计 --> |
| 11 | + <div v-if="cacheInfo" class="grid grid-cols-1 md:grid-cols-2 gap-4"> |
| 12 | + <div class="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg"> |
| 13 | + <div class="flex items-center justify-between"> |
| 14 | + <div> |
| 15 | + <p class="text-sm text-gray-600 dark:text-gray-400">插件执行缓存</p> |
| 16 | + <p class="text-2xl font-semibold text-gray-900 dark:text-gray-100 mt-1"> |
| 17 | + {{ formatSize(cacheInfo.plugins_cache_size) }} |
| 18 | + </p> |
| 19 | + </div> |
| 20 | + <FolderOpen class="w-8 h-8 text-blue-600 dark:text-blue-400"/> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + |
| 24 | + <div class="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg"> |
| 25 | + <div class="flex items-center justify-between"> |
| 26 | + <div> |
| 27 | + <p class="text-sm text-gray-600 dark:text-gray-400">总缓存大小</p> |
| 28 | + <p class="text-2xl font-semibold text-gray-900 dark:text-gray-100 mt-1"> |
| 29 | + {{ formatSize(cacheInfo.total_cache_size) }} |
| 30 | + </p> |
| 31 | + </div> |
| 32 | + <HardDrive class="w-8 h-8 text-green-600 dark:text-green-400"/> |
| 33 | + </div> |
| 34 | + </div> |
| 35 | + </div> |
| 36 | + |
| 37 | + <!-- 加载状态 --> |
| 38 | + <div v-if="isLoading" class="flex items-center justify-center py-8"> |
| 39 | + <div class="flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400"> |
| 40 | + <svg class="animate-spin h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> |
| 41 | + <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> |
| 42 | + <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path> |
| 43 | + </svg> |
| 44 | + <span>加载中...</span> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + |
| 48 | + <!-- 错误信息 --> |
| 49 | + <div v-if="error" class="p-3 bg-red-50 dark:bg-red-900/20 rounded-lg"> |
| 50 | + <div class="flex items-center space-x-2 text-red-600 dark:text-red-400"> |
| 51 | + <AlertCircle class="w-5 h-5"/> |
| 52 | + <span class="text-sm">{{ error }}</span> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + <!-- 成功信息 --> |
| 57 | + <div v-if="success" class="p-3 bg-green-50 dark:bg-green-900/20 rounded-lg"> |
| 58 | + <div class="flex items-center space-x-2 text-green-600 dark:text-green-400"> |
| 59 | + <CheckCircle class="w-5 h-5"/> |
| 60 | + <span class="text-sm">{{ success }}</span> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + |
| 64 | + <!-- 缓存清理选项 --> |
| 65 | + <div class="space-y-4"> |
| 66 | + <div class="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"> |
| 67 | + <div class="flex-1"> |
| 68 | + <h4 class="font-medium text-gray-900 dark:text-gray-100">清理插件执行缓存</h4> |
| 69 | + <p class="text-sm text-gray-600 dark:text-gray-400 mt-1"> |
| 70 | + 清理代码执行产生的临时文件 |
| 71 | + </p> |
| 72 | + </div> |
| 73 | + <Button |
| 74 | + type="danger" |
| 75 | + :icon="Trash2" |
| 76 | + :disabled="isClearing" |
| 77 | + @click="clearPluginsCache"> |
| 78 | + 清理 |
| 79 | + </Button> |
| 80 | + </div> |
| 81 | + |
| 82 | + <div class="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"> |
| 83 | + <div class="flex-1"> |
| 84 | + <h4 class="font-medium text-gray-900 dark:text-gray-100">清理所有缓存</h4> |
| 85 | + <p class="text-sm text-gray-600 dark:text-gray-400 mt-1"> |
| 86 | + 清理应用所有缓存数据 |
| 87 | + </p> |
| 88 | + </div> |
| 89 | + <Button |
| 90 | + type="danger" |
| 91 | + :icon="Trash2" |
| 92 | + :disabled="isClearing" |
| 93 | + @click="clearAllCache"> |
| 94 | + 清理 |
| 95 | + </Button> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | +</template> |
| 100 | + |
| 101 | +<script setup lang="ts"> |
| 102 | +import { onMounted, ref } from 'vue' |
| 103 | +import { invoke } from '@tauri-apps/api/core' |
| 104 | +import { AlertCircle, CheckCircle, FolderOpen, HardDrive, Trash2 } from 'lucide-vue-next' |
| 105 | +import Button from '../../ui/Button.vue' |
| 106 | +
|
| 107 | +interface CacheInfo { |
| 108 | + plugins_cache_size: number |
| 109 | + total_cache_size: number |
| 110 | +} |
| 111 | +
|
| 112 | +const cacheInfo = ref<CacheInfo | null>(null) |
| 113 | +const isLoading = ref(false) |
| 114 | +const isClearing = ref(false) |
| 115 | +const error = ref<string | null>(null) |
| 116 | +const success = ref<string | null>(null) |
| 117 | +
|
| 118 | +// 格式化文件大小 |
| 119 | +const formatSize = (bytes: number) => { |
| 120 | + if (bytes === 0) return '0 B' |
| 121 | + const k = 1024 |
| 122 | + const sizes = ['B', 'KB', 'MB', 'GB'] |
| 123 | + const i = Math.floor(Math.log(bytes) / Math.log(k)) |
| 124 | + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] |
| 125 | +} |
| 126 | +
|
| 127 | +// 获取缓存信息 |
| 128 | +const fetchCacheInfo = async () => { |
| 129 | + isLoading.value = true |
| 130 | + error.value = null |
| 131 | +
|
| 132 | + try { |
| 133 | + const info = await invoke<CacheInfo>('get_cache_info') |
| 134 | + cacheInfo.value = info |
| 135 | + } |
| 136 | + catch (e) { |
| 137 | + error.value = e as string |
| 138 | + console.error('获取缓存信息失败:', e) |
| 139 | + } |
| 140 | + finally { |
| 141 | + isLoading.value = false |
| 142 | + } |
| 143 | +} |
| 144 | +
|
| 145 | +// 清理插件缓存 |
| 146 | +const clearPluginsCache = async () => { |
| 147 | + isClearing.value = true |
| 148 | + error.value = null |
| 149 | + success.value = null |
| 150 | +
|
| 151 | + try { |
| 152 | + await invoke('clear_plugins_cache') |
| 153 | + success.value = '插件执行缓存已清理' |
| 154 | + await fetchCacheInfo() |
| 155 | +
|
| 156 | + // 3秒后清除成功信息 |
| 157 | + setTimeout(() => { |
| 158 | + success.value = null |
| 159 | + }, 3000) |
| 160 | + } |
| 161 | + catch (e) { |
| 162 | + error.value = e as string |
| 163 | + console.error('清理插件缓存失败:', e) |
| 164 | + } |
| 165 | + finally { |
| 166 | + isClearing.value = false |
| 167 | + } |
| 168 | +} |
| 169 | +
|
| 170 | +// 清理所有缓存 |
| 171 | +const clearAllCache = async () => { |
| 172 | + isClearing.value = true |
| 173 | + error.value = null |
| 174 | + success.value = null |
| 175 | +
|
| 176 | + try { |
| 177 | + await invoke('clear_all_cache') |
| 178 | + success.value = '所有缓存已清理' |
| 179 | + await fetchCacheInfo() |
| 180 | +
|
| 181 | + // 3秒后清除成功信息 |
| 182 | + setTimeout(() => { |
| 183 | + success.value = null |
| 184 | + }, 3000) |
| 185 | + } |
| 186 | + catch (e) { |
| 187 | + error.value = e as string |
| 188 | + console.error('清理所有缓存失败:', e) |
| 189 | + } |
| 190 | + finally { |
| 191 | + isClearing.value = false |
| 192 | + } |
| 193 | +} |
| 194 | +
|
| 195 | +onMounted(async () => { |
| 196 | + await fetchCacheInfo() |
| 197 | +}) |
| 198 | +</script> |
0 commit comments