Login.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="main">
  3. <a-form-model class="user-layout-login" @keyup.enter.native="handleSubmit">
  4. <a-tabs :activeKey="customActiveKey" :tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }" @change="handleTabClick">
  5. <a-tab-pane key="tab1" tab="账号密码登录">
  6. <login-account ref="alogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-account>
  7. </a-tab-pane>
  8. <!-- <a-tab-pane key="tab2" tab="手机号或员工号登录">
  9. <login-phone ref="plogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-phone>
  10. </a-tab-pane>-->
  11. </a-tabs>
  12. <a-form-item style="margin-top:24px">
  13. <a-button size="large" type="primary" htmlType="submit" class="login-button" :loading="loginBtn" @click.stop.prevent="handleSubmit" :disabled="loginBtn">确定
  14. </a-button>
  15. </a-form-item>
  16. </a-form-model>
  17. <two-step-captcha v-if="requiredTwoStepCaptcha" :visible="stepCaptchaVisible" @success="stepCaptchaSuccess" @cancel="stepCaptchaCancel"></two-step-captcha>
  18. <login-select-tenant ref="loginSelect" @success="loginSelectOk"></login-select-tenant>
  19. </div>
  20. </template>
  21. <script>
  22. import Vue from 'vue'
  23. import { ACCESS_TOKEN, ENCRYPTED_STRING } from '@/store/mutation-types'
  24. import ThirdLogin from './third/ThirdLogin'
  25. import LoginSelectTenant from './LoginSelectTenant'
  26. import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha'
  27. import { getEncryptedString } from '@/utils/encryption/aesEncrypt'
  28. import { timeFix } from '@/utils/util'
  29. import LoginAccount from './LoginAccount'
  30. import LoginPhone from './LoginPhone'
  31. export default {
  32. components: {
  33. LoginSelectTenant,
  34. TwoStepCaptcha,
  35. ThirdLogin,
  36. LoginAccount,
  37. LoginPhone
  38. },
  39. data () {
  40. return {
  41. customActiveKey: 'tab1',
  42. rememberMe: true,
  43. loginBtn: false,
  44. requiredTwoStepCaptcha: false,
  45. stepCaptchaVisible: false,
  46. encryptedString:{
  47. key:"",
  48. iv:"",
  49. },
  50. }
  51. },
  52. created() {
  53. Vue.ls.remove(ACCESS_TOKEN)
  54. this.getRouterData();
  55. this.rememberMe = true
  56. },
  57. methods:{
  58. handleTabClick(key){
  59. this.customActiveKey = key
  60. },
  61. handleRememberMeChange(e){
  62. this.rememberMe = e.target.checked
  63. },
  64. /**跳转到登录页面的参数-账号获取*/
  65. getRouterData(){
  66. this.$nextTick(() => {
  67. let temp = this.$route.params.username || this.$route.query.username || ''
  68. if (temp) {
  69. this.$refs.alogin.acceptUsername(temp)
  70. }
  71. })
  72. },
  73. //登录
  74. handleSubmit () {
  75. this.loginBtn = true;
  76. if (this.customActiveKey === 'tab1') {
  77. // 使用账户密码登录
  78. this.$refs.alogin.handleLogin(this.rememberMe)
  79. } else {
  80. //手机号码登录
  81. this.$refs.plogin.handleLogin(this.rememberMe)
  82. }
  83. },
  84. // 校验失败
  85. validateFail(){
  86. this.loginBtn = false;
  87. },
  88. // 登录后台成功
  89. requestSuccess(loginResult){
  90. this.$refs.loginSelect.show(loginResult)
  91. },
  92. //登录后台失败
  93. requestFailed (err) {
  94. let description = ((err.response || {}).data || {}).message || err.message || "请求出现错误,请稍后再试"
  95. this.$notification[ 'error' ]({
  96. message: '登录失败',
  97. description: description,
  98. duration: 4,
  99. });
  100. //账户密码登录错误后更新验证码
  101. if(this.customActiveKey === 'tab1' && description.indexOf('密码错误')>0){
  102. this.$refs.alogin.handleChangeCheckCode()
  103. }
  104. this.loginBtn = false;
  105. },
  106. loginSelectOk(){
  107. this.loginSuccess()
  108. },
  109. //登录成功
  110. loginSuccess () {
  111. this.$router.push({ path: "/dashboard/analysis" }).catch(()=>{
  112. console.log('登录跳转首页出错,这个错误从哪里来的')
  113. })
  114. },
  115. stepCaptchaSuccess () {
  116. this.loginSuccess()
  117. },
  118. stepCaptchaCancel () {
  119. this.Logout().then(() => {
  120. this.loginBtn = false
  121. this.stepCaptchaVisible = false
  122. })
  123. },
  124. //获取密码加密规则
  125. getEncrypte(){
  126. var encryptedString = Vue.ls.get(ENCRYPTED_STRING);
  127. if(encryptedString == null){
  128. getEncryptedString().then((data) => {
  129. this.encryptedString = data
  130. });
  131. }else{
  132. this.encryptedString = encryptedString;
  133. }
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="less" scoped>
  139. .user-layout-login {
  140. label {
  141. font-size: 14px;
  142. }
  143. .getCaptcha {
  144. display: block;
  145. width: 100%;
  146. height: 40px;
  147. }
  148. .forge-password {
  149. font-size: 14px;
  150. }
  151. button.login-button {
  152. padding: 0 15px;
  153. font-size: 16px;
  154. height: 40px;
  155. width: 100%;
  156. }
  157. .user-login-other {
  158. text-align: left;
  159. margin-top: 24px;
  160. line-height: 22px;
  161. .item-icon {
  162. font-size: 24px;
  163. color: rgba(0,0,0,.2);
  164. margin-left: 16px;
  165. vertical-align: middle;
  166. cursor: pointer;
  167. transition: color .3s;
  168. &:hover {
  169. color: #1890ff;
  170. }
  171. }
  172. .register {
  173. float: right;
  174. }
  175. }
  176. }
  177. </style>
  178. <style>
  179. .valid-error .ant-select-selection__placeholder{
  180. color: #f5222d;
  181. }
  182. </style>