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

121 lines
3.5 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-03-12 10:29:44 +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"
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>
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'
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')
// @ts-ignore
MsgSuccess(t('views.applicationOverview.appInfo.LimitDialog.settingSuccessMessage'))
2024-03-12 10:55:50 +00:00
dialogVisible.value = false
})
}
})
}
2024-03-12 10:29:44 +00:00
defineExpose({ open })
</script>
2024-07-01 01:45:59 +00:00
<style lang="scss" scope></style>