index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div class="app-quote-chart">
  3. <div class="app-quote-chart__header">
  4. <Tabs v-model:active="tabIndex" :before-change="onTabChange" :ellipsis="false">
  5. <Tab :title="$t('chart.time')" />
  6. <Tab>
  7. <template #title>
  8. <Popover :actions="actions" @select="onPopoverSelect">
  9. <template #reference>{{ selectedText || $t('chart.minutes') }}</template>
  10. </Popover>
  11. </template>
  12. </Tab>
  13. <Tab :title="$t('chart.dayline')" />
  14. <Tab :title="$t('chart.weekline')" />
  15. <Tab :title="$t('chart.monthline')" />
  16. </Tabs>
  17. <Icon name="setting-o" style="padding: 0 16px;" v-if="false" />
  18. </div>
  19. <MLine v-bind="{ symbol, goodsCode }" v-if="tabIndex === 0" />
  20. <KLine v-bind="{ symbol, goodsCode, cycleType }" v-else />
  21. </div>
  22. </template>
  23. <script lang="ts" setup>
  24. import { shallowRef } from 'vue'
  25. import { Tab, Tabs, Popover, Icon, PopoverAction } from 'vant'
  26. import { ChartCycleType } from '@/constants/chart'
  27. import MLine from './timeline/index.vue'
  28. import KLine from './candlestick/index.vue'
  29. import { i18n } from '@/stores'
  30. defineProps({
  31. goodsCode: {
  32. type: String,
  33. required: true
  34. }
  35. })
  36. const { global: { t } } = i18n
  37. const symbol = '000000.et' // https://blog.csdn.net/jones2000/article/details/104457569
  38. const tabIndex = shallowRef(0) // 当前选中的标签
  39. const selectedText = shallowRef('') // 当前选中的分钟线
  40. const cycleType = shallowRef(ChartCycleType.Minutes) // 图表周期类型
  41. const actions = [
  42. { text: t('chart.oneminutes') },
  43. { text: t('chart.fiveminutes'), },
  44. { text: t('chart.thirtyminutes'), },
  45. { text: t('chart.onehour'), },
  46. { text: t('chart.fourhour'), }
  47. ]
  48. // 切换图表
  49. const onTabChange = (index: number) => {
  50. switch (index) {
  51. case 1: {
  52. return false
  53. }
  54. case 2: {
  55. cycleType.value = ChartCycleType.Day
  56. return true
  57. }
  58. case 3: {
  59. cycleType.value = ChartCycleType.Week
  60. return true
  61. }
  62. case 4: {
  63. cycleType.value = ChartCycleType.Month
  64. return true
  65. }
  66. default: {
  67. return true
  68. }
  69. }
  70. }
  71. // 切换分钟
  72. const onPopoverSelect = (action: PopoverAction) => {
  73. tabIndex.value = 1
  74. selectedText.value = action.text
  75. switch (action.text) {
  76. case t('chart.oneminutes'): {
  77. cycleType.value = ChartCycleType.Minutes
  78. break
  79. }
  80. case t('chart.fiveminutes'): {
  81. cycleType.value = ChartCycleType.Minutes5
  82. break
  83. }
  84. case t('chart.thirtyminutes'): {
  85. cycleType.value = ChartCycleType.Minutes30
  86. break
  87. }
  88. case t('chart.onehour'): {
  89. cycleType.value = ChartCycleType.Minutes60
  90. break
  91. }
  92. case '2小时': {
  93. cycleType.value = ChartCycleType.Hours2
  94. break
  95. }
  96. case t('chart.fourhour'): {
  97. cycleType.value = ChartCycleType.Hours4
  98. break
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="less">
  104. @import './index.less';
  105. </style>