37 lines
802 B
TypeScript
37 lines
802 B
TypeScript
import { ref } from 'vue'
|
|
import api from '@/api/client'
|
|
|
|
export interface Preset {
|
|
id: number
|
|
name: string
|
|
service_type: string
|
|
params_json: string
|
|
}
|
|
|
|
export function usePresets(serviceType: string) {
|
|
const items = ref<Preset[]>([])
|
|
|
|
async function load() {
|
|
const res = await api.get<{ items: Preset[] }>('/user/presets', {
|
|
params: { service_type: serviceType },
|
|
})
|
|
items.value = res.data.items
|
|
}
|
|
|
|
async function save(name: string, params: Record<string, unknown>) {
|
|
await api.post('/user/presets', {
|
|
name,
|
|
service_type: serviceType,
|
|
params_json: JSON.stringify(params),
|
|
})
|
|
await load()
|
|
}
|
|
|
|
async function remove(id: number) {
|
|
await api.delete(`/user/presets/${id}`)
|
|
await load()
|
|
}
|
|
|
|
return { items, load, save, remove }
|
|
}
|