perf: add quick settings for ttl dialog
This commit is contained in:
parent
18f1b976c6
commit
36a8c38877
|
@ -207,6 +207,7 @@ const onClose = () => {
|
||||||
v-model:value="newForm.ttl"
|
v-model:value="newForm.ttl"
|
||||||
:max="Number.MAX_SAFE_INTEGER"
|
:max="Number.MAX_SAFE_INTEGER"
|
||||||
:min="-1"
|
:min="-1"
|
||||||
|
:show-button="false"
|
||||||
placeholder="TTL">
|
placeholder="TTL">
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
{{ $t('common.second') }}
|
{{ $t('common.second') }}
|
||||||
|
|
|
@ -55,9 +55,9 @@ const onClose = () => {
|
||||||
:closable="false"
|
:closable="false"
|
||||||
:close-on-esc="false"
|
:close-on-esc="false"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
:negative-button-props="{ size: 'medium' }"
|
:negative-button-props="{ focusable: false, size: 'medium' }"
|
||||||
:negative-text="$t('common.cancel')"
|
:negative-text="$t('common.cancel')"
|
||||||
:positive-button-props="{ size: 'medium' }"
|
:positive-button-props="{ focusable: false, size: 'medium' }"
|
||||||
:positive-text="$t('common.confirm')"
|
:positive-text="$t('common.confirm')"
|
||||||
:show-icon="false"
|
:show-icon="false"
|
||||||
:title="$t('interface.rename_key')"
|
:title="$t('interface.rename_key')"
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, watchEffect } from 'vue'
|
import { computed, reactive, watchEffect } from 'vue'
|
||||||
import useDialog from 'stores/dialog'
|
import useDialog from 'stores/dialog'
|
||||||
import useTabStore from 'stores/tab.js'
|
import useTabStore from 'stores/tab.js'
|
||||||
import Binary from '@/components/icons/Binary.vue'
|
import Binary from '@/components/icons/Binary.vue'
|
||||||
import { isEmpty } from 'lodash'
|
import { isEmpty } from 'lodash'
|
||||||
import useBrowserStore from 'stores/browser.js'
|
import useBrowserStore from 'stores/browser.js'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
const ttlForm = reactive({
|
const ttlForm = reactive({
|
||||||
server: '',
|
server: '',
|
||||||
|
@ -12,6 +13,7 @@ const ttlForm = reactive({
|
||||||
key: '',
|
key: '',
|
||||||
keyCode: null,
|
keyCode: null,
|
||||||
ttl: -1,
|
ttl: -1,
|
||||||
|
unit: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
const dialogStore = useDialog()
|
const dialogStore = useDialog()
|
||||||
|
@ -27,6 +29,7 @@ watchEffect(() => {
|
||||||
ttlForm.db = tab.db
|
ttlForm.db = tab.db
|
||||||
ttlForm.key = tab.key
|
ttlForm.key = tab.key
|
||||||
ttlForm.keyCode = tab.keyCode
|
ttlForm.keyCode = tab.keyCode
|
||||||
|
ttlForm.unit = 1
|
||||||
if (tab.ttl < 0) {
|
if (tab.ttl < 0) {
|
||||||
// forever
|
// forever
|
||||||
ttlForm.ttl = -1
|
ttlForm.ttl = -1
|
||||||
|
@ -37,6 +40,36 @@ watchEffect(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const i18n = useI18n()
|
||||||
|
const unit = computed(() => [
|
||||||
|
{ value: 1, label: i18n.t('common.second') },
|
||||||
|
{
|
||||||
|
value: 60,
|
||||||
|
label: i18n.t('common.minute'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 3600,
|
||||||
|
label: i18n.t('common.hour'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 86400,
|
||||||
|
label: i18n.t('common.day'),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const quickOption = computed(() => [
|
||||||
|
{ value: -1, unit: 1, label: i18n.t('interface.forever') },
|
||||||
|
{ value: 10, unit: 1, label: `10 ${i18n.t('common.second')}` },
|
||||||
|
{ value: 1, unit: 60, label: `1 ${i18n.t('common.minute')}` },
|
||||||
|
{ value: 1, unit: 3600, label: `1 ${i18n.t('common.hour')}` },
|
||||||
|
{ value: 1, unit: 86400, label: `1 ${i18n.t('common.day')}` },
|
||||||
|
])
|
||||||
|
|
||||||
|
const onQuickSet = (opt) => {
|
||||||
|
ttlForm.ttl = opt.value
|
||||||
|
ttlForm.unit = opt.unit
|
||||||
|
}
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
dialogStore.closeTTLDialog()
|
dialogStore.closeTTLDialog()
|
||||||
}
|
}
|
||||||
|
@ -48,13 +81,14 @@ const onConfirm = async () => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const key = isEmpty(ttlForm.keyCode) ? ttlForm.key : ttlForm.keyCode
|
const key = isEmpty(ttlForm.keyCode) ? ttlForm.key : ttlForm.keyCode
|
||||||
const success = await browserStore.setTTL(tab.name, tab.db, key, ttlForm.ttl)
|
const ttl = ttlForm.ttl * (ttlForm.unit || 1)
|
||||||
|
const success = await browserStore.setTTL(tab.name, tab.db, key, ttl)
|
||||||
if (success) {
|
if (success) {
|
||||||
tabStore.updateTTL({
|
tabStore.updateTTL({
|
||||||
server: ttlForm.server,
|
server: ttlForm.server,
|
||||||
db: ttlForm.db,
|
db: ttlForm.db,
|
||||||
key: ttlForm.key,
|
key: ttlForm.key,
|
||||||
ttl: ttlForm.ttl,
|
ttl: ttl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -71,6 +105,12 @@ const onConfirm = async () => {
|
||||||
:closable="false"
|
:closable="false"
|
||||||
:close-on-esc="false"
|
:close-on-esc="false"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
|
:negative-button-props="{ focusable: false, size: 'medium' }"
|
||||||
|
:negative-text="$t('common.cancel')"
|
||||||
|
:on-negative-click="onClose"
|
||||||
|
:on-positive-click="onConfirm"
|
||||||
|
:positive-button-props="{ focusable: false, size: 'medium' }"
|
||||||
|
:positive-text="$t('common.save')"
|
||||||
:show-icon="false"
|
:show-icon="false"
|
||||||
:title="$t('dialogue.ttl.title')"
|
:title="$t('dialogue.ttl.title')"
|
||||||
preset="dialog"
|
preset="dialog"
|
||||||
|
@ -84,27 +124,30 @@ const onConfirm = async () => {
|
||||||
</n-input>
|
</n-input>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item :label="$t('interface.ttl')" required>
|
<n-form-item :label="$t('interface.ttl')" required>
|
||||||
|
<n-input-group>
|
||||||
<n-input-number
|
<n-input-number
|
||||||
v-model:value="ttlForm.ttl"
|
v-model:value="ttlForm.ttl"
|
||||||
:max="Number.MAX_SAFE_INTEGER"
|
:max="Number.MAX_SAFE_INTEGER"
|
||||||
:min="-1"
|
:min="-1"
|
||||||
style="width: 100%">
|
:show-button="false"
|
||||||
<template #suffix>
|
class="flex-item-expand" />
|
||||||
{{ $t('common.second') }}
|
<n-select v-model:value="ttlForm.unit" :options="unit" style="max-width: 150px" />
|
||||||
</template>
|
</n-input-group>
|
||||||
</n-input-number>
|
</n-form-item>
|
||||||
|
<n-form-item :label="$t('dialogue.ttl.quick_set')" :show-feedback="false">
|
||||||
|
<n-space :wrap="true" :wrap-item="false">
|
||||||
|
<n-button
|
||||||
|
v-for="(opt, i) in quickOption"
|
||||||
|
:key="i"
|
||||||
|
round
|
||||||
|
secondary
|
||||||
|
size="small"
|
||||||
|
@click="onQuickSet(opt)">
|
||||||
|
{{ opt.label }}
|
||||||
|
</n-button>
|
||||||
|
</n-space>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-form>
|
</n-form>
|
||||||
|
|
||||||
<template #action>
|
|
||||||
<div class="flex-item-expand">
|
|
||||||
<n-button :focusable="false" @click="ttlForm.ttl = -1">{{ $t('dialogue.key.persist_key') }}</n-button>
|
|
||||||
</div>
|
|
||||||
<div class="flex-item n-dialog__action">
|
|
||||||
<n-button :focusable="false" @click="onClose">{{ $t('common.cancel') }}</n-button>
|
|
||||||
<n-button :focusable="false" type="primary" @click="onConfirm">{{ $t('common.save') }}</n-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</n-modal>
|
</n-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
"update": "Update",
|
"update": "Update",
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"second": "Second(s)",
|
"second": "Second(s)",
|
||||||
|
"minute": "Minutes(s)",
|
||||||
|
"hour": "Hour(s)",
|
||||||
|
"day": "Day(s)",
|
||||||
"unit_day": "D",
|
"unit_day": "D",
|
||||||
"unit_hour": "H",
|
"unit_hour": "H",
|
||||||
"unit_minute": "M",
|
"unit_minute": "M",
|
||||||
|
@ -294,7 +297,8 @@
|
||||||
"import_completed": "Import completed, {success} successes, {ignored} failed"
|
"import_completed": "Import completed, {success} successes, {ignored} failed"
|
||||||
},
|
},
|
||||||
"ttl": {
|
"ttl": {
|
||||||
"title": "Set Key TTL"
|
"title": "Set Key TTL",
|
||||||
|
"quick_set": "Quick Settings"
|
||||||
},
|
},
|
||||||
"upgrade": {
|
"upgrade": {
|
||||||
"title": "New Version Available",
|
"title": "New Version Available",
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
"update": "更新",
|
"update": "更新",
|
||||||
"none": "无",
|
"none": "无",
|
||||||
"second": "秒",
|
"second": "秒",
|
||||||
|
"minute": "分钟",
|
||||||
|
"hour": "小时",
|
||||||
|
"day": "天",
|
||||||
"unit_day": "天",
|
"unit_day": "天",
|
||||||
"unit_hour": "小时",
|
"unit_hour": "小时",
|
||||||
"unit_minute": "分钟",
|
"unit_minute": "分钟",
|
||||||
|
@ -296,7 +299,8 @@
|
||||||
"import_completed": "已完成导入操作,成功{success}个,忽略{ignored}个"
|
"import_completed": "已完成导入操作,成功{success}个,忽略{ignored}个"
|
||||||
},
|
},
|
||||||
"ttl": {
|
"ttl": {
|
||||||
"title": "设置键存活时间"
|
"title": "设置键存活时间",
|
||||||
|
"quick_set": "快捷设置"
|
||||||
},
|
},
|
||||||
"upgrade": {
|
"upgrade": {
|
||||||
"title": "有可用新版本",
|
"title": "有可用新版本",
|
||||||
|
|
Loading…
Reference in New Issue