@@ -5,6 +5,7 @@ import { useStorage } from '@vueuse/core'
5
5
const toast = useToast ()
6
6
const key = ref (' ' )
7
7
const columns = [
8
+ { key: ' name' , label: ' Name' },
8
9
{ key: ' key' , label: ' Key' },
9
10
{ key: ' totalLimit' , label: ' Limit' },
10
11
{ key: ' totalUsage' , label: ' Usage' },
@@ -25,13 +26,12 @@ function showToast(msg: string, { color = 'primary' } = {}) {
25
26
}
26
27
27
28
function checkKeyAdded (key : string ) {
28
- const index = keyStore .value .findIndex (item => item .key === key .trim ())
29
- return index > - 1
29
+ return checkRow (keyStore , key )
30
30
}
31
31
32
32
async function getUsages (key : string ) {
33
33
loading .value = true
34
- const { data, pending } = await useFetch < KeyData > (' /api/openai/usage' , {
34
+ const { data, pending } = await useFetch (' /api/openai/usage' , {
35
35
query: {
36
36
key
37
37
},
@@ -54,24 +54,31 @@ async function doQuery () {
54
54
}
55
55
const res = await getUsages (validatedKey )
56
56
res && keyStore .value .push ({
57
+ name: ` Key${keyStore .value .length + 1 } ` ,
57
58
... res
58
59
})
60
+ // cleanup input
61
+ key .value = ' '
62
+ }
63
+
64
+ function onEditName (row : KeyData ) {
65
+ const name = prompt (' Enter your Name' , row .name || ' Key' )
66
+ name && updateRow (keyStore , row .key , {
67
+ name ,
68
+ })
59
69
}
60
70
61
71
async function onRefetchKey(row : KeyData ) {
62
72
const res = await getUsages (row .key )
63
- const index = keyStore . value . findIndex ( item => item . key === row .key . trim ())
64
- if ( index > - 1 ) {
65
- res && keyStore . value . splice ( index , 1 , res )
66
- }
73
+ updateRow ( keyStore , row .key , {
74
+ name: row . name ,
75
+ ... res
76
+ })
67
77
}
68
78
69
79
function onDeleteKey(row : KeyData ) {
70
- const index = keyStore .value .findIndex (item => item .key === row .key .trim ())
71
- if (index > - 1 ) {
72
- keyStore .value .splice (index , 1 )
73
- showToast (' Key has deleted' )
74
- }
80
+ const deleted = deleteRow (keyStore , row .key )
81
+ deleted && showToast (' Key has deleted' )
75
82
}
76
83
</script >
77
84
@@ -100,8 +107,16 @@ function onDeleteKey(row: KeyData) {
100
107
:columns =" columns"
101
108
:rows =" keyStore"
102
109
>
110
+ <template #name-data =" { row } " >
111
+ <div class =" flex items-center justify-center" >
112
+ <span >{{ row.name }}</span >
113
+ <UButton class =" ml-1" size =" 2xs" color =" blue" variant =" ghost" icon =" i-heroicons-pencil-square" @click =" onEditName(row)" />
114
+ </div >
115
+ </template >
103
116
<template #key-data =" { row } " >
104
- <span >{{ hideApiKey(row.key) }}</span >
117
+ <span >
118
+ {{ hideApiKey(row.key) }}
119
+ </span >
105
120
</template >
106
121
<template #totalLimit-data =" { row } " >
107
122
<span class =" font-bold" >${{ row.totalLimit }}</span >
0 commit comments