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

188 lines
6.1 KiB
Vue
Raw Normal View History

2024-03-12 10:29:44 +00:00
<template>
2024-07-01 01:45:59 +00:00
<el-dialog
:title="$t('views.applicationOverview.appInfo.LimitDialog.dialogTitle')"
v-model="dialogVisible"
2024-09-24 11:01:35 +00:00
:close-on-click-modal="false"
:close-on-press-escape="false"
2024-07-01 01:45:59 +00:00
>
2024-10-18 07:50:29 +00:00
<el-form label-position="top" ref="limitFormRef" :model="form">
2024-07-22 10:52:56 +00:00
<!-- <el-form-item
2024-07-01 01:45:59 +00:00
:label="$t('views.applicationOverview.appInfo.LimitDialog.showSourceLabel')"
@click.prevent
>
<el-switch size="small" v-model="form.show_source"></el-switch>
2024-07-22 10:52:56 +00:00
</el-form-item> -->
2024-07-01 01:45:59 +00:00
<el-form-item
:label="$t('views.applicationOverview.appInfo.LimitDialog.clientQueryLimitLabel')"
>
2024-03-12 10:29:44 +00:00
<el-input-number
2024-03-12 10:55:50 +00:00
v-model="form.access_num"
2024-03-12 10:29:44 +00:00
:min="0"
:step="1"
2024-07-01 09:14:04 +00:00
:value-on-clear="0"
2024-03-12 10:29:44 +00:00
controls-position="right"
2024-10-18 07:50:29 +00:00
style="width: 268px"
2024-03-12 10:29:44 +00:00
step-strictly
/>
2024-07-01 01:45:59 +00:00
<span class="ml-4">{{
$t('views.applicationOverview.appInfo.LimitDialog.timesDays')
}}</span>
2024-03-12 10:29:44 +00:00
</el-form-item>
<!-- 身份验证 -->
<el-form-item
:label="$t('views.applicationOverview.appInfo.LimitDialog.authentication')"
v-hasPermission="new ComplexPermission([], ['x-pack'], 'OR')"
>
2024-10-18 07:50:29 +00:00
<el-switch size="small" v-model="form.authentication" @change="firstGeneration"></el-switch>
</el-form-item>
<el-form-item
2024-10-16 10:56:54 +00:00
prop="authentication_value"
v-if="form.authentication"
:label="$t('views.applicationOverview.appInfo.LimitDialog.authenticationValue')"
v-hasPermission="new ComplexPermission([], ['x-pack'], 'OR')"
>
2024-10-18 07:50:29 +00:00
<el-input v-model="form.authentication_value" readonly style="width: 268px" disabled>
<template #append>
<div class="button-container">
<el-tooltip content="复制" placement="top">
<el-button
type="primary"
text
@click="copyClick(form.authentication_value)"
style="width: 24px; height: 24px"
>
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
<el-tooltip content="刷新" placement="top">
<el-button
@click="refreshAuthentication"
type="primary"
text
style="width: 24px; height: 24px; margin-left: 20px"
>
<el-icon><RefreshRight /></el-icon>
</el-button>
</el-tooltip>
</div>
</template>
</el-input>
</el-form-item>
2024-07-01 01:45:59 +00:00
<el-form-item
:label="$t('views.applicationOverview.appInfo.LimitDialog.whitelistLabel')"
@click.prevent
>
2024-03-12 10:55:50 +00:00
<el-switch size="small" v-model="form.white_active"></el-switch>
2024-03-12 10:29:44 +00:00
</el-form-item>
<el-form-item>
<el-input
2024-03-12 10:55:50 +00:00
v-model="form.white_list"
:placeholder="$t('views.applicationOverview.appInfo.LimitDialog.whitelistPlaceholder')"
2024-03-12 10:29:44 +00:00
:rows="10"
type="textarea"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
2024-07-01 01:45:59 +00:00
<el-button @click.prevent="dialogVisible = false"
>{{ $t('views.applicationOverview.appInfo.LimitDialog.cancelButtonText') }}
</el-button>
2024-03-12 10:29:44 +00:00
<el-button type="primary" @click="submit(limitFormRef)" :loading="loading">
2024-07-01 01:45:59 +00:00
{{ $t('views.applicationOverview.appInfo.LimitDialog.saveButtonText') }}
2024-03-12 10:29:44 +00:00
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
2024-03-12 10:55:50 +00:00
import type { FormInstance, FormRules } from 'element-plus'
import applicationApi from '@/api/application'
2024-03-12 10:29:44 +00:00
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { t } from '@/locales'
import { copyClick } from '@/utils/clipboard'
import { ComplexPermission } from '@/utils/permission/type'
2024-10-18 07:50:29 +00:00
import { first } from 'lodash'
2024-03-12 10:55:50 +00:00
2024-03-12 10:29:44 +00:00
const route = useRoute()
const {
params: { id }
} = route
2024-03-12 10:55:50 +00:00
const emit = defineEmits(['refresh'])
2024-03-12 10:29:44 +00:00
const limitFormRef = ref()
const form = ref<any>({
2024-03-12 10:55:50 +00:00
access_num: 0,
white_active: true,
white_list: '',
authentication_value: '',
authentication: false
2024-03-12 10:29:44 +00:00
})
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
watch(dialogVisible, (bool) => {
if (!bool) {
form.value = {
2024-03-12 10:55:50 +00:00
access_num: 0,
white_active: true,
white_list: ''
2024-03-12 10:29:44 +00:00
}
}
})
2024-03-12 10:55:50 +00:00
const open = (data: any) => {
form.value.access_num = data.access_num
form.value.white_active = data.white_active
2024-03-14 06:04:49 +00:00
form.value.white_list = data.white_list?.length ? data.white_list?.join('\n') : ''
form.value.authentication_value = data.authentication_value
form.value.authentication = data.authentication
2024-03-12 10:29:44 +00:00
dialogVisible.value = true
}
2024-03-12 10:55:50 +00:00
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
const obj = {
2024-03-14 06:04:49 +00:00
white_list: form.value.white_list ? form.value.white_list.split('\n') : [],
2024-03-12 10:55:50 +00:00
white_active: form.value.white_active,
access_num: form.value.access_num,
authentication: form.value.authentication,
authentication_value: form.value.authentication_value
2024-03-12 10:55:50 +00:00
}
applicationApi.putAccessToken(id as string, obj, loading).then((res) => {
emit('refresh')
// @ts-ignore
MsgSuccess(t('views.applicationOverview.appInfo.LimitDialog.settingSuccessMessage'))
2024-03-12 10:55:50 +00:00
dialogVisible.value = false
})
}
})
}
function generateAuthenticationValue(length: number = 10) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const randomValues = new Uint8Array(length)
window.crypto.getRandomValues(randomValues)
return Array.from(randomValues)
.map((value) => chars[value % chars.length])
.join('')
}
function refreshAuthentication() {
form.value.authentication_value = generateAuthenticationValue()
}
2024-03-12 10:29:44 +00:00
2024-10-18 07:50:29 +00:00
function firstGeneration() {
if (form.value.authentication && !form.value.authentication_value) {
form.value.authentication_value = generateAuthenticationValue()
}
}
2024-03-12 10:29:44 +00:00
defineExpose({ open })
</script>
2024-07-01 01:45:59 +00:00
<style lang="scss" scope></style>