index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <view class="user-banner" v-if="isLogin">
  4. <div>
  5. <image v-if="user.avatar!=null && user.avatar!=''" class="avatar" :src="user.avatar"></image>
  6. <image v-else class="avatar" src="../../static/avatar.png"></image>
  7. </div>
  8. <view class="name">
  9. {{user.realName}}
  10. </view>
  11. <view class="dept">{{user.departId_dictText}}</view>
  12. <view class="points">
  13. {{user.points}}积分
  14. </view>
  15. </view>
  16. <!-- 左侧显示略缩图、图标 -->
  17. <uni-list>
  18. <uni-list-item thumb-size="sm" title="修改资料" link="navigateTo" to="/pages/user/info/info">
  19. </uni-list-item>
  20. <uni-list-item thumb-size="sm" title="学习记录" link="navigateTo" to="/pages/course/my">
  21. </uni-list-item>
  22. <uni-list-item thumb-size="sm" title="我的成绩" link="navigateTo" to="/pages/paper/index">
  23. </uni-list-item>
  24. <uni-list-item thumb-size="sm" title="训练记录" link="navigateTo" to="/pages/repo/history">
  25. </uni-list-item>
  26. <uni-list-item thumb-size="sm" title="积分日志" link="navigateTo" to="/pages/user/points/points">
  27. </uni-list-item>
  28. <uni-list-item thumb-size="sm" title="密码安全" link="navigateTo" to="/pages/login/passwd">
  29. </uni-list-item>
  30. <!-- <uni-list-item
  31. thumb-size="sm"
  32. title="关于我们"
  33. link="navigateTo"
  34. to="/pages/sys/about">
  35. </uni-list-item> -->
  36. <!-- <uni-list-item thumb-size="sm" title="跳转App" link="navigateTo" to="/pages/jumpApp/index">
  37. </uni-list-item> -->
  38. <uni-list-item thumb-size="sm" title="退出登录" link="navigateTo" @click="handleLogout()">
  39. </uni-list-item>
  40. </uni-list>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. logout,
  46. info
  47. } from '@/api/user'
  48. export default {
  49. components: {},
  50. data() {
  51. return {
  52. isLogin: false,
  53. user: {},
  54. }
  55. },
  56. onShow() {
  57. this.handleInfo()
  58. },
  59. methods: {
  60. handleInfo() {
  61. let token = uni.getStorageSync('token');
  62. info(token).then(res => {
  63. this.isLogin = true
  64. this.user = res
  65. })
  66. },
  67. handleLogout() {
  68. logout().then(res => {
  69. // 移除会话
  70. uni.removeStorageSync('token');
  71. // 到登录页面
  72. this.$navs.toLogin()
  73. })
  74. }
  75. }
  76. }
  77. </script>
  78. <style>
  79. .user-banner {
  80. height: 160px;
  81. display: flex;
  82. background: url('https://cdn.yfhl.net/static/user-bg.jpg') no-repeat;
  83. align-items: center;
  84. background-position: center;
  85. background-size: 100% 100%;
  86. justify-content: center;
  87. width: 100%;
  88. flex-direction: column;
  89. }
  90. .user-banner .avatar {
  91. width: 80px;
  92. height: 80px;
  93. border: #efefef 2px solid;
  94. border-radius: 50%;
  95. }
  96. .user-banner .points {
  97. position: absolute;
  98. top: 15px;
  99. right: 15px;
  100. color: #FDBF40;
  101. font-weight: bold;
  102. font-weight: 700;
  103. font-size: 16px;
  104. }
  105. .user-banner .name {
  106. color: #fff;
  107. font-weight: 700;
  108. font-size: 18px;
  109. }
  110. .user-banner .dept {
  111. color: #eee;
  112. font-weight: 700;
  113. font-size: 14px;
  114. }
  115. </style>