-
Notifications
You must be signed in to change notification settings - Fork 697
Expand file tree
/
Copy pathindex.vue
More file actions
257 lines (250 loc) · 7.05 KB
/
index.vue
File metadata and controls
257 lines (250 loc) · 7.05 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<template>
<div class="authentication">
<p class="router-title">{{ t('system.authentication_settings') }}</p>
<div v-loading="loading" class="authentication-content">
<div class="auth-card-container">
<div v-for="item in showInfos" :key="item.name" class="authentication-card">
<div class="inner-card">
<div class="inner-card-info">
<span class="card-info-left">
<span class="card-span">{{
item.name === 'oauth2' ? 'OAuth2' : item.name.toLocaleUpperCase()
}}</span>
<span
class="card-status"
:class="{
'card-hidden-status': !item.id,
'valid-status': item.id && item.valid,
}"
>{{ item.valid ? t('authentication.valid') : t('authentication.invalid') }}</span
>
</span>
<el-tooltip
v-if="!item.valid"
class="box-item"
effect="dark"
:content="t('authentication.be_turned_on')"
placement="top"
>
<el-switch
v-model="item.enable"
:disabled="!item.valid"
@change="switchEnable(item)"
/>
</el-tooltip>
<el-switch v-else v-model="item.enable" @change="switchEnable(item)" />
</div>
<div class="inner-card-btn">
<el-button secondary @click="editInfo(item)">{{ t('datasource.edit') }}</el-button>
<el-button class="card-validate-btn" secondary @click="validate(item.id)">{{
t('ds.test_connection')
}}</el-button>
</div>
</div>
</div>
</div>
</div>
<cas-editor ref="casEdit" @saved="init" />
<oidc-editor ref="oidcEdit" @saved="init" />
<ldap-editor ref="ldapEdit" @saved="init" />
<oauth2-editor ref="oauth2Edit" @saved="init" />
<saml2-editor ref="saml2Edit" @saved="init" />
</div>
</template>
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { ref } from 'vue'
import { request } from '@/utils/request'
import CasEditor from './CasEditor.vue'
import LdapEditor from './LdapEditor.vue'
import OidcEditor from './OidcEditor.vue'
import Oauth2Editor from './Oauth2Editor.vue'
import Saml2Editor from './SAML2Editor.vue'
import { ElMessage } from 'element-plus-secondary'
const { t } = useI18n()
const loading = ref(false)
interface CardInfo {
id: string
name: string
valid: boolean
enable: boolean
}
const casEdit = ref()
const oidcEdit = ref()
const oauth2Edit = ref()
const saml2Edit = ref()
const ldapEdit = ref()
const infos = ref([] as CardInfo[])
const showInfos = ref([] as CardInfo[])
const init = (needLoading: boolean) => {
if (needLoading) {
loading.value = true
}
const url = '/system/authentication'
request
.get(url)
.then((res) => {
if (res) {
const templateArray = ['ldap', 'oidc', 'cas', 'oauth2']
const resultList = [...(res as CardInfo[])].filter((item) => item.name !== 'saml2')
let resultMap = {} as any
resultList.forEach((item: any) => {
resultMap[item.name] = item
})
infos.value = templateArray.map((item: string) => resultMap[item])
showInfos.value = [...infos.value]
}
loading.value = false
})
.catch((e) => {
console.error(e)
loading.value = false
})
}
const switchEnable = (item: CardInfo) => {
const url = '/system/authentication/enable'
const data = { id: item.id, enable: item.enable }
loading.value = true
request
.patch(url, data)
.then(() => {
init(false)
})
.catch((e) => {
console.error(e)
})
.finally(() => {
loading.value = false
})
}
const editInfo = (item: CardInfo) => {
if (item.name === 'oidc') {
oidcEdit.value?.edit()
} else if (item.name === 'cas') {
casEdit.value?.edit()
} else if (item.name === 'ldap') {
ldapEdit.value?.edit()
} else if (item.name === 'oauth2') {
oauth2Edit.value?.edit()
} else if (item.name === 'saml2') {
saml2Edit.value?.edit()
}
}
const validate = (id: any) => {
loading.value = true
request
.patch('/system/authentication/status', { type: id, name: '', config: '' })
.then((res) => {
if (res) {
ElMessage.success(t('ds.connection_success'))
} else {
ElMessage.error(t('ds.connection_failed'))
}
init(false)
})
.finally(() => {
loading.value = false
})
}
init(true)
</script>
<style lang="less" scoped>
.authentication {
position: relative;
height: 100%;
.router-title {
color: #1f2329;
font-feature-settings:
'clig' off,
'liga' off;
font-family: var(--de-custom_font, 'PingFang');
font-size: 20px;
font-style: normal;
font-weight: 500;
line-height: 28px;
}
.authentication-content {
padding: 16px 0 24px 0;
width: 100%;
height: calc(100% - 28px);
}
.auth-card-container {
height: initial;
display: flex;
flex-wrap: wrap;
gap: 16px;
.authentication-card {
width: calc(25% - 12px);
min-width: 230px;
height: 100px;
padding: 16px;
border-radius: 12px;
background-color: #fff;
border: 1px solid #dee0e3;
&:hover {
box-shadow: 0px 6px 24px 0px #1f232914;
}
.inner-card {
position: relative;
.inner-card-info {
height: 24px;
display: flex;
align-items: center;
.card-info-left {
width: calc(100% - 40px);
display: flex;
align-items: center;
.card-span {
font-family: var(--de-custom_font, 'PingFang');
font-size: 16px;
font-weight: 500;
line-height: 24px;
text-align: left;
}
.card-hidden-status {
display: none;
}
.valid-status {
background-color: #34c72433 !important;
color: #2ca91f !important;
}
.card-status {
margin-left: 8px;
padding: 0 4px;
border-radius: 4px;
background-color: #f54a4533;
color: #d03f3b;
line-height: 20px;
font-size: 12px;
font-weight: 400;
}
}
.ed-switch {
height: 22px;
}
}
.inner-card-btn {
float: left;
height: 28px;
margin-top: 16px;
button {
height: 28px;
min-width: 46px !important;
padding: 4px 11px !important;
:deep(span) {
height: 20px !important;
line-height: 20px !important;
font-size: 12px !important;
display: inline-block;
vertical-align: middle;
}
}
.card-validate-btn {
margin-left: 8px;
}
}
}
}
}
}
</style>