myCenter.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="container">
  3. <!-- 顶部个人信息区域 -->
  4. <view class="header">
  5. <img class="header_img" src="../../static/images/center-bg.png" />
  6. <!-- 头像区域 -->
  7. <img
  8. mode="aspectFill"
  9. class="user_photo"
  10. :src="userInfo.headImage || '../../static/images/header.png'"
  11. @click="previewImage(userInfo.headImage || '../../static/images/header.png')"
  12. />
  13. <!-- 姓名区域 -->
  14. <view class="user_name">{{ userInfo.name }}</view>
  15. <!-- 班级区域 -->
  16. <view class="user_grade">{{ userInfo.departmentName }}</view>
  17. <!-- 切换身份按钮区域 -->
  18. <view v-if="showChange" class="user_change" @click="handleChange">
  19. <img class="img" src="@/static/images/2.png" />
  20. 切换身份
  21. </view>
  22. </view>
  23. <!-- 列表区域 -->
  24. <view class="body">
  25. <!-- 每一个盒子区域 -->
  26. <view class="body_box" v-for="item in list" :key="item.id" @click="goPage(item.page)">
  27. <img class="box_img" :src="item.url" />
  28. <text class="box_title">{{ item.title }}</text>
  29. <img class="box_icon" src="../../static/images/right.png" />
  30. </view>
  31. </view>
  32. <!-- 退出登录按钮 -->
  33. <view class="logout" @click="handleLogout">退出登录</view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import { ref } from 'vue'
  38. import { onLoad } from '@dcloudio/uni-app'
  39. import { previewImage } from '@/utils/previewImage.js'
  40. // 用户信息
  41. const userInfo = ref({})
  42. // 是否展示切换身份按钮
  43. const showChange = ref(false)
  44. onLoad(() => {
  45. userInfo.value = uni.getStorageSync('userInfo')
  46. let length = uni.getStorageSync('allData').user.length
  47. if (length > 1) {
  48. showChange.value = true
  49. }
  50. })
  51. // 列表信息
  52. const list = ref([
  53. {
  54. id: 1,
  55. title: '我的信息',
  56. url: '../../static/images/message.png',
  57. page: '/pages/myMsg/myMsg'
  58. },
  59. {
  60. id: 2,
  61. title: '消息提醒',
  62. url: '../../static/images/warn.png',
  63. page: '/pages/msgWarn/msgWarn'
  64. }
  65. ])
  66. // 跳转页面函数
  67. const goPage = (url) => {
  68. uni.navigateTo({
  69. url
  70. })
  71. }
  72. // 切换身份按钮回调
  73. const handleChange = () => {
  74. let info = encodeURIComponent(JSON.stringify(uni.getStorageSync('allData')))
  75. // console.log(info)
  76. uni.navigateTo({
  77. url: `/pages/switch/switch?info=${info}`
  78. })
  79. }
  80. // 退出登录按钮回调
  81. const handleLogout = () => {
  82. uni.showModal({
  83. title: '提示',
  84. content: '确定退出登录吗?',
  85. success: (res) => {
  86. if (res.confirm) {
  87. uni.clearStorageSync()
  88. uni.reLaunch({
  89. url: '/pages/main/main'
  90. })
  91. } else if (res.cancel) {
  92. }
  93. }
  94. })
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .container {
  99. padding: 0 20rpx;
  100. min-height: 100vh;
  101. background-color: #f1f6fe;
  102. // 顶部个人信息区域样式
  103. .header {
  104. position: relative;
  105. width: 710rpx;
  106. height: 260rpx;
  107. text-align: end;
  108. .header_img {
  109. margin-top: -24rpx;
  110. margin-right: -45rpx;
  111. width: 589rpx;
  112. height: 320rpx;
  113. }
  114. .user_photo {
  115. position: absolute;
  116. top: 80rpx;
  117. left: 20rpx;
  118. width: 120rpx;
  119. height: 120rpx;
  120. border-radius: 50%;
  121. }
  122. .user_name {
  123. position: absolute;
  124. top: 90rpx;
  125. left: 167rpx;
  126. font-size: 40rpx;
  127. font-weight: bold;
  128. }
  129. .user_grade {
  130. position: absolute;
  131. top: 160rpx;
  132. left: 167rpx;
  133. font-size: 24rpx;
  134. color: #666666;
  135. }
  136. .user_change {
  137. position: absolute;
  138. right: -20rpx;
  139. top: 80rpx;
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. width: 171rpx;
  144. height: 67rpx;
  145. font-size: 24rpx;
  146. border-radius: 173rpx 0 0 173rpx;
  147. background-color: rgba(0, 97, 255, 0.05);
  148. .img {
  149. margin-right: 10rpx;
  150. width: 29rpx;
  151. height: 29rpx;
  152. }
  153. }
  154. }
  155. // 列表区域样式
  156. .body {
  157. z-index: 1;
  158. position: relative;
  159. padding: 0 30rpx;
  160. border-radius: 8rpx;
  161. background-color: #fff;
  162. .body_box {
  163. display: flex;
  164. align-items: center;
  165. height: 110rpx;
  166. .box_img {
  167. width: 50rpx;
  168. height: 50rpx;
  169. border-radius: 50%;
  170. }
  171. .box_title {
  172. flex: 1;
  173. margin-left: 18rpx;
  174. font-size: 32rpx;
  175. }
  176. .box_icon {
  177. width: 31rpx;
  178. height: 31rpx;
  179. }
  180. }
  181. }
  182. .logout {
  183. position: absolute;
  184. bottom: 100rpx;
  185. display: flex;
  186. justify-content: center;
  187. align-items: center;
  188. width: 710rpx;
  189. height: 100rpx;
  190. font-size: 32rpx;
  191. border-radius: 8rpx;
  192. background-color: #fff;
  193. }
  194. }
  195. </style>