-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathAPIKeyDialog.vue
More file actions
160 lines (147 loc) · 4.71 KB
/
APIKeyDialog.vue
File metadata and controls
160 lines (147 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
<el-dialog
:title="$t('layout.apiKey')"
v-model="dialogVisible"
width="800"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-card shadow="never" class="layout-bg mb-16">
<el-text type="info" class="color-secondary">{{ $t('layout.apiServiceAddress') }}</el-text>
<p style="margin-top: 10px">
<span class="vertical-middle lighter break-all">
{{ apiUrl }}
</span>
<el-button type="primary" text @click="copyClick(apiUrl)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</p>
</el-card>
<el-button type="primary" class="mb-16" @click="createApiKey">
{{ $t('common.create') }}
</el-button>
<el-table :data="apiKey" class="mb-16" :loading="loading">
<el-table-column prop="secret_key" label="API Key">
<template #default="{ row }">
<span class="vertical-middle lighter break-all">
{{ row.secret_key }}
</span>
<el-button type="primary" text @click="copyClick(row.secret_key)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</template>
</el-table-column>
<el-table-column :label="$t('common.status.label')" width="80">
<template #default="{ row }">
<div @click.stop>
<el-switch size="small" v-model="row.is_active" @change="changeState($event, row)" />
</div>
</template>
</el-table-column>
<el-table-column prop="name" :label="$t('common.createDate')" width="170">
<template #default="{ row }">
{{ datetimeFormat(row.create_time) }}
</template>
</el-table-column>
<el-table-column :label="$t('common.setting')" align="left" width="80">
<template #default="{ row }">
<span class="mr-4">
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
<el-button type="primary" text @click.stop="settingApiKey(row)">
<AppIcon iconName="app-setting"></AppIcon>
</el-button>
</el-tooltip>
</span>
<el-tooltip effect="dark" :content="$t('common.delete')" placement="top">
<el-button type="primary" text @click="deleteApiKey(row)">
<AppIcon iconName="app-delete"></AppIcon>
</el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<SettingAPIKeyDialog ref="SettingAPIKeyDialogRef" @refresh="refresh" />
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { copyClick } from '@/utils/clipboard'
import systemKeyApi from '@/api/system/api-key'
import { datetimeFormat } from '@/utils/time'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { t } from '@/locales'
import SettingAPIKeyDialog from '@/views/application-overview/component/SettingAPIKeyDialog.vue'
const route = useRoute()
const {
params: { id },
} = route
const props = defineProps({
userId: {
type: String,
default: '',
},
})
const emit = defineEmits(['addData'])
const apiUrl = window.location.origin + `${window.MaxKB.prefix}/api-doc/`
const SettingAPIKeyDialogRef = ref()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
const apiKey = ref<any>(null)
watch(dialogVisible, (bool) => {
if (!bool) {
apiKey.value = null
}
})
function settingApiKey(row: any) {
SettingAPIKeyDialogRef.value.open(row, 'USER')
}
function deleteApiKey(row: any) {
MsgConfirm(
`${t('views.applicationOverview.appInfo.APIKeyDialog.msgConfirm1')}: ${row.secret_key}?`,
t(t('views.applicationOverview.appInfo.APIKeyDialog.msgConfirm2')),
{
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),
confirmButtonClass: 'danger',
},
)
.then(() => {
systemKeyApi.delAPIKey(row.id, loading).then(() => {
MsgSuccess(t('common.deleteSuccess'))
getApiKeyList()
})
})
.catch(() => {})
}
function changeState(bool: boolean, row: any) {
const obj = {
is_active: bool,
}
const str = bool ? t('common.enabled') : t('common.disabled')
systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => {
MsgSuccess(str)
getApiKeyList()
})
}
function createApiKey() {
systemKeyApi.postAPIKey(loading).then((res) => {
getApiKeyList()
})
}
const open = () => {
getApiKeyList()
dialogVisible.value = true
}
function getApiKeyList() {
systemKeyApi.getAPIKey().then((res) => {
res.data.sort((x: any, y: any) => (x.name < y.name ? 1 : -1))
apiKey.value = res.data
})
}
function refresh() {
getApiKeyList()
}
defineExpose({ open })
</script>
<style lang="scss" scope></style>