refactor: use 'auto-refresh-form' in value content

This commit is contained in:
Lykin 2024-01-12 15:45:07 +08:00
parent a663ecdeb5
commit ba8d19a121
1 changed files with 8 additions and 37 deletions

View File

@ -11,9 +11,10 @@ import IconButton from '@/components/common/IconButton.vue'
import Copy from '@/components/icons/Copy.vue' import Copy from '@/components/icons/Copy.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js' import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { computed, onUnmounted, reactive, watch } from 'vue' import { computed, onUnmounted, reactive, watch } from 'vue'
import { isNumber, padStart } from 'lodash' import { padStart } from 'lodash'
import { NIcon, useThemeVars } from 'naive-ui' import { NIcon, useThemeVars } from 'naive-ui'
import { timeout } from '@/utils/promise.js' import { timeout } from '@/utils/promise.js'
import AutoRefreshForm from '@/components/common/AutoRefreshForm.vue'
const props = defineProps({ const props = defineProps({
server: String, server: String,
@ -70,14 +71,6 @@ const ttlString = computed(() => {
}) })
const startAutoRefresh = async () => { const startAutoRefresh = async () => {
if (autoRefresh.on) {
return
}
autoRefresh.on = true
if (!isNumber(autoRefresh.interval)) {
autoRefresh.interval = 2
}
autoRefresh.interval = Math.max(autoRefresh.interval, 1)
let lastExec = Date.now() let lastExec = Date.now()
do { do {
if (!autoRefresh.on) { if (!autoRefresh.on) {
@ -154,34 +147,12 @@ const onTTL = () => {
</n-icon> </n-icon>
</icon-button> </icon-button>
</template> </template>
<n-form <auto-refresh-form
:show-feedback="false" v-model:interval="autoRefresh.interval"
label-align="right" v-model:on="autoRefresh.on"
label-placement="left"
label-width="auto"
size="small">
<n-form-item :label="$t('interface.auto_refresh')">
<n-switch
:loading="props.loading"
:value="autoRefresh.on"
@update:value="onToggleRefresh" />
</n-form-item>
<n-form-item :label="$t('interface.refresh_interval')">
<n-input-number
v-model:value="autoRefresh.interval"
:autofocus="false"
:default-value="2" :default-value="2"
:disabled="autoRefresh.on" :loading="props.loading"
:max="9999" @toggle="onToggleRefresh" />
:min="1"
:show-button="false"
style="max-width: 100px">
<template #suffix>
{{ $t('common.unit_second') }}
</template>
</n-input-number>
</n-form-item>
</n-form>
</n-popover> </n-popover>
</template> </template>
</n-input> </n-input>