|
1 | | -<script lang="ts" setup> |
| 1 | +<script lang="ts" setup> |
2 | 2 | import type { Downloader, DownloaderType } from '#/config'; |
3 | 3 | import type { SettingItem } from '#/components'; |
| 4 | +import { ref, onMounted } from 'vue'; |
| 5 | +import { apiProgram } from '@/api/program'; |
4 | 6 |
|
5 | 7 | const { t } = useMyI18n(); |
6 | 8 | const { getSettingGroup } = useConfigStore(); |
7 | 9 |
|
8 | 10 | const downloader = getSettingGroup('downloader'); |
9 | 11 | const downloaderType: DownloaderType = ['qbittorrent']; |
10 | 12 |
|
| 13 | +const platform = ref<string>('linux'); |
| 14 | +
|
| 15 | +onMounted(async () => { |
| 16 | + try { |
| 17 | + const status = await apiProgram.status(); |
| 18 | + platform.value = status.platform; |
| 19 | + } catch { |
| 20 | + platform.value = 'linux'; |
| 21 | + } |
| 22 | +}); |
| 23 | +
|
| 24 | +function convertPath() { |
| 25 | + const current = downloader.path as string; |
| 26 | + if (!current) return; |
| 27 | + if (platform.value === 'linux') { |
| 28 | + const winPath = current.replace(/^\/downloads\//, 'D:\\').replace(/\//g, '\\'); |
| 29 | + if (winPath !== current) { |
| 30 | + downloader.path = winPath; |
| 31 | + } |
| 32 | + } else { |
| 33 | + const linuxPath = current.replace(/^[A-Za-z]:\\/, '/downloads/').replace(/\\/g, '/'); |
| 34 | + if (linuxPath !== current) { |
| 35 | + downloader.path = linuxPath; |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | +
|
11 | 40 | const items: SettingItem<Downloader>[] = [ |
12 | 41 | { |
13 | 42 | configKey: 'type', |
@@ -72,6 +101,59 @@ const items: SettingItem<Downloader>[] = [ |
72 | 101 | v-bind="i" |
73 | 102 | v-model:data="downloader[i.configKey]" |
74 | 103 | ></ab-setting> |
| 104 | + <div class="convert-bar"> |
| 105 | + <span class="convert-label">{{ $t('config.downloader_set.path') }}</span> |
| 106 | + <div class="convert-actions"> |
| 107 | + <span class="platform-badge">{{ platform === 'linux' ? 'Linux/Docker' : 'Windows' }}</span> |
| 108 | + <button class="convert-btn" @click="convertPath"> |
| 109 | + 路径转换 → |
| 110 | + </button> |
| 111 | + </div> |
| 112 | + </div> |
75 | 113 | </div> |
76 | 114 | </ab-fold-panel> |
77 | 115 | </template> |
| 116 | + |
| 117 | +<style scoped> |
| 118 | +.convert-bar { |
| 119 | + display: flex; |
| 120 | + align-items: center; |
| 121 | + justify-content: space-between; |
| 122 | + padding: 8px 12px; |
| 123 | + background: var(--el-color-info-light-9); |
| 124 | + border-radius: 6px; |
| 125 | + font-size: 13px; |
| 126 | + margin-top: 8px; |
| 127 | +} |
| 128 | +.convert-label { |
| 129 | + color: var(--el-text-color-secondary); |
| 130 | +} |
| 131 | +.convert-actions { |
| 132 | + display: flex; |
| 133 | + align-items: center; |
| 134 | + gap: 8px; |
| 135 | +} |
| 136 | +.platform-badge { |
| 137 | + padding: 2px 8px; |
| 138 | + border-radius: 4px; |
| 139 | + background: var(--el-color-primary-light-9); |
| 140 | + color: var(--el-color-primary); |
| 141 | + font-size: 12px; |
| 142 | + font-weight: 500; |
| 143 | +} |
| 144 | +.convert-btn { |
| 145 | + padding: 4px 12px; |
| 146 | + border: 1px solid var(--el-border-color); |
| 147 | + border-radius: 4px; |
| 148 | + background: var(--el-bg-color); |
| 149 | + color: var(--el-text-color-primary); |
| 150 | + cursor: pointer; |
| 151 | + font-size: 12px; |
| 152 | + transition: all 0.2s; |
| 153 | +} |
| 154 | +.convert-btn:hover { |
| 155 | + background: var(--el-color-primary-light-9); |
| 156 | + border-color: var(--el-color-primary); |
| 157 | + color: var(--el-color-primary); |
| 158 | +} |
| 159 | +</style> |
0 commit comments