fetch essentials from url

This commit is contained in:
Julian Freeman
2026-03-30 17:45:09 -04:00
parent 8f55da1940
commit 626a9c21b0
7 changed files with 980 additions and 55 deletions

View File

@@ -34,19 +34,30 @@
全部软件
</router-link>
<!-- 底部日志选项 -->
<router-link to="/logs" class="nav-item nav-logs">
<span class="nav-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
</span>
运行日志
</router-link>
<!-- 底部选项 -->
<div class="sidebar-footer">
<router-link to="/logs" class="nav-item nav-logs">
<span class="nav-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
</span>
运行日志
</router-link>
<router-link to="/settings" class="nav-item nav-settings">
<span class="nav-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3"></circle>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1Z"></path>
</svg>
</span>
软件设置
</router-link>
</div>
</nav>
</div>
</template>
@@ -106,8 +117,15 @@
justify-content: center;
}
.nav-logs {
margin-top: auto; /* 将日志推到底部 */
margin-bottom: 20px;
.sidebar-footer {
margin-top: auto;
padding-bottom: 20px;
display: flex;
flex-direction: column;
gap: 8px;
}
.nav-logs, .nav-settings {
margin-top: 0;
}
</style>

View File

@@ -22,6 +22,10 @@ const router = createRouter({
{
path: '/logs',
component: () => import('../views/Logs.vue')
},
{
path: '/settings',
component: () => import('../views/Settings.vue')
}
]
})

View File

@@ -20,12 +20,16 @@ export const useSoftwareStore = defineStore('software', {
selectedEssentialIds: [] as string[],
selectedUpdateIds: [] as string[],
logs: [] as LogEntry[],
settings: {
repo_url: 'https://karlblue.github.io/winget-repo'
},
loading: false,
isInitialized: false,
initStatus: '正在检查系统环境...',
lastFetched: 0
}),
getters: {
// ... (mergedEssentials, sortedUpdates, sortedAllSoftware, isBusy getters stay the same)
mergedEssentials: (state) => {
return state.essentials.map(item => {
const isInstalled = state.allSoftware.some(s => s.id.toLowerCase() === item.id.toLowerCase());
@@ -55,8 +59,10 @@ export const useSoftwareStore = defineStore('software', {
actions: {
async initializeApp() {
if (this.isInitialized) return;
this.initStatus = '正在同步 Winget 模块...';
this.initStatus = '正在加载应用配置...';
try {
this.settings = await invoke('get_settings');
this.initStatus = '正在同步 Winget 模块...';
await invoke('initialize_app');
this.isInitialized = true;
} catch (err) {
@@ -64,6 +70,23 @@ export const useSoftwareStore = defineStore('software', {
setTimeout(() => { this.isInitialized = true; }, 2000);
}
},
async saveSettings(newSettings: any) {
await invoke('save_settings', { settings: newSettings });
this.settings = newSettings;
},
async syncEssentials() {
this.loading = true;
try {
await invoke('sync_essentials');
await this.fetchEssentials();
} finally {
this.loading = false;
}
},
// ... (Selection methods stay the same)
toggleSelection(id: string, type: 'essential' | 'update') {
if (this.isBusy) return;
const list = type === 'essential' ? this.selectedEssentialIds : this.selectedUpdateIds;
@@ -130,6 +153,9 @@ export const useSoftwareStore = defineStore('software', {
async fetchAllData() {
this.loading = true;
try {
// 在获取全量数据之前,先同步云端清单
await invoke('sync_essentials').catch(() => {});
const [essentials, all, updates] = await Promise.all([
invoke('get_essentials'),
invoke('get_all_software'),

298
src/views/Settings.vue Normal file
View File

@@ -0,0 +1,298 @@
<template>
<div class="settings-view">
<header class="view-header">
<h1>软件设置</h1>
<p class="subtitle">管理仓库地址与应用配置</p>
</header>
<div class="settings-content">
<section class="settings-section">
<h3 class="section-title">仓库配置</h3>
<div class="settings-card">
<div class="setting-item">
<div class="setting-info">
<label>仓库地址</label>
<p>应用将从该地址同步装机必备软件清单</p>
</div>
<div class="setting-action">
<input
type="text"
v-model="tempRepoUrl"
placeholder="https://..."
class="settings-input"
/>
</div>
</div>
<div class="setting-footer">
<button
@click="handleSave"
class="btn-primary"
:disabled="isSaving || !isValidUrl"
>
{{ isSaving ? '正在保存...' : '保存配置' }}
</button>
<button
@click="handleSync"
class="btn-secondary"
:disabled="store.loading"
>
<span v-if="store.loading" class="spinner"></span>
{{ store.loading ? '正在同步...' : '立即同步清单' }}
</button>
</div>
</div>
</section>
<section class="settings-section">
<h3 class="section-title">关于</h3>
<div class="settings-card about-card">
<p>Windows 软件管理器 v0.1.0</p>
<p class="hint">基于 Tauri WinGet 构建的现代化软件管理工具</p>
</div>
</section>
</div>
<!-- 通知提示 -->
<transition name="toast">
<div v-if="toast" class="toast" :class="toast.type">
{{ toast.message }}
</div>
</transition>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useSoftwareStore } from '../store/software'
const store = useSoftwareStore()
const tempRepoUrl = ref('')
const isSaving = ref(false)
const toast = ref<{ message: string, type: 'success' | 'error' } | null>(null)
const isValidUrl = computed(() => {
try {
new URL(tempRepoUrl.value)
return true
} catch {
return false
}
})
onMounted(() => {
tempRepoUrl.value = store.settings.repo_url
})
const showToast = (message: string, type: 'success' | 'error' = 'success') => {
toast.value = { message, type }
setTimeout(() => {
toast.value = null
}, 3000)
}
const handleSave = async () => {
if (!isValidUrl.value) return
isSaving.value = true
try {
await store.saveSettings({ repo_url: tempRepoUrl.value })
showToast('配置已保存')
} catch (err) {
showToast('保存失败: ' + err, 'error')
} finally {
isSaving.value = false
}
}
const handleSync = async () => {
try {
await store.syncEssentials()
showToast('清单同步成功')
} catch (err) {
showToast('同步失败,请检查网络或地址', 'error')
}
}
</script>
<style scoped>
.settings-view {
padding: 60px;
height: 100%;
overflow-y: auto;
background-color: var(--bg-light);
}
.view-header {
margin-bottom: 40px;
}
.view-header h1 {
font-size: 34px;
font-weight: 700;
letter-spacing: -0.5px;
margin-bottom: 8px;
}
.subtitle {
color: var(--text-sec);
font-size: 17px;
}
.settings-content {
max-width: 800px;
}
.settings-section {
margin-bottom: 40px;
}
.section-title {
font-size: 13px;
font-weight: 600;
text-transform: uppercase;
color: var(--text-sec);
margin-bottom: 12px;
padding-left: 4px;
}
.settings-card {
background: white;
border-radius: var(--radius-card);
padding: 24px;
box-shadow: var(--card-shadow);
border: 1px solid var(--border-color);
}
.setting-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
}
.setting-info label {
display: block;
font-size: 16px;
font-weight: 600;
margin-bottom: 4px;
}
.setting-info p {
font-size: 14px;
color: var(--text-sec);
}
.settings-input {
width: 320px;
padding: 12px 16px;
border-radius: 10px;
border: 1px solid var(--border-color);
font-size: 14px;
transition: all 0.2s ease;
background-color: #f5f5f7;
}
.settings-input:focus {
outline: none;
border-color: var(--primary-color);
background-color: white;
box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}
.setting-footer {
display: flex;
gap: 12px;
border-top: 1px solid var(--border-color);
padding-top: 24px;
}
.btn-primary, .btn-secondary {
padding: 10px 20px;
border-radius: 10px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
border: none;
display: flex;
align-items: center;
gap: 8px;
}
.btn-primary {
background-color: var(--primary-color);
color: white;
}
.btn-primary:hover:not(:disabled) {
background-color: var(--primary-hover);
transform: translateY(-1px);
}
.btn-primary:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-secondary {
background-color: #f5f5f7;
color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
background-color: #e5e5e7;
}
.about-card p {
margin-bottom: 4px;
font-weight: 600;
}
.hint {
font-size: 14px;
color: var(--text-sec);
font-weight: 400 !important;
}
/* Toast */
.toast {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
padding: 12px 24px;
border-radius: 12px;
background: #323232;
color: white;
font-size: 14px;
font-weight: 500;
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
z-index: 1000;
}
.toast.error {
background: #ff3b30;
}
.toast-enter-active, .toast-leave-active {
transition: all 0.3s ease;
}
.toast-enter-from, .toast-leave-to {
opacity: 0;
transform: translate(-50%, 20px);
}
.spinner {
width: 16px;
height: 16px;
border: 2px solid rgba(0,0,0,0.1);
border-top-color: var(--text-main);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>