-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathSettingAPIKeyDialog.vue
More file actions
113 lines (102 loc) · 3.08 KB
/
SettingAPIKeyDialog.vue
File metadata and controls
113 lines (102 loc) · 3.08 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
<template>
<el-dialog
:title="$t('common.setting')"
v-model="dialogVisible"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-form label-position="top" ref="settingFormRef" :model="form">
<el-form-item
:label="$t('views.applicationOverview.appInfo.SettingAPIKeyDialog.allowCrossDomainLabel')"
@click.prevent
>
<el-switch size="small" v-model="form.allow_cross_domain"></el-switch>
</el-form-item>
<el-form-item>
<el-input
v-model="form.cross_domain_list"
:placeholder="
$t('views.applicationOverview.appInfo.SettingAPIKeyDialog.crossDomainPlaceholder')
"
:rows="10"
type="textarea"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="submit(settingFormRef)" :loading="loading">
{{ $t('common.save') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import type { FormInstance, FormRules } from 'element-plus'
import overviewApi from '@/api/application-overview'
import overviewSystemApi from '@/api/system-api-key'
import { MsgSuccess } from '@/utils/message'
import { t } from '@/locales'
const route = useRoute()
const {
params: { id }
} = route
const emit = defineEmits(['refresh'])
const settingFormRef = ref()
const form = ref<any>({
allow_cross_domain: false,
cross_domain_list: ''
})
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
const APIKeyId = ref('')
const APIType = ref('APPLICATION')
watch(dialogVisible, (bool) => {
if (!bool) {
form.value = {
allow_cross_domain: false,
cross_domain_list: ''
}
}
})
const open = (data: any, type: string) => {
APIKeyId.value = data.id
APIType.value = type
form.value.allow_cross_domain = data.allow_cross_domain
form.value.cross_domain_list = data.cross_domain_list?.length
? data.cross_domain_list?.join('\n')
: ''
dialogVisible.value = true
}
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
const obj = {
allow_cross_domain: form.value.allow_cross_domain,
cross_domain_list: form.value.cross_domain_list
? form.value.cross_domain_list.split('\n').filter(function (item: string) {
return item !== ''
})
: []
}
const apiCall =
APIType.value === 'APPLICATION'
? overviewApi.putAPIKey(id as string, APIKeyId.value, obj, loading)
: overviewSystemApi.putAPIKey(APIKeyId.value, obj, loading)
apiCall.then((res) => {
emit('refresh')
//@ts-ignore
MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
}
})
}
defineExpose({ open })
</script>
<style lang="scss" scope></style>