uniapp,h5

tabbar-5.vue 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="page">
  3. <view class="action">
  4. <view>
  5. <image src="../../../static/img/userInfo/scan.png"></image>
  6. </view>
  7. <view>
  8. <image src="../../../static/img/userInfo/setting.png"></image>
  9. </view>
  10. </view>
  11. <view class="user" @click="onUserInfoClick()">
  12. <image class="avatar" :src="user.avatar"></image>
  13. <view class="name">
  14. <text>{{ user.username }}</text>
  15. <text>{{ user.bio }}</text>
  16. </view>
  17. <image class="right" src="../../../static/img/userInfo/right.png"></image>
  18. </view>
  19. <view class="card" v-for="(v, k) in menus" :key="k">
  20. <view class="menu">
  21. <view class="item" v-for="(v_, k_) in v" :key="k_" @click="menuClick(v_)">
  22. <image :src="v_.icon"></image>
  23. <view>{{v_.name}}</view>
  24. <image class="arrow" v-if="v_.arrow" src="../../../static/img/userInfo/right.png"></image>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. user: {}, // 直接在data中定义user
  35. menus: [
  36. [{
  37. index: 0,
  38. name: '上传管理',
  39. icon: '../../../static/img/userInfo/self.png',
  40. arrow: true
  41. },
  42. {
  43. index: 1,
  44. name: '我的账户',
  45. icon: '../../../static/img/userInfo/self.png',
  46. arrow: true
  47. },
  48. {
  49. index: 2,
  50. name: '我的设置',
  51. icon: '../../../static/img/userInfo/self.png',
  52. arrow: false
  53. },
  54. ],
  55. [{
  56. index: 3,
  57. name: '联系客服',
  58. icon: '../../../static/img/userInfo/self.png',
  59. arrow: true
  60. },
  61. {
  62. index: 4,
  63. name: '退出登录',
  64. icon: '../../../static/img/userInfo/self.png',
  65. arrow: false
  66. },
  67. ]
  68. ]
  69. }
  70. },
  71. onLoad() {
  72. // 尝试从本地缓存中读取userInfo
  73. this.user = uni.getStorageSync('userInfo');
  74. },
  75. onShow() {
  76. uni.$on("refreshData", res=>{
  77. this.user = uni.getStorageSync('userInfo');
  78. // console.log("刷新数据");
  79. uni.$off('refreshData');
  80. })
  81. },
  82. methods: {
  83. menuClick(e) {
  84. switch (e.index) {
  85. case 0:
  86. uni.navigateTo({
  87. url: './uploadMgr'
  88. });
  89. break;
  90. case 4:
  91. uni.reLaunch({
  92. url: '../login/login'
  93. });
  94. break;
  95. default:
  96. console.log('Default case triggered for index: ', e.index);
  97. break;
  98. }
  99. console.log(e);
  100. },
  101. onUserInfoClick() {
  102. uni.navigateTo({
  103. url: './userInfo'
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .page {
  111. background: #f5f5f5;
  112. min-height: 80vh;
  113. .action {
  114. display: flex;
  115. justify-content: flex-end;
  116. padding: 10upx;
  117. background: #3f5b71;
  118. view {
  119. padding: 10rpx;
  120. margin: 0 10rpx;
  121. border-radius: 8rpx;
  122. width: 45rpx;
  123. height: 45rpx;
  124. &:active {
  125. background: #ccc;
  126. }
  127. image {
  128. width: 45rpx;
  129. height: 45rpx;
  130. }
  131. }
  132. }
  133. .user {
  134. display: flex;
  135. align-items: center;
  136. padding: 25rpx;
  137. background: #3f5b71;
  138. &:active {
  139. background: #f0f0f0;
  140. }
  141. .avatar {
  142. width: 120rpx;
  143. height: 120rpx;
  144. border-radius: 12rpx;
  145. border: 3px solid #abb0b6;
  146. }
  147. .right {
  148. width: 30rpx;
  149. height: 30rpx;
  150. }
  151. .name {
  152. flex-grow: 1;
  153. display: flex;
  154. flex-direction: column;
  155. padding-left: 25rpx;
  156. gap: 15rpx;
  157. text {
  158. color: #fff;
  159. &:nth-child(1) {
  160. font-size: 24px;
  161. font-weight: bold;
  162. }
  163. &:nth-child(2) {
  164. font-size: 12px;
  165. color: #f0f0f0;
  166. }
  167. }
  168. }
  169. }
  170. .card {
  171. background: #fff;
  172. box-sizing: border-box;
  173. width: 700rpx;
  174. margin: auto;
  175. padding: 15rpx;
  176. margin-top: 20rpx;
  177. border-radius: 12rpx;
  178. .menu {
  179. .item {
  180. display: flex;
  181. height: 100rpx;
  182. align-items: center;
  183. padding: 0 20rpx;
  184. box-sizing: border-box;
  185. width: 700upx;
  186. &:active {
  187. background: #f0f0f0;
  188. }
  189. image {
  190. height: 45rpx;
  191. width: 45rpx;
  192. }
  193. view {
  194. font-size: 14px;
  195. color: #444;
  196. padding-left: 15upx;
  197. box-sizing: border-box;
  198. width: calc(100% - 100rpx);
  199. }
  200. .arrow {
  201. width: 26upx;
  202. height: 26upx;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. </style>