index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. <template>
  2. <view class="page-container">
  3. <!-- 遮罩层 -->
  4. <view v-if="showDropdown && suggestions.length > 0" class="mask" @click="closeDropdown"></view>
  5. <scroll-view class="scroll-view" scroll-y>
  6. <view class="content-wrapper">
  7. <!-- 顶部查询卡片 -->
  8. <view class="card search-card">
  9. <text class="card-title">量化分数实时查询 & 历史数据</text>
  10. <view class="search-box">
  11. <view class="search-input-wrap">
  12. <input
  13. class="search-input"
  14. type="text"
  15. placeholder="请输入股票代码/名称 (如: 600030)"
  16. v-model="keyword"
  17. @input="onKeywordChange"
  18. @confirm="handleSearchClick"
  19. @focus="onInputFocus"
  20. />
  21. <view class="search-button" @click="handleSearchClick">
  22. <image class="search-icon" src="/static/images/tab_search.png" mode="aspectFit"></image>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 搜索建议下拉 -->
  27. <view v-if="showDropdown && suggestions.length > 0" class="suggestions-dropdown">
  28. <view
  29. v-for="(item, index) in suggestions"
  30. :key="index"
  31. class="suggestion-item"
  32. @click="onSelectSuggestion(item)"
  33. >
  34. <text class="suggestion-name">{{ item.name }}</text>
  35. <text class="suggestion-code">{{ item.code }}</text>
  36. </view>
  37. </view>
  38. <view v-if="showDropdown && searching" class="suggestions-dropdown">
  39. <view class="suggestion-loading">
  40. <text>搜索中...</text>
  41. </view>
  42. </view>
  43. <text class="search-tip">支持A股代码或名称模糊查询{{ isLoggedIn ? '' : '(需登录)' }}</text>
  44. </view>
  45. <!-- 查询结果 -->
  46. <view v-if="hasSearched" class="card result-card">
  47. <view v-if="loading">
  48. <text class="result-loading">正在查询,请稍候...</text>
  49. </view>
  50. <view v-else-if="errorMsg">
  51. <text class="result-error">{{errorMsg}}</text>
  52. </view>
  53. <view v-else-if="result">
  54. <view class="detail-header">
  55. <view class="stock-info-left">
  56. <view class="detail-name">{{result.stockName}}</view>
  57. <view class="detail-code">{{result.stockCode}}</view>
  58. </view>
  59. <view class="stock-price-right">
  60. <view class="current-price" :class="getPriceClass(result.changePercent)">
  61. {{result.currentPrice || '--'}}
  62. </view>
  63. <view class="price-change" :class="getPriceClass(result.changePercent)">
  64. {{result.priceChange || '--'}} ({{result.changePercent || '--'}})
  65. </view>
  66. </view>
  67. </view>
  68. <view class="quote-section" v-if="result.currentPrice">
  69. <view class="quote-grid">
  70. <view class="quote-item">
  71. <text class="quote-label">开盘</text>
  72. <text class="quote-value">{{result.openPrice || '--'}}</text>
  73. </view>
  74. <view class="quote-item">
  75. <text class="quote-label">最高</text>
  76. <text class="quote-value price-up">{{result.highPrice || '--'}}</text>
  77. </view>
  78. <view class="quote-item">
  79. <text class="quote-label">最低</text>
  80. <text class="quote-value price-down">{{result.lowPrice || '--'}}</text>
  81. </view>
  82. <view class="quote-item">
  83. <text class="quote-label">成交量</text>
  84. <text class="quote-value">{{result.volume || '--'}}</text>
  85. </view>
  86. <view class="quote-item">
  87. <text class="quote-label">成交额</text>
  88. <text class="quote-value">{{result.amount || '--'}}</text>
  89. </view>
  90. <view class="quote-item">
  91. <text class="quote-label">换手率</text>
  92. <text class="quote-value">{{result.turnoverRate || '--'}}</text>
  93. </view>
  94. </view>
  95. </view>
  96. <view class="section" v-if="result.score">
  97. <view class="section-title">量化系统评分</view>
  98. <view class="score-display">
  99. <view class="score-badge">{{result.score}}</view>
  100. </view>
  101. </view>
  102. <view class="section" v-if="result.history && result.history.length > 0">
  103. <view class="section-title">历史评分趋势</view>
  104. <view class="history-row" v-for="(item, idx) in result.history" :key="idx">
  105. <text class="history-date">{{item.date}} 的量化评分:</text>
  106. <text :class="['history-score', item.score >= 90 ? 'tag-danger' : (item.score >= 80 ? 'tag-success' : 'tag-info')]">
  107. {{item.score}}
  108. </text>
  109. </view>
  110. <text class="history-note">(注意:此为模拟历史数据,仅供展示。)</text>
  111. </view>
  112. <view class="section" v-if="result.factors && result.factors.length > 0">
  113. <view class="section-title">评分因子构成</view>
  114. <view class="factor-row" v-for="(item, idx) in result.factors" :key="idx">
  115. <text class="factor-name">{{item.name}}</text>
  116. <text class="factor-score">{{item.value}}</text>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- 量化投资的优势 -->
  122. <view class="card advantage-card">
  123. <view class="card-header">
  124. <view class="icon-circle">
  125. <text class="icon-check">✓</text>
  126. </view>
  127. <text class="card-header-title">量化投资的优势</text>
  128. </view>
  129. <view class="advantage-item">
  130. <text class="advantage-label">客观纪律性:</text>
  131. <text class="advantage-desc">排除情绪干扰,严格执行预设的交易信号。</text>
  132. </view>
  133. <view class="advantage-item">
  134. <text class="advantage-label">高效覆盖广度:</text>
  135. <text class="advantage-desc">能同时分析数千只股票,人工无法企及。</text>
  136. </view>
  137. </view>
  138. <!-- 风险提示 -->
  139. <view class="card risk-card">
  140. <view class="card-header">
  141. <view class="icon-warning">
  142. <text class="icon-warning-text">!</text>
  143. </view>
  144. <text class="card-header-title">风险提示(免责声明)</text>
  145. </view>
  146. <text class="risk-text">
  147. 本系统的量化分数和股票池信息均基于历史数据和特定模型计算,并非对未来市场的保证或预测。市场环境瞬息万变,
  148. 量化模型可能存在失效或回撤风险。请勿将本系统数据作为投资决策的唯一依据,请您充分理解股票投资风险,并独立做出投资判断。
  149. </text>
  150. </view>
  151. <view class="bottom-safe-area"></view>
  152. </view>
  153. </scroll-view>
  154. </view>
  155. </template>
  156. <script setup>
  157. import { ref, onMounted } from 'vue'
  158. import { getSuggestions, searchStocks } from '../../utils/api.js'
  159. import { isLoggedIn as checkLoginStatus } from '../../utils/auth.js'
  160. import { onShow, onHide } from '@dcloudio/uni-app'
  161. const keyword = ref('')
  162. const loading = ref(false)
  163. const hasSearched = ref(false)
  164. const errorMsg = ref('')
  165. const result = ref(null)
  166. const suggestions = ref([])
  167. const showDropdown = ref(false)
  168. const searching = ref(false)
  169. const isLoggedIn = ref(false)
  170. let searchTimer = null
  171. onMounted(() => {
  172. isLoggedIn.value = checkLoginStatus()
  173. })
  174. onShow(() => {
  175. isLoggedIn.value = checkLoginStatus()
  176. uni.setNavigationBarTitle({ title: '量化交易大师' })
  177. })
  178. onHide(() => {
  179. showDropdown.value = false
  180. })
  181. const onInputFocus = () => {
  182. if (suggestions.value.length > 0) {
  183. showDropdown.value = true
  184. }
  185. }
  186. const onKeywordChange = (e) => {
  187. const value = e.detail.value
  188. keyword.value = value
  189. if (searchTimer) clearTimeout(searchTimer)
  190. if (!value || !value.trim()) {
  191. suggestions.value = []
  192. showDropdown.value = false
  193. return
  194. }
  195. searching.value = true
  196. showDropdown.value = true
  197. searchTimer = setTimeout(async () => {
  198. try {
  199. const response = await getSuggestions(value.trim())
  200. if (response.code === 200 && response.data) {
  201. suggestions.value = Array.isArray(response.data) ? response.data : []
  202. } else {
  203. suggestions.value = []
  204. }
  205. } catch (err) {
  206. console.error('搜索建议错误:', err)
  207. suggestions.value = []
  208. } finally {
  209. searching.value = false
  210. }
  211. }, 300)
  212. }
  213. const closeDropdown = () => {
  214. showDropdown.value = false
  215. }
  216. const onSelectSuggestion = (item) => {
  217. keyword.value = `${item.name} (${item.code})`
  218. suggestions.value = []
  219. showDropdown.value = false
  220. doSearch(item.code)
  221. }
  222. const handleSearchClick = () => {
  223. if (!isLoggedIn.value) {
  224. uni.showModal({
  225. title: '登录提示',
  226. content: '此功能需要登录后使用,是否前往登录?',
  227. confirmText: '去登录',
  228. cancelText: '取消',
  229. success: (res) => {
  230. if (res.confirm) {
  231. uni.navigateTo({ url: '/pages/login/login' })
  232. }
  233. }
  234. })
  235. return
  236. }
  237. onSearch()
  238. }
  239. const onSearch = () => {
  240. const kw = (keyword.value || '').trim()
  241. if (!kw) {
  242. uni.showToast({ title: '请输入股票代码或名称', icon: 'none' })
  243. return
  244. }
  245. showDropdown.value = false
  246. suggestions.value = []
  247. let searchCode = kw
  248. const codeMatch = kw.match(/\((\d{6})\)/)
  249. if (codeMatch) {
  250. searchCode = codeMatch[1]
  251. }
  252. doSearch(searchCode)
  253. }
  254. const doSearch = async (queryCode) => {
  255. loading.value = true
  256. hasSearched.value = true
  257. errorMsg.value = ''
  258. result.value = null
  259. showDropdown.value = false
  260. suggestions.value = []
  261. try {
  262. const res = await searchStocks(queryCode)
  263. if (res.code === 200 && res.data) {
  264. result.value = res.data
  265. } else {
  266. errorMsg.value = res.message || '未查询到相关股票数据'
  267. }
  268. } catch (err) {
  269. errorMsg.value = '网络请求失败,请检查网络连接'
  270. } finally {
  271. loading.value = false
  272. }
  273. }
  274. const getPriceClass = (changePercent) => {
  275. if (!changePercent) return ''
  276. if (changePercent.startsWith('+')) return 'price-up'
  277. if (changePercent.startsWith('-')) return 'price-down'
  278. return ''
  279. }
  280. </script>
  281. <style scoped>
  282. .page-container {
  283. height: 100vh;
  284. display: flex;
  285. flex-direction: column;
  286. background: #f5f6fb;
  287. }
  288. .scroll-view {
  289. flex: 1;
  290. height: 0;
  291. }
  292. .content-wrapper {
  293. padding: 32rpx 32rpx 48rpx;
  294. }
  295. /* 遮罩层 */
  296. .mask {
  297. position: fixed;
  298. top: 0;
  299. left: 0;
  300. right: 0;
  301. bottom: 0;
  302. background: rgba(0, 0, 0, 0.3);
  303. z-index: 99;
  304. }
  305. .card {
  306. background: #ffffff;
  307. border-radius: 24rpx;
  308. padding: 32rpx 32rpx 36rpx;
  309. box-shadow: 0 16rpx 40rpx rgba(37, 52, 94, 0.08);
  310. margin-bottom: 32rpx;
  311. }
  312. /* 搜索卡片 - 关键:设置 z-index 和 position */
  313. .search-card {
  314. margin-top: 16rpx;
  315. position: relative;
  316. z-index: 100;
  317. }
  318. .card-title {
  319. display: block;
  320. font-size: 32rpx;
  321. font-weight: 600;
  322. color: #222222;
  323. margin-bottom: 32rpx;
  324. }
  325. .search-box {
  326. position: relative;
  327. }
  328. .search-input-wrap {
  329. display: flex;
  330. align-items: center;
  331. background: #f7f8fc;
  332. border-radius: 999rpx;
  333. padding: 0 8rpx 0 32rpx;
  334. height: 96rpx;
  335. box-sizing: border-box;
  336. }
  337. .search-input {
  338. flex: 1;
  339. font-size: 28rpx;
  340. color: #222222;
  341. }
  342. .search-button {
  343. width: 96rpx;
  344. height: 80rpx;
  345. margin-left: 12rpx;
  346. border-radius: 999rpx;
  347. background: #f5f6fb;
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. }
  352. .search-icon {
  353. width: 48rpx;
  354. height: 48rpx;
  355. }
  356. .search-tip {
  357. display: block;
  358. margin-top: 20rpx;
  359. font-size: 24rpx;
  360. color: #9ca2b5;
  361. }
  362. /* 搜索建议下拉 - 关键样式 */
  363. .suggestions-dropdown {
  364. position: absolute;
  365. top: 100%;
  366. left: 0;
  367. right: 0;
  368. background: #ffffff;
  369. border-radius: 16rpx;
  370. margin-top: 12rpx;
  371. box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.15);
  372. max-height: 480rpx;
  373. overflow-y: auto;
  374. z-index: 101;
  375. }
  376. .suggestion-item {
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: center;
  380. padding: 28rpx 24rpx;
  381. border-bottom: 1rpx solid #f5f6fb;
  382. }
  383. .suggestion-item:last-child {
  384. border-bottom: none;
  385. }
  386. .suggestion-item:active {
  387. background: #f9f9fb;
  388. }
  389. .suggestion-name {
  390. font-size: 28rpx;
  391. font-weight: 600;
  392. color: #222222;
  393. }
  394. .suggestion-code {
  395. font-size: 24rpx;
  396. color: #9ca2b5;
  397. }
  398. .suggestion-loading {
  399. padding: 48rpx;
  400. text-align: center;
  401. color: #9ca2b5;
  402. font-size: 28rpx;
  403. }
  404. .result-card {
  405. margin-top: 8rpx;
  406. }
  407. .result-loading {
  408. font-size: 26rpx;
  409. color: #666a7f;
  410. }
  411. .result-error {
  412. font-size: 26rpx;
  413. color: #ff5b5b;
  414. }
  415. .detail-header {
  416. display: flex;
  417. justify-content: space-between;
  418. align-items: flex-start;
  419. margin-bottom: 24rpx;
  420. padding-bottom: 24rpx;
  421. border-bottom: 1rpx solid #f1f2f6;
  422. }
  423. .stock-info-left {
  424. flex: 1;
  425. }
  426. .detail-name {
  427. font-size: 34rpx;
  428. font-weight: 700;
  429. color: #1f1f2e;
  430. }
  431. .detail-code {
  432. margin-top: 8rpx;
  433. font-size: 26rpx;
  434. color: #9da3b5;
  435. }
  436. .stock-price-right {
  437. text-align: right;
  438. }
  439. .current-price {
  440. font-size: 44rpx;
  441. font-weight: 700;
  442. color: #333;
  443. }
  444. .price-change {
  445. margin-top: 6rpx;
  446. font-size: 26rpx;
  447. }
  448. .price-up { color: #e74c3c; }
  449. .price-down { color: #27ae60; }
  450. .quote-section {
  451. margin-bottom: 24rpx;
  452. }
  453. .quote-grid {
  454. display: flex;
  455. flex-wrap: wrap;
  456. background: #f8f9fc;
  457. border-radius: 16rpx;
  458. padding: 20rpx 16rpx;
  459. }
  460. .quote-item {
  461. width: 33.33%;
  462. display: flex;
  463. flex-direction: column;
  464. align-items: center;
  465. padding: 12rpx 0;
  466. }
  467. .quote-label {
  468. font-size: 24rpx;
  469. color: #9da3b5;
  470. margin-bottom: 8rpx;
  471. }
  472. .quote-value {
  473. font-size: 28rpx;
  474. font-weight: 600;
  475. color: #333;
  476. }
  477. .score-display {
  478. display: flex;
  479. justify-content: center;
  480. margin-top: 16rpx;
  481. }
  482. .score-badge {
  483. min-width: 140rpx;
  484. padding: 12rpx 22rpx;
  485. border-radius: 20rpx;
  486. background: #f16565;
  487. color: #ffffff;
  488. font-size: 40rpx;
  489. font-weight: 700;
  490. text-align: center;
  491. box-shadow: 0 10rpx 24rpx rgba(241, 101, 101, 0.35);
  492. }
  493. .section {
  494. margin-top: 20rpx;
  495. }
  496. .section-title {
  497. font-size: 28rpx;
  498. font-weight: 700;
  499. color: #1f1f2e;
  500. margin-bottom: 16rpx;
  501. }
  502. .history-row {
  503. display: flex;
  504. align-items: center;
  505. justify-content: space-between;
  506. padding: 18rpx 0;
  507. border-bottom: 1rpx solid #f1f2f6;
  508. }
  509. .history-row:last-child {
  510. border-bottom: none;
  511. }
  512. .history-date {
  513. font-size: 26rpx;
  514. color: #3c4050;
  515. }
  516. .history-score {
  517. min-width: 96rpx;
  518. text-align: center;
  519. padding: 6rpx 18rpx;
  520. border-radius: 30rpx;
  521. font-size: 28rpx;
  522. font-weight: 700;
  523. color: #ffffff;
  524. }
  525. .tag-danger { background: #f16565; }
  526. .tag-success { background: #3abf81; }
  527. .tag-info { background: #4c86ff; }
  528. .history-note {
  529. display: block;
  530. margin-top: 12rpx;
  531. font-size: 22rpx;
  532. color: #9da3b5;
  533. }
  534. .factor-row {
  535. display: flex;
  536. align-items: center;
  537. justify-content: space-between;
  538. padding: 14rpx 0;
  539. }
  540. .factor-name {
  541. font-size: 26rpx;
  542. color: #3c4050;
  543. }
  544. .factor-score {
  545. font-size: 28rpx;
  546. font-weight: 600;
  547. color: #4c86ff;
  548. }
  549. .card-header {
  550. display: flex;
  551. align-items: center;
  552. margin-bottom: 24rpx;
  553. }
  554. .card-header-title {
  555. font-size: 30rpx;
  556. font-weight: 600;
  557. color: #222222;
  558. }
  559. .icon-circle {
  560. width: 40rpx;
  561. height: 40rpx;
  562. border-radius: 50%;
  563. background: #e7f7ef;
  564. display: flex;
  565. align-items: center;
  566. justify-content: center;
  567. margin-right: 16rpx;
  568. }
  569. .icon-check {
  570. font-size: 24rpx;
  571. color: #28a745;
  572. }
  573. .advantage-item {
  574. margin-bottom: 12rpx;
  575. font-size: 26rpx;
  576. line-height: 1.6;
  577. color: #4a4f63;
  578. }
  579. .advantage-label {
  580. font-weight: 600;
  581. }
  582. .advantage-desc {
  583. font-weight: 400;
  584. }
  585. .risk-card {
  586. margin-bottom: 24rpx;
  587. }
  588. .icon-warning {
  589. width: 40rpx;
  590. height: 40rpx;
  591. border-radius: 50%;
  592. background: #ffecef;
  593. display: flex;
  594. align-items: center;
  595. justify-content: center;
  596. margin-right: 16rpx;
  597. }
  598. .icon-warning-text {
  599. font-size: 26rpx;
  600. color: #ff5b5b;
  601. }
  602. .risk-text {
  603. display: block;
  604. font-size: 24rpx;
  605. line-height: 1.8;
  606. color: #666a7f;
  607. }
  608. .bottom-safe-area {
  609. height: 80rpx;
  610. }
  611. </style>