login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. <LoginFormMobile v-show="showLogin" @login="userLogin" />
  31. <LoginFormPassword v-show="showLogin1 === true" @login="userLogin" />
  32. <RegisterForm v-show="showLogin === false" @register="userRegister" />
  33. <v-row justify="center">
  34. <v-col cols="5">
  35. <v-btn text color="primary">忘记密码</v-btn>
  36. </v-col>
  37. <v-col cols="5" style="text-align:right">
  38. <v-btn text @click="moveRegister">{{ moveMessage }}</v-btn>
  39. </v-col>
  40. </v-row>
  41. </v-card>
  42. </v-col>
  43. </v-row>
  44. <v-snackbar
  45. v-model="showMessage"
  46. :top="true"
  47. :timeout="3000"
  48. >
  49. {{ message }}
  50. <template v-slot:action="{ attrs }">
  51. <v-btn
  52. color="pink"
  53. text
  54. v-bind="attrs"
  55. @click="showMessage = false"
  56. >
  57. 关闭
  58. </v-btn>
  59. </template>
  60. </v-snackbar>
  61. </v-container>
  62. </v-main>
  63. </template>
  64. <script>
  65. import LoginFormMobile from '@/components/login-form-mobile.vue'
  66. import LoginFormPassword from '@/components/login-form-password.vue'
  67. import RegisterForm from '@/components/register-form.vue'
  68. export default {
  69. name: 'Login',
  70. components: {
  71. LoginFormMobile,
  72. LoginFormPassword,
  73. RegisterForm
  74. },
  75. data() {
  76. return {
  77. captchaUrl: '',
  78. r: '',
  79. user: {},
  80. type: '登录',
  81. moveMessage: '没有账号,创建账号',
  82. showLogin: true,
  83. showLogin1: false,
  84. message: '',
  85. showMessage: false
  86. }
  87. },
  88. created() {
  89. },
  90. methods: {
  91. userLogin(value) {
  92. // 调用 store/modules/user.js 中的 login 方法
  93. this.$store.dispatch('user/login', value).then(() => {
  94. // 登录成功后返回到首页
  95. this.$router.push('/')
  96. }).catch(() => {
  97. })
  98. },
  99. userRegister(value) {
  100. this.$store.dispatch('user/register', value).then(() => {
  101. this.message = '注册成功,即将为你跳转到登录页面!'
  102. this.showMessage = true
  103. this.moveRegister()
  104. }).catch(() => {
  105. alert('用户注册失败')
  106. })
  107. },
  108. moveRegister() {
  109. if (this.type === '登录') {
  110. this.type = '注册'
  111. } else {
  112. this.type = '登录'
  113. }
  114. if (this.moveMessage === '没有账号,创建账号') {
  115. this.moveMessage = '已有账号,我要登录'
  116. } else {
  117. this.moveMessage = '没有账号,创建账号'
  118. }
  119. this.showLogin = !this.showLogin
  120. },
  121. backHome() {
  122. this.$router.push('/')
  123. }
  124. }
  125. }
  126. </script>
  127. <style>
  128. </style>