login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <v-main>
  3. <v-container fill-height>
  4. <v-row justify="center" align="center">
  5. <v-col cols="12">
  6. <v-card
  7. class="mx-auto"
  8. max-width="500"
  9. >
  10. <v-row style="height: 64px" justify="center">
  11. <v-col cols="10">
  12. <v-btn text @click="backHome">
  13. <v-icon>
  14. mdi-arrow-left
  15. </v-icon>
  16. 返回
  17. </v-btn>
  18. </v-col>
  19. </v-row>
  20. <v-row justify="center">
  21. <img
  22. :src="this.$store.state.webInfo.logoUrl"
  23. height="36px"
  24. >
  25. </v-row>
  26. <v-row justify="center">
  27. <h1>{{ this.$store.state.webInfo.name }} &nbsp; &nbsp; {{ type }}</h1>
  28. </v-row>
  29. <v-row style="height: 48px" />
  30. <LoginFrom v-show="showLogin" @login="userLogin" />
  31. <RegisterFrom v-show="showLogin === false" @register="userRegister" />
  32. <v-row justify="center">
  33. <v-col cols="5">
  34. <v-btn text color="primary">忘记密码</v-btn>
  35. </v-col>
  36. <v-col cols="5" style="text-align:right">
  37. <v-btn text @click="moveRegister">{{ moveMessage }}</v-btn>
  38. </v-col>
  39. </v-row>
  40. </v-card>
  41. </v-col>
  42. </v-row>
  43. <v-snackbar
  44. v-model="showMessage"
  45. :top="true"
  46. :timeout="3000"
  47. >
  48. {{ message }}
  49. <template v-slot:action="{ attrs }">
  50. <v-btn
  51. color="pink"
  52. text
  53. v-bind="attrs"
  54. @click="showMessage = false"
  55. >
  56. 关闭
  57. </v-btn>
  58. </template>
  59. </v-snackbar>
  60. </v-container>
  61. </v-main>
  62. </template>
  63. <script>
  64. import LoginFrom from '@/components/login-form.vue'
  65. import RegisterFrom from '@/components/register-from.vue'
  66. export default {
  67. name: 'Login',
  68. components: {
  69. LoginFrom,
  70. RegisterFrom
  71. },
  72. data() {
  73. return {
  74. captchaUrl: '',
  75. r: '',
  76. user: {},
  77. type: '登录',
  78. moveMessage: '没有账号,创建账号',
  79. showLogin: true,
  80. message: '',
  81. showMessage: false
  82. }
  83. },
  84. created() {
  85. },
  86. methods: {
  87. userLogin(value) {
  88. // 调用 store/modules/user.js 中的 login 方法
  89. this.$store.dispatch('user/login', value).then(() => {
  90. // 登录成功后返回到首页
  91. this.$router.push('/')
  92. }).catch(() => {
  93. })
  94. },
  95. userRegister(value) {
  96. this.$store.dispatch('user/register', value).then(() => {
  97. this.message = '注册成功,即将为你跳转到登录页面!'
  98. this.showMessage = true
  99. this.moveRegister()
  100. }).catch(() => {
  101. alert('用户注册失败')
  102. })
  103. },
  104. moveRegister() {
  105. if (this.type === '登录') {
  106. this.type = '注册'
  107. } else {
  108. this.type = '登录'
  109. }
  110. if (this.moveMessage === '没有账号,创建账号') {
  111. this.moveMessage = '已有账号,我要登录'
  112. } else {
  113. this.moveMessage = '没有账号,创建账号'
  114. }
  115. this.showLogin = !this.showLogin
  116. },
  117. backHome() {
  118. this.$router.push('/')
  119. }
  120. }
  121. }
  122. </script>
  123. <style>
  124. </style>