mine.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. </view>
  29. <!-- 退出登录按钮(仅登录后显示) -->
  30. <view class="logout-section" v-if="isLoggedIn">
  31. <button class="logout-btn" @click="handleLogout">
  32. 退出登录
  33. </button>
  34. </view>
  35. <!-- 预留底部空间 -->
  36. <view class="bottom-safe-area"></view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </template>
  41. <script setup>
  42. import { ref, onMounted } from 'vue'
  43. import { onShow } from '@dcloudio/uni-app'
  44. import { isLoggedIn as checkLogin, getUserInfo as getStoredUserInfo, logout, checkLogin as requireLogin } from '@/utils/auth.js'
  45. const isLoggedIn = ref(false)
  46. const showPhoneAuth = ref(false)
  47. const userInfo = ref({
  48. nickname: '',
  49. avatar: '',
  50. phone: ''
  51. })
  52. /**
  53. * 页面加载时检查登录状态
  54. */
  55. onMounted(() => {
  56. loadUserInfo()
  57. })
  58. /**
  59. * 页面显示时刷新用户信息
  60. */
  61. onShow(() => {
  62. loadUserInfo()
  63. // 设置导航栏标题
  64. uni.setNavigationBarTitle({ title: '量化交易大师' })
  65. })
  66. /**
  67. * 加载用户信息
  68. */
  69. const loadUserInfo = async () => {
  70. isLoggedIn.value = checkLogin()
  71. console.log('[个人中心] 登录状态:', isLoggedIn.value)
  72. if (isLoggedIn.value) {
  73. const storedInfo = getStoredUserInfo()
  74. if (storedInfo) {
  75. userInfo.value = storedInfo
  76. console.log('[个人中心] 加载用户信息:', userInfo.value)
  77. }
  78. }
  79. }
  80. /**
  81. * 点击用户卡片
  82. */
  83. const handleUserCardClick = () => {
  84. if (!isLoggedIn.value) {
  85. handleLogin()
  86. }
  87. }
  88. /**
  89. * 处理登录
  90. */
  91. const handleLogin = async () => {
  92. console.log('[我的] 开始登录流程')
  93. // 跳转到登录页面
  94. uni.navigateTo({
  95. url: '/pages/login/login'
  96. })
  97. }
  98. /**
  99. * 退出登录
  100. */
  101. const handleLogout = () => {
  102. uni.showModal({
  103. title: '提示',
  104. content: '确定要退出登录吗?',
  105. success: (res) => {
  106. if (res.confirm) {
  107. logout()
  108. isLoggedIn.value = false
  109. userInfo.value = { nickname: '', avatar: '', phone: '' }
  110. uni.showToast({ title: '已退出登录', icon: 'none' })
  111. }
  112. }
  113. })
  114. }
  115. /**
  116. * 订阅记录
  117. */
  118. const handleSubscriptionRecord = () => {
  119. if (!requireLogin(() => {
  120. handleSubscriptionRecord()
  121. })) {
  122. return
  123. }
  124. // 跳转到订阅记录页面
  125. uni.navigateTo({
  126. url: '/pages/transaction/transaction'
  127. })
  128. }
  129. </script>
  130. <style>
  131. .page-mine {
  132. height: 100vh;
  133. display: flex;
  134. flex-direction: column;
  135. background: #f5f6fb;
  136. }
  137. .scroll-view {
  138. flex: 1;
  139. height: 0;
  140. }
  141. .content-wrapper {
  142. padding: 32rpx;
  143. background: #f5f6fb;
  144. min-height: 100%;
  145. }
  146. /* 用户信息卡片 */
  147. .user-info-card {
  148. background: #ffffff;
  149. border-radius: 24rpx;
  150. padding: 40rpx 32rpx;
  151. margin-bottom: 32rpx;
  152. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  153. }
  154. .user-header {
  155. display: flex;
  156. align-items: center;
  157. }
  158. .user-avatar {
  159. width: 100rpx;
  160. height: 100rpx;
  161. border-radius: 50%;
  162. background: #f5f6fb;
  163. margin-right: 24rpx;
  164. border: 4rpx solid #f5f6fb;
  165. }
  166. .user-details {
  167. flex: 1;
  168. display: flex;
  169. flex-direction: column;
  170. }
  171. .user-name {
  172. font-size: 32rpx;
  173. font-weight: 600;
  174. color: #222222;
  175. margin-bottom: 8rpx;
  176. }
  177. .arrow-icon {
  178. font-size: 48rpx;
  179. color: #9ca2b5;
  180. font-weight: 300;
  181. }
  182. /* 菜单列表 */
  183. .menu-list {
  184. background: #ffffff;
  185. border-radius: 24rpx;
  186. overflow: hidden;
  187. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  188. margin-bottom: 32rpx;
  189. }
  190. .menu-item {
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. padding: 32rpx;
  195. border-bottom: 1rpx solid #f5f6fb;
  196. }
  197. .menu-item:last-child {
  198. border-bottom: none;
  199. }
  200. .menu-left {
  201. display: flex;
  202. align-items: center;
  203. }
  204. .menu-icon {
  205. font-size: 36rpx;
  206. margin-right: 20rpx;
  207. }
  208. .menu-label {
  209. font-size: 28rpx;
  210. color: #222222;
  211. }
  212. .menu-arrow {
  213. font-size: 40rpx;
  214. color: #9ca2b5;
  215. font-weight: 300;
  216. }
  217. /* 退出登录按钮 */
  218. .logout-section {
  219. margin-top: 20rpx;
  220. }
  221. .logout-btn {
  222. width: 100%;
  223. background: #5d55e8;
  224. color: #ffffff;
  225. border-radius: 16rpx;
  226. padding: 28rpx 0;
  227. text-align: center;
  228. font-size: 30rpx;
  229. font-weight: 600;
  230. box-shadow: 0 12rpx 24rpx rgba(93, 85, 232, 0.3);
  231. border: none;
  232. line-height: 1;
  233. }
  234. .logout-btn::after {
  235. border: none;
  236. }
  237. .logout-btn:active {
  238. opacity: 0.8;
  239. }
  240. .bottom-safe-area {
  241. height: 80rpx;
  242. }
  243. </style>