strong.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. <template>
  2. <view class="page-container">
  3. <scroll-view class="scroll-view" scroll-y>
  4. <view class="content-wrapper">
  5. <!-- 强势趋势池标题 -->
  6. <view class="pool-header-section">
  7. <view class="pool-header">
  8. <text class="pool-icon">📈</text>
  9. <text class="pool-title">强势趋势池</text>
  10. </view>
  11. <text class="pool-desc">本月精选,专注于中长期趋势跟踪</text>
  12. </view>
  13. <!-- 性能指标卡片 -->
  14. <view class="card performance-card">
  15. <view class="performance-item">
  16. <text class="performance-label">历史成功率</text>
  17. <text class="performance-value success">88%</text>
  18. </view>
  19. <view class="performance-item">
  20. <text class="performance-label">平均收益率</text>
  21. <text class="performance-value profit">+12.5%</text>
  22. </view>
  23. <view class="performance-item">
  24. <text class="performance-label">总交易次数</text>
  25. <text class="performance-value">45</text>
  26. </view>
  27. </view>
  28. <!-- 强势趋势池区域 -->
  29. <view class="card pool-card">
  30. <!-- 未购买时显示锁定状态 -->
  31. <view v-if="!isPurchased" class="locked-content">
  32. <view class="lock-icon-wrapper">
  33. <text class="lock-icon">🔒</text>
  34. </view>
  35. <text class="lock-text">权限锁定: 查看 强势趋势池 </text>
  36. <text class="lock-desc">强势池为每日实时更新,捕捉中长期趋势机会。</text>
  37. <view class="unlock-button" @click="showPurchaseModal">
  38. <text class="unlock-button-text">立即打赏</text>
  39. </view>
  40. </view>
  41. <!-- 已购买时显示内容 -->
  42. <view v-else class="unlocked-content">
  43. <text class="unlocked-tip">您已解锁,可以查看强势趋势池内容</text>
  44. <view class="stock-item" v-for="(stock, index) in stockList" :key="index">
  45. <view class="stock-info">
  46. <view class="stock-name-row">
  47. <text class="stock-name">{{ stock.name }}</text>
  48. <text class="stock-code">{{ stock.code }}</text>
  49. </view>
  50. </view>
  51. <view class="stock-right">
  52. <view class="stock-actions">
  53. <view class="action-btn buy-btn" @click="addToMyStocks(stock)">
  54. <text class="action-icon">+</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 历史股票池回顾 -->
  62. <view class="card history-card">
  63. <view class="history-header">
  64. <text class="history-icon">📅</text>
  65. <text class="history-title">历史股票池回顾</text>
  66. </view>
  67. <!-- 月份区间选择 -->
  68. <view class="date-range-row">
  69. <picker
  70. mode="date"
  71. fields="month"
  72. :value="startMonth"
  73. @change="onStartMonthChange"
  74. class="date-picker-half"
  75. >
  76. <view class="date-input">
  77. <text class="date-text">{{ formatMonth(startMonth) }}</text>
  78. <text class="date-icon">📅</text>
  79. </view>
  80. </picker>
  81. <text class="date-separator">至</text>
  82. <picker
  83. mode="date"
  84. fields="month"
  85. :value="endMonth"
  86. @change="onEndMonthChange"
  87. class="date-picker-half"
  88. >
  89. <view class="date-input">
  90. <text class="date-text">{{ formatMonth(endMonth) }}</text>
  91. <text class="date-icon">📅</text>
  92. </view>
  93. </picker>
  94. </view>
  95. <!-- 查询按钮 -->
  96. <view class="history-search-button-full" @click="onHistorySearch">
  97. <text class="search-button-text">🔍 查询历史数据</text>
  98. </view>
  99. <text class="history-tip">选择时间区间,查询该期间的入池股票及表现。</text>
  100. </view>
  101. <!-- 预留底部空间 -->
  102. <view class="bottom-safe-area"></view>
  103. </view>
  104. </scroll-view>
  105. <!-- 购买弹窗 -->
  106. <view v-if="showModal" class="modal-overlay" @click="closePurchaseModal">
  107. <view class="modal-content" @click.stop>
  108. <view class="modal-close-btn" @click="closePurchaseModal">
  109. <text class="close-icon">✕</text>
  110. </view>
  111. <view class="reward-header">
  112. <text class="reward-icon">📅</text>
  113. <text class="reward-title">年订阅解锁</text>
  114. </view>
  115. <view class="reward-info">
  116. <text class="reward-desc">订阅全年,解锁强势趋势池内容</text>
  117. <view class="reward-amount-simple">
  118. <text class="amount-label">订阅金额:</text>
  119. <text class="amount-value">¥98</text>
  120. </view>
  121. </view>
  122. <view class="modal-footer">
  123. <view class="pay-button" @click="handlePurchase">
  124. <text class="pay-button-text">确认支付</text>
  125. </view>
  126. <text class="agreement-text">点击即表示同意《用户订阅协议》</text>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </template>
  132. <script setup>
  133. import { ref } from 'vue'
  134. import { onLoad, onShow } from '@dcloudio/uni-app'
  135. import { isLoggedIn as checkLoginStatus } from '../../utils/auth.js'
  136. import { getStockQuotes, addUserStock } from '../../utils/api.js'
  137. // 购买状态
  138. const isPurchased = ref(false)
  139. const showModal = ref(false)
  140. // 股票列表数据
  141. const stockList = ref([
  142. {
  143. name: '信维通信',
  144. code: '300136',
  145. },
  146. {
  147. name: '中国卫星',
  148. code: '600118',
  149. }
  150. ])
  151. const startMonth = ref('2025-01') // 开始月份
  152. const endMonth = ref('2025-11') // 结束月份
  153. // 格式化月份显示
  154. const formatMonth = (monthStr) => {
  155. if (!monthStr) return '请选择'
  156. const [year, month] = monthStr.split('-')
  157. return `${year}年${month}月`
  158. }
  159. // 检查购买状态
  160. const checkPurchaseStatus = () => {
  161. // 先检查登录状态
  162. if (!checkLoginStatus()) {
  163. isPurchased.value = false
  164. return
  165. }
  166. try {
  167. const purchaseInfo = uni.getStorageSync('strong_pool_purchase')
  168. if (purchaseInfo) {
  169. const now = Date.now()
  170. const expireTime = purchaseInfo.expireTime
  171. if (now < expireTime) {
  172. isPurchased.value = true
  173. } else {
  174. // 已过期,清除购买信息
  175. uni.removeStorageSync('strong_pool_purchase')
  176. isPurchased.value = false
  177. }
  178. } else {
  179. isPurchased.value = false
  180. }
  181. } catch (e) {
  182. console.error('检查购买状态失败:', e)
  183. isPurchased.value = false
  184. }
  185. }
  186. // 显示购买弹窗(需要登录)
  187. const showPurchaseModal = () => {
  188. // 检查登录状态
  189. if (!checkLoginStatus()) {
  190. uni.showModal({
  191. title: '登录提示',
  192. content: '此功能需要登录后使用,是否前往登录?',
  193. confirmText: '去登录',
  194. cancelText: '取消',
  195. success: (res) => {
  196. if (res.confirm) {
  197. uni.navigateTo({
  198. url: '/pages/login/login'
  199. })
  200. }
  201. }
  202. })
  203. return
  204. }
  205. showModal.value = true
  206. }
  207. // 关闭购买弹窗
  208. const closePurchaseModal = () => {
  209. showModal.value = false
  210. }
  211. // 处理购买
  212. const handlePurchase = () => {
  213. // 计算过期时间 - 年订阅365天后过期
  214. const now = Date.now()
  215. const expireTime = now + 365 * 24 * 60 * 60 * 1000
  216. // 保存购买信息
  217. const purchaseInfo = {
  218. plan: 'yearly',
  219. purchaseTime: now,
  220. expireTime: expireTime
  221. }
  222. uni.setStorageSync('strong_pool_purchase', purchaseInfo)
  223. // 更新购买状态
  224. isPurchased.value = true
  225. // 关闭弹窗
  226. closePurchaseModal()
  227. // 显示成功提示
  228. uni.showToast({
  229. title: '解锁成功',
  230. icon: 'success'
  231. })
  232. }
  233. // 开始月份选择变化
  234. const onStartMonthChange = (e) => {
  235. startMonth.value = e.detail.value
  236. }
  237. // 结束月份选择变化
  238. const onEndMonthChange = (e) => {
  239. endMonth.value = e.detail.value
  240. }
  241. // 历史查询
  242. const onHistorySearch = () => {
  243. if (!startMonth.value || !endMonth.value) {
  244. uni.showToast({
  245. title: '请选择开始和结束月份',
  246. icon: 'none'
  247. })
  248. return
  249. }
  250. // 验证时间区间
  251. if (startMonth.value > endMonth.value) {
  252. uni.showToast({
  253. title: '开始月份不能晚于结束月份',
  254. icon: 'none'
  255. })
  256. return
  257. }
  258. uni.showToast({
  259. title: `查询${formatMonth(startMonth.value)}至${formatMonth(endMonth.value)}`,
  260. icon: 'none',
  261. duration: 2000
  262. })
  263. }
  264. // 添加到我的股票
  265. const addToMyStocks = async (stock) => {
  266. // 检查登录状态
  267. if (!checkLoginStatus()) {
  268. uni.showModal({
  269. title: '登录提示',
  270. content: '添加自选股票需要登录,是否前往登录?',
  271. confirmText: '去登录',
  272. cancelText: '取消',
  273. success: (res) => {
  274. if (res.confirm) {
  275. uni.navigateTo({ url: '/pages/login/login' })
  276. }
  277. }
  278. })
  279. return
  280. }
  281. try {
  282. // 显示加载提示
  283. uni.showLoading({ title: '添加中...' })
  284. // 获取股票实时行情数据
  285. let currentPrice = null
  286. try {
  287. const quoteRes = await getStockQuotes(stock.code)
  288. console.log('[添加股票] 行情数据:', JSON.stringify(quoteRes))
  289. if (quoteRes.code === 200 && quoteRes.data && quoteRes.data.length > 0) {
  290. const quoteData = quoteRes.data[0]
  291. currentPrice = quoteData.currentPrice
  292. }
  293. } catch (e) {
  294. console.error('获取行情数据失败:', e)
  295. }
  296. // 调用后端接口保存到数据库
  297. console.log('[添加股票] 请求参数:', { stockCode: stock.code, stockName: stock.name, currentPrice })
  298. const addRes = await addUserStock({
  299. stockCode: stock.code,
  300. stockName: stock.name,
  301. currentPrice: currentPrice
  302. })
  303. console.log('[添加股票] 服务器返回:', JSON.stringify(addRes))
  304. uni.hideLoading()
  305. if (addRes.code === 200 && addRes.data === true) {
  306. uni.showToast({
  307. title: '添加成功',
  308. icon: 'success'
  309. })
  310. } else if (addRes.code === 200 && addRes.data === false) {
  311. uni.showToast({
  312. title: '股票已存在',
  313. icon: 'none'
  314. })
  315. } else {
  316. uni.showToast({
  317. title: addRes.message || '添加失败',
  318. icon: 'none'
  319. })
  320. }
  321. } catch (e) {
  322. uni.hideLoading()
  323. console.error('添加股票失败:', e)
  324. uni.showToast({
  325. title: '添加失败',
  326. icon: 'none'
  327. })
  328. }
  329. }
  330. onLoad(() => {
  331. // 页面加载时检查登录状态和购买状态
  332. const loginStatus = checkLoginStatus()
  333. console.log('[强势池] 登录状态:', loginStatus)
  334. checkPurchaseStatus()
  335. })
  336. onShow(() => {
  337. // 页面显示时检查登录状态和购买状态(从登录页返回时会触发)
  338. const loginStatus = checkLoginStatus()
  339. console.log('[强势池] 登录状态:', loginStatus)
  340. checkPurchaseStatus()
  341. // 设置导航栏标题
  342. uni.setNavigationBarTitle({ title: '量化交易大师' })
  343. })
  344. </script>
  345. <style>
  346. .page-container {
  347. height: 100vh;
  348. display: flex;
  349. flex-direction: column;
  350. background: #f5f6fb;
  351. }
  352. .scroll-view {
  353. flex: 1;
  354. height: 0;
  355. }
  356. .content-wrapper {
  357. padding: 32rpx;
  358. background: #f5f6fb;
  359. min-height: 100%;
  360. }
  361. .card {
  362. background: #ffffff;
  363. border-radius: 24rpx;
  364. padding: 32rpx;
  365. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  366. margin-bottom: 32rpx;
  367. }
  368. /* 强势趋势池标题区域 */
  369. .pool-header-section {
  370. margin-bottom: 24rpx;
  371. }
  372. .pool-header {
  373. display: flex;
  374. align-items: center;
  375. margin-bottom: 12rpx;
  376. }
  377. .pool-icon {
  378. font-size: 32rpx;
  379. margin-right: 12rpx;
  380. }
  381. .pool-title {
  382. font-size: 32rpx;
  383. font-weight: 600;
  384. color: #222222;
  385. }
  386. .pool-desc {
  387. font-size: 26rpx;
  388. color: #666a7f;
  389. }
  390. /* 性能指标卡片 */
  391. .performance-card {
  392. display: flex;
  393. justify-content: space-around;
  394. align-items: center;
  395. background: #f7f8fc;
  396. padding: 32rpx 24rpx;
  397. }
  398. .performance-item {
  399. display: flex;
  400. flex-direction: column;
  401. align-items: center;
  402. }
  403. .performance-label {
  404. font-size: 24rpx;
  405. color: #666a7f;
  406. margin-bottom: 12rpx;
  407. }
  408. .performance-value {
  409. font-size: 32rpx;
  410. font-weight: 700;
  411. color: #222222;
  412. }
  413. .performance-value.success {
  414. color: #3abf81;
  415. }
  416. .performance-value.profit {
  417. color: #f16565;
  418. }
  419. /* 股票池卡片 */
  420. .pool-card {
  421. padding: 32rpx;
  422. }
  423. .stock-item {
  424. display: flex;
  425. justify-content: space-between;
  426. align-items: center;
  427. padding: 24rpx 0;
  428. border-bottom: 1rpx solid #f1f2f6;
  429. }
  430. .stock-item:last-child {
  431. border-bottom: none;
  432. }
  433. .stock-info {
  434. flex: 1;
  435. }
  436. .stock-name-row {
  437. display: flex;
  438. align-items: center;
  439. margin-bottom: 12rpx;
  440. }
  441. .stock-name {
  442. font-size: 28rpx;
  443. font-weight: 600;
  444. color: #222222;
  445. margin-right: 16rpx;
  446. }
  447. .stock-code {
  448. font-size: 24rpx;
  449. color: #9ca2b5;
  450. }
  451. .stock-right {
  452. display: flex;
  453. align-items: center;
  454. gap: 16rpx;
  455. }
  456. .stock-actions {
  457. display: flex;
  458. gap: 12rpx;
  459. }
  460. .action-btn {
  461. width: 56rpx;
  462. height: 56rpx;
  463. border-radius: 50%;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
  468. }
  469. .buy-btn {
  470. background: linear-gradient(135deg, #5d55e8, #7568ff);
  471. }
  472. .action-icon {
  473. font-size: 32rpx;
  474. font-weight: 700;
  475. color: #ffffff;
  476. }
  477. /* 历史股票池回顾 */
  478. .history-card {
  479. padding: 32rpx;
  480. }
  481. .history-header {
  482. display: flex;
  483. align-items: center;
  484. margin-bottom: 24rpx;
  485. }
  486. .history-icon {
  487. font-size: 28rpx;
  488. margin-right: 12rpx;
  489. }
  490. .history-title {
  491. font-size: 30rpx;
  492. font-weight: 600;
  493. color: #222222;
  494. }
  495. .history-search-row {
  496. display: flex;
  497. align-items: center;
  498. }
  499. .date-range-row {
  500. display: flex;
  501. align-items: center;
  502. gap: 16rpx;
  503. margin-bottom: 24rpx;
  504. }
  505. .date-picker-half {
  506. flex: 1;
  507. }
  508. .date-separator {
  509. font-size: 26rpx;
  510. color: #666a7f;
  511. padding: 0 8rpx;
  512. }
  513. .date-input {
  514. background: #f7f8fc;
  515. border-radius: 12rpx;
  516. padding: 24rpx;
  517. font-size: 26rpx;
  518. color: #222222;
  519. display: flex;
  520. justify-content: space-between;
  521. align-items: center;
  522. }
  523. .date-text {
  524. flex: 1;
  525. }
  526. .date-icon {
  527. font-size: 28rpx;
  528. margin-left: 12rpx;
  529. }
  530. .history-search-button-full {
  531. width: 100%;
  532. background: linear-gradient(135deg, #5d55e8, #7568ff);
  533. border-radius: 16rpx;
  534. padding: 28rpx 0;
  535. text-align: center;
  536. margin-top: 12rpx;
  537. margin-bottom: 24rpx;
  538. box-shadow: 0 8rpx 20rpx rgba(93, 85, 232, 0.3);
  539. }
  540. .search-button-text {
  541. font-size: 28rpx;
  542. font-weight: 600;
  543. color: #ffffff;
  544. }
  545. .history-tip {
  546. font-size: 24rpx;
  547. color: #9ca2b5;
  548. line-height: 1.6;
  549. }
  550. .history-search-button {
  551. width: 80rpx;
  552. height: 80rpx;
  553. background: #5d55e8;
  554. border-radius: 12rpx;
  555. display: flex;
  556. align-items: center;
  557. justify-content: center;
  558. margin-left: 16rpx;
  559. }
  560. .search-icon {
  561. font-size: 32rpx;
  562. color: #ffffff;
  563. }
  564. /* 弹窗样式 */
  565. .modal-overlay {
  566. position: fixed;
  567. top: 0;
  568. left: 0;
  569. right: 0;
  570. bottom: 0;
  571. background: rgba(0, 0, 0, 0.5);
  572. display: flex;
  573. align-items: center;
  574. justify-content: center;
  575. z-index: 1000;
  576. }
  577. .modal-content {
  578. width: 640rpx;
  579. background: #ffffff;
  580. border-radius: 24rpx;
  581. padding: 48rpx 40rpx 40rpx;
  582. box-sizing: border-box;
  583. position: relative;
  584. }
  585. .modal-close-btn {
  586. position: absolute;
  587. top: 24rpx;
  588. right: 24rpx;
  589. width: 48rpx;
  590. height: 48rpx;
  591. display: flex;
  592. align-items: center;
  593. justify-content: center;
  594. z-index: 10;
  595. }
  596. .close-icon {
  597. font-size: 36rpx;
  598. color: #9ca2b5;
  599. font-weight: 300;
  600. line-height: 1;
  601. }
  602. .reward-header {
  603. display: flex;
  604. flex-direction: column;
  605. align-items: center;
  606. margin-bottom: 40rpx;
  607. }
  608. .reward-icon {
  609. font-size: 64rpx;
  610. margin-bottom: 16rpx;
  611. }
  612. .reward-title {
  613. font-size: 32rpx;
  614. font-weight: 600;
  615. color: #222222;
  616. }
  617. .reward-info {
  618. margin-bottom: 40rpx;
  619. }
  620. .reward-desc {
  621. display: block;
  622. font-size: 26rpx;
  623. color: #666a7f;
  624. text-align: center;
  625. margin-bottom: 24rpx;
  626. line-height: 1.6;
  627. }
  628. .reward-amount-simple {
  629. display: flex;
  630. justify-content: center;
  631. align-items: center;
  632. gap: 8rpx;
  633. }
  634. .amount-label {
  635. font-size: 28rpx;
  636. color: #666a7f;
  637. }
  638. .amount-value {
  639. font-size: 36rpx;
  640. font-weight: 700;
  641. color: #f16565;
  642. }
  643. .modal-footer {
  644. display: flex;
  645. flex-direction: column;
  646. align-items: center;
  647. }
  648. .pay-button {
  649. width: 100%;
  650. background: linear-gradient(135deg, #5d55e8, #7568ff);
  651. border-radius: 16rpx;
  652. padding: 28rpx 0;
  653. text-align: center;
  654. margin-bottom: 24rpx;
  655. box-shadow: 0 8rpx 20rpx rgba(93, 85, 232, 0.3);
  656. }
  657. .pay-button-text {
  658. font-size: 30rpx;
  659. font-weight: 600;
  660. color: #ffffff;
  661. }
  662. .agreement-text {
  663. font-size: 22rpx;
  664. color: #9ca2b5;
  665. }
  666. .bottom-safe-area {
  667. height: 80rpx;
  668. }
  669. /* 锁定内容样式 */
  670. .locked-content {
  671. display: flex;
  672. flex-direction: column;
  673. align-items: center;
  674. padding: 60rpx 0 40rpx;
  675. }
  676. .lock-icon-wrapper {
  677. margin-bottom: 32rpx;
  678. }
  679. .locked-content .lock-icon {
  680. font-size: 80rpx;
  681. }
  682. .lock-text {
  683. font-size: 28rpx;
  684. color: #222222;
  685. margin-bottom: 16rpx;
  686. text-align: center;
  687. }
  688. .lock-desc {
  689. font-size: 24rpx;
  690. color: #9ca2b5;
  691. margin-bottom: 48rpx;
  692. text-align: center;
  693. line-height: 1.6;
  694. }
  695. .locked-content .unlock-button {
  696. width: 100%;
  697. background: linear-gradient(135deg, #5d55e8, #7568ff);
  698. border-radius: 16rpx;
  699. padding: 28rpx 0;
  700. text-align: center;
  701. box-shadow: 0 12rpx 24rpx rgba(93, 85, 232, 0.4);
  702. }
  703. .locked-content .unlock-button-text {
  704. font-size: 30rpx;
  705. font-weight: 600;
  706. color: #ffffff;
  707. }
  708. /* 已解锁内容样式 */
  709. .unlocked-content {
  710. margin-top: 32rpx;
  711. }
  712. .unlocked-tip {
  713. font-size: 26rpx;
  714. color: #3abf81;
  715. margin-bottom: 24rpx;
  716. display: block;
  717. }
  718. .bottom-safe-area {
  719. height: 80rpx;
  720. }
  721. </style>