|
|
@@ -1,19 +1,30 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<div class="intro">Sign in</div>
|
|
|
+ <b-notification type="is-danger" :active.sync="isServerError">
|
|
|
+ {{ errorMassage }}
|
|
|
+ </b-notification>
|
|
|
<b-field
|
|
|
- label="Username"
|
|
|
- :type="!$v.username.required ? 'is-danger' : ''"
|
|
|
- :message="!$v.username.required ? 'username required' : ''"
|
|
|
+ label="邮箱"
|
|
|
+ :type="$v.username.$error ? 'is-danger' : ''"
|
|
|
+ :message="$v.username.$error ? '请输入邮箱' : ''"
|
|
|
>
|
|
|
- <b-input v-model="username" placeholder="input username here"></b-input>
|
|
|
+ <b-input
|
|
|
+ type="email"
|
|
|
+ v-model="$v.username.$model"
|
|
|
+ placeholder="在此输入邮箱"
|
|
|
+ ></b-input>
|
|
|
</b-field>
|
|
|
|
|
|
- <b-field label="Password">
|
|
|
+ <b-field
|
|
|
+ label="密码"
|
|
|
+ :type="$v.password.$error ? 'is-danger' : ''"
|
|
|
+ :message="$v.password.$error ? '请输入密码' : ''"
|
|
|
+ >
|
|
|
<b-input
|
|
|
type="password"
|
|
|
- v-model="password"
|
|
|
- placeholder="input password here"
|
|
|
+ v-model="$v.password.$model"
|
|
|
+ placeholder="在此输入密码"
|
|
|
password-reveal
|
|
|
>
|
|
|
</b-input>
|
|
|
@@ -29,7 +40,7 @@
|
|
|
登 陆
|
|
|
</button>
|
|
|
<router-link
|
|
|
- :to="{ name: 'register' }"
|
|
|
+ :to="{ name: 'REGISTER' }"
|
|
|
:class="{ 'is-text': true }"
|
|
|
class="button"
|
|
|
type="submit"
|
|
|
@@ -41,68 +52,66 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { required } from "vuelidate/lib/validators";
|
|
|
+import { required, email } from "vuelidate/lib/validators";
|
|
|
+import { login } from "@/api/auth";
|
|
|
+import { SET_PROFILE } from "@/store/type/mutations.type";
|
|
|
+import { destroyToken, saveToken } from "@/util/tokenStorage";
|
|
|
+import { HOME } from "@/router/name";
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
username: "",
|
|
|
password: "",
|
|
|
- submitting: false
|
|
|
+ submitting: false,
|
|
|
+ errorMassage: null,
|
|
|
+ isServerError: false
|
|
|
};
|
|
|
},
|
|
|
validations: {
|
|
|
username: {
|
|
|
- required
|
|
|
+ required,
|
|
|
+ email
|
|
|
},
|
|
|
password: {
|
|
|
required
|
|
|
}
|
|
|
},
|
|
|
- computed: {},
|
|
|
+ mounted() {
|
|
|
+ destroyToken();
|
|
|
+ },
|
|
|
methods: {
|
|
|
- loginAction() {
|
|
|
- this.$router.push("");
|
|
|
+ async loginAction() {
|
|
|
+ this.$v.$touch();
|
|
|
+ if (!this.$v.$invalid) {
|
|
|
+ const { username = "", password = "" } = this;
|
|
|
+ try {
|
|
|
+ this.submitting = true;
|
|
|
+ const {
|
|
|
+ data,
|
|
|
+ _header: { Authorization }
|
|
|
+ } = await login({ username, password });
|
|
|
+ saveToken(Authorization);
|
|
|
+ this.$store.commit(SET_PROFILE, data);
|
|
|
+ this.$router.push({ name: HOME });
|
|
|
+ } catch (e) {
|
|
|
+ this.errorMassage = e.message;
|
|
|
+ this.isServerError = true;
|
|
|
+ this.submitting = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // @State((state: RootState) => state.auth.isLoginError)
|
|
|
- // public isLoginError: boolean;
|
|
|
- // public mounted() {
|
|
|
- // this.$store.dispatch(LOGOUT);
|
|
|
- // Validator.extend("truthy", {
|
|
|
- // getMessage: (field: string): string => "两次输入的密码不相同",
|
|
|
- // validate: (value: string): boolean => value === this.credentials.password
|
|
|
- // });
|
|
|
- // }
|
|
|
- // public closeError() {
|
|
|
- // this.$store.commit(SET_LOGIN_ERROR, false);
|
|
|
- // }
|
|
|
- // public submit() {
|
|
|
- // this.$validator.validateAll().then(async result => {
|
|
|
- // if (result) {
|
|
|
- // this.submitting = true;
|
|
|
- // await this.$store.dispatch(LOGIN, this.credentials);
|
|
|
- // if (!this.isLoginError) {
|
|
|
- // this.$router.push({ name: "home" });
|
|
|
- // } else {
|
|
|
- // this.submitting = false;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.intro {
|
|
|
- /*<!--color: $oc-gray-7;-->*/
|
|
|
text-align: center;
|
|
|
font-size: 25px;
|
|
|
padding: 10px 0 30px;
|
|
|
}
|
|
|
.link {
|
|
|
- /*<!--color: $oc-blue-5;-->*/
|
|
|
text-decoration: none;
|
|
|
}
|
|
|
.action-section {
|