rank.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <view class="page-rank">
  3. <!-- 顶部标题卡片 -->
  4. <view class="page-title-card">
  5. <text class="page-title-text">量化选股大师</text>
  6. </view>
  7. <scroll-view class="scroll-view" scroll-y>
  8. <view class="content-wrapper" :class="{ 'blur-content': !isLoggedIn }">
  9. <!-- 我的模拟资产卡片 -->
  10. <view class="portfolio-card">
  11. <view class="portfolio-header">
  12. <view class="portfolio-icon">💼</view>
  13. <text class="portfolio-title">我的模拟资产</text>
  14. </view>
  15. <view class="portfolio-content">
  16. <view class="portfolio-main">
  17. <view class="portfolio-label">当前账户余额 (¥)</view>
  18. <view class="portfolio-amount">{{ formatAmount(portfolio.balance) }}</view>
  19. </view>
  20. <view class="portfolio-profit">
  21. <view class="profit-label">总盈亏 / 收益率</view>
  22. <view :class="['profit-value', portfolio.profitRate >= 0 ? 'profit-positive' : 'profit-negative']">
  23. ¥ {{ formatProfit(portfolio.profit) }} ({{ formatRate(portfolio.profitRate) }}%)
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 模拟交易排行榜 -->
  29. <view class="leaderboard-section">
  30. <view class="section-header">
  31. <view class="trophy-icon">🏆</view>
  32. <text class="section-title">模拟交易排行榜</text>
  33. </view>
  34. <!-- 当前用户排名 -->
  35. <view class="my-rank-card">
  36. <view class="rank-number">#{{ myRank.rank }}</view>
  37. <view class="rank-info">
  38. <text class="rank-name">您 (本期收益)</text>
  39. </view>
  40. <view :class="['rank-rate', myRank.rate >= 0 ? 'rate-positive' : 'rate-negative']">
  41. {{ myRank.rate >= 0 ? '+' : '' }}{{ myRank.rate }}%
  42. </view>
  43. </view>
  44. <!-- 排行榜列表 -->
  45. <view class="leaderboard-list">
  46. <view
  47. v-for="(item, index) in leaderboard"
  48. :key="index"
  49. class="leaderboard-item"
  50. >
  51. <view :class="['rank-badge', getRankClass(item.rank)]">
  52. #{{ item.rank }}
  53. </view>
  54. <view class="user-info">
  55. <text class="user-name">{{ item.name }}</text>
  56. </view>
  57. <view :class="['user-rate', item.rate >= 0 ? 'rate-positive' : 'rate-negative']">
  58. {{ item.rate >= 0 ? '+' : '' }}{{ item.rate }}%
  59. </view>
  60. </view>
  61. </view>
  62. <view class="leaderboard-note">
  63. <text class="note-text">排名每日更新,收益基于系统信号的模拟交易。</text>
  64. </view>
  65. </view>
  66. <!-- 预留底部空间 -->
  67. <view class="bottom-safe-area"></view>
  68. </view>
  69. </scroll-view>
  70. <!-- 未登录遮罩层 -->
  71. <view v-if="!isLoggedIn" class="login-mask">
  72. <view class="login-prompt">
  73. <view class="lock-icon">🔒</view>
  74. <text class="prompt-title">登录后查看完整数据</text>
  75. <text class="prompt-desc">使用微信授权快速登录</text>
  76. <!-- 微信授权登录按钮 -->
  77. <button
  78. class="login-button-native"
  79. open-type="getPhoneNumber"
  80. @getphonenumber="onGetPhoneNumber"
  81. >
  82. <text class="button-icon">📱</text>
  83. <text>微信授权登录</text>
  84. </button>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script setup>
  90. import { ref, onMounted } from 'vue'
  91. import { getUserPortfolio, getLeaderboard } from '../../utils/api.js'
  92. import { isLoggedIn as checkIsLoggedIn, wxAuthLogin } from '../../utils/auth.js'
  93. // 登录状态
  94. const isLoggedIn = ref(false)
  95. const portfolio = ref({
  96. balance: 100000,
  97. profit: 0,
  98. profitRate: 0
  99. })
  100. const myRank = ref({
  101. rank: 5,
  102. rate: 0
  103. })
  104. // 模糊数据 - 未登录时显示
  105. const mockLeaderboard = [
  106. { rank: 1, name: '量化王者 ***', rate: 35.2 },
  107. { rank: 2, name: '短线猎手 ***', rate: 28.9 },
  108. { rank: 3, name: '趋势追踪者 ***', rate: 22.1 },
  109. { rank: 4, name: '稳健投资 ***', rate: 18.5 },
  110. { rank: 5, name: '价值发现 ***', rate: 15.3 }
  111. ]
  112. const leaderboard = ref(mockLeaderboard)
  113. const formatAmount = (amount) => {
  114. return amount.toLocaleString('zh-CN')
  115. }
  116. const formatProfit = (profit) => {
  117. return Math.abs(profit).toLocaleString('zh-CN')
  118. }
  119. const formatRate = (rate) => {
  120. return rate.toFixed(2)
  121. }
  122. const getRankClass = (rank) => {
  123. if (rank === 1) return 'rank-first'
  124. if (rank === 2) return 'rank-second'
  125. if (rank === 3) return 'rank-third'
  126. return ''
  127. }
  128. // 处理手机号授权 - 静默登录
  129. const onGetPhoneNumber = async (e) => {
  130. console.log('[模拟排名] 获取手机号回调:', e.detail)
  131. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  132. const phoneCode = e.detail.code
  133. console.log('[模拟排名] phoneCode:', phoneCode)
  134. uni.showLoading({
  135. title: '登录中...',
  136. mask: true
  137. })
  138. try {
  139. // 获取微信登录code
  140. const loginRes = await uni.login()
  141. console.log('[模拟排名] uni.login完整响应:', loginRes)
  142. console.log('[模拟排名] 微信登录code:', loginRes.code)
  143. if (!loginRes.code) {
  144. throw new Error('获取微信登录code失败')
  145. }
  146. // 调用后端登录接口(只传code和phoneCode)
  147. const result = await wxAuthLogin(loginRes.code, phoneCode)
  148. uni.hideLoading()
  149. if (result) {
  150. // 登录成功,重新加载数据
  151. checkLoginAndLoadData()
  152. }
  153. } catch (error) {
  154. uni.hideLoading()
  155. console.error('[模拟排名] 登录失败:', error)
  156. }
  157. } else {
  158. // 用户拒绝授权手机号
  159. uni.showToast({
  160. title: '需要授权手机号才能登录',
  161. icon: 'none',
  162. duration: 2000
  163. })
  164. }
  165. }
  166. // 检查登录状态并加载数据
  167. const checkLoginAndLoadData = () => {
  168. isLoggedIn.value = checkIsLoggedIn()
  169. console.log('[模拟排名] 登录状态:', isLoggedIn.value)
  170. if (isLoggedIn.value) {
  171. loadRealData()
  172. } else {
  173. // 未登录,显示模糊数据
  174. leaderboard.value = mockLeaderboard
  175. }
  176. }
  177. // 加载真实数据
  178. const loadRealData = async () => {
  179. try {
  180. const portfolioRes = await getUserPortfolio()
  181. if (portfolioRes.code === 0 && portfolioRes.data) {
  182. portfolio.value = portfolioRes.data
  183. }
  184. } catch (err) {
  185. console.error('获取资产数据失败:', err)
  186. }
  187. try {
  188. const leaderboardRes = await getLeaderboard()
  189. if (leaderboardRes.code === 0 && leaderboardRes.data) {
  190. leaderboard.value = leaderboardRes.data.list || []
  191. myRank.value = leaderboardRes.data.myRank || { rank: 5, rate: 0 }
  192. }
  193. } catch (err) {
  194. console.error('获取排行榜数据失败:', err)
  195. }
  196. }
  197. onMounted(() => {
  198. checkLoginAndLoadData()
  199. })
  200. </script>
  201. <style>
  202. .page-rank {
  203. display: flex;
  204. flex-direction: column;
  205. background: #f5f6fb;
  206. height: 100vh;
  207. }
  208. .page-title-card {
  209. background: #ffffff;
  210. padding: 30rpx 0;
  211. text-align: center;
  212. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  213. border-radius: 0;
  214. }
  215. .page-title-text {
  216. font-size: 36rpx;
  217. font-weight: 800;
  218. color: #3F51F7;
  219. letter-spacing: 2rpx;
  220. }
  221. .scroll-view {
  222. flex: 1;
  223. height: 0;
  224. }
  225. .content-wrapper {
  226. padding: 32rpx;
  227. }
  228. /* 模拟资产卡片 */
  229. .portfolio-card {
  230. background: linear-gradient(135deg, #5d55e8, #7568ff);
  231. border-radius: 24rpx;
  232. padding: 40rpx 32rpx;
  233. margin-bottom: 32rpx;
  234. box-shadow: 0 16rpx 40rpx rgba(93, 85, 232, 0.3);
  235. }
  236. .portfolio-header {
  237. display: flex;
  238. align-items: center;
  239. margin-bottom: 32rpx;
  240. }
  241. .portfolio-icon {
  242. font-size: 40rpx;
  243. margin-right: 16rpx;
  244. }
  245. .portfolio-title {
  246. font-size: 32rpx;
  247. font-weight: 600;
  248. color: #ffffff;
  249. }
  250. .portfolio-content {
  251. display: flex;
  252. justify-content: space-between;
  253. align-items: flex-end;
  254. }
  255. .portfolio-main {
  256. flex: 1;
  257. }
  258. .portfolio-label {
  259. font-size: 24rpx;
  260. color: rgba(255, 255, 255, 0.8);
  261. margin-bottom: 12rpx;
  262. }
  263. .portfolio-amount {
  264. font-size: 56rpx;
  265. font-weight: 700;
  266. color: #ffffff;
  267. line-height: 1.2;
  268. }
  269. .portfolio-profit {
  270. text-align: right;
  271. }
  272. .profit-label {
  273. font-size: 22rpx;
  274. color: rgba(255, 255, 255, 0.7);
  275. margin-bottom: 8rpx;
  276. }
  277. .profit-value {
  278. font-size: 28rpx;
  279. font-weight: 600;
  280. }
  281. .profit-positive {
  282. color: #4fffb0;
  283. }
  284. .profit-negative {
  285. color: #ff6b9d;
  286. }
  287. /* 排行榜区域 */
  288. .leaderboard-section {
  289. background: #ffffff;
  290. border-radius: 24rpx;
  291. padding: 32rpx;
  292. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  293. }
  294. .section-header {
  295. display: flex;
  296. align-items: center;
  297. margin-bottom: 24rpx;
  298. }
  299. .trophy-icon {
  300. font-size: 36rpx;
  301. margin-right: 12rpx;
  302. }
  303. .section-title {
  304. font-size: 32rpx;
  305. font-weight: 600;
  306. color: #222222;
  307. }
  308. /* 当前用户排名卡片 */
  309. .my-rank-card {
  310. background: linear-gradient(135deg, #fff9e6, #fffbf0);
  311. border: 2rpx solid #ffd966;
  312. border-radius: 16rpx;
  313. padding: 24rpx 28rpx;
  314. display: flex;
  315. align-items: center;
  316. margin-bottom: 24rpx;
  317. }
  318. .rank-number {
  319. font-size: 40rpx;
  320. font-weight: 700;
  321. color: #ff9800;
  322. margin-right: 24rpx;
  323. min-width: 80rpx;
  324. }
  325. .rank-info {
  326. flex: 1;
  327. }
  328. .rank-name {
  329. font-size: 28rpx;
  330. color: #333333;
  331. font-weight: 500;
  332. }
  333. .rank-rate {
  334. font-size: 32rpx;
  335. font-weight: 700;
  336. }
  337. .rate-positive {
  338. color: #00c853;
  339. }
  340. .rate-negative {
  341. color: #ff5252;
  342. }
  343. /* 排行榜列表 */
  344. .leaderboard-list {
  345. margin-bottom: 24rpx;
  346. }
  347. .leaderboard-item {
  348. display: flex;
  349. align-items: center;
  350. padding: 24rpx 0;
  351. border-bottom: 1rpx solid #f5f6fb;
  352. }
  353. .leaderboard-item:last-child {
  354. border-bottom: none;
  355. }
  356. .rank-badge {
  357. font-size: 32rpx;
  358. font-weight: 700;
  359. color: #666666;
  360. margin-right: 24rpx;
  361. min-width: 80rpx;
  362. }
  363. .rank-first {
  364. color: #ff5252;
  365. }
  366. .rank-second {
  367. color: #ff9800;
  368. }
  369. .rank-third {
  370. color: #ffc107;
  371. }
  372. .user-info {
  373. flex: 1;
  374. }
  375. .user-name {
  376. font-size: 28rpx;
  377. color: #333333;
  378. }
  379. .user-rate {
  380. font-size: 32rpx;
  381. font-weight: 700;
  382. }
  383. .leaderboard-note {
  384. padding-top: 16rpx;
  385. border-top: 1rpx solid #f5f6fb;
  386. }
  387. .note-text {
  388. font-size: 22rpx;
  389. color: #999999;
  390. line-height: 1.6;
  391. }
  392. .bottom-safe-area {
  393. height: 80rpx;
  394. }
  395. /* 模糊效果 */
  396. .blur-content {
  397. filter: blur(8rpx);
  398. pointer-events: none;
  399. }
  400. /* 登录遮罩层 */
  401. .login-mask {
  402. position: fixed;
  403. top: 0;
  404. left: 0;
  405. right: 0;
  406. bottom: 0;
  407. background: rgba(0, 0, 0, 0.4);
  408. display: flex;
  409. align-items: center;
  410. justify-content: center;
  411. z-index: 999;
  412. }
  413. .login-prompt {
  414. width: 560rpx;
  415. max-width: 560rpx;
  416. background: #ffffff;
  417. border-radius: 24rpx;
  418. padding: 50rpx 40rpx;
  419. margin: 0 auto;
  420. text-align: center;
  421. box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.3);
  422. box-sizing: border-box;
  423. }
  424. .lock-icon {
  425. font-size: 72rpx;
  426. margin-bottom: 20rpx;
  427. }
  428. .prompt-title {
  429. display: block;
  430. font-size: 32rpx;
  431. font-weight: 600;
  432. color: #222222;
  433. margin-bottom: 12rpx;
  434. }
  435. .prompt-desc {
  436. display: block;
  437. font-size: 24rpx;
  438. color: #999999;
  439. line-height: 1.5;
  440. margin-bottom: 32rpx;
  441. }
  442. .login-button-native {
  443. width: 100%;
  444. height: 80rpx;
  445. background: linear-gradient(135deg, #4CAF50, #66BB6A);
  446. color: #ffffff;
  447. border-radius: 40rpx;
  448. font-size: 30rpx;
  449. font-weight: 600;
  450. box-shadow: 0 8rpx 24rpx rgba(76, 175, 80, 0.4);
  451. display: flex;
  452. align-items: center;
  453. justify-content: center;
  454. border: none;
  455. padding: 0;
  456. line-height: 80rpx;
  457. }
  458. .login-button-native::after {
  459. border: none;
  460. }
  461. .button-icon {
  462. font-size: 32rpx;
  463. margin-right: 12rpx;
  464. }
  465. </style>