Login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. window.localStorage.setItem('token', datas.data.access_token)
  98. that.getTokenCode(datas.data.access_token)
  99. } else {
  100. ElMessage.error(datas.message);
  101. that.loginLoading = false
  102. }
  103. }
  104. }).catch(e =>{
  105. that.loading = false
  106. })
  107. },
  108. // 根据token获取code
  109. getTokenCode(val) {
  110. let that = this
  111. apiGetCodeByToken(val).then(datas =>{
  112. if (datas && datas.data) {
  113. // setToken('code', datas.data)
  114. window.localStorage.setItem('code', datas.data)
  115. that.getUserMsg(datas.data)
  116. }
  117. })
  118. },
  119. getUserMsg(val) {
  120. let that = this
  121. apiGetUserMsg(val).then(datas =>{
  122. if (datas && datas.data) {
  123. // setToken('user', JSON.stringify(datas.data))
  124. let obj = {
  125. unitId: datas.data.unitId,
  126. unitName: datas.data.unitName,
  127. deptId: datas.data.deptId,
  128. deptName: datas.data.deptName,
  129. name: datas.data.name,
  130. id: datas.data.id
  131. }
  132. window.sessionStorage.setItem('user', JSON.stringify(obj))
  133. that.getApprverData()
  134. }
  135. })
  136. },
  137. getApprverData() {
  138. let that = this
  139. apiGetPrivilegesOfCurrentUserAll().then(datas =>{
  140. if (datas && datas.data) {
  141. // setToken('purview', JSON.stringify(datas.data.data))
  142. window.localStorage.setItem('purview', JSON.stringify(datas.data.data))
  143. that.$router.push({ path: "/home"})
  144. }
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. @media screen and (max-width: 1200px) {
  152. .loginPic{
  153. .login_left {
  154. display: none;
  155. }
  156. }
  157. }
  158. .loginPic{
  159. position: relative;
  160. width: 100%;
  161. height:1080px;
  162. background-image: url('../assets/loginImage/logindefBak.png');
  163. background-position: 0 0;
  164. background-repeat: no-repeat;
  165. display: flex;
  166. .login_left{
  167. position: fixed;
  168. left: 15%;
  169. top: 35%;
  170. p{
  171. margin-bottom: 0px;
  172. font-size: 32px;
  173. color: #fff;
  174. margin-top: 10px;
  175. }
  176. .title{
  177. letter-spacing: 5px;
  178. }
  179. }
  180. .login_right{
  181. width: 470px;
  182. height:680px;
  183. background: rgba(0,0,0,0.4);
  184. position: fixed;
  185. right: 15%;
  186. top: 15%;
  187. .titleIcon{
  188. margin: 100px 0px 43px 95px;
  189. }
  190. .loginCom{
  191. margin: 0 30px 0px 43px;
  192. width: 384px;
  193. height: 56px;
  194. background: #1B1A1F;
  195. border-radius: 5px;
  196. display: flex;
  197. .userIcon {
  198. width: 24px;
  199. height: 24px;
  200. margin: 16px;
  201. }
  202. .passwordIcon {
  203. width: 24px;
  204. height: 24px;
  205. margin: 16px;
  206. }
  207. .el-input{
  208. border: 0 solid transparent;
  209. .el-input__wrapper{
  210. background: transparent;
  211. box-shadow: none;
  212. .el-input__inner, .el-input__inner:focus{
  213. background-color: transparent;
  214. border: none !important;
  215. color: #fff;
  216. height: 30px;
  217. width: 100%;
  218. font-size: 14px;
  219. }
  220. }
  221. }
  222. }
  223. .remeber{
  224. margin: 0 0 0 50px;
  225. .el-checkbox{
  226. .el-checkbox__label{
  227. color: #fff;
  228. font-size: 12px;
  229. padding-left:6px;
  230. }
  231. }
  232. }
  233. .loginBtn{
  234. margin: 48px 0 0 43px;
  235. width: 384px;
  236. height: 56px;
  237. background-image: url('../assets/loginImage/loginBtn.png');
  238. cursor: pointer;
  239. .loginSpan{
  240. position: relative;
  241. top: 27%;
  242. left: 45%;
  243. font-size: 18px;
  244. font-family: Microsoft YaHei;
  245. font-weight: 400;
  246. color: #FFFFFF;
  247. }
  248. .loading{
  249. display: flex;
  250. justify-content: center;
  251. padding-top: 13px;
  252. .loadingSpan{
  253. position: relative;
  254. top: 2px;
  255. left: -9px;
  256. font-size: 18px;
  257. font-family: Microsoft YaHei;
  258. font-weight: 400;
  259. color: #FFFFFF;
  260. }
  261. .el-icon{
  262. position: relative;
  263. top: 7px;
  264. left: -12px;
  265. }
  266. }
  267. }
  268. input::-webkit-input-placeholder{ /*WebKit browsers*/
  269. color: #fff;
  270. }
  271. input::-moz-input-placeholder{ /*Mozilla Firefox*/
  272. color: #fff;
  273. }
  274. input::-ms-input-placeholder{ /*Internet Explorer*/
  275. color: #fff;
  276. }
  277. }
  278. .loginFooter{
  279. height: 40px;
  280. line-height: 40px;
  281. position: fixed;
  282. bottom: 0;
  283. width: 100%;
  284. text-align: center;
  285. color: #fff;
  286. font-family: Arial;
  287. font-size: 12px;
  288. letter-spacing: 1px;
  289. }
  290. }
  291. </style>