LoginCard.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <el-card class="login-card">
  3. <div class="login-welcome">
  4. <img :src="!this.userImg?logo_background:this.userImg" alt="welcome-img"
  5. class="pull-left welcome-img">
  6. <div style="margin-left: 46px">
  7. <div class="welcome-title">
  8. hi,欢迎使用{{ logoTitle }}
  9. </div>
  10. <div class="welcome-content">
  11. {{ login_description }}
  12. </div>
  13. </div>
  14. <div class="welcome-btn">
  15. <a :href="loginUrl">
  16. <el-button type="primary" size="mini" class="pull-left login-btn" v-if="!isLogin">登录</el-button>
  17. </a>
  18. <el-button type="primary" size="mini" class="pull-right cancel-btn" v-if="isLogin" @click.native="userLogout()">
  19. 登出
  20. </el-button>
  21. </div>
  22. </div>
  23. </el-card>
  24. </template>
  25. <script>
  26. import Http from '@/js/http.js'
  27. import {logout, storageGet} from '@/js/index.js'
  28. import {mapActions, mapGetters} from 'vuex'
  29. import {CONFIG, login_url} from "../../config";
  30. import {storageRemove} from "../../js/index";
  31. export default {
  32. name: "LoginCard",
  33. data() {
  34. return {
  35. logoTitle: CONFIG.logoTitle,
  36. logo_background: CONFIG.logo_background,
  37. isLogin: false,
  38. user: {},
  39. loginUrl: login_url,
  40. userImg: '',
  41. login_description: CONFIG.login_description
  42. }
  43. },
  44. computed: {
  45. ...mapGetters(['getUserInfo'])
  46. },
  47. methods: {
  48. loadData() {
  49. if (storageGet('user') || this.getUserInfo.id) {
  50. this.isLogin = true;
  51. this.user = storageGet('user') || this.getUserInfo;
  52. }
  53. },
  54. userLogout() {
  55. this.isLogin = false
  56. logout().then((res) => {
  57. console.log('logout');
  58. storageRemove('user');
  59. location.reload();
  60. })
  61. },
  62. getUserImg() {
  63. if (this.user && this.user.userVO && this.user.userVO.id) {
  64. Http.get(`/api/user/image/${this.user.userVO.id}`).then((res) => {
  65. if (res.data) {
  66. this.userImg = res.data;
  67. }
  68. })
  69. }
  70. }
  71. },
  72. mounted() {
  73. this.loadData();
  74. this.getUserImg();
  75. },
  76. watch: {
  77. getUserInfo(val) {
  78. this.loadData();
  79. this.getUserImg();
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. @import "../../style/main";
  86. .login-card {
  87. margin-bottom: 13px;
  88. .welcome-img {
  89. width: 40px;
  90. height: 40px;
  91. display: inline-block;
  92. margin: 2px 0;
  93. }
  94. .welcome-title {
  95. font-size: 14px;
  96. font-family: Source Han Sans CN;
  97. font-weight: bold;
  98. color: rgba(0, 0, 0, 1);
  99. }
  100. .welcome-content {
  101. font-size: 13px;
  102. font-family: Source Han Sans CN;
  103. font-weight: 400;
  104. color: rgba(0, 0, 0, 1);
  105. }
  106. .welcome-btn {
  107. width: 100%;
  108. height: 28px;
  109. margin-top: 20px;
  110. }
  111. }
  112. </style>