index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="login-container">
  3. <a-row>
  4. <a-col :xs="0" :md="0" :sm="12" :lg="14" :xl="16"></a-col>
  5. <a-col :xs="24" :sm="24" :md="12" :lg="10" :xl="6">
  6. <div class="login-container-form">
  7. <div class="login-container-hello">hello!</div>
  8. <div class="login-container-title">欢迎来到 {{ title }}</div>
  9. <a-form :model="form" @submit="handleSubmit" @submit.prevent>
  10. <a-form-item>
  11. <a-input v-model:value="form.username" placeholder="Username">
  12. <template v-slot:prefix>
  13. <UserOutlined style="color: rgba(0, 0, 0, 0.25)" />
  14. </template>
  15. </a-input>
  16. </a-form-item>
  17. <a-form-item>
  18. <a-input
  19. v-model:value="form.password"
  20. type="password"
  21. placeholder="Password"
  22. >
  23. <template v-slot:prefix>
  24. <LockOutlined style="color: rgba(0, 0, 0, 0.25)" />
  25. </template>
  26. </a-input>
  27. </a-form-item>
  28. <a-form-item>
  29. <a-button
  30. type="primary"
  31. html-type="submit"
  32. :disabled="form.username === '' || form.password === ''"
  33. >
  34. 登录
  35. </a-button>
  36. </a-form-item>
  37. </a-form>
  38. </div>
  39. </a-col>
  40. </a-row>
  41. <!-- <div class="login-container-tips">
  42. 基于vue{{ dependencies['vue'] }}
  43. + ant-design-vue
  44. {{ dependencies['ant-design-vue'] }}开发
  45. </div> -->
  46. </div>
  47. </template>
  48. <script>
  49. import { dependencies, devDependencies } from '*/package.json'
  50. import { mapActions, mapGetters } from 'vuex'
  51. import { useRouter } from 'vue-router'
  52. import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
  53. export default {
  54. name: 'Login',
  55. components: {
  56. UserOutlined,
  57. LockOutlined,
  58. },
  59. data() {
  60. return {
  61. form: {
  62. username: '',
  63. password: '',
  64. },
  65. redirect: undefined,
  66. dependencies: dependencies,
  67. devDependencies: devDependencies,
  68. }
  69. },
  70. computed: {
  71. ...mapGetters({
  72. logo: 'settings/logo',
  73. title: 'settings/title',
  74. }),
  75. },
  76. watch: {
  77. $route: {
  78. handler(route) {
  79. this.redirect = (route.query && route.query.redirect) || '/'
  80. },
  81. immediate: true,
  82. },
  83. },
  84. mounted() {
  85. this.form.username = 'admin'
  86. this.form.password = 'admin123'
  87. const router = useRouter()
  88. console.log(router)
  89. if (router.currentRoute.value.query.userName === 'admin') {
  90. this.handleSubmit()
  91. }
  92. // setTimeout(() => {
  93. // this.handleSubmit()
  94. // }, 3000)
  95. },
  96. methods: {
  97. ...mapActions({
  98. login: 'user/login',
  99. }),
  100. handleRoute() {
  101. return this.redirect === '/404' || this.redirect === '/403'
  102. ? '/'
  103. : this.redirect
  104. },
  105. async handleSubmit() {
  106. await this.login(this.form)
  107. await this.$router.push(this.handleRoute())
  108. },
  109. },
  110. }
  111. </script>
  112. <style lang="less">
  113. .login-container {
  114. width: 100%;
  115. height: 100vh;
  116. background: url('~@/assets/login_images/login_background.png');
  117. background-size: cover;
  118. &-form {
  119. width: calc(100% - 40px);
  120. height: 380px;
  121. padding: 4vh;
  122. margin-top: calc((100vh - 380px) / 2);
  123. margin-right: 20px;
  124. margin-left: 20px;
  125. background: url('~@/assets/login_images/login_form.png');
  126. background-size: 100% 100%;
  127. border-radius: 10px;
  128. box-shadow: 0 2px 8px 0 rgba(7, 17, 27, 0.06);
  129. }
  130. &-hello {
  131. font-size: 32px;
  132. color: #fff;
  133. }
  134. &-title {
  135. margin-bottom: 30px;
  136. font-size: 20px;
  137. color: #fff;
  138. }
  139. &-tips {
  140. position: fixed;
  141. bottom: @vab-margin;
  142. width: 100%;
  143. height: 40px;
  144. color: rgba(255, 255, 255, 0.856);
  145. text-align: center;
  146. }
  147. .ant-col {
  148. width: 100%;
  149. padding: 0 10px 0 10px;
  150. }
  151. .ant-input {
  152. height: 35px;
  153. }
  154. .ant-btn {
  155. width: 100%;
  156. height: 45px;
  157. border-radius: 99px;
  158. }
  159. }
  160. </style>