mine.vue 6.2 KB

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