index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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
  19. thumb-size="sm"
  20. title="修改资料"
  21. link="navigateTo"
  22. to="/pages/user/info/info">
  23. </uni-list-item>
  24. <uni-list-item
  25. thumb-size="sm"
  26. title="学习记录"
  27. link="navigateTo"
  28. to="/pages/course/my">
  29. </uni-list-item>
  30. <uni-list-item
  31. thumb-size="sm"
  32. title="我的成绩"
  33. link="navigateTo"
  34. to="/pages/paper/index">
  35. </uni-list-item>
  36. <uni-list-item
  37. thumb-size="sm"
  38. title="训练记录"
  39. link="navigateTo"
  40. to="/pages/repo/history">
  41. </uni-list-item>
  42. <uni-list-item
  43. thumb-size="sm"
  44. title="积分日志"
  45. link="navigateTo"
  46. to="/pages/user/points/points">
  47. </uni-list-item>
  48. <uni-list-item
  49. thumb-size="sm"
  50. title="密码安全"
  51. link="navigateTo"
  52. to="/pages/login/passwd">
  53. </uni-list-item>
  54. <!-- <uni-list-item
  55. thumb-size="sm"
  56. title="关于我们"
  57. link="navigateTo"
  58. to="/pages/sys/about">
  59. </uni-list-item> -->
  60. <uni-list-item
  61. thumb-size="sm"
  62. title="退出登录"
  63. link="navigateTo"
  64. @click="handleLogout()">
  65. </uni-list-item>
  66. </uni-list>
  67. </view>
  68. </template>
  69. <script>
  70. import {
  71. logout, info
  72. } from '@/api/user'
  73. export default {
  74. components: { },
  75. data() {
  76. return {
  77. isLogin: false,
  78. user: {},
  79. }
  80. },
  81. onShow(){
  82. this.handleInfo()
  83. },
  84. methods: {
  85. handleInfo(){
  86. let token = uni.getStorageSync('token');
  87. info(token).then(res=>{
  88. this.isLogin = true
  89. this.user = res
  90. })
  91. },
  92. handleLogout(){
  93. logout().then(res=>{
  94. // 移除会话
  95. uni.removeStorageSync('token');
  96. // 到登录页面
  97. this.$navs.toLogin()
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style>
  104. .user-banner {
  105. height: 160px;
  106. display: flex;
  107. background: url('https://cdn.yfhl.net/static/user-bg.jpg') no-repeat;
  108. align-items: center;
  109. background-position: center;
  110. background-size: 100% 100%;
  111. justify-content: center;
  112. width: 100%;
  113. flex-direction: column;
  114. }
  115. .user-banner .avatar{
  116. width: 80px;
  117. height: 80px;
  118. border: #efefef 2px solid;
  119. border-radius: 50%;
  120. }
  121. .user-banner .points{
  122. position: absolute;
  123. top: 15px;
  124. right: 15px;
  125. color: #FDBF40;
  126. font-weight: bold;
  127. font-weight: 700;
  128. font-size: 16px;
  129. }
  130. .user-banner .name{
  131. color: #fff;
  132. font-weight: 700;
  133. font-size: 18px;
  134. }
  135. .user-banner .dept{
  136. color: #eee;
  137. font-weight: 700;
  138. font-size: 14px;
  139. }
  140. </style>