123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <script setup lang="ts">
- import type { InstallLockResponse } from '@/api/install'
- import install from '@/api/install'
- import SetLanguage from '@/components/SetLanguage/SetLanguage.vue'
- import SwitchAppearance from '@/components/SwitchAppearance/SwitchAppearance.vue'
- import { DatabaseOutlined, LockOutlined, MailOutlined, UserOutlined } from '@ant-design/icons-vue'
- import { Form, message } from 'ant-design-vue'
- const thisYear = new Date().getFullYear()
- const loading = ref(false)
- const installTimeout = ref(false)
- const router = useRouter()
- function init() {
- install.get_lock().then(async (r: InstallLockResponse) => {
- if (r.lock)
- await router.push('/login')
- if (r.timeout) {
- installTimeout.value = true
- }
- })
- }
- onMounted(() => {
- if (import.meta.env.DEV) {
- const route = useRoute()
- if (route.query.install !== 'false') {
- init()
- }
- else {
- installTimeout.value = route.query.timeout === 'true'
- }
- }
- else {
- init()
- }
- })
- const modelRef = reactive({
- email: '',
- username: '',
- password: '',
- database: '',
- })
- const rulesRef = reactive({
- email: [
- {
- required: true,
- type: 'email',
- message: () => $gettext('Please input your E-mail!'),
- },
- ],
- username: [
- {
- required: true,
- message: () => $gettext('Please input your username!'),
- },
- ],
- password: [
- {
- required: true,
- message: () => $gettext('Please input your password!'),
- },
- {
- max: 20,
- message: () => $gettext('Password length cannot exceed 20 characters'),
- },
- ],
- database: [
- {
- message: () =>
- $gettext('The filename cannot contain the following characters: %{c}', { c: '& " ? < > # {} % ~ / \\' }),
- },
- ],
- })
- const { validate, validateInfos } = Form.useForm(modelRef, rulesRef)
- function onSubmit() {
- validate().then(() => {
- // modelRef
- loading.value = true
- install.install_nginx_ui(modelRef).then(async () => {
- message.success($gettext('Install successfully'))
- await router.push('/login')
- }).catch(error => {
- if (error && error.code === 40308) {
- installTimeout.value = true
- }
- }).finally(() => {
- loading.value = false
- })
- })
- }
- </script>
- <template>
- <ALayout>
- <ALayoutContent>
- <div class="login-container">
- <div class="login-form">
- <div class="project-title">
- <h1>Nginx UI</h1>
- </div>
- <AAlert
- v-if="installTimeout"
- type="warning"
- :message="$gettext('Installation is not allowed after 10 minutes of system startup, please restart the Nginx UI.')"
- show-icon
- style="margin-bottom: 20px;"
- />
- <AForm v-else id="components-form-install">
- <AFormItem v-bind="validateInfos.email">
- <AInput
- v-model:value="modelRef.email"
- :placeholder="$gettext('Email (*)')"
- >
- <template #prefix>
- <MailOutlined />
- </template>
- </AInput>
- </AFormItem>
- <AFormItem v-bind="validateInfos.username">
- <AInput
- v-model:value="modelRef.username"
- :placeholder="$gettext('Username (*)')"
- >
- <template #prefix>
- <UserOutlined />
- </template>
- </AInput>
- </AFormItem>
- <AFormItem v-bind="validateInfos.password">
- <AInputPassword
- v-model:value="modelRef.password"
- :placeholder="$gettext('Password (*)')"
- >
- <template #prefix>
- <LockOutlined />
- </template>
- </AInputPassword>
- </AFormItem>
- <AFormItem>
- <AInput
- v-bind="validateInfos.database"
- v-model:value="modelRef.database"
- :placeholder="$gettext('Database (Optional, default: database)')"
- >
- <template #prefix>
- <DatabaseOutlined />
- </template>
- </AInput>
- </AFormItem>
- <AFormItem>
- <AButton
- type="primary"
- block
- html-type="submit"
- :loading="loading"
- :disabled="installTimeout"
- @click="onSubmit"
- >
- {{ $gettext('Install') }}
- </AButton>
- </AFormItem>
- </AForm>
- <div class="footer">
- <p>Copyright © 2021 - {{ thisYear }} Nginx UI</p>
- Language
- <SetLanguage class="inline" />
- <div class="flex justify-center mt-4">
- <SwitchAppearance />
- </div>
- </div>
- </div>
- </div>
- </ALayoutContent>
- </ALayout>
- </template>
- <style lang="less" scoped>
- .ant-layout-content {
- background: #fff;
- }
- .dark .ant-layout-content {
- background: transparent;
- }
- .login-container {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 100vh;
- .login-form {
- max-width: 400px;
- width: 80%;
- .project-title {
- margin: 50px;
- h1 {
- font-size: 50px;
- font-weight: 100;
- text-align: center;
- }
- }
- .anticon {
- color: #a8a5a5 !important;
- }
- .footer {
- padding: 30px;
- text-align: center;
- font-size: 14px;
- }
- }
- }
- </style>
|