Skip to content

Commit

Permalink
磁盘监控增加表单验证
Browse files Browse the repository at this point in the history
  • Loading branch information
hslr-s committed Jan 8, 2024
1 parent 3905717 commit fc56328
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
34 changes: 32 additions & 2 deletions src/components/deskModule/SystemMonitor/Edit/DiskEditor/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import type { FormInst, FormRules } from 'naive-ui'
import { NColorPicker, NForm, NFormItem, NSelect } from 'naive-ui'
import type { DiskExtendParam } from '../../typings'
import GenericMonitorCard from '../../components/GenericMonitorCard/index.vue'
import GenericProgress from '../../components/GenericProgress/index.vue'
import { PanelPanelConfigStyleEnum } from '@/enums'
import { getDiskMountpoints } from '@/api/system/systemMonitor'
import { defautSwatchesBackground } from '@/utils/defaultData'
import { t } from '@/locales'
interface Emit {
(e: 'update:diskExtendParam', visible: DiskExtendParam): void
Expand All @@ -16,6 +18,14 @@ const props = defineProps<{
diskExtendParam: DiskExtendParam
}>()
const emit = defineEmits<Emit>()
const formRef = ref<FormInst | null>(null)
const rules: FormRules = {
path: {
required: true,
message: t('form.required'),
trigger: 'blur',
},
}
const mountPointList = ref<{
label: string
Expand Down Expand Up @@ -52,6 +62,26 @@ async function getMountPointList() {
onMounted(() => {
getMountPointList()
})
defineExpose({
async verification(): Promise<boolean> {
try {
const errors = await formRef.value?.validate()
if (!errors) {
return Promise.resolve(true)
}
else {
console.log(errors)
return Promise.resolve(false)
}
}
catch (error) {
console.error('An error occurred during validation:', error)
return Promise.resolve(false)
}
},
})
</script>

<template>
Expand Down Expand Up @@ -102,8 +132,8 @@ onMounted(() => {
</div>
</div>

<NForm ref="formRef" v-model="extendParam">
<NFormItem :label="$t('deskModule.systemMonitor.diskMountPoint')">
<NForm ref="formRef" v-model="extendParam" :model="extendParam" :rules="rules">
<NFormItem :label="$t('deskModule.systemMonitor.diskMountPoint')" path="path">
<NSelect v-model:value="extendParam.path" size="small" :options="mountPointList" />
</NFormItem>
<NFormItem :label="$t('deskModule.systemMonitor.progressColor')">
Expand Down
16 changes: 12 additions & 4 deletions src/components/deskModule/SystemMonitor/Edit/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
const props = defineProps<Props>()
const emit = defineEmits<Emit>()
const DiskEditorRef = ref<InstanceType<typeof DiskEditor>>()
// 默认通用的进度扩展参数
const defaultGenericProgressStyleExtendParam: GenericProgressStyleExtendParam = {
Expand Down Expand Up @@ -78,14 +79,21 @@ function handleResetExtendParam() {
// 保存提交
async function handleSubmit() {
let verificationRes = true
currentMonitorData.value.monitorType = active.value as MonitorType
if (currentMonitorData.value.monitorType === MonitorType.cpu || currentMonitorData.value.monitorType === MonitorType.memory)
if (currentMonitorData.value.monitorType === MonitorType.cpu || currentMonitorData.value.monitorType === MonitorType.memory) {
currentMonitorData.value.extendParam = currentGenericProgressStyleExtendParam
else if (currentMonitorData.value.monitorType === MonitorType.disk)
}
else if (currentMonitorData.value.monitorType === MonitorType.disk) {
currentMonitorData.value.extendParam = currentDiskExtendParam
const res = await DiskEditorRef.value?.verification()
if (res !== undefined)
verificationRes = res
}
// console.log('保存', currentMonitorData.value.extendParam)
if (!verificationRes)
return
if (props.index !== null) {
const res = await saveByIndex(props.index, currentMonitorData.value)
Expand Down Expand Up @@ -125,7 +133,7 @@ async function handleSubmit() {
<GenericProgressStyleEditor v-model:genericProgressStyleExtendParam="currentGenericProgressStyleExtendParam" />
</NTabPane>
<NTabPane :name="MonitorType.disk" :tab="$t('deskModule.systemMonitor.diskState')">
<DiskEditor v-model:disk-extend-param="currentDiskExtendParam" />
<DiskEditor ref="DiskEditorRef" v-model:disk-extend-param="currentDiskExtendParam" />
</NTabPane>
</NTabs>
<NButton @click="handleResetExtendParam">
Expand Down

0 comments on commit fc56328

Please sign in to comment.