Login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="main iot-login-content">
  3. <div class="top-img"></div>
  4. <div class="sign-text">登录到 联锁管理平台</div>
  5. <a-form-model class="user-layout-login" @keyup.enter.native="handleSubmit">
  6. <a-tabs :activeKey="customActiveKey" :tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }" @change="handleTabClick" class="login-tabs">
  7. <a-tab-pane key="tab1" tab="SSO">
  8. <login-account ref="alogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-account>
  9. </a-tab-pane>
  10. <!-- 修改框架 -->
  11. <!-- <a-tab-pane key="tab2" tab="手机号登录">
  12. <login-phone ref="plogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-phone>
  13. </a-tab-pane> -->
  14. </a-tabs>
  15. <a-form-model-item>
  16. <a-checkbox @change="handleRememberMeChange" default-checked>记住我</a-checkbox>
  17. <!-- 修改框架 -->
  18. <!-- <router-link :to="{ name: 'alteration'}" class="forge-password" style="float: right;">
  19. 忘记密码
  20. </router-link> -->
  21. <!-- <router-link :to="{ name: 'register'}" class="forge-password" style="float: right;margin-right: 10px" >
  22. 注册账户
  23. </router-link> -->
  24. </a-form-model-item>
  25. <a-form-item style="margin-top:24px">
  26. <a-button size="large" type="primary" htmlType="submit" class="login-button" :loading="loginBtn" @click.stop.prevent="handleSubmit" :disabled="loginBtn">登录
  27. </a-button>
  28. </a-form-item>
  29. </a-form-model>
  30. <two-step-captcha v-if="requiredTwoStepCaptcha" :visible="stepCaptchaVisible" @success="stepCaptchaSuccess" @cancel="stepCaptchaCancel"></two-step-captcha>
  31. <login-select-tenant ref="loginSelect" @success="loginSelectOk"></login-select-tenant>
  32. <!-- 修改框架 -->
  33. <!-- <third-login ref="thirdLogin"></third-login> -->
  34. </div>
  35. </template>
  36. <script>
  37. import Vue from 'vue'
  38. import { ACCESS_TOKEN, ENCRYPTED_STRING } from '@/store/mutation-types'
  39. import ThirdLogin from './third/ThirdLogin'
  40. import LoginSelectTenant from './LoginSelectTenant'
  41. import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha'
  42. import { getEncryptedString } from '@/utils/encryption/aesEncrypt'
  43. import { timeFix } from '@/utils/util'
  44. import LoginAccount from './LoginAccount'
  45. import LoginPhone from './LoginPhone'
  46. export default {
  47. components: {
  48. LoginSelectTenant,
  49. TwoStepCaptcha,
  50. ThirdLogin,
  51. LoginAccount,
  52. LoginPhone
  53. },
  54. data () {
  55. return {
  56. customActiveKey: 'tab1',
  57. rememberMe: true,
  58. loginBtn: false,
  59. requiredTwoStepCaptcha: false,
  60. stepCaptchaVisible: false,
  61. encryptedString:{
  62. key:"",
  63. iv:"",
  64. },
  65. }
  66. },
  67. created() {
  68. Vue.ls.remove(ACCESS_TOKEN)
  69. this.getRouterData();
  70. this.rememberMe = true
  71. },
  72. methods:{
  73. handleTabClick(key){
  74. this.customActiveKey = key
  75. },
  76. handleRememberMeChange(e){
  77. this.rememberMe = e.target.checked
  78. },
  79. /**跳转到登录页面的参数-账号获取*/
  80. getRouterData(){
  81. this.$nextTick(() => {
  82. let temp = this.$route.params.username || this.$route.query.username || ''
  83. if (temp) {
  84. this.$refs.alogin.acceptUsername(temp)
  85. }
  86. })
  87. },
  88. //登录
  89. handleSubmit () {
  90. this.loginBtn = true;
  91. if (this.customActiveKey === 'tab1') {
  92. // 使用账户密码登录
  93. this.$refs.alogin.handleLogin(this.rememberMe)
  94. } else {
  95. //手机号码登录
  96. this.$refs.plogin.handleLogin(this.rememberMe)
  97. }
  98. },
  99. // 校验失败
  100. validateFail(){
  101. this.loginBtn = false;
  102. },
  103. // 登录后台成功
  104. requestSuccess(loginResult){
  105. this.$refs.loginSelect.show(loginResult)
  106. },
  107. //登录后台失败
  108. requestFailed (err) {
  109. let description = ((err.response || {}).data || {}).message || err.message || "请求出现错误,请稍后再试"
  110. this.$notification[ 'error' ]({
  111. message: '登录失败',
  112. description: description,
  113. duration: 4,
  114. });
  115. //账户密码登录错误后更新验证码
  116. if(this.customActiveKey === 'tab1' && description.indexOf('密码错误')>0){
  117. this.$refs.alogin.handleChangeCheckCode()
  118. }
  119. this.loginBtn = false;
  120. },
  121. loginSelectOk(){
  122. this.loginSuccess()
  123. },
  124. //登录成功
  125. loginSuccess () {
  126. this.$router.push({ path: "/interLock/summary" }).catch(()=>{
  127. // this.$router.push({ path: "/dashboard/analysis" }).catch(()=>{
  128. console.log('登录跳转首页出错,这个错误从哪里来的')
  129. })
  130. this.$notification.success({
  131. message: '欢迎',
  132. description: `${timeFix()},欢迎回来`,
  133. });
  134. },
  135. stepCaptchaSuccess () {
  136. this.loginSuccess()
  137. },
  138. stepCaptchaCancel () {
  139. this.Logout().then(() => {
  140. this.loginBtn = false
  141. this.stepCaptchaVisible = false
  142. })
  143. },
  144. //获取密码加密规则
  145. getEncrypte(){
  146. var encryptedString = Vue.ls.get(ENCRYPTED_STRING);
  147. if(encryptedString == null){
  148. getEncryptedString().then((data) => {
  149. this.encryptedString = data
  150. });
  151. }else{
  152. this.encryptedString = encryptedString;
  153. }
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="less">
  159. .login-tabs{
  160. .ant-tabs-nav-container{
  161. font-size: 16px !important;
  162. }
  163. .ant-tabs-nav{
  164. width: 50%;
  165. }
  166. .ant-tabs-nav .ant-tabs-tab-active{
  167. color: #3395ff !important;
  168. }
  169. .ant-tabs-ink-bar{
  170. width: 100% !important;
  171. height: 3px;
  172. background: #3395ff;
  173. }
  174. }
  175. .iot-login-content{
  176. .ant-checkbox-checked .ant-checkbox-inner{
  177. background-color: #3395FF !important;
  178. border-color: #3395FF;
  179. }
  180. }
  181. </style>
  182. <style lang="less" scoped>
  183. .top-img{
  184. width: 100%;
  185. height: 64px;
  186. background: url('../../assets/login_logo.svg') no-repeat;
  187. background-size: 100%;
  188. }
  189. .sign-text{
  190. width: 100%;
  191. height: 32px;
  192. font-size: 16px;
  193. font-weight: 400;
  194. color: #646464;
  195. margin-top: 8px;
  196. }
  197. .user-layout-login {
  198. label {
  199. font-size: 14px;
  200. }
  201. .getCaptcha {
  202. display: block;
  203. width: 100%;
  204. height: 40px;
  205. }
  206. .forge-password {
  207. font-size: 14px;
  208. }
  209. button.login-button {
  210. width: 100%;
  211. height: 40px;
  212. padding: 0 15px;
  213. font-size: 16px;
  214. background: #004280;
  215. font-weight: 700;
  216. border-color: transparent;
  217. }
  218. .user-login-other {
  219. text-align: left;
  220. margin-top: 24px;
  221. line-height: 22px;
  222. .item-icon {
  223. font-size: 24px;
  224. color: rgba(0,0,0,.2);
  225. margin-left: 16px;
  226. vertical-align: middle;
  227. cursor: pointer;
  228. transition: color .3s;
  229. &:hover {
  230. color: #1890ff;
  231. }
  232. }
  233. .register {
  234. float: right;
  235. }
  236. }
  237. }
  238. </style>
  239. <style>
  240. .valid-error .ant-select-selection__placeholder{
  241. color: #f5222d;
  242. }
  243. </style>