|
| 1 | +<script setup lang="ts"> |
| 2 | +import {Form, message} from 'ant-design-vue' |
| 3 | +import SetLanguage from '@/components/SetLanguage/SetLanguage.vue' |
| 4 | +import {reactive, ref} from 'vue' |
| 5 | +import gettext from '@/gettext' |
| 6 | +import install from '@/api' |
| 7 | +import {useRoute, useRouter} from 'vue-router' |
| 8 | +import {MailOutlined, UserOutlined, LockOutlined, DatabaseOutlined} from '@ant-design/icons-vue' |
| 9 | +
|
| 10 | +const {$gettext, interpolate} = gettext |
| 11 | +
|
| 12 | +const thisYear = new Date().getFullYear() |
| 13 | +const loading = ref(false) |
| 14 | +
|
| 15 | +const route = useRoute() |
| 16 | +const router = useRouter() |
| 17 | +
|
| 18 | +install.get_lock().then(async (r: { lock: boolean }) => { |
| 19 | + if (r.lock) { |
| 20 | + await router.push('/login') |
| 21 | + } |
| 22 | +}) |
| 23 | +
|
| 24 | +const modelRef = reactive({ |
| 25 | + email: '', |
| 26 | + username: '', |
| 27 | + password: '', |
| 28 | + database: '' |
| 29 | +}) |
| 30 | +
|
| 31 | +const rulesRef = reactive({ |
| 32 | + email: [ |
| 33 | + { |
| 34 | + required: true, |
| 35 | + type: 'email', |
| 36 | + message: () => $gettext('Please input your E-mail!'), |
| 37 | + } |
| 38 | + ], |
| 39 | + username: [ |
| 40 | + { |
| 41 | + required: true, |
| 42 | + message: () => $gettext('Please input your username!'), |
| 43 | + } |
| 44 | + ], |
| 45 | + password: [ |
| 46 | + { |
| 47 | + required: true, |
| 48 | + message: () => $gettext('Please input your password!'), |
| 49 | + } |
| 50 | + ], |
| 51 | + database: [ |
| 52 | + { |
| 53 | + message: () => interpolate( |
| 54 | + $gettext('The filename cannot contain the following characters: %{c}'), |
| 55 | + {c: '& " ? < > # {} % ~ / \\'} |
| 56 | + ), |
| 57 | + } |
| 58 | + ], |
| 59 | +}) |
| 60 | +
|
| 61 | +const {validate, validateInfos} = Form.useForm(modelRef, rulesRef) |
| 62 | +
|
| 63 | +const onSubmit = () => { |
| 64 | + validate().then(() => { |
| 65 | + // modelRef |
| 66 | + loading.value = true |
| 67 | + install.install_nginx_ui(modelRef).then(async () => { |
| 68 | + message.success($gettext('Install successfully')) |
| 69 | + await router.push('/login') |
| 70 | + }).catch(e => { |
| 71 | + message.error(e.message ?? $gettext('Server error')) |
| 72 | + }).finally(() => { |
| 73 | + loading.value = false |
| 74 | + }) |
| 75 | + }) |
| 76 | +} |
| 77 | +</script> |
| 78 | + |
1 | 79 | <template> |
2 | 80 | <div class="login-form"> |
3 | 81 | <div class="project-title"> |
4 | 82 | <h1>Nginx UI</h1> |
5 | 83 | </div> |
6 | | - <a-form |
7 | | - id="components-form-install" |
8 | | - :form="form" |
9 | | - class="login-form" |
10 | | - @submit="handleSubmit" |
11 | | - > |
12 | | - <a-form-item> |
| 84 | + <a-form id="components-form-install" class="login-form"> |
| 85 | + <a-form-item v-bind="validateInfos.email"> |
13 | 86 | <a-input |
14 | | - v-decorator="[ |
15 | | - 'email', |
16 | | - { rules: [{ |
17 | | - type: 'email', |
18 | | - message: $gettext('Invalid E-mail!'), |
19 | | - }, |
20 | | - { |
21 | | - required: true, |
22 | | - message: $gettext('Please input your E-mail!'), |
23 | | - },] }, |
24 | | - ]" |
| 87 | + v-model:value="modelRef.email" |
25 | 88 | :placeholder="$gettext('Email (*)')" |
26 | 89 | > |
27 | | - <a-icon slot="prefix" type="mail" style="color: rgba(0,0,0,.25)"/> |
| 90 | + <template #prefix> |
| 91 | + <MailOutlined/> |
| 92 | + </template> |
28 | 93 | </a-input> |
29 | 94 | </a-form-item> |
30 | | - <a-form-item> |
| 95 | + <a-form-item v-bind="validateInfos.username"> |
31 | 96 | <a-input |
32 | | - v-decorator="[ |
33 | | - 'username', |
34 | | - { rules: [{ required: true, message: $gettext('Please input your username!') }] }, |
35 | | - ]" |
| 97 | + v-model:value="modelRef.username" |
36 | 98 | :placeholder="$gettext('Username (*)')" |
37 | 99 | > |
38 | | - <a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)"/> |
| 100 | + <template #prefix> |
| 101 | + <UserOutlined/> |
| 102 | + </template> |
39 | 103 | </a-input> |
40 | 104 | </a-form-item> |
41 | | - <a-form-item> |
42 | | - <a-input |
43 | | - v-decorator="[ |
44 | | - 'password', |
45 | | - { rules: [{ required: true, message: $gettext('Please input your password!') }] }, |
46 | | - ]" |
47 | | - type="password" |
| 105 | + <a-form-item v-bind="validateInfos.password"> |
| 106 | + <a-input-password |
| 107 | + v-model:value="modelRef.password" |
48 | 108 | :placeholder="$gettext('Password (*)')" |
49 | 109 | > |
50 | | - <a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)"/> |
51 | | - </a-input> |
| 110 | + <template #prefix> |
| 111 | + <LockOutlined/> |
| 112 | + </template> |
| 113 | + </a-input-password> |
52 | 114 | </a-form-item> |
53 | 115 | <a-form-item> |
54 | 116 | <a-input |
55 | | - v-decorator="[ |
56 | | - 'database', |
57 | | - { rules: [{ pattern: /^[^\\/:*?\x22<>|]{1,120}$/, |
58 | | - message: $gettextInterpolate( |
59 | | - $gettext('The filename cannot contain the following characters: %{c}'), |
60 | | - {c: '& " ? < > # {} % ~ / \\'} |
61 | | - )}] }, |
62 | | - ]" |
| 117 | + v-bind="validateInfos.database" |
| 118 | + v-model:value="modelRef.database" |
63 | 119 | :placeholder="$gettext('Database (Optional, default: database)')" |
64 | 120 | > |
65 | | - <a-icon slot="prefix" type="database" style="color: rgba(0,0,0,.25)"/> |
| 121 | + <template #prefix> |
| 122 | + <DatabaseOutlined/> |
| 123 | + </template> |
66 | 124 | </a-input> |
67 | 125 | </a-form-item> |
68 | 126 | <a-form-item> |
69 | | - <a-button type="primary" :block="true" html-type="submit" :loading="loading"> |
| 127 | + <a-button type="primary" :block="true" @click="onSubmit" html-type="submit" :loading="loading"> |
70 | 128 | <translate>Install</translate> |
71 | 129 | </a-button> |
72 | 130 | </a-form-item> |
|
79 | 137 |
|
80 | 138 | </template> |
81 | 139 |
|
82 | | -<script> |
83 | | -import SetLanguage from '@/components/SetLanguage/SetLanguage' |
84 | | -
|
85 | | -export default { |
86 | | - name: 'Login', |
87 | | - components: {SetLanguage}, |
88 | | - data() { |
89 | | - return { |
90 | | - form: {}, |
91 | | - lock: true, |
92 | | - thisYear: new Date().getFullYear(), |
93 | | - loading: false |
94 | | - } |
95 | | - }, |
96 | | - created() { |
97 | | - this.form = this.$form.createForm(this) |
98 | | - }, |
99 | | - mounted() { |
100 | | - this.$api.install.get_lock().then(r => { |
101 | | - if (r.lock) { |
102 | | - this.$router.push('/login') |
103 | | - } |
104 | | - }) |
105 | | - }, |
106 | | - methods: { |
107 | | - handleSubmit: async function (e) { |
108 | | - e.preventDefault() |
109 | | - this.loading = true |
110 | | - await this.form.validateFields(async (err, values) => { |
111 | | - if (!err) { |
112 | | - this.$api.install.install_nginx_ui(values).then(() => { |
113 | | - this.$router.push('/login') |
114 | | - }) |
115 | | - } |
116 | | - this.loading = false |
117 | | - }) |
118 | | - }, |
119 | | - }, |
120 | | -} |
121 | | -</script> |
122 | 140 | <style lang="less"> |
123 | 141 | .project-title { |
124 | 142 | margin: 50px; |
|
0 commit comments