11<script setup lang="ts">
22import type { ConfigFormModal } from ' #components'
3+ import * as mutations from ' ~/mutations'
4+ import * as queries from ' ~/queries'
35
46const apiStore = useAPIStore ()
57const defaults = await apiStore .getDefaults ()
@@ -12,37 +14,7 @@ const updateConfigFormModalRef = ref<InstanceType<typeof ConfigFormModal>>()
1214const { data : configs, execute : reloadConfigs } = useAsyncData (
1315 ' configs' ,
1416 async () => {
15- const data = await apiStore .apiClient ?.query (
16- graphql (`
17- query Configs {
18- configs {
19- id
20- name
21- selected
22- global {
23- logLevel
24- tproxyPort
25- allowInsecure
26- checkInterval
27- checkTolerance
28- lanInterface
29- wanInterface
30- udpCheckDns
31- tcpCheckUrl
32- dialMode
33- tcpCheckHttpMethod
34- disableWaitingNetwork
35- autoConfigKernelParameter
36- sniffingTimeout
37- tlsImplementation
38- utlsImitate
39- tproxyPortProtect
40- }
41- }
42- }
43- ` ),
44- {}
45- )
17+ const data = await apiStore .apiClient ?.query (queries .configs , {})
4618
4719 return data ?.data ?.configs
4820 }
@@ -54,20 +26,27 @@ const removeConfig = async (id: string | number) => {
5426 isRemovingConfig .value = true
5527
5628 try {
57- await apiStore .apiClient ?.mutation (
58- graphql (`
59- mutation RemoveConfig($id: ID!) {
60- removeConfig(id: $id)
61- }
62- ` ),
63- { id }
64- )
29+ await apiStore .apiClient ?.mutation (mutations .removeConfig , { id })
6530
6631 await reloadConfigs ()
6732 } finally {
6833 isRemovingConfig .value = false
6934 }
7035}
36+
37+ const isSelectingConfig = ref (false )
38+
39+ const selectConfig = async (id : string | number ) => {
40+ isSelectingConfig .value = true
41+
42+ try {
43+ await apiStore .apiClient ?.mutation (mutations .selectConfig , { id })
44+
45+ await reloadConfigs ()
46+ } finally {
47+ isSelectingConfig .value = false
48+ }
49+ }
7150 </script >
7251
7352<template >
@@ -114,11 +93,21 @@ const removeConfig = async (id: string | number) => {
11493
11594 <UButton
11695 :loading =" isRemovingConfig"
117- :disabled =" config.id === defaults?.defaultConfigID"
96+ :disabled ="
97+ config.id === defaults?.defaultConfigID || config.selected
98+ "
11899 size =" xs"
119100 icon =" i-heroicons-minus"
120101 @click =" removeConfig(config.id)"
121102 />
103+
104+ <UButton
105+ :loading =" isSelectingConfig"
106+ :disabled =" config.selected"
107+ size =" xs"
108+ icon =" i-heroicons-map-pin"
109+ @click =" selectConfig(config.id)"
110+ />
122111 </div >
123112 </template >
124113 </UCard >
0 commit comments