Commit cb96a4e7 authored by Kittisak Maneewong's avatar Kittisak Maneewong

change login page to dialog

parent 919023ab
This source diff could not be displayed because it is too large. You can view the blob instead.
<template>
<v-dialog v-model="dialog" transition="dialog-bottom-transition" width="40%">
<slot></slot>
</v-dialog>
</template>
<script>
export default {
computed: {
dialog: {
get () {
return this.$store.getters.getDialog
},
set (value) {
this.$store.commit('setDialog', value)
}
}
}
}
</script>
<template>
<v-snackbar
v-model="show"
:color="color"
:timeout="6000"
>
{{ text }}
<v-btn
dark
flat
@click="snackbar = false"
>
ปิด
</v-btn>
</v-snackbar>
</template>
<script>
export default {
data () {
return {
snackbar: false
}
},
computed: {
show: {
get () {
return this.$store.getters.getSnackbar.show
},
set (value) {
this.$store.commit('setSnackbar', {
show: false,
color: null,
text: null
})
}
},
color () {
return this.$store.getters.getSnackbar.color
},
text () {
return this.$store.getters.getSnackbar.text
}
}
}
</script>
...@@ -6,8 +6,11 @@ ...@@ -6,8 +6,11 @@
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn small="" dark color="deep-orange darken-4" class="elevation-0" @click="$router.push('/employer/login')">สำหรับผู้ประกอบการ</v-btn> <v-btn small="" dark color="deep-orange darken-4" class="elevation-0" @click="$router.push('/employer/login')">สำหรับผู้ประกอบการ</v-btn>
<v-divider inset vertical></v-divider> <v-divider inset vertical></v-divider>
<v-btn round small outline color="deep-orange darken-4" @click="$router.push('/account')"> <v-btn small outline color="deep-orange darken-4" @click.stop="$store.commit('setDialog', !$store.getters.getDialog)">
<v-icon>person</v-icon> เข้าสู่ระบบ / สมัครสมาชิก <v-icon>person</v-icon> เข้าสู่ระบบ
</v-btn>
<v-btn small outline color="deep-orange darken-4" @click="$router.push('/register')">
<v-icon>account_box</v-icon> ลงทะเบียน
</v-btn> </v-btn>
</v-toolbar> </v-toolbar>
</v-flex> </v-flex>
...@@ -69,12 +72,19 @@ ...@@ -69,12 +72,19 @@
</v-toolbar> </v-toolbar>
</v-flex> </v-flex>
</v-layout> </v-layout>
<login></login>
</div> </div>
</template> </template>
<script> <script>
import Login from '../views/Login.vue';
import Register from '../views/Register.vue';
export default { export default {
props: ['page'], props: ['page'],
components: {
'login': Login,
'register': Register
},
data () { data () {
return { return {
responsive: false responsive: false
......
...@@ -13,16 +13,19 @@ ...@@ -13,16 +13,19 @@
</v-container> </v-container>
</v-content> </v-content>
<Footer></Footer> <Footer></Footer>
<Snackbar></Snackbar>
</div> </div>
</template> </template>
<script> <script>
import Toolbar from '../components/Toolbar.vue'; import Toolbar from '../components/Toolbar.vue';
import Footer from '../components/Footer.vue'; import Footer from '../components/Footer.vue';
import Snackbar from '../components/Snackbar.vue';
export default { export default {
components: { components: {
Toolbar, Toolbar,
Footer Footer,
Snackbar
} }
} }
</script> </script>
......
...@@ -8,6 +8,8 @@ import EmployerLayout from './layouts/EmployerLayout.vue'; ...@@ -8,6 +8,8 @@ import EmployerLayout from './layouts/EmployerLayout.vue';
import Home from './views/Home.vue'; import Home from './views/Home.vue';
import Account from './views/Account.vue'; import Account from './views/Account.vue';
import Login from './views/Login.vue';
import Register from './views/Register.vue'
import LoginEmployer from './views/LoginEmployer.vue'; import LoginEmployer from './views/LoginEmployer.vue';
import PageNotFound from './views/PageNotFound.vue'; import PageNotFound from './views/PageNotFound.vue';
import Addjob from './views/Addjob.vue'; import Addjob from './views/Addjob.vue';
......
...@@ -10,9 +10,12 @@ export default new Vuex.Store({ ...@@ -10,9 +10,12 @@ export default new Vuex.Store({
message: 'Kittisak Maneewong', message: 'Kittisak Maneewong',
jwt: localStorage.getItem('access_token') || null, jwt: localStorage.getItem('access_token') || null,
jwt_employer: localStorage.getItem('access_token_employer') || null, jwt_employer: localStorage.getItem('access_token_employer') || null,
loading1: false, dialog: false,
loading2: false, snackbar: {
error: null show: false,
color: null,
text: null
}
}, },
mutations: { mutations: {
setJwt (state, payload) { setJwt (state, payload) {
...@@ -21,14 +24,11 @@ export default new Vuex.Store({ ...@@ -21,14 +24,11 @@ export default new Vuex.Store({
setJwtEmployer (state, payload) { setJwtEmployer (state, payload) {
state.jwt_employer = payload state.jwt_employer = payload
}, },
setLoading1 (state, payload) { setDialog (state, payload) {
state.loading1 = payload state.dialog = payload
},
setLoading2 (state, payload) {
state.loading2 = payload
}, },
setError (state, payload) { setSnackbar (state, payload) {
state.error = payload state.snackbar = payload
} }
}, },
actions: { actions: {
...@@ -39,11 +39,16 @@ export default new Vuex.Store({ ...@@ -39,11 +39,16 @@ export default new Vuex.Store({
if (payload.role == 1) { if (payload.role == 1) {
localStorage.setItem('access_token', res.data.token) localStorage.setItem('access_token', res.data.token)
commit('setJwt', res.data.token) commit('setJwt', res.data.token)
router.push('/')
} else { } else {
localStorage.setItem('access_token_employer', res.data.token) localStorage.setItem('access_token_employer', res.data.token)
commit('setJwtEmployer', res.data.token) commit('setJwtEmployer', res.data.token)
} }
commit('setSnackbar', {
show: true,
color: 'success',
text: 'เข้าสู่ระบบสำเร็จ!'
})
commit('setDialog', false)
console.log(res) console.log(res)
resolve(res) resolve(res)
}) })
...@@ -83,14 +88,11 @@ export default new Vuex.Store({ ...@@ -83,14 +88,11 @@ export default new Vuex.Store({
getJwtEmployer (state) { getJwtEmployer (state) {
return state.jwt_employer; return state.jwt_employer;
}, },
getLoading1 (state) { getDialog (state) {
return state.loading1 return state.dialog
},
getLoading2 (state) {
return state.loading2
}, },
getError (state) { getSnackbar (state) {
return state.error return state.snackbar
} }
} }
}); });
<template>
<div>
<Dialog>
<v-card>
<v-toolbar dark color="deep-orange darken-4" flat>
<v-toolbar-title>เข้าสู่ระบบ</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon @click="$store.commit('setDialog', false)">
<v-icon>close</v-icon>
</v-btn>
</v-toolbar>
<v-layout row wrap justify-center>
<v-card-text>
<v-container grid-list-md text-xs-center>
<v-layout row wrap>
<v-flex>
<!-- <v-alert
:value="true"
color="error"
outline
>
This is a error alert.
</v-alert> -->
<v-form @submit.prevent="login()" ref="login">
<v-text-field
label="อีเมล"
color="deep-orange darken-4"
type="email"
v-model="loginData.email_users"
:rules="clickLogin ? [rules.required, rules.email] : []"
required
></v-text-field>
<v-text-field
label="รหัสผ่าน"
color="deep-orange darken-4"
v-model="loginData.password"
:append-icon="showPassword ? 'visibility' : 'visibility_off'"
:type="showPassword ? 'text' : 'password'"
@click:append="showPassword = !showPassword"
:rules="clickLogin ? [rules.required] : []"
required
></v-text-field>
<p class="text-xs-right"><router-link to="/" class="body-2 font-weight-medium">ลืมรหัสผ่าน?</router-link></p>
<v-btn color="deep-orange darken-4" large dark block type="submit">เข้าสู่ระบบ</v-btn>
</v-form>
<div class="my-3"><span class="font-weight-bold">หรือ</span></div>
<v-btn color="primary" block><v-icon>fab fa-facebook</v-icon>&nbsp;เข้าสู่ระบบ Facebook</v-btn>
<v-btn color="deep-orange" class="white--text" block><v-icon>fab fa-google</v-icon>&nbsp;เข้าสู่ระบบ Google</v-btn>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
</v-layout>
</v-card>
</Dialog>
</div>
</template>
<script>
import Dialog from '../components/Dialog.vue';
export default {
components: {
Dialog
},
data () {
return {
loginData: {
email_users: '',
password: '',
role: 1
},
showPassword: false,
clickLogin: false,
rules: {
required: v => !!v || 'จำเป็นต้องกรอก',
email: v => /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(v) || 'รูปแบบอีเมลล์ไม่ถูกต้อง'
}
}
},
methods: {
login () {
this.clickLogin = true
if(this.$refs.login.validate() && this.loginData.email_users !== '' && this.loginData.password !== '') {
this.$store.dispatch('login', this.loginData)
.then(res => {
this.clickLogin = false
this.loginData = {
email_users: '',
password: '',
role: 1
}
})
}
}
}
}
</script>
<style lang="scss" scoped>
a {
text-decoration: none;
color: #000;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment