mine.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="page-mine">
  3. <scroll-view class="scroll-view" scroll-y>
  4. <view class="content-wrapper">
  5. <!-- 用户信息卡片 -->
  6. <view class="user-info-card" @click="handleUserCardClick">
  7. <view class="user-header">
  8. <image
  9. class="user-avatar"
  10. :src="isLoggedIn && userInfo.avatar ? getImageUrl(userInfo.avatar) : '/static/images/head.png'"
  11. mode="aspectFill"
  12. ></image>
  13. <view class="user-details">
  14. <text class="user-name">{{ isLoggedIn ? (userInfo.nickname || '微信用户') : '登录/注册' }}</text>
  15. </view>
  16. <view class="arrow-icon">›</view>
  17. </view>
  18. </view>
  19. <!-- 菜单列表 -->
  20. <view class="menu-list">
  21. <view class="menu-item" @click="handleOrderRecord">
  22. <view class="menu-left">
  23. <text class="menu-icon">📋</text>
  24. <text class="menu-label">我的订单</text>
  25. </view>
  26. <text class="menu-arrow">›</text>
  27. </view>
  28. <!-- 管理员专属菜单 -->
  29. <view class="menu-item" v-if="isAdmin" @click="handleShortPoolManage">
  30. <view class="menu-left">
  31. <text class="menu-icon">⚡</text>
  32. <text class="menu-label">超短池管理</text>
  33. </view>
  34. <text class="menu-arrow">›</text>
  35. </view>
  36. </view>
  37. <!-- 退出登录按钮(仅登录后显示) -->
  38. <view class="logout-section" v-if="isLoggedIn">
  39. <button class="logout-btn" @click="handleLogout">
  40. 退出登录
  41. </button>
  42. </view>
  43. <!-- 预留底部空间 -->
  44. <view class="bottom-safe-area"></view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </template>
  49. <script setup>
  50. import { ref } from 'vue'
  51. import { onShow } from '@dcloudio/uni-app'
  52. import { isLoggedIn as checkLogin, getUserInfo as getStoredUserInfo, refreshUserInfo, logout, checkLogin as requireLogin } from '@/utils/auth.js'
  53. import { getImageUrl } from '@/utils/api.js'
  54. const isLoggedIn = ref(false)
  55. const isAdmin = ref(false)
  56. const userInfo = ref({
  57. nickname: '',
  58. avatar: '',
  59. status: 0
  60. })
  61. /**
  62. * 页面显示时刷新用户信息
  63. */
  64. onShow(() => {
  65. loadUserInfo()
  66. uni.setNavigationBarTitle({ title: '量化交易大师' })
  67. })
  68. /**
  69. * 加载用户信息(从后端获取最新状态)
  70. */
  71. const loadUserInfo = async () => {
  72. isLoggedIn.value = checkLogin()
  73. if (isLoggedIn.value) {
  74. // 先显示本地缓存
  75. const storedInfo = getStoredUserInfo()
  76. if (storedInfo) {
  77. userInfo.value = storedInfo
  78. isAdmin.value = storedInfo.status === 2
  79. console.log('[我的] 本地缓存头像:', storedInfo.avatar)
  80. }
  81. // 从后端刷新最新状态
  82. const latestInfo = await refreshUserInfo()
  83. if (latestInfo) {
  84. userInfo.value = latestInfo
  85. isAdmin.value = latestInfo.status === 2
  86. console.log('[我的] 后端返回头像:', latestInfo.avatar)
  87. console.log('[我的] 处理后头像URL:', latestInfo.avatar ? getImageUrl(latestInfo.avatar) : '无')
  88. }
  89. } else {
  90. isAdmin.value = false
  91. }
  92. }
  93. /**
  94. * 点击用户卡片
  95. */
  96. const handleUserCardClick = () => {
  97. if (!isLoggedIn.value) {
  98. handleLogin()
  99. } else {
  100. // 已登录,跳转到编辑资料页面
  101. uni.navigateTo({
  102. url: '/pages/profile/edit'
  103. })
  104. }
  105. }
  106. /**
  107. * 处理登录
  108. */
  109. const handleLogin = async () => {
  110. console.log('[我的] 开始登录流程')
  111. // 跳转到登录页面
  112. uni.navigateTo({
  113. url: '/pages/login/login'
  114. })
  115. }
  116. /**
  117. * 退出登录
  118. */
  119. const handleLogout = () => {
  120. uni.showModal({
  121. title: '提示',
  122. content: '确定要退出登录吗?',
  123. success: (res) => {
  124. if (res.confirm) {
  125. logout()
  126. isLoggedIn.value = false
  127. userInfo.value = { nickname: '', avatar: '' }
  128. uni.showToast({ title: '已退出登录', icon: 'none' })
  129. }
  130. }
  131. })
  132. }
  133. /**
  134. * 订单记录
  135. */
  136. const handleOrderRecord = () => {
  137. if (!requireLogin(() => {
  138. handleOrderRecord()
  139. })) {
  140. return
  141. }
  142. // 跳转到订单记录页面
  143. uni.navigateTo({
  144. url: '/pages/order/order'
  145. })
  146. }
  147. /**
  148. * 超短池管理(管理员专属)
  149. */
  150. const handleShortPoolManage = () => {
  151. if (!isAdmin.value) {
  152. uni.showToast({ title: '无权限访问', icon: 'none' })
  153. return
  154. }
  155. uni.navigateTo({
  156. url: '/pages/admin/shortPool'
  157. })
  158. }
  159. </script>
  160. <style>
  161. .page-mine {
  162. height: 100vh;
  163. display: flex;
  164. flex-direction: column;
  165. background: #f5f6fb;
  166. }
  167. .scroll-view {
  168. flex: 1;
  169. height: 0;
  170. }
  171. .content-wrapper {
  172. padding: 32rpx;
  173. background: #f5f6fb;
  174. min-height: 100%;
  175. }
  176. /* 用户信息卡片 */
  177. .user-info-card {
  178. background: #ffffff;
  179. border-radius: 24rpx;
  180. padding: 40rpx 32rpx;
  181. margin-bottom: 32rpx;
  182. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  183. }
  184. .user-header {
  185. display: flex;
  186. align-items: center;
  187. }
  188. .user-avatar {
  189. width: 100rpx;
  190. height: 100rpx;
  191. border-radius: 50%;
  192. background: #f5f6fb;
  193. margin-right: 24rpx;
  194. border: 4rpx solid #f5f6fb;
  195. }
  196. .user-details {
  197. flex: 1;
  198. display: flex;
  199. flex-direction: column;
  200. }
  201. .user-name {
  202. font-size: 32rpx;
  203. font-weight: 600;
  204. color: #222222;
  205. margin-bottom: 8rpx;
  206. }
  207. .arrow-icon {
  208. font-size: 48rpx;
  209. color: #9ca2b5;
  210. font-weight: 300;
  211. }
  212. /* 菜单列表 */
  213. .menu-list {
  214. background: #ffffff;
  215. border-radius: 24rpx;
  216. overflow: hidden;
  217. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  218. margin-bottom: 32rpx;
  219. }
  220. .menu-item {
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. padding: 32rpx;
  225. border-bottom: 1rpx solid #f5f6fb;
  226. }
  227. .menu-item:last-child {
  228. border-bottom: none;
  229. }
  230. .menu-left {
  231. display: flex;
  232. align-items: center;
  233. }
  234. .menu-icon {
  235. font-size: 36rpx;
  236. margin-right: 20rpx;
  237. }
  238. .menu-label {
  239. font-size: 28rpx;
  240. color: #222222;
  241. }
  242. .menu-arrow {
  243. font-size: 40rpx;
  244. color: #9ca2b5;
  245. font-weight: 300;
  246. }
  247. .admin-badge {
  248. background: linear-gradient(135deg, #ff9500, #ff5e3a);
  249. color: #ffffff;
  250. font-size: 20rpx;
  251. padding: 4rpx 12rpx;
  252. border-radius: 20rpx;
  253. margin-right: 12rpx;
  254. }
  255. /* 退出登录按钮 */
  256. .logout-section {
  257. margin-top: 20rpx;
  258. }
  259. .logout-btn {
  260. width: 100%;
  261. background: #5d55e8;
  262. color: #ffffff;
  263. border-radius: 16rpx;
  264. padding: 28rpx 0;
  265. text-align: center;
  266. font-size: 30rpx;
  267. font-weight: 600;
  268. box-shadow: 0 12rpx 24rpx rgba(93, 85, 232, 0.3);
  269. border: none;
  270. line-height: 1;
  271. }
  272. .logout-btn::after {
  273. border: none;
  274. }
  275. .logout-btn:active {
  276. opacity: 0.8;
  277. }
  278. .bottom-safe-area {
  279. height: 80rpx;
  280. }
  281. </style>