detect
This commit is contained in:
@@ -9,6 +9,32 @@ export const useSoftwareStore = defineStore('software', {
|
||||
allSoftware: [] as any[],
|
||||
loading: false
|
||||
}),
|
||||
getters: {
|
||||
mergedEssentials: (state) => {
|
||||
return state.essentials.map(item => {
|
||||
const isInstalled = state.allSoftware.some(s => s.id.toLowerCase() === item.id.toLowerCase());
|
||||
const hasUpdate = state.updates.some(s => s.id.toLowerCase() === item.id.toLowerCase());
|
||||
|
||||
let displayStatus = item.status;
|
||||
let actionLabel = '安装';
|
||||
|
||||
if (isInstalled) {
|
||||
if (hasUpdate) {
|
||||
actionLabel = '更新';
|
||||
} else if (displayStatus === 'idle') {
|
||||
displayStatus = 'installed';
|
||||
actionLabel = '已安装';
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
status: displayStatus,
|
||||
actionLabel
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async fetchEssentials() {
|
||||
this.essentials = await invoke('get_essentials')
|
||||
@@ -23,6 +49,19 @@ export const useSoftwareStore = defineStore('software', {
|
||||
this.allSoftware = await invoke('get_all_software')
|
||||
this.loading = false
|
||||
},
|
||||
async fetchAllData() {
|
||||
this.loading = true;
|
||||
// 并行获取三类数据
|
||||
const [essentials, all, updates] = await Promise.all([
|
||||
invoke('get_essentials'),
|
||||
invoke('get_all_software'),
|
||||
invoke('get_updates')
|
||||
]);
|
||||
this.essentials = essentials as any[];
|
||||
this.allSoftware = all as any[];
|
||||
this.updates = updates as any[];
|
||||
this.loading = false;
|
||||
},
|
||||
async install(id: string) {
|
||||
const software = this.findSoftware(id)
|
||||
if (software) software.status = 'pending'
|
||||
|
||||
Reference in New Issue
Block a user