index.vue 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="mainPage">
  3. <div class="centerLabel">
  4. <div class="top">
  5. <i class="iconfont icon-yinchenglogo"></i>
  6. <span>城的空间 · 登录</span>
  7. </div>
  8. <div class="login">
  9. <input type="text" v-model="account" placeholder="请输入账号">
  10. <input type="password" v-model="password" placeholder="请输入密码">
  11. <div>
  12. <label :class="{'active':remberAccount}" @click="triggerRember">
  13. <i class="iconfont icon-gouxuan"></i>
  14. <span onselectstart="return false">记住账号密码</span>
  15. </label>
  16. </div>
  17. <a class="btn" @click="toLogin">登 录</a>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: '',
  25. data () {
  26. return {
  27. account: '', // 账号
  28. password: '', // 密码
  29. remberAccount: true, // 记住账号密码
  30. }
  31. },
  32. mounted () {
  33. this.$nextTick(function () {
  34. this.initLogin()
  35. })
  36. },
  37. methods: {
  38. // 登录
  39. toLogin () {
  40. if (this.remberAccount) {
  41. var aData = { account: this.account, password: this.password, remberAccount: true }
  42. this.$cookie.set('accountInfo', JSON.stringify(aData))
  43. } else {
  44. this.$cookie.delete('accountInfo')
  45. }
  46. },
  47. // 初始化登陆逻辑
  48. initLogin () {
  49. var aData = {}
  50. if (this.$cookie.get('accountInfo') === undefined || this.$cookie.get('accountInfo') === null) {
  51. aData = { account: '', password: '', remberAccount: true }
  52. this.$cookie.set('accountInfo', JSON.stringify(aData))
  53. } else {
  54. aData = this.$cookie.get('accountInfo')
  55. aData = JSON.parse(aData)
  56. for (var n in aData) {
  57. this[n] = aData[n]
  58. }
  59. }
  60. },
  61. // 切换记住账号密码状态
  62. triggerRember () {
  63. this.remberAccount = !this.remberAccount
  64. },
  65. },
  66. }
  67. </script>
  68. <!-- Add "scoped" attribute to limit CSS to this component only -->
  69. <style lang="scss" scoped>
  70. @import "page.scss";
  71. </style>