Skip to content

Commit bbcc451

Browse files
feat: user
1 parent 31f6da2 commit bbcc451

File tree

12 files changed

+1882
-25
lines changed

12 files changed

+1882
-25
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
2+
<div class="authentication-setting__main main-calc-height">
3+
<el-scrollbar>
4+
<div class="form-container p-24" v-loading="loading">
5+
<el-form
6+
ref="authFormRef"
7+
:rules="rules"
8+
:model="form"
9+
label-position="top"
10+
require-asterisk-position="right"
11+
>
12+
<el-form-item
13+
:label="$t('views.system.authentication.cas.ldpUri')"
14+
prop="config.ldpUri"
15+
>
16+
<el-input
17+
v-model="form.config.ldpUri"
18+
:placeholder="$t('views.system.authentication.cas.ldpUriPlaceholder')"
19+
/>
20+
</el-form-item>
21+
<el-form-item
22+
:label="$t('views.system.authentication.cas.validateUrl')"
23+
prop="config.validateUrl"
24+
>
25+
<el-input
26+
v-model="form.config.validateUrl"
27+
:placeholder="$t('views.system.authentication.cas.validateUrlPlaceholder')"
28+
/>
29+
</el-form-item>
30+
<el-form-item
31+
:label="$t('views.system.authentication.cas.redirectUrl')"
32+
prop="config.redirectUrl"
33+
>
34+
<el-input
35+
v-model="form.config.redirectUrl"
36+
:placeholder="$t('views.system.authentication.cas.redirectUrlPlaceholder')"
37+
/>
38+
</el-form-item>
39+
<el-form-item>
40+
<el-checkbox v-model="form.is_active"
41+
>{{ $t('views.system.authentication.cas.enableAuthentication') }}
42+
</el-checkbox>
43+
</el-form-item>
44+
</el-form>
45+
46+
<div class="text-right">
47+
<el-button @click="submit(authFormRef)" type="primary" :disabled="loading">
48+
{{ $t('common.save') }}
49+
</el-button>
50+
</div>
51+
</div>
52+
</el-scrollbar>
53+
</div>
54+
</template>
55+
<script setup lang="ts">
56+
import { reactive, ref, watch, onMounted } from 'vue'
57+
import authApi from '@/api/system-settings/auth-setting'
58+
import type { FormInstance, FormRules } from 'element-plus'
59+
import { t } from '@/locales'
60+
import { MsgSuccess } from '@/utils/message'
61+
62+
const form = ref<any>({
63+
id: '',
64+
auth_type: 'CAS',
65+
config: {
66+
ldpUri: '',
67+
validateUrl: '',
68+
redirectUrl: ''
69+
},
70+
is_active: true
71+
})
72+
73+
const authFormRef = ref()
74+
75+
const loading = ref(false)
76+
77+
const rules = reactive<FormRules<any>>({
78+
'config.ldpUri': [
79+
{
80+
required: true,
81+
message: t('views.system.authentication.cas.ldpUriPlaceholder'),
82+
trigger: 'blur'
83+
}
84+
],
85+
'config.validateUrl': [
86+
{
87+
required: true,
88+
message: t('views.system.authentication.cas.validateUrlPlaceholder'),
89+
trigger: 'blur'
90+
}
91+
],
92+
'config.redirectUrl': [
93+
{
94+
required: true,
95+
message: t('views.system.authentication.cas.redirectUrlPlaceholder'),
96+
trigger: 'blur'
97+
}
98+
]
99+
})
100+
101+
const submit = async (formEl: FormInstance | undefined) => {
102+
if (!formEl) return
103+
await formEl.validate((valid, fields) => {
104+
if (valid) {
105+
authApi.putAuthSetting(form.value.auth_type, form.value, loading).then((res) => {
106+
MsgSuccess(t('common.saveSuccess'))
107+
})
108+
}
109+
})
110+
}
111+
112+
function getDetail() {
113+
authApi.getAuthSetting(form.value.auth_type, loading).then((res: any) => {
114+
if (res.data && JSON.stringify(res.data) !== '{}') {
115+
if (!res.data.config.validateUrl) {
116+
res.data.config.validateUrl = res.data.config.ldpUri
117+
}
118+
form.value = res.data
119+
}
120+
})
121+
}
122+
123+
onMounted(() => {
124+
getDetail()
125+
})
126+
</script>
127+
<style lang="scss" scoped></style>
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
template
2+
<template>
3+
<el-drawer
4+
v-model="visible"
5+
size="60%"
6+
:append-to-body="true"
7+
:destroy-on-close="true"
8+
@close="handleClose"
9+
>
10+
<template #header>
11+
<div class="flex align-center" style="margin-left: -8px">
12+
<h4>
13+
{{ currentPlatform.name + $t('views.system.authentication.scanTheQRCode.setting') }}
14+
</h4>
15+
</div>
16+
</template>
17+
18+
<el-form
19+
:model="currentPlatform.config"
20+
label-width="120px"
21+
label-position="top"
22+
require-asterisk-position="right"
23+
ref="formRef"
24+
>
25+
<el-form-item
26+
v-for="(value, key) in currentPlatform.config"
27+
:key="key"
28+
:label="formatFieldName(key)"
29+
:prop="key"
30+
:rules="getValidationRules(key)"
31+
>
32+
<el-input
33+
v-model="currentPlatform.config[key]"
34+
:type="isPasswordField(key) ? 'password' : 'text'"
35+
:show-password="isPasswordField(key)"
36+
>
37+
</el-input>
38+
</el-form-item>
39+
</el-form>
40+
<template #footer>
41+
<span class="dialog-footer">
42+
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
43+
<el-button @click="validateConnection">{{
44+
$t('views.system.authentication.scanTheQRCode.validate')
45+
}}</el-button>
46+
<el-button type="primary" @click="validateForm">{{ $t('common.save') }}</el-button>
47+
</span>
48+
</template>
49+
</el-drawer>
50+
</template>
51+
52+
<script setup lang="ts">
53+
import { reactive, ref } from 'vue'
54+
import { ElForm } from 'element-plus'
55+
import platformApi from '@/api/system-settings/platform-source'
56+
import { MsgError, MsgSuccess } from '@/utils/message'
57+
import { t } from '@/locales'
58+
59+
const visible = ref(false)
60+
const loading = ref(false)
61+
const formRef = ref<InstanceType<typeof ElForm>>()
62+
63+
interface PlatformConfig {
64+
[key: string]: string
65+
}
66+
67+
interface Platform {
68+
key: string
69+
logoSrc: string
70+
name: string
71+
isActive: boolean
72+
isValid: boolean
73+
config: PlatformConfig
74+
}
75+
76+
const currentPlatform = reactive<Platform>({
77+
key: '',
78+
logoSrc: '',
79+
name: '',
80+
isActive: false,
81+
isValid: false,
82+
config: {}
83+
})
84+
85+
const formatFieldName = (key?: any): string => {
86+
const fieldNames: { [key: string]: string } = {
87+
corp_id: 'Corp ID',
88+
app_key: currentPlatform?.key != 'lark' ? 'APP Key' : 'App ID',
89+
app_secret: 'APP Secret',
90+
agent_id: 'Agent ID',
91+
callback_url: t('views.application.applicationAccess.callback')
92+
}
93+
return (
94+
fieldNames[key as keyof typeof fieldNames] ||
95+
(key ? key.charAt(0).toUpperCase() + key.slice(1) : '')
96+
)
97+
}
98+
99+
const getValidationRules = (key: any) => {
100+
switch (key) {
101+
case 'app_key':
102+
return [
103+
{
104+
required: true,
105+
message: t('views.system.authentication.scanTheQRCode.appKeyPlaceholder'),
106+
trigger: ['blur', 'change']
107+
}
108+
]
109+
case 'app_secret':
110+
return [
111+
{
112+
required: true,
113+
message: t('views.system.authentication.scanTheQRCode.appSecretPlaceholder'),
114+
trigger: ['blur', 'change']
115+
}
116+
]
117+
case 'corp_id':
118+
return [
119+
{
120+
required: true,
121+
message: t('views.system.authentication.scanTheQRCode.corpIdPlaceholder'),
122+
trigger: ['blur', 'change']
123+
}
124+
]
125+
case 'agent_id':
126+
return [
127+
{
128+
required: true,
129+
message: t('views.system.authentication.scanTheQRCode.agentIdPlaceholder'),
130+
trigger: ['blur', 'change']
131+
}
132+
]
133+
case 'callback_url':
134+
return [
135+
{
136+
required: true,
137+
message: t('views.application.applicationAccess.callbackTip'),
138+
trigger: ['blur', 'change']
139+
},
140+
{
141+
pattern: /^https?:\/\/.+/,
142+
message: t('views.system.authentication.scanTheQRCode.callbackWarning'),
143+
trigger: ['blur', 'change']
144+
}
145+
]
146+
default:
147+
return []
148+
}
149+
}
150+
151+
const open = async (platform: Platform) => {
152+
visible.value = true
153+
loading.value = true
154+
Object.assign(currentPlatform, platform)
155+
156+
// 设置默认的 callback_url
157+
const defaultCallbackUrl = window.location.origin
158+
switch (platform.key) {
159+
case 'wecom':
160+
if (currentPlatform.config.app_key) {
161+
currentPlatform.config.agent_id = currentPlatform.config.app_key
162+
delete currentPlatform.config.app_key
163+
}
164+
currentPlatform.config.callback_url = `${defaultCallbackUrl}/api/wecom`
165+
break
166+
case 'dingtalk':
167+
if (currentPlatform.config.agent_id) {
168+
currentPlatform.config.corp_id = currentPlatform.config.agent_id
169+
delete currentPlatform.config.agent_id
170+
}
171+
currentPlatform.config = {
172+
corp_id: currentPlatform.config.corp_id,
173+
app_key: currentPlatform.config.app_key,
174+
app_secret: currentPlatform.config.app_secret,
175+
callback_url: defaultCallbackUrl
176+
}
177+
currentPlatform.config.callback_url = `${defaultCallbackUrl}/api/dingtalk`
178+
break
179+
case 'lark':
180+
currentPlatform.config.callback_url = `${defaultCallbackUrl}/api/feishu`
181+
break
182+
default:
183+
break
184+
}
185+
formRef.value?.clearValidate()
186+
}
187+
defineExpose({ open })
188+
189+
const validateForm = () => {
190+
formRef.value?.validate((valid) => {
191+
if (valid) {
192+
saveConfig()
193+
} else {
194+
MsgError(t('views.system.authentication.scanTheQRCode.validateFailedTip'))
195+
}
196+
})
197+
}
198+
199+
const handleClose = () => {
200+
visible.value = false
201+
formRef.value?.clearValidate()
202+
emit('refresh')
203+
}
204+
205+
function validateConnection() {
206+
platformApi.validateConnection(currentPlatform, loading).then((res: any) => {
207+
if (res.data) {
208+
MsgSuccess(t('views.system.authentication.scanTheQRCode.validateSuccess'))
209+
} else {
210+
MsgError(t('views.system.authentication.scanTheQRCode.validateFailed'))
211+
}
212+
})
213+
}
214+
215+
const passwordFields = new Set(['app_secret', 'client_secret', 'secret'])
216+
217+
const isPasswordField = (key: any) => passwordFields.has(key)
218+
const emit = defineEmits(['refresh'])
219+
220+
function saveConfig() {
221+
platformApi.updateConfig(currentPlatform, loading).then((res: any) => {
222+
MsgSuccess(t('common.saveSuccess'))
223+
emit('refresh')
224+
visible.value = false
225+
formRef.value?.clearValidate()
226+
})
227+
}
228+
</script>
229+
230+
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)