Skip to content

Commit ffa641d

Browse files
author
Andrey Solodovnikov
committed
AUTH-18 setups vue-material and vuelidate
1 parent 679505b commit ffa641d

File tree

10 files changed

+134
-25
lines changed

10 files changed

+134
-25
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"element-ui": "^2.4.5",
1515
"vue": "^2.5.17",
1616
"vue-i18n": "^8.0.0",
17+
"vue-material": "^1.0.0-beta-10.2",
1718
"vuelidate": "^0.7.4",
1819
"vuex": "^3.0.1"
1920
},

src/App.vue

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,48 @@
33
<center>
44
<img alt="Vue logo" src="./assets/logo.png">
55
</center>
6-
<AuthForm/>
6+
<div class="container">
7+
<LocaleChanger/>
8+
<h1>{{ $t('title') }}</h1>
9+
<AuthForm/>
10+
</div>
711
</div>
812
</template>
913

1014
<script>
1115
import AuthForm from './components/AuthForm.vue';
16+
import LocaleChanger from './components/LocaleChanger.vue';
1217
1318
export default {
1419
name: 'Root',
1520
components: {
1621
AuthForm,
22+
LocaleChanger,
1723
},
1824
};
1925
</script>
26+
27+
<style lang="scss" scoped>
28+
@import 'assets/styles/gui.scss';
29+
30+
.container {
31+
font-family: $ui-font-family-common;
32+
color: $ui-color-grey13;
33+
box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
34+
background: $ui-color-white;
35+
padding: 20px;
36+
width: 500px;
37+
margin: 15px auto 0;
38+
}
39+
</style>
40+
41+
<i18n>
42+
{
43+
"ru": {
44+
"title": "Авторизация в ProtocolONE"
45+
},
46+
"en": {
47+
"title": "ProtocolONE Authorization"
48+
}
49+
}
50+
</i18n>

src/components/AuthForm.vue

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,89 @@
11
<template>
22
<div class="auth-form">
3-
<LocaleChanger/>
4-
<h1>ProtocolONE Auth Form</h1>
5-
<HelloI18n/>
3+
<form novalidate @submit.prevent="validateUser">
4+
<md-field :class="getValidationClass('username')">
5+
<label>{{ $t('fieldUsernameLabel') }}</label>
6+
<md-input v-model="username"></md-input>
7+
<span class="md-error" v-if="!$v.username.required">{{ $t('errorMessageRequired') }}</span>
8+
</md-field>
9+
10+
<md-field :class="getValidationClass('password')">
11+
<label>{{ $t('fieldPasswordLabel') }}</label>
12+
<md-input type="password" v-model="password"></md-input>
13+
<span class="md-error" v-if="!$v.password.required">{{ $t('errorMessageRequired') }}</span>
14+
</md-field>
15+
16+
<md-card-actions>
17+
<md-button type="submit" class="md-raised md-primary">
18+
{{ $t('submitButtonText') }}
19+
</md-button>
20+
</md-card-actions>
21+
</form>
622
</div>
723
</template>
824

925
<script>
10-
import HelloI18n from './HelloI18n.vue';
11-
import LocaleChanger from './LocaleChanger.vue';
26+
import { required } from 'vuelidate/lib/validators';
1227
1328
export default {
1429
name: 'AuthForm',
1530
16-
components: {
17-
HelloI18n,
18-
LocaleChanger,
31+
data() {
32+
return {
33+
username: '',
34+
password: '',
35+
};
36+
},
37+
38+
methods: {
39+
getValidationClass(fieldName) {
40+
const field = this.$v[fieldName];
41+
42+
if (field) {
43+
return {
44+
'md-invalid': field.$invalid && field.$dirty,
45+
};
46+
}
47+
48+
return '';
49+
},
50+
51+
validateUser() {
52+
this.$v.$touch();
53+
54+
if (!this.$v.$invalid) {
55+
console.log('success');
56+
}
57+
},
58+
},
59+
60+
validations: {
61+
username: {
62+
required,
63+
},
64+
65+
password: {
66+
required,
67+
},
1968
},
2069
};
2170
</script>
22-
2371
<style scoped lang="scss">
24-
@import '../assets/styles/gui.scss';
25-
2672
.auth-form {
27-
font-family: $ui-font-family-common;
28-
color: $ui-color-grey13;
29-
box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
30-
background: $ui-color-white;
31-
padding: 20px;
32-
width: 500px;
33-
margin: 15px auto 0;
3473
}
3574
</style>
75+
76+
<i18n>
77+
{
78+
"ru": {
79+
"fieldUsernameLabel": "Имя пользователя",
80+
"fieldPasswordLabel": "Пароль",
81+
"submitButtonText": "Войти"
82+
},
83+
"en": {
84+
"fieldUsernameLabel": "Username",
85+
"fieldPasswordLabel": "Password",
86+
"submitButtonText": "Sign in"
87+
}
88+
}
89+
</i18n>

src/components/LocaleChanger.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<template>
22
<div class="locale-changer">
3-
<select v-model="$i18n.locale">
4-
<option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</option>
5-
</select>
3+
<md-field>
4+
<md-select v-model="$i18n.locale">
5+
<md-option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</md-option>
6+
</md-select>
7+
</md-field>
68
</div>
79
</template>
810

911
<script>
1012
export default {
1113
name: 'locale-changer',
1214
data() {
13-
return { langs: ['ru', 'en'] };
15+
return {
16+
langs: ['ru', 'en'],
17+
};
1418
},
1519
};
1620
</script>

src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"message": "hello i18n !!"
2+
"message": "hello i18n !!",
3+
"errorMessageRequired": "The field is required"
34
}

src/locales/ru.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"message": "дратути i18n !!"
2+
"message": "дратути i18n !!",
3+
"errorMessageRequired": "Это поле обязательно"
34
}

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
import Vue from 'vue';
7+
import './plugins/vue-material';
8+
import './plugins/vuelidate';
79
import App from './App.vue';
810
import store from './store/RootStore';
911
import i18n from './i18n';

src/plugins/vue-material.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Vue from 'vue';
2+
import VueMaterial from 'vue-material';
3+
import 'vue-material/dist/vue-material.min.css';
4+
import 'vue-material/dist/theme/default.css';
5+
6+
Vue.use(VueMaterial);

src/plugins/vuelidate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Vue from 'vue';
2+
import Vuelidate from 'vuelidate';
3+
4+
Vue.use(Vuelidate);

0 commit comments

Comments
 (0)