mirror of https://github.com/1Panel-dev/1Panel
ssongliu
2 years ago
committed by
GitHub
22 changed files with 783 additions and 842 deletions
@ -0,0 +1,100 @@
|
||||
<template> |
||||
<div> |
||||
<el-drawer v-model="drawerVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%"> |
||||
<template #header> |
||||
<DrawerHeader :header="$t('setting.entrance')" :back="handleClose" /> |
||||
</template> |
||||
<el-form label-position="top" v-loading="loading"> |
||||
<el-form-item :label="$t('setting.entrance')" prop="days"> |
||||
<el-input clearable v-model="securityEntrance"> |
||||
<template #append> |
||||
<el-button @click="random" icon="RefreshRight"></el-button> |
||||
</template> |
||||
</el-input> |
||||
<span class="input-help"> |
||||
{{ $t('setting.entranceInputHelper') }} |
||||
</span> |
||||
<span class="input-error" v-if="codeError"> |
||||
{{ $t('setting.entranceError') }} |
||||
</span> |
||||
</el-form-item> |
||||
</el-form> |
||||
<template #footer> |
||||
<span class="dialog-footer"> |
||||
<el-button @click="drawerVisiable = false">{{ $t('commons.button.cancel') }}</el-button> |
||||
<el-button :disabled="loading" type="primary" @click="submitEntrance"> |
||||
{{ $t('commons.button.confirm') }} |
||||
</el-button> |
||||
</span> |
||||
</template> |
||||
</el-drawer> |
||||
</div> |
||||
</template> |
||||
<script lang="ts" setup> |
||||
import { ref } from 'vue'; |
||||
import i18n from '@/lang'; |
||||
import { MsgSuccess } from '@/utils/message'; |
||||
import { updateSetting } from '@/api/modules/setting'; |
||||
import { GlobalStore } from '@/store'; |
||||
import { getRandomStr } from '@/utils/util'; |
||||
const globalStore = GlobalStore(); |
||||
|
||||
const emit = defineEmits<{ (e: 'search'): void }>(); |
||||
|
||||
interface DialogProps { |
||||
securityEntrance: string; |
||||
} |
||||
const securityEntrance = ref(); |
||||
const drawerVisiable = ref(); |
||||
const loading = ref(); |
||||
const codeError = ref(); |
||||
|
||||
const acceptParams = (params: DialogProps): void => { |
||||
securityEntrance.value = params.securityEntrance; |
||||
drawerVisiable.value = true; |
||||
}; |
||||
|
||||
const random = async () => { |
||||
securityEntrance.value = getRandomStr(8); |
||||
}; |
||||
|
||||
const submitEntrance = async () => { |
||||
if (securityEntrance.value !== '') { |
||||
const reg = /^[A-Za-z0-9]{6,10}$/; |
||||
if (!reg.test(securityEntrance.value)) { |
||||
codeError.value = true; |
||||
return; |
||||
} |
||||
} |
||||
let param = { |
||||
key: 'SecurityEntrance', |
||||
value: securityEntrance.value, |
||||
}; |
||||
loading.value = true; |
||||
await updateSetting(param) |
||||
.then(() => { |
||||
globalStore.entrance = securityEntrance.value; |
||||
loading.value = false; |
||||
drawerVisiable.value = false; |
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); |
||||
emit('search'); |
||||
}) |
||||
.catch(() => { |
||||
loading.value = false; |
||||
}); |
||||
}; |
||||
|
||||
const handleClose = () => { |
||||
drawerVisiable.value = false; |
||||
}; |
||||
|
||||
defineExpose({ |
||||
acceptParams, |
||||
}); |
||||
</script> |
||||
|
||||
<style scoped lang="scss"> |
||||
.margintop { |
||||
margin-top: 10px; |
||||
} |
||||
</style> |
@ -0,0 +1,81 @@
|
||||
<template> |
||||
<div> |
||||
<el-drawer v-model="drawerVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%"> |
||||
<template #header> |
||||
<DrawerHeader :header="$t('setting.expirationTime')" :back="handleClose" /> |
||||
</template> |
||||
<el-form ref="timeoutFormRef" label-position="top" :model="form"> |
||||
<el-form-item :label="$t('setting.days')" prop="days" :rules="[Rules.number, checkNumberRange(0, 60)]"> |
||||
<el-input clearable v-model.number="form.days" /> |
||||
<span class="input-help">{{ $t('setting.expirationHelper') }}</span> |
||||
</el-form-item> |
||||
</el-form> |
||||
<template #footer> |
||||
<span class="dialog-footer"> |
||||
<el-button @click="drawerVisiable = false">{{ $t('commons.button.cancel') }}</el-button> |
||||
<el-button type="primary" @click="submitTimeout(timeoutFormRef)"> |
||||
{{ $t('commons.button.confirm') }} |
||||
</el-button> |
||||
</span> |
||||
</template> |
||||
</el-drawer> |
||||
</div> |
||||
</template> |
||||
<script lang="ts" setup> |
||||
import { reactive, ref } from 'vue'; |
||||
import { MsgSuccess } from '@/utils/message'; |
||||
import { updateSetting } from '@/api/modules/setting'; |
||||
import { FormInstance } from 'element-plus'; |
||||
import { Rules, checkNumberRange } from '@/global/form-rules'; |
||||
import i18n from '@/lang'; |
||||
|
||||
const emit = defineEmits<{ (e: 'search'): void }>(); |
||||
|
||||
interface DialogProps { |
||||
expirationDays: number; |
||||
} |
||||
const drawerVisiable = ref(); |
||||
const loading = ref(); |
||||
|
||||
const timeoutFormRef = ref(); |
||||
const form = reactive({ |
||||
days: 0, |
||||
}); |
||||
|
||||
const acceptParams = (params: DialogProps): void => { |
||||
form.days = params.expirationDays; |
||||
drawerVisiable.value = true; |
||||
}; |
||||
|
||||
const submitTimeout = async (formEl: FormInstance | undefined) => { |
||||
if (!formEl) return; |
||||
formEl.validate(async (valid) => { |
||||
if (!valid) return; |
||||
loading.value = true; |
||||
await updateSetting({ key: 'ExpirationDays', value: form.days + '' }) |
||||
.then(() => { |
||||
loading.value = false; |
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); |
||||
emit('search'); |
||||
drawerVisiable.value = false; |
||||
}) |
||||
.catch(() => { |
||||
loading.value = false; |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
const handleClose = () => { |
||||
drawerVisiable.value = false; |
||||
}; |
||||
|
||||
defineExpose({ |
||||
acceptParams, |
||||
}); |
||||
</script> |
||||
|
||||
<style scoped lang="scss"> |
||||
.margintop { |
||||
margin-top: 10px; |
||||
} |
||||
</style> |
Loading…
Reference in new issue