my.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="settings-page">
  3. <!-- 顶部用户信息 -->
  4. <view class="user-header">
  5. <view class="user-info">
  6. <u-avatar :size="60" :src="avatar || defaultAvatar"></u-avatar>
  7. <view class="greeting">
  8. <text class="time">{{ greeting }}!</text>
  9. <text class="name">{{ userName }}</text>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 设置列表 -->
  14. <view class="settings-list">
  15. <u-cell-group :border="false">
  16. <u-cell
  17. v-for="(item, index) in settingsList"
  18. :key="index"
  19. :title="item.title"
  20. :isLink="true"
  21. @click="handleClick(item)"
  22. :border="index == settingsList.length - 1 ? false : true"
  23. >
  24. <template #icon>
  25. <view class="cell-icon">
  26. <u-icon :name="item.icon || 'setting'" size="22" color="#333"></u-icon>
  27. </view>
  28. </template>
  29. </u-cell>
  30. </u-cell-group>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref, onMounted } from "vue";
  36. import { onLoad } from "@dcloudio/uni-app";
  37. let defaultAvatar =
  38. "https://img20.360buyimg.com/da/jfs/t1/141592/25/8861/261559/5f68d8c1E33ed78ab/698ad655bfcfbaed.png";
  39. const settingsList = ref([
  40. {
  41. title: "用户信息",
  42. path: "/pages/my/page/user-info",
  43. },
  44. {
  45. title: "默认仓库",
  46. path: "/pages/my/page/warehouse",
  47. },
  48. {
  49. title: "学校设置",
  50. path: "/pages/my/page/school",
  51. },
  52. {
  53. title: "审核未完成",
  54. path: "/pages/my/page/audit-unfinished",
  55. },
  56. {
  57. title: "版本设置",
  58. path: "/pages/my/page/version",
  59. icon: "tags",
  60. },
  61. {
  62. title: "音频设置",
  63. path: "/pages/my/page/volume",
  64. },
  65. {
  66. title: "图书显示设置",
  67. path: "/pages/my/page/book-display",
  68. },
  69. {
  70. title: "修改密码",
  71. icon: "lock",
  72. path: "/pages/my/page/password",
  73. },
  74. {
  75. title: "退出账号",
  76. path: "/pages/my/page/logout",
  77. type: "logout",
  78. },
  79. ]);
  80. const greeting = ref("");
  81. const updateGreeting = () => {
  82. const hour = new Date().getHours();
  83. if (hour >= 5 && hour < 12) {
  84. greeting.value = "早上好";
  85. } else if (hour >= 12 && hour < 14) {
  86. greeting.value = "中午好";
  87. } else if (hour >= 14 && hour < 18) {
  88. greeting.value = "下午好";
  89. } else if (hour >= 18 && hour < 22) {
  90. greeting.value = "晚上好";
  91. } else {
  92. greeting.value = "夜深了";
  93. }
  94. };
  95. const userName = ref('-');
  96. const avatar = ref('');
  97. //获取登录者信息
  98. function getUserInfo() {
  99. uni.$u.http.get("/app/appUser/getUserInfoById").then((res) => {
  100. if (res.code == 200) {
  101. userName.value = res.data.userName;
  102. avatar.value = res.data.avatar;
  103. }
  104. });
  105. }
  106. // 初始化时更新问候语
  107. onLoad(() => {
  108. updateGreeting();
  109. // 可选:每分钟更新一次问候语
  110. setInterval(updateGreeting, 60 * 60 * 1000);
  111. getUserInfo();
  112. });
  113. const handleClick = (item) => {
  114. if (item.type === "logout") {
  115. uni.showModal({
  116. title: "提示",
  117. content: "确定要退出登录吗?",
  118. success: (res) => {
  119. if (res.confirm) {
  120. // 执行退出登录逻辑
  121. uni.clearStorageSync();
  122. uni.reLaunch({
  123. url: "/pages/login/login",
  124. });
  125. }
  126. },
  127. });
  128. return;
  129. }
  130. uni.navigateTo({
  131. url: item.path,
  132. });
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. .settings-page {
  137. .user-header {
  138. background: #22ac38;
  139. padding: 40rpx 32rpx;
  140. .user-info {
  141. display: flex;
  142. align-items: center;
  143. .greeting {
  144. display: flex;
  145. flex-direction: column;
  146. margin-left: 20rpx;
  147. .time {
  148. font-size: 36rpx;
  149. color: #ffffff;
  150. margin-bottom: 8rpx;
  151. }
  152. .name {
  153. font-size: 40rpx;
  154. color: #ffffff;
  155. font-weight: 500;
  156. }
  157. }
  158. }
  159. }
  160. :deep(.u-cell) {
  161. .u-cell__body {
  162. padding: 15px;
  163. }
  164. .u-cell__title-text {
  165. font-size: 34rpx;
  166. }
  167. }
  168. .settings-list {
  169. padding: 20rpx;
  170. :deep(.u-cell-group) {
  171. border-radius: 16rpx;
  172. overflow: hidden;
  173. background: #ffffff;
  174. }
  175. }
  176. }
  177. </style>