st-comp 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,28 +34,31 @@
34
34
  import type { KlineDataType, IndicatorDataType, IndicatorConfigType } from './type.d.ts'
35
35
  import { getKline, getIndicator, getIndicatorConfigList, getOption } from './utils'
36
36
 
37
+ /**
38
+ * 组件接收参数
39
+ * @param {String} code 品种代码
40
+ * @param {Number} defaultCount 默认K线总条数
41
+ * @param {String} tradeDate 最终交易日时间
42
+ * @param {String} frequency 周期名称
43
+ * @param {String} indicator 指标线类型
44
+ */
37
45
  const props = defineProps({
38
- // 品种代码
39
46
  code: {
40
47
  type: String,
41
48
  required: true,
42
49
  },
43
- // 默认展示K线条数
44
50
  defaultCount: {
45
51
  type: Number,
46
52
  default: () => 500,
47
53
  },
48
- // 结束时间
49
54
  tradeDate: {
50
55
  type: String,
51
56
  required: true,
52
57
  },
53
- // 周期名称
54
58
  frequency: {
55
59
  type: String,
56
60
  required: true,
57
61
  },
58
- // 指标线类型
59
62
  indicator: {
60
63
  type: String,
61
64
  required: true,
@@ -114,16 +117,20 @@
114
117
  // 4.获取指标相关配置
115
118
  indicatorConfigList.value = (await getIndicatorConfigList()).data
116
119
  // 5.获取图表配置
117
- option.value = await getOption({
120
+ const params = {
118
121
  kLineData: klineData.value,
119
122
  indicatorData: indicatorData.value,
120
123
  indicator: props.indicator,
121
124
  indicatorConfigList: indicatorConfigList.value,
122
125
  defaultShowBarCount: 200,
123
- })
126
+ }
127
+ option.value = await getOption(params)
124
128
  }
125
129
 
126
- // 图表高亮,用于记录当前高亮tooltip
130
+ /**
131
+ * echarts相关事件--
132
+ * 鼠标移动激活数据时触发,动态更新Tips数据
133
+ */
127
134
  const highlight = (data: any, chart: EChartsType) => {
128
135
  if (data) {
129
136
  // 图表内部移动
@@ -137,63 +144,12 @@
137
144
  }
138
145
  }
139
146
  }
140
- // 默认区域刷选
147
+ /**
148
+ * echarts相关事件--
149
+ * 修改echarts图表配置渲染后,进行的回调
150
+ */
141
151
  const afterInit = (chart: EChartsType) => {
142
- /**
143
- * 获取匹配用户选择的交易日期对应X轴的索引,用于刷选范围区域
144
- * 匹配思路:
145
- * 1.时间轴均转换为年月日字符串做对比,相等则算匹配成功
146
- * 2.特殊周期K线需要特殊处理:
147
- * [1w]:时间需要均转换成所处星期的星期五日期,判断它们星期五日期是否相等
148
- * [1m,5m,15m,30m,60m]:包含前一交易日21点后的,排除掉交易日期21点后的
149
- */
150
- const { tradeDate, frequency } = props
151
- const xAxisData = option.value.xAxis.data
152
- let brushXIndexList: Array<number> = []
153
- // 长周期判断
154
- xAxisData.forEach((xItem: number, index: number) => {
155
- // X轴年月日
156
- const xItemDate = dayjs(xItem * 1000).format('YYYY-MM-DD')
157
- xItemDate === tradeDate && brushXIndexList.push(index)
158
- // 如果是周线,则需要判断两者周五日期是否相等
159
- if (frequency === '1w') {
160
- dayjs(xItemDate).day(5).format('YYYY-MM-DD') ===
161
- dayjs(tradeDate).day(5).format('YYYY-MM-DD') && brushXIndexList.push(index)
162
- }
163
- })
164
- const shortFreq = ['1m', '5m', '15m', '30m', '60m']
165
- // 短周期判断
166
- if (shortFreq.includes(frequency)) {
167
- // 拿到上一个交易日
168
- const lastTradeDateIndex = brushXIndexList[0] - 1
169
- const lastTradeDate = dayjs(xAxisData[lastTradeDateIndex] * 1000).format('YYYY-MM-DD')
170
- // 包含了上一个交易日21点之后的数据索引数组
171
- const lastTrade21List: Array<number> = []
172
- xAxisData.forEach((xItem: number, index: number) => {
173
- if (
174
- dayjs(xItem * 1000).format('YYYY-MM-DD') === lastTradeDate &&
175
- dayjs(xItem * 1000).isSameOrAfter(`${lastTradeDate} 21:00:00`)
176
- ) {
177
- lastTrade21List.push(index)
178
- }
179
- })
180
- // 排除匹配到交易日期21点之后的数据索引
181
- const finallyDateIndex = brushXIndexList[brushXIndexList.length - 1]
182
- const finallyDate = dayjs(xAxisData[finallyDateIndex] * 1000).format('YYYY-MM-DD 21:00:00')
183
- brushXIndexList = [...lastTrade21List, ...brushXIndexList].filter(item => {
184
- return dayjs(xAxisData[item] * 1000).isBefore(finallyDate)
185
- })
186
- }
187
- chart.dispatchAction({
188
- type: 'brush',
189
- areas: [
190
- {
191
- brushType: 'lineX',
192
- coordRange: [brushXIndexList[0], brushXIndexList.slice(-1)[0]],
193
- xAxisIndex: 0,
194
- },
195
- ],
196
- })
152
+
197
153
  }
198
154
 
199
155
  onMounted(() => {
@@ -13,7 +13,7 @@ export interface InOption {
13
13
  kLineData: KlineDataItem[];
14
14
  indicatorData: IndicatorDataItem[];
15
15
  indicator: string;
16
- indicatorList: any;
16
+ indicatorConfigList: any;
17
17
  defaultShowBarCount: number;
18
18
  }
19
19
 
@@ -1,28 +1,6 @@
1
1
  import axios from 'axios'
2
2
  import dayjs from 'dayjs'
3
- import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
4
- import type { KlineDataItem, IndicatorDataItem, InOption } from './type.d.ts'
5
- dayjs.extend(isSameOrAfter)
6
-
7
- /**
8
- * @description: 获取固定间隔后的交易日
9
- * @param {string} currentDate 初始交易日期
10
- * @param {number | undefined} days 间隔天数
11
- * @return {*}
12
- */
13
- const getTradeByAddDays = (currentDate: string, days: number | undefined) => {
14
- return axios({
15
- headers: {
16
- Token: '8c9e48f3bfff810c3403829233f76515',
17
- },
18
- method: 'post',
19
- url: '/proxy/review/review/getTradeByAddDays',
20
- data: {
21
- currentDate,
22
- days,
23
- },
24
- })
25
- }
3
+ import type { KlineDataItem, InOption } from './type.d.ts'
26
4
 
27
5
  /**
28
6
  * @description: 获取K线数据
@@ -38,28 +16,7 @@ export const getKline = async (
38
16
  tradeDate: string,
39
17
  frequency: string
40
18
  ) => {
41
- // 周期对应的间隔交易日
42
- const timeIntervalMap = new Map([
43
- ['1m', 1],
44
- ['5m', 1],
45
- ['15m', 4],
46
- ['30m', 8],
47
- ['60m', 16],
48
- ['1d', 80],
49
- ['1w', 80],
50
- ])
51
- // 根据周期判断逻辑请求到对应的间隔末尾交易日
52
- const interval = timeIntervalMap.get(frequency)
53
- const res = await getTradeByAddDays(tradeDate, interval)
54
- const nowDate = dayjs().format('YYYY-MM-DD')
55
- const resDate = res.data.body.tradeDate.split(' ')[0]
56
- let dt: null | string = null
57
- // 判断接口获取到的交易日是否大于等于今日,如果为真,则以今日日期为末尾
58
- if (dayjs(resDate).isSameOrAfter(nowDate)) {
59
- dt = dayjs().format('YYYY-MM-DD HH:mm:ss')
60
- } else {
61
- dt = `${resDate} 23:59:59`
62
- }
19
+ let dt: null | string = dayjs(tradeDate).format('YYYY-MM-DD HH:mm:ss')
63
20
  return axios(
64
21
  `http://116.62.161.92:8005/history_kline?code=${code}&bar_count=${bar_count}&dt=${dt}&frequency=${frequency}`
65
22
  )
@@ -10,8 +10,8 @@
10
10
  :page-sizes="pageSizes"
11
11
  :layout="layout"
12
12
  v-bind="$attrs"
13
- @size-change="handlePageChange"
14
- @current-change="handlePageChange"
13
+ @size-change="change"
14
+ @current-change="change"
15
15
  />
16
16
  </el-config-provider>
17
17
  </template>
@@ -20,7 +20,7 @@
20
20
  import zhCn from 'element-plus/es/locale/lang/zh-cn'
21
21
  import { computed } from 'vue'
22
22
 
23
- const emit = defineEmits(['update:pageData', 'handlePageChange'])
23
+ const emit = defineEmits(['update:pageData', 'change'])
24
24
  /**
25
25
  * 组件接收参数
26
26
  * @param {Object} pageData 页码和每页条数
@@ -72,8 +72,8 @@
72
72
  /**
73
73
  * 分页数据变动
74
74
  */
75
- const handlePageChange = () => {
76
- emit('handlePageChange', props.pageData)
75
+ const change = () => {
76
+ emit('change', props.pageData)
77
77
  }
78
78
  </script>
79
79
 
package/packages/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { App } from "vue"
2
+ import StChartLayout from "./ChartLayout/index.ts"
3
+ import StDialog from "./Dialog/index.ts"
2
4
  import StEcharts from "./Echarts/index.ts"
3
5
  import StKline from "./Kline/index.ts"
4
6
  import StPagination from "./Pagination/index.ts"
@@ -6,6 +8,8 @@ import StTable from "./Table/index.ts"
6
8
 
7
9
  export default {
8
10
  install(app: App) {
11
+ StChartLayout.install(app)
12
+ StDialog.install(app)
9
13
  StEcharts.install(app)
10
14
  StKline.install(app)
11
15
  StPagination.install(app)
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <div :style="{ width: '100%', height: '600px' }">
3
+ <el-button @click="dialogVisible = true">
4
+ click to open the Dialog
5
+ </el-button>
6
+ <st-dialog v-model="dialogVisible"> </st-dialog>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ import { ref } from 'vue'
12
+ const dialogVisible = ref(false);
13
+
14
+ </script>
15
+
16
+ <style lang="scss" scoped></style>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <div style="width: 100%;height: 100%;">
3
+ <st-chartLayout
4
+ :data="data"
5
+ :row="2"
6
+ :col="3"
7
+ >
8
+ <template #default="{ data }">
9
+ <div style="width: 100%;height: 100%;;background: #ccc">{{ data }}</div>
10
+ </template>
11
+ </st-chartLayout>
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ const data = [
17
+ 1,2,3,4,5,6
18
+ ]
19
+ </script>
20
+
21
+ <style lang="scss" scoped>
22
+ </style>
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <div :style="{ width: '100%', height: '600px' }">
3
+ <el-button @click="dialogVisible = true">
4
+ click to open the Dialog
5
+ </el-button>
6
+ <st-dialog v-model="dialogVisible"> </st-dialog>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ import { ref } from 'vue'
12
+ const dialogVisible = ref(false);
13
+
14
+ </script>
15
+
16
+ <style lang="scss" scoped></style>
@@ -1,12 +1,21 @@
1
1
  <template>
2
- <div>
3
- Kline123456
2
+ <div id="Kline">
3
+ <st-kline
4
+ code="ao8888.SHFE"
5
+ tradeDate="2023-10-13T16:24:28"
6
+ indicator="DKX_EMA"
7
+ frequency="1m"
8
+ />
4
9
  </div>
5
10
  </template>
6
11
 
7
12
  <script setup lang="ts">
8
13
  </script>
9
14
 
10
- <style lang="scss" scoped>
11
-
15
+ <style scoped>
16
+ #Kline{
17
+ margin: auto;
18
+ width: 1200px;
19
+ height: 600px;
20
+ }
12
21
  </style>
@@ -2,7 +2,7 @@
2
2
  <st-pagination
3
3
  :total="total"
4
4
  v-model:pageData="pageData"
5
- @handlePageChange="getTableData"
5
+ @change="getTableData"
6
6
  />
7
7
  </template>
8
8
 
@@ -17,7 +17,7 @@
17
17
 
18
18
  // 模拟表格数据接口请求发送函数
19
19
  const getTableData = () => {
20
- // console.log('分页数据自动更新:', pageData.value)
20
+ console.log('分页数据自动更新:', pageData.value)
21
21
  }
22
22
  </script>
23
23
 
@@ -1,4 +1,14 @@
1
1
  export default [
2
+ {
3
+ path: '/chartLayout',
4
+ name: 'ChartLayout',
5
+ component: () => import('../pages/ChartLayout/index.vue'),
6
+ },
7
+ {
8
+ path: '/dialog',
9
+ name: 'Dialog',
10
+ component: () => import('../pages/Dialog/index.vue'),
11
+ },
2
12
  {
3
13
  path: '/echarts',
4
14
  name: 'Echarts',
@@ -1,58 +0,0 @@
1
- <!-- KlineGroup [默认六宫格]多周期业务K线组件 -->
2
- <script setup lang="ts">
3
- import dayjs from 'dayjs'
4
- const props = defineProps({
5
- // 品种代码
6
- code: {
7
- type: String,
8
- require: true,
9
- },
10
- // 周期名称
11
- freqNameArray: {
12
- type: Array,
13
- default: () => {
14
- return ['5m', '15m', '30m', '60m', '1d', '1w']
15
- },
16
- },
17
- // 指标类型
18
- indicatorType: {
19
- type: String,
20
- default: 'DKX_EMA',
21
- },
22
- // 交易日期
23
- tradeDate: {
24
- type: String,
25
- default: dayjs().format('YYYY-MM-DD'),
26
- },
27
- })
28
- console.log('六宫格需要接收到的参数:',props)
29
- </script>
30
-
31
- <template>
32
- <h2>传入的交易时间: 2023-10-13</h2>
33
- <div class="KlineGroup element-dark">
34
- <st-kline
35
- class="st-kline"
36
- v-for="item in freqNameArray"
37
- code="ao8888.SHFE"
38
- indicator="DKX_EMA"
39
- :frequency="item"
40
- tradeDate="2023-10-13"
41
- />
42
- </div>
43
- </template>
44
-
45
- <style lang="scss" scoped>
46
- .KlineGroup {
47
- display: flex;
48
- flex-wrap: wrap;
49
- width: 100%;
50
- height: 800px;
51
- justify-content: space-between;
52
- align-content: space-between;
53
- .st-kline {
54
- width: calc(100% / 3 - 2px);
55
- height: calc(100% / 2 - 2px);
56
- }
57
- }
58
- </style>