This commit is contained in:
2025-11-10 00:59:40 +08:00
parent 78c46aed71
commit bac96fcbe6
76 changed files with 8726 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import { defineStore } from 'pinia'
import storage from '@/utils/storage'
const STORAGE_KEY = 'cosy_voice_profiles'
export const useVoiceCopyStore = defineStore('voiceCopy', {
state: () => ({
profiles: [],
activeId: '',
loaded: false,
}),
getters: {
activeProfile(state) {
return state.profiles.find(p => p.id === state.activeId) || null
}
},
actions: {
generateId() {
return `${Date.now()}_${Math.floor(Math.random() * 1e6)}`
},
async load() {
if (this.loaded) return
const list = await storage.getJSON(STORAGE_KEY, [])
this.profiles = Array.isArray(list) ? list : []
if (!this.activeId && this.profiles.length) this.activeId = this.profiles[0].id
this.loaded = true
},
async persist() {
await storage.setJSON(STORAGE_KEY, this.profiles)
},
async add(profile) {
const id = this.generateId()
const name = profile.name || `克隆语音-${this.profiles.length + 1}`
const payload = { ...profile, id, name }
this.profiles.unshift(payload)
this.activeId = id
await this.persist()
return payload
},
async update(profile) {
const idx = this.profiles.findIndex(p => p.id === profile.id)
if (idx === -1) return await this.add({ ...profile, id: '' })
this.profiles[idx] = { ...profile }
await this.persist()
return this.profiles[idx]
},
async duplicate(profile, name) {
const copy = { ...profile, id: '', name }
return await this.add(copy)
},
async remove(id) {
this.profiles = this.profiles.filter(p => p.id !== id)
if (this.activeId === id) this.activeId = this.profiles[0]?.id || ''
await this.persist()
},
select(id) {
this.activeId = id
}
}
})