my.vue 4.9 KB

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