index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div class="app-echats-kline">
  3. <template v-if="loading">
  4. <div class="app-echats-kline__tip">正在加载...</div>
  5. </template>
  6. <template v-else-if="isEmpty">
  7. <div class="app-echats-kline__tip">暂无数据</div>
  8. </template>
  9. <template v-else>
  10. <div class="app-echats-kline__container">
  11. <ul class="legend" v-if="false">
  12. <li class="legend-item">开: {{ selectedItem.open }}</li>
  13. <li class="legend-item">收: {{ selectedItem.close }}</li>
  14. <li class="legend-item">高: {{ selectedItem.highest }}</li>
  15. <li class="legend-item">低: {{ selectedItem.lowest }}</li>
  16. <li class="legend-item">MA5: {{ selectedItem.ma5 }}</li>
  17. <li class="legend-item">MA10: {{ selectedItem.ma10 }}</li>
  18. <li class="legend-item">MA15: {{ selectedItem.ma15 }}</li>
  19. </ul>
  20. <app-echarts :option="options.candlestick" v-model:dataIndex="dataIndex" @ready="initOptions" />
  21. </div>
  22. </template>
  23. </div>
  24. </template>
  25. <script lang="ts" setup>
  26. import { PropType, watch } from 'vue'
  27. import { ChartCycleType } from '@/constants/chart'
  28. import { useCandlestickChart } from '@/hooks/echarts/candlestick'
  29. import AppEcharts from '@/components/base/echarts/index.vue'
  30. const props = defineProps({
  31. goodscode: {
  32. type: String,
  33. default: '',
  34. },
  35. // 周期类型
  36. cycleType: {
  37. type: Number as PropType<ChartCycleType>,
  38. default: ChartCycleType.Minutes,
  39. },
  40. // 是否显示指标
  41. showIndicator: {
  42. type: Boolean,
  43. default: true,
  44. },
  45. })
  46. const { loading, dataIndex, isEmpty, options, selectedItem, initData, initOptions } = useCandlestickChart(props.goodscode);
  47. // 监听周期选择变化
  48. watch(() => props.cycleType, (val) => {
  49. initData(val);
  50. }, {
  51. immediate: true
  52. })
  53. </script>
  54. <style lang="less">
  55. @import './index.less';
  56. </style>