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

111 lines
2.9 KiB
Vue
Raw Normal View History

2024-03-12 10:29:44 +00:00
<template>
<el-dialog title="访问限制" v-model="dialogVisible">
<el-form label-position="top" ref="limitFormRef" :model="form">
2024-03-12 10:55:50 +00:00
<el-form-item label="客户端提问限制">
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"
controls-position="right"
step-strictly
/>
2024-03-12 10:55:50 +00:00
<span class="ml-4"> / </span>
2024-03-12 10:29:44 +00:00
</el-form-item>
<el-form-item label="白名单" @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"
2024-03-14 06:14:20 +00:00
placeholder="请输入允许嵌入第三方的源地址一行一个
http://127.0.0.1:5678
https://dataease.io"
2024-03-12 10:29:44 +00:00
:rows="10"
type="textarea"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
<el-button type="primary" @click="submit(limitFormRef)" :loading="loading">
保存
</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'
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: ''
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') : ''
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
}
applicationApi.putAccessToken(id as string, obj, loading).then((res) => {
emit('refresh')
MsgSuccess('设置成功')
dialogVisible.value = false
})
}
})
}
2024-03-12 10:29:44 +00:00
defineExpose({ open })
</script>
<style lang="scss" scope>
.embed-dialog {
.code {
color: var(--app-text-color) !important;
background: var(--app-layout-bg-color);
font-weight: 400;
font-size: 13px;
white-space: pre;
height: 180px;
}
}
</style>