UnisKB/ui/src/views/application-overview/component/SettingAPIKeyDialog.vue

114 lines
3.1 KiB
Vue
Raw Normal View History

2024-05-08 09:13:13 +00:00
<template>
2024-09-24 11:01:35 +00:00
<el-dialog
2025-01-22 08:46:12 +00:00
:title="$t('common.setting')"
2024-09-24 11:01:35 +00:00
v-model="dialogVisible"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
2024-05-08 09:13:13 +00:00
<el-form label-position="top" ref="settingFormRef" :model="form">
2024-09-24 11:01:35 +00:00
<el-form-item
:label="$t('views.applicationOverview.appInfo.SettingAPIKeyDialog.allowCrossDomainLabel')"
@click.prevent
>
2024-05-08 09:13:13 +00:00
<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"
2024-09-24 11:01:35 +00:00
:placeholder="
$t('views.applicationOverview.appInfo.SettingAPIKeyDialog.crossDomainPlaceholder')
"
2024-05-08 09:13:13 +00:00
:rows="10"
type="textarea"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
2025-01-13 03:15:51 +00:00
<el-button @click.prevent="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
2024-05-08 09:13:13 +00:00
<el-button type="primary" @click="submit(settingFormRef)" :loading="loading">
2025-01-13 03:15:51 +00:00
{{ $t('common.save') }}
2024-05-08 09:13:13 +00:00
</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'
2025-01-13 03:15:51 +00:00
import overviewSystemApi from '@/api/system-api-key'
2025-03-05 02:56:04 +00:00
import { MsgSuccess } from '@/utils/message'
import { t } from '@/locales'
2025-01-13 03:15:51 +00:00
2024-05-08 09:13:13 +00:00
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('')
2025-01-13 03:15:51 +00:00
const APIType = ref('APPLICATION')
2024-05-08 09:13:13 +00:00
watch(dialogVisible, (bool) => {
if (!bool) {
form.value = {
allow_cross_domain: false,
cross_domain_list: ''
}
}
})
2025-01-13 03:15:51 +00:00
const open = (data: any, type: string) => {
2024-05-08 09:13:13 +00:00
APIKeyId.value = data.id
2025-01-13 03:15:51 +00:00
APIType.value = type
2024-05-08 09:13:13 +00:00
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
2024-05-09 09:58:21 +00:00
? form.value.cross_domain_list.split('\n').filter(function (item: string) {
return item !== ''
})
2024-05-08 09:13:13 +00:00
: []
}
2025-01-13 03:15:51 +00:00
const apiCall =
APIType.value === 'APPLICATION'
? overviewApi.putAPIKey(id as string, APIKeyId.value, obj, loading)
: overviewSystemApi.putAPIKey(APIKeyId.value, obj, loading)
apiCall.then((res) => {
2024-05-08 09:13:13 +00:00
emit('refresh')
//@ts-ignore
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.settingSuccess'))
2024-05-08 09:13:13 +00:00
dialogVisible.value = false
})
}
})
}
defineExpose({ open })
</script>
<style lang="scss" scoped></style>