1
|
|
-import { dateUtil, formatToDateTime } from '/@/utils/dateUtil';
|
2
|
|
-import { ref } from 'vue';
|
|
1
|
+import { dateUtil } from '/@/utils/dateUtil';
|
|
2
|
+import { Ref, ref } from 'vue';
|
3
|
3
|
import { getTrendData } from '/@/api/dashboard';
|
4
|
4
|
import { RangePickerValue } from 'ant-design-vue/lib/date-picker/interface';
|
|
5
|
+import moment from 'moment';
|
5
|
6
|
|
6
|
7
|
export enum ShortcutQueryKeyEnum {
|
7
|
8
|
LATEST_1_MONTH = 'LATEST_1_MONTH',
|
...
|
...
|
@@ -42,8 +43,8 @@ export function getDateByShortcutQueryKey(value: ShortcutQueryKeyEnum) { |
42
|
43
|
export function useDate() {
|
43
|
44
|
const tenantDateValue = ref([]);
|
44
|
45
|
const customerDateValue = ref<RangePickerValue>([]);
|
45
|
|
- const tenantTrendList = ref([]);
|
46
|
|
- const customerTrendList = ref([]);
|
|
46
|
+ const tenantTrendList = ref<[string, string][]>([]);
|
|
47
|
+ const customerTrendList = ref<[string, string][]>([]);
|
47
|
48
|
const activeTenantIndex = ref(0);
|
48
|
49
|
const activeCustomerIndex = ref(0);
|
49
|
50
|
const TenantOrCustomerDateList = ref([
|
...
|
...
|
@@ -80,52 +81,39 @@ export function useDate() { |
80
|
81
|
}
|
81
|
82
|
|
82
|
83
|
// 获取选中的时间范围内的数据
|
83
|
|
- async function getDateData(startTs, endTs, trend: 'CUSTOMER_TREND' | 'TENANT_TREND', list) {
|
84
|
|
- // 计算时间间隔
|
85
|
|
- function computedInterval(startTs: number, endTs: number) {
|
86
|
|
- /**
|
87
|
|
- * 选择的时间间隔
|
88
|
|
- * <=1 2h
|
89
|
|
- * <=30 1day
|
90
|
|
- * >30<90 2day
|
91
|
|
- * >90 1month
|
92
|
|
- */
|
93
|
|
- let interval = 86400000;
|
94
|
|
- if (endTs - startTs <= 86400000) {
|
95
|
|
- interval = 7200000;
|
96
|
|
- } else if (endTs - startTs <= 2592000000) {
|
97
|
|
- interval = 86400000;
|
98
|
|
- } else if (endTs - startTs > 2592000000 && endTs - startTs < 7776000000) {
|
99
|
|
- interval = 172800000;
|
100
|
|
- } else if (endTs - startTs > 7776000000) {
|
101
|
|
- interval = 2592000000;
|
102
|
|
- }
|
103
|
|
- return interval;
|
104
|
|
- }
|
105
|
|
- startTs = parseInt(formatToDateTime(startTs, 'x')) - 86400000;
|
106
|
|
- endTs = parseInt(formatToDateTime(endTs, 'x'));
|
|
84
|
+ async function getDateData(
|
|
85
|
+ startTs: moment.Moment,
|
|
86
|
+ endTs: moment.Moment,
|
|
87
|
+ trend: 'CUSTOMER_TREND' | 'TENANT_TREND',
|
|
88
|
+ list: Ref<[string, string][]>
|
|
89
|
+ ) {
|
107
|
90
|
const res = await getTrendData({
|
108
|
|
- startTs,
|
109
|
|
- endTs,
|
110
|
|
- interval: computedInterval(startTs, endTs),
|
|
91
|
+ startTs: startTs.valueOf(),
|
|
92
|
+ endTs: endTs.valueOf(),
|
|
93
|
+ interval: 24 * 60 * 60 * 1000,
|
111
|
94
|
trend,
|
112
|
95
|
});
|
113
|
|
- list.value = res.map((item) => [item.ts, item.value]);
|
|
96
|
+ list.value = res.map((item) => [item.date, item.value]);
|
114
|
97
|
}
|
115
|
98
|
|
116
|
99
|
// 租户选择日期
|
117
|
|
- function onDateTenantChange(_, dateString) {
|
118
|
|
- if (!_.length) return;
|
119
|
|
- const [startTs, endTs] = dateString;
|
|
100
|
+ function onDateTenantChange(range: RangePickerValue) {
|
|
101
|
+ if (!range.length) return;
|
|
102
|
+ const [startTs, endTs] = range;
|
120
|
103
|
activeTenantIndex.value = -1;
|
121
|
|
- getDateData(startTs, endTs, 'TENANT_TREND', tenantTrendList);
|
|
104
|
+ getDateData(startTs as moment.Moment, endTs as moment.Moment, 'TENANT_TREND', tenantTrendList);
|
122
|
105
|
}
|
123
|
106
|
// 客户趋势选择日期
|
124
|
|
- function onDateCustomerChange(_, dateString) {
|
125
|
|
- if (!_.length) return;
|
126
|
|
- const [startTs, endTs] = dateString;
|
|
107
|
+ function onDateCustomerChange(range: RangePickerValue) {
|
|
108
|
+ if (!range.length) return;
|
|
109
|
+ const [startTs, endTs] = range;
|
127
|
110
|
activeCustomerIndex.value = -1;
|
128
|
|
- getDateData(startTs, endTs, 'CUSTOMER_TREND', customerTrendList);
|
|
111
|
+ getDateData(
|
|
112
|
+ startTs as moment.Moment,
|
|
113
|
+ endTs as moment.Moment,
|
|
114
|
+ 'CUSTOMER_TREND',
|
|
115
|
+ customerTrendList
|
|
116
|
+ );
|
129
|
117
|
}
|
130
|
118
|
return {
|
131
|
119
|
tenantDateValue,
|
...
|
...
|
|