LoginCard.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <el-card class="login-card">
  3. <div class="login-welcome">
  4. <img :src="this.userImg==null?defaultValue.image:this.userImg" alt="welcome-img"
  5. class="pull-left welcome-img">
  6. <!-- <img v-else src="../../assets/img/logo-project.png" alt="welcome-img" class="pull-left welcome-img">-->
  7. <div style="margin-left: 46px">
  8. <div class="welcome-title">
  9. hi,欢迎使用群智众测平台
  10. </div>
  11. <div class="welcome-content">
  12. 众测群智,不一样的深度测试
  13. </div>
  14. </div>
  15. <div class="welcome-btn">
  16. <a :href="loginUrl">
  17. <el-button type="primary" size="mini" class="pull-left login-btn" v-if="!isLogin">登录</el-button>
  18. </a>
  19. <el-button type="danger" size="mini" class="pull-right cancel-btn" v-if="isLogin" @click.native="userLogout()">
  20. 登出
  21. </el-button>
  22. </div>
  23. </div>
  24. </el-card>
  25. </template>
  26. <script>
  27. import Http from '@/js/http.js'
  28. import Apis from '@/js/api.js'
  29. import {storageGet,logout,defaultValue} from '@/js/index.js'
  30. export default {
  31. name: "LoginCard",
  32. data() {
  33. return {
  34. isLogin: false,
  35. user: {},
  36. loginUrl: process.env.LOGIN_URL,
  37. userImg:require('../../assets/img/logo-project.png')
  38. }
  39. },
  40. methods: {
  41. loadData() {
  42. if (storageGet('user') != null) {
  43. this.isLogin = true;
  44. this.user = storageGet('user');
  45. }
  46. },
  47. userLogout() {
  48. this.isLogin = false
  49. logout().then((res) => {
  50. this.$router.go(0)
  51. })
  52. },
  53. getUserImg() {
  54. if (this.user == null) {
  55. this.userImg = null
  56. }else{
  57. Http.get(`/api/user/image/${this.user.userVO.id}`).then((res)=>{
  58. if(res.data){
  59. this.userImg = res.data;
  60. }
  61. })
  62. }
  63. }
  64. },
  65. mounted() {
  66. this.loadData();
  67. this.getUserImg();
  68. }
  69. }
  70. </script>
  71. <style scoped lang="less">
  72. .login-card {
  73. margin-bottom: 13px;
  74. .welcome-img {
  75. width: 40px;
  76. height: 40px;
  77. display: inline-block;
  78. margin: 2px 0;
  79. }
  80. .welcome-title {
  81. font-size: 14px;
  82. font-family: Source Han Sans CN;
  83. font-weight: bold;
  84. color: rgba(0, 0, 0, 1);
  85. }
  86. .welcome-content {
  87. font-size: 13px;
  88. font-family: Source Han Sans CN;
  89. font-weight: 400;
  90. color: rgba(0, 0, 0, 1);
  91. }
  92. .welcome-btn {
  93. width: 100%;
  94. height: 28px;
  95. margin-top: 20px;
  96. .login-btn {
  97. background-color: rgba(0, 118, 203, 1);
  98. &:hover {
  99. background-color: rgba(0, 118, 203, 0.8);
  100. }
  101. }
  102. .cancel-btn {
  103. background-color: rgba(217, 92, 93, 1);
  104. &:hover {
  105. background-color: rgba(217, 92, 93, 0.8);
  106. }
  107. }
  108. }
  109. }
  110. </style>