Login.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="loginPic">
  3. <!-- <div class="login_left">
  4. <p>Welcome!</p>
  5. <p class="title">光耀集中式风电功率预测系统</p>
  6. </div> -->
  7. <div class="login_right">
  8. <img class="titleIcon" src="../assets/loginImage/logo.png" alt="">
  9. <div class="loginCom" style="margin-bottom: 30px">
  10. <img class="userIcon" src="../assets/loginImage/userIcon.png" alt="">
  11. <el-input v-model="inputUser" placeholder="请输入用户名" />
  12. </div>
  13. <div class="loginCom" style="margin-bottom: 16px">
  14. <img class="passwordIcon" src="../assets/loginImage/passwordIcon.png" alt="">
  15. <el-input type="password" v-model="inputMima" placeholder="请输入密码" />
  16. </div>
  17. <div class="remeber">
  18. <el-checkbox v-model="ememberMe" @change="changeBox">记住密码</el-checkbox>
  19. </div>
  20. <!-- v-if="!loginLoading" v-else -->
  21. <div class="loginBtn" @click="handleLogin" v-if="!loginLoading">
  22. <span class="loginSpan">登录</span>
  23. </div>
  24. <div class="loginBtn" v-else>
  25. <div class="loading">
  26. <el-icon color="#fff"><Loading /></el-icon>
  27. <span class="loadingSpan">登录</span>
  28. </div>
  29. </div>
  30. </div>
  31. <!-- 底部 -->
  32. <!-- <div class="loginFooter">
  33. <span>Copyright © 2021-2022 GuangYaoDianLi All Rights Reserved.</span>
  34. </div> -->
  35. </div>
  36. </template>
  37. <script>
  38. import { setToken } from '@/api/auth'
  39. import { ElMessage } from "element-plus";
  40. import { loginApi, apiGetCodeByToken, apiGetUserMsg, apiGetPrivilegesOfCurrentUserAll } from '../api/api'
  41. export default {
  42. data() {
  43. return {
  44. inputUser:'',
  45. // inputUser:'testrsadmin',Gddl!#%135
  46. inputMima:'',
  47. codeUrl:'',
  48. ememberMe:false,
  49. loading:false,
  50. loginText: '',
  51. loginLoading: false
  52. }
  53. },
  54. created() {
  55. if (window.localStorage.getItem('userData')) {
  56. let userData = JSON.parse(window.localStorage.getItem('userData'))
  57. this.inputUser = userData.user
  58. this.inputMima = userData.password
  59. this.ememberMe = true
  60. } else {
  61. this.ememberMe = false
  62. }
  63. },
  64. methods:{
  65. handleLogin() {
  66. if (this.inputUser !== '' && this.inputMima !== '') {
  67. this.loginLoading = true
  68. if (this.ememberMe) {
  69. this.changeBox(this.ememberMe)
  70. }
  71. this.getLogin(this.inputUser, this.inputMima)
  72. } else {
  73. ElMessage.error('请输入账号或密码');
  74. }
  75. },
  76. changeBox(val) {
  77. if (val) {
  78. if (this.inputUser !== '' && this.inputMima !== '') {
  79. let obj = {
  80. user: this.inputUser,
  81. password: this.inputMima
  82. }
  83. window.localStorage.setItem('userData', JSON.stringify(obj))
  84. }
  85. } else {
  86. window.localStorage.removeItem('userData')
  87. }
  88. },
  89. //登录接口
  90. getLogin(userName, password) {
  91. // setToken('userMsg', params)
  92. let that = this
  93. loginApi(userName, password).then(datas=>{
  94. if (datas) {
  95. if (datas.success) {
  96. setToken('token', datas.data.access_token)
  97. that.getTokenCode(datas.data.access_token)
  98. } else {
  99. ElMessage.error(datas.message);
  100. that.loginLoading = false
  101. }
  102. }
  103. }).catch(e =>{
  104. that.loading = false
  105. })
  106. },
  107. // 根据token获取code
  108. getTokenCode(val) {
  109. let that = this
  110. apiGetCodeByToken(val).then(datas =>{
  111. if (datas && datas.data) {
  112. setToken('code', datas.data)
  113. that.getUserMsg(datas.data)
  114. }
  115. })
  116. },
  117. getUserMsg(val) {
  118. let that = this
  119. apiGetUserMsg(val).then(datas =>{
  120. if (datas && datas.data) {
  121. // setToken('user', JSON.stringify(datas.data))
  122. let obj = {
  123. name: datas.data.name,
  124. id: datas.data.id
  125. }
  126. window.sessionStorage.setItem('user', JSON.stringify(obj))
  127. that.getApprverData()
  128. }
  129. })
  130. },
  131. getApprverData() {
  132. let that = this
  133. apiGetPrivilegesOfCurrentUserAll().then(datas =>{
  134. if (datas && datas.data) {
  135. setToken('purview', JSON.stringify(datas.data.data))
  136. that.$router.push({ path: "/home"})
  137. }
  138. })
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss">
  144. @media screen and (max-width: 1200px) {
  145. .loginPic{
  146. .login_left {
  147. display: none;
  148. }
  149. }
  150. }
  151. .loginPic{
  152. position: relative;
  153. width: 100%;
  154. height:1080px;
  155. background-image: url('../assets/loginImage/logindefBak.png');
  156. background-position: 0 0;
  157. background-repeat: no-repeat;
  158. display: flex;
  159. .login_left{
  160. position: fixed;
  161. left: 15%;
  162. top: 35%;
  163. p{
  164. margin-bottom: 0px;
  165. font-size: 32px;
  166. color: #fff;
  167. margin-top: 10px;
  168. }
  169. .title{
  170. letter-spacing: 5px;
  171. }
  172. }
  173. .login_right{
  174. width: 470px;
  175. height:680px;
  176. background: rgba(0,0,0,0.4);
  177. position: fixed;
  178. right: 15%;
  179. top: 15%;
  180. .titleIcon{
  181. margin: 100px 0px 43px 95px;
  182. }
  183. .loginCom{
  184. margin: 0 30px 0px 43px;
  185. width: 384px;
  186. height: 56px;
  187. background: #1B1A1F;
  188. border-radius: 5px;
  189. display: flex;
  190. .userIcon {
  191. width: 24px;
  192. height: 24px;
  193. margin: 16px;
  194. }
  195. .passwordIcon {
  196. width: 24px;
  197. height: 24px;
  198. margin: 16px;
  199. }
  200. .el-input{
  201. border: 0 solid transparent;
  202. .el-input__wrapper{
  203. background: transparent;
  204. box-shadow: none;
  205. .el-input__inner, .el-input__inner:focus{
  206. background: none;
  207. border: none !important;
  208. color: #fff;
  209. height: 30px;
  210. width: 100%;
  211. font-size: 14px;
  212. }
  213. }
  214. }
  215. }
  216. .remeber{
  217. margin: 0 0 0 50px;
  218. .el-checkbox{
  219. .el-checkbox__label{
  220. color: #fff;
  221. font-size: 12px;
  222. padding-left:6px;
  223. }
  224. }
  225. }
  226. .loginBtn{
  227. margin: 48px 0 0 43px;
  228. width: 384px;
  229. height: 56px;
  230. background-image: url('../assets/loginImage/loginBtn.png');
  231. cursor: pointer;
  232. .loginSpan{
  233. position: relative;
  234. top: 27%;
  235. left: 45%;
  236. font-size: 18px;
  237. font-family: Microsoft YaHei;
  238. font-weight: 400;
  239. color: #FFFFFF;
  240. }
  241. .loading{
  242. display: flex;
  243. justify-content: center;
  244. padding-top: 13px;
  245. .loadingSpan{
  246. position: relative;
  247. top: 2px;
  248. left: -9px;
  249. font-size: 18px;
  250. font-family: Microsoft YaHei;
  251. font-weight: 400;
  252. color: #FFFFFF;
  253. }
  254. .el-icon{
  255. position: relative;
  256. top: 7px;
  257. left: -12px;
  258. }
  259. }
  260. }
  261. input::-webkit-input-placeholder{ /*WebKit browsers*/
  262. color: #fff;
  263. }
  264. input::-moz-input-placeholder{ /*Mozilla Firefox*/
  265. color: #fff;
  266. }
  267. input::-ms-input-placeholder{ /*Internet Explorer*/
  268. color: #fff;
  269. }
  270. }
  271. .loginFooter{
  272. height: 40px;
  273. line-height: 40px;
  274. position: fixed;
  275. bottom: 0;
  276. width: 100%;
  277. text-align: center;
  278. color: #fff;
  279. font-family: Arial;
  280. font-size: 12px;
  281. letter-spacing: 1px;
  282. }
  283. }
  284. </style>