index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="login-container">
  3. <el-card :body-style="{padding:0}" shadow="none">
  4. <div slot="header" class="clearfix">
  5. <span>数据资源中心</span>
  6. <!-- <div style="float: right; color: #666666">-->
  7. <!-- 服务热线:<span style="color: #FF970F;font-weight: bold">400-698-5980</span>-->
  8. <!-- </div>-->
  9. </div>
  10. <div style="min-height: 500px;">
  11. <el-row style="width: 1000px;margin: 99px auto 0 auto;overflow: hidden;">
  12. <el-col :span="16">
  13. <el-image src="http://lcadmin.tongyu99.com/statics/image/dl01.png" />
  14. </el-col>
  15. <el-col :span="8">
  16. <el-card shadow="always">
  17. <div slot="header" class="clearfix">
  18. <strong>用户登录</strong>
  19. </div>
  20. <el-form
  21. ref="loginForm"
  22. :model="loginForm"
  23. class="login-form"
  24. auto-complete="on"
  25. label-position="left"
  26. >
  27. <el-form-item prop="username">
  28. <el-input
  29. ref="username"
  30. v-model="loginForm.username"
  31. placeholder="请输入手机号/邮箱"
  32. name="username"
  33. type="text"
  34. auto-complete="on"
  35. >
  36. <span slot="prepend" class="svg-container el-icon-user-solid" />
  37. </el-input>
  38. </el-form-item>
  39. <el-form-item prop="password">
  40. <el-input
  41. :key="passwordType"
  42. ref="password"
  43. v-model="loginForm.password"
  44. :type="passwordType"
  45. placeholder="请输入登录密码"
  46. name="password"
  47. auto-complete="on"
  48. @keyup.enter.native="handleLogin"
  49. >
  50. <span slot="prepend" class="svg-container el-icon-lock" />
  51. <span slot="append" class="show-pwd" @click="showPwd">
  52. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  53. </span>
  54. </el-input>
  55. </el-form-item>
  56. <el-row>
  57. <el-col :span="16">
  58. <el-form-item prop="password">
  59. <el-input
  60. ref="captcha"
  61. v-model="loginForm.captcha"
  62. placeholder="请输入验证码"
  63. name="captcha"
  64. type="text"
  65. >
  66. <span slot="prepend" class="svg-container el-icon-warning" />
  67. </el-input>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8" style="text-align: right">
  71. <el-image
  72. v-if="captcha && captcha!==''"
  73. :src="captcha"
  74. style="width: 80px"
  75. class="show-pwd"
  76. @click="refreshCaptcha"
  77. />
  78. </el-col>
  79. </el-row>
  80. <el-button
  81. :loading="loading"
  82. type="primary"
  83. style="width: 100%; margin-bottom: 30px"
  84. @click.native.prevent="handleLogin"
  85. >
  86. 登录
  87. </el-button>
  88. </el-form>
  89. </el-card>
  90. </el-col>
  91. </el-row>
  92. </div>
  93. </el-card>
  94. <div class="footer">
  95. ©2022 智慧旅游 版权所有 All Rights Reserved.
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. import { getCaptcha } from '@/api/oauth'
  101. export default {
  102. name: 'Login',
  103. data() {
  104. return {
  105. loginForm: {
  106. username: '',
  107. password: '',
  108. captcha: ''
  109. },
  110. loading: false,
  111. passwordType: 'password',
  112. redirect: undefined,
  113. token: '',
  114. captcha: ''
  115. }
  116. },
  117. watch: {
  118. $route: {
  119. handler: function(route) {
  120. this.redirect = route.query && route.query.redirect
  121. },
  122. immediate: true
  123. }
  124. },
  125. created() {
  126. this.refreshCaptcha()
  127. },
  128. methods: {
  129. refreshCaptcha() {
  130. getCaptcha().then((v) => {
  131. console.log(v)
  132. this.token = v.token
  133. this.captcha = v.captcha
  134. })
  135. },
  136. showPwd() {
  137. if (this.passwordType === 'password') {
  138. this.passwordType = ''
  139. } else {
  140. this.passwordType = 'password'
  141. }
  142. this.$nextTick(() => {
  143. this.$refs.password.focus()
  144. })
  145. },
  146. handleLogin() {
  147. this.$refs.loginForm.validate((valid) => {
  148. if (valid) {
  149. this.loading = true
  150. this.$store
  151. .dispatch('user/login', { ...this.loginForm, token: this.token })
  152. .then(() => {
  153. this.$router.push({ path: this.redirect || '/' })
  154. this.loading = false
  155. })
  156. .catch(() => {
  157. this.loading = false
  158. })
  159. } else {
  160. console.log('error submit!!')
  161. return false
  162. }
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="css">
  169. .footer {
  170. height: 68px;
  171. line-height: 68px;
  172. color: #333;
  173. text-align: center;
  174. background: #eaeaea;
  175. font-size: 12px;
  176. }
  177. .footer a {
  178. color: #333;
  179. }
  180. .footer a:hover {
  181. color: #f08200;
  182. }
  183. </style>