index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="login-wrapper">
  3. <div class="login-writh">
  4. <div class="login-padding">
  5. <div class="login-left">
  6. <img src="../../static/img/simple-img.jpg" alt="">
  7. </div>
  8. <div class="login-box">
  9. <div class="white-box">
  10. <h3 class="white-box-title">Welcome</h3><!--欢迎回来-->
  11. <el-form ref="form" :model="loginForm" label-width="80px">
  12. <el-form-item label-width="0px" class="border-bottom username">
  13. <el-input v-model="loginForm.userName" placeholder="UserName" @change="refreshLoginVerifyStatus"><!--账户-->
  14. <template slot="prepend"><!--<i class="el-icon-user"></i>--><i></i></template>
  15. </el-input>
  16. </el-form-item>
  17. <el-form-item label-width="0px" class="border-bottom key-name">
  18. <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="Password"><!--密码-->
  19. <template slot="prepend"><!--<i class="el-icon-lock"></i>--><i></i></template>
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item label-width="0px" class="border-bottom key-name" v-show="isLoginVerify">
  23. <el-input type="verifyCode" v-model="loginForm.verifyCode" auto-complete="off" @keyup.enter.native="onSubmit" placeholder="Captcha"><!--验证码-->
  24. <template slot="prepend"><i></i></template>
  25. </el-input>
  26. <el-image :src="captchaUrl" @click="changeCaptcha">
  27. </el-image>
  28. </el-form-item>
  29. <el-form-item label-width="0px" style="border-radius: 0">
  30. <el-button class="submit-button" type="primary" @click="onSubmit" :loading="submitButtonStat">Login</el-button><!--登录-->
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import network from '@/utils/network'
  41. import tool from '@/utils/tool'
  42. import userInfo from '@/utils/userInfo'
  43. import store from '@/utils/vuexStore'
  44. import baseInfo from '@/utils/baseInfo'
  45. import {REQUEST_URL} from '@/utils/config'
  46. import axiosObj from "@/utils/axiosPlugin";
  47. export default {
  48. name: 'login',
  49. data () {
  50. return {
  51. errorMsg: {
  52. title: '',
  53. type: ''
  54. },
  55. loginForm: {
  56. userName: '',
  57. password: '',
  58. verifyCode: '',
  59. },
  60. submitButtonStat: false,
  61. pageId: '',
  62. captchaUrl: '',
  63. isLoginVerify: false,
  64. baseInfo: baseInfo,
  65. }
  66. },
  67. beforeCreate () {
  68. let path = 'site/page-data'
  69. axiosObj.get(path, this.passwordInfo).then(response => {
  70. this.pageId = response.pageId
  71. this.captchaUrl = REQUEST_URL + 'site/captcha?page_id=' + this.pageId + '&v=' + Math.random()
  72. }).catch(error => {
  73. error = tool.errorHandle(error)
  74. this.$message.error(error.message)
  75. console.log(error)
  76. })
  77. },
  78. mounted () {
  79. network.getSiteInfo()
  80. // 检测用户是否已经登录,如果已经登录则直接跳转到控制台页
  81. // if(userInfo.hasLogin()){
  82. // this.$router.push('dashboard/index');
  83. // }
  84. },
  85. methods: {
  86. onSubmit () {
  87. this.submitButtonStat = true
  88. let promise = null
  89. // 查看是否存在当前时间差,如果不存在,则向服务器请求时间差
  90. let userName = this.loginForm.userName
  91. let password = this.loginForm.password
  92. let pageId = this.pageId
  93. if (baseInfo.daysDiff() === null) {
  94. promise = network.getDaysDiff().then(response => {
  95. if (this.isLoginVerify) {
  96. let verifyCode = this.loginForm.verifyCode
  97. let data = {
  98. userName,
  99. password,
  100. verifyCode,
  101. }
  102. return network.loginGetAccessToken(userName, password, `oauth/login?page_id=${pageId}`, data)
  103. }else {
  104. return network.loginGetAccessToken(userName, password)
  105. }
  106. })
  107. } else {
  108. if (this.isLoginVerify) {
  109. let verifyCode = this.loginForm.verifyCode
  110. let data = {
  111. userName,
  112. password,
  113. verifyCode,
  114. }
  115. promise = network.loginGetAccessToken(userName, password, `oauth/login?page_id=${pageId}`, data)
  116. } else {
  117. promise = network.loginGetAccessToken(userName, password)
  118. }
  119. }
  120. promise.then(response => {
  121. return network.getUserInfo()
  122. }).then(response => {
  123. return network.getBaseInfo()
  124. }).then(response => {
  125. return network.getData('message/unread-num')
  126. }).then(response => {
  127. if (response > 0) {
  128. store.state.baseInfo.messageUnreadNum = response
  129. }
  130. if (!this.baseInfo.whetherBA()) {
  131. this.$router.push('dashboard/index')
  132. } else {
  133. this.$router.push('dashboard/ba-index')
  134. }
  135. }).catch(error => {
  136. console.log(error);
  137. this.refreshLoginVerifyStatus();
  138. if (this.isLoginVerify) {
  139. this.changeCaptcha()
  140. }
  141. if (error.message === 'ERROR_IS_MODIFY_PASSWORD') {
  142. // this.submitButtonStat = false
  143. // console.log(this.loginForm.userName);
  144. this.$router.push(`/modify-password/${this.loginForm.userName}`)
  145. } else {
  146. error = tool.errorHandle(error)
  147. this.$message.error(error.message)
  148. // this.submitButtonStat = false
  149. }
  150. // error = tool.errorHandle(error)
  151. // this.$message.error(error.message)
  152. // this.submitButtonStat = false
  153. })
  154. },
  155. changeCaptcha () {
  156. this.captchaUrl = REQUEST_URL + 'site/captcha?page_id=' + this.pageId + '&v=' + Math.random();
  157. },
  158. refreshLoginVerifyStatus () {
  159. let path = 'oauth/is-login-verify'
  160. axiosObj.post(path, {userName:this.loginForm.userName}).then(response => {
  161. this.isLoginVerify = response === 1;
  162. this.submitButtonStat = false
  163. }).catch(error => {
  164. error = tool.errorHandle(error)
  165. this.$message.error(error.message)
  166. console.log(error)
  167. this.submitButtonStat = false
  168. })
  169. },
  170. }
  171. }
  172. </script>
  173. <style>
  174. @import '../../static/plugins/css/font-awesome.min.css';
  175. .login-wrapper {
  176. background: url(../../static/img/login-register.jpg) center center no-repeat;
  177. width: 100%;
  178. height: 100%;
  179. position: fixed;background-size: 100% 100% ;
  180. }
  181. .username .el-input-group__prepend{ background: url(../../static/img/user.png) center center no-repeat;background-size:contain }
  182. .key-name .el-input-group__prepend{ background: url(../../static/img/key.png) center center no-repeat;background-size:contain}
  183. .login-wrapper .login-box {
  184. width: 40%;
  185. margin: 0% auto 0;float: right;
  186. }
  187. .login-wrapper .white-box {
  188. background: #fff;
  189. padding: 25px;
  190. margin-bottom: 15px;
  191. border-radius: 0;box-shadow: 0 0 10px #f2f1f4;
  192. }
  193. .white-box .white-box-title {
  194. margin: 0 0 12px;
  195. font-weight: 500;
  196. text-transform: uppercase;
  197. font-size: 20px;
  198. line-height: 30px;
  199. text-align: center;
  200. color: #522989;
  201. }
  202. .login-wrapper .el-input-group__prepend {
  203. background-color: #fff !important;
  204. border-radius: 0 !important;
  205. padding: 0 15px 0 10px ;width: 5%;display: block;;float: left;padding: 0px!important;height:35px;
  206. }
  207. .login-wrapper .el-input-group--prepend i{font-size: 16px;}
  208. .login-wrapper .el-input__inner {
  209. border-radius: 20px !important;
  210. border-top-left-radius: 0 !important;
  211. border-bottom-left-radius: 0 !important;
  212. }
  213. .login-wrapper .submit-button {
  214. width: 80%;margin: 0 auto;display: block;
  215. border-radius: 20px !important;margin-top: 15px;
  216. background-color: #0c195d !important;
  217. border-color: #0c195d !important;
  218. }
  219. .el-input-group--prepend .el-input__inner, .el-input-group__append{border: none;background: none;border-radius: 0;width:94%;float: right;display: block; }
  220. .border-bottom {border-bottom:2px #0c195d solid;}
  221. .el-input-group__append, .el-input-group__prepend{border: none;}
  222. input:-webkit-autofill {
  223. transition: background-color 5000s ease-in-out 0s;
  224. }
  225. input:-webkit-autofill:focus {
  226. transition: background-color 5000s ease-in-out 0s;
  227. }
  228. .login-padding:after{content: '';display: table;clear: both;}
  229. .login-left{width: 40%;float: left; }
  230. .login-left img{width: 100%;height: auto;}
  231. .login-padding{background: url(../../static/img/shu.png) center center no-repeat;background-size:contain}
  232. @media (min-width: 34em) {
  233. .login-padding{width:600px;margin: 20% auto;}
  234. }
  235. @media (min-width: 48em) {
  236. .login-padding{width: 700px;margin: 20% auto;}
  237. }
  238. @media (min-width: 62em) {
  239. .login-padding{width: 1000px;margin: 13% auto;/*padding: 5% 0;*/}
  240. }
  241. @media (min-width:1550px) {
  242. .login-padding{width: 1000px;margin: 11% auto;/*padding: 5% 0;*/}
  243. }
  244. @media only screen and (max-width:766px) {
  245. .login-left{width: 40%;float: left;display: none; }
  246. .login-wrapper .login-box{width: 70%;float: none;margin: 25% auto 0;}
  247. .login-wrapper .el-input-group__prepend{ }
  248. .login-padding{background: none;}
  249. .login-wrapper .white-box{box-shadow: none;}
  250. .login-wrapper .el-input-group__prepend{width: 8%;}
  251. .el-input-group--prepend .el-input__inner, .el-input-group__append{width: 90%;}
  252. }
  253. </style>