index.vue 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="mainPage">
  3. <img src="../../../static/images/bg.jpg" class="centerLabel cover" alt="">
  4. <div class="centerLabel">
  5. <img src="../../../static/images/loginName.png" class="title" width="260" alt="">
  6. <ul>
  7. <li class="flex-h">
  8. <div>
  9. <i class="iconfont icon-yonghuming centerLabel"></i>
  10. </div>
  11. <div class="flex-item">
  12. <input type="text" v-model="account" placeholder="用户名">
  13. </div>
  14. </li>
  15. <li class="flex-h">
  16. <div>
  17. <i class="iconfont icon-mima1 centerLabel"></i>
  18. </div>
  19. <div class="flex-item">
  20. <input type="password" v-model="password" placeholder="请输入密码">
  21. </div>
  22. </li>
  23. </ul>
  24. <div class="remberAccount">
  25. <span>记住用户名和密码</span>
  26. <i class="iconfont" :class="{'icon-ic_check_box_outline_blank': !remberAccount, 'icon-md-checkbox-outline': remberAccount, 'active': remberAccount}" @click="triggerRember"></i>
  27. </div>
  28. <a class="btn" @click="toLogin">登 录</a>
  29. <!-- <div class="top">
  30. <i class="iconfont icon-yinchenglogo"></i>
  31. <span>城的空间 · 登录</span>
  32. </div>
  33. <div class="login">
  34. <input type="text" v-model="account" placeholder="请输入账号">
  35. <input type="password" v-model="password" placeholder="请输入密码">
  36. <div>
  37. <label :class="{'active':remberAccount}" @click="triggerRember">
  38. <i class="iconfont icon-gouxuan"></i>
  39. <span onselectstart="return false">记住账号密码</span>
  40. </label>
  41. </div>
  42. <a class="btn" @click="toLogin">登 录</a>
  43. </div> -->
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. export default {
  49. name: '',
  50. data () {
  51. return {
  52. account: '', // 账号
  53. password: '', // 密码
  54. remberAccount: true, // 记住账号密码
  55. token: ''
  56. }
  57. },
  58. mounted () {
  59. this.$nextTick(function () {
  60. var _that = this
  61. this.initLogin()
  62. document.onkeydown = function (event) {
  63. var e = event || window.event
  64. var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode
  65. if (keyCode === 13) {
  66. _that.toLogin()
  67. }
  68. }
  69. })
  70. },
  71. methods: {
  72. // 登录
  73. toLogin () {
  74. if (!this.account) {
  75. this.$message({
  76. message: '请输入用户名',
  77. type: 'error'
  78. })
  79. return
  80. } else if (!this.password) {
  81. this.$message({
  82. message: '请输入密码',
  83. type: 'error'
  84. })
  85. return
  86. }
  87. let userName = this.account
  88. let passWord = this.md5(this.password)
  89. let token = this.token
  90. this.$ajax(this.$api.login.signin.url, {
  91. method: this.$api.login.signin.method,
  92. data: {
  93. username: userName,
  94. password: passWord,
  95. token: token
  96. }
  97. }).then(res => {
  98. console.log(res)
  99. this.saveToken(res.token)
  100. this.$message({
  101. message: '登陆成功',
  102. type: 'success',
  103. duration: 1000
  104. })
  105. setTimeout(() => {
  106. this.$router.push({ name: 'dashboard' })
  107. }, 1000)
  108. }).catch(msg => {
  109. })
  110. },
  111. // 初始化登陆逻辑
  112. initLogin () {
  113. var aData = {}
  114. if (this.$cookie.get('accountInfo') === undefined || this.$cookie.get('accountInfo') === null) {
  115. aData = { account: '', password: '', remberAccount: true, token: '' }
  116. this.$cookie.set('accountInfo', JSON.stringify(aData))
  117. } else {
  118. aData = this.$cookie.get('accountInfo')
  119. aData = JSON.parse(aData)
  120. for (var n in aData) {
  121. this[n] = aData[n]
  122. }
  123. }
  124. },
  125. // 切换记住账号密码状态
  126. triggerRember () {
  127. this.remberAccount = !this.remberAccount
  128. },
  129. saveToken (token) {
  130. if (this.remberAccount) {
  131. var aData = { account: this.account, password: this.password, remberAccount: true, token: token }
  132. this.$cookie.set('accountInfo', JSON.stringify(aData))
  133. } else {
  134. this.$cookie.delete('accountInfo')
  135. }
  136. }
  137. },
  138. }
  139. </script>
  140. <!-- Add "scoped" attribute to limit CSS to this component only -->
  141. <style lang="scss" scoped>
  142. @import "page.scss";
  143. </style>