@peng_kai/kit 0.3.0-beta.17 → 0.3.0-beta.18
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.
|
@@ -70,6 +70,12 @@ export function standardizeTzParam(tz: string) {
|
|
|
70
70
|
return tz;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
export function getLocalOffset(tz: string) {
|
|
74
|
+
const offsetTzMinutes = dayjs().tz(tz).utcOffset();
|
|
75
|
+
const offsetLocalMinutes = dayjs().utcOffset();
|
|
76
|
+
return (offsetLocalMinutes - offsetTzMinutes) * 60 * 1000;
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
type OfDayType = dayjs.Dayjs | undefined | null;
|
|
74
80
|
type UnitType = dayjs.QUnitType | dayjs.OpUnitType;
|
|
75
81
|
export const datetime = {
|
|
@@ -92,14 +98,18 @@ export const datetime = {
|
|
|
92
98
|
|
|
93
99
|
const _tz = standardizeTzParam(tz);
|
|
94
100
|
const _keys = (Array.isArray(keys) && keys?.length > 1) ? keys : ['start_time', 'end_time'];
|
|
101
|
+
const offsetMS = getLocalOffset(_tz);
|
|
95
102
|
|
|
96
103
|
type RetType = KS extends readonly [string, string]
|
|
97
104
|
? Simplify<{ [K in KS[0]]: number } & { [K in KS[1]]: number }>
|
|
98
105
|
: { start_time: number; end_time: number };
|
|
99
106
|
|
|
107
|
+
const startTime = dayjs(days[0].valueOf()).startOf(unit).valueOf() + offsetMS;
|
|
108
|
+
const endTime = dayjs(days[1].valueOf()).endOf(unit).valueOf() + offsetMS;
|
|
109
|
+
|
|
100
110
|
return {
|
|
101
|
-
[_keys[0]]:
|
|
102
|
-
[_keys[1]]:
|
|
111
|
+
[_keys[0]]: startTime,
|
|
112
|
+
[_keys[1]]: endTime,
|
|
103
113
|
} as RetType;
|
|
104
114
|
},
|
|
105
115
|
/**
|
|
@@ -3,18 +3,14 @@ import dayjs, { type Dayjs } from '../../../libs/dayjs';
|
|
|
3
3
|
import { type ComponentProps } from 'vue-component-type-helpers'
|
|
4
4
|
|
|
5
5
|
export const antdRangePickerPresets = [
|
|
6
|
-
{ label: '今天', value: [dayjs().startOf('day'), dayjs().endOf('day')] },
|
|
7
|
-
{ label: '昨天', value: [dayjs().subtract(1, 'day').startOf('day'), dayjs().subtract(1, 'day').endOf('day')] },
|
|
8
|
-
{ label: '
|
|
9
|
-
{ label: '
|
|
10
|
-
{ label: '
|
|
11
|
-
{ label: '
|
|
12
|
-
{ label: '
|
|
13
|
-
|
|
14
|
-
{ label: '上上月', value: [dayjs().subtract(2, 'month').startOf('month'), dayjs().subtract(2, 'month').endOf('month')] },
|
|
15
|
-
{ label: '近7天', value: [dayjs().subtract(6, 'day').startOf('day'), dayjs().endOf('day')] },
|
|
16
|
-
{ label: '近30天', value: [dayjs().subtract(29, 'day').startOf('day'), dayjs().endOf('day')] },
|
|
17
|
-
] as { label: string; value: [Dayjs, Dayjs] }[]
|
|
6
|
+
{ label: '今天', key: 'today', value: [dayjs().startOf('day'), dayjs().endOf('day')] },
|
|
7
|
+
{ label: '昨天', key: 'yesterday', value: [dayjs().subtract(1, 'day').startOf('day'), dayjs().subtract(1, 'day').endOf('day')] },
|
|
8
|
+
{ label: '本月', key: 'thisMonth', value: [dayjs().startOf('month'), dayjs().endOf('month')] },
|
|
9
|
+
{ label: '上个月', key: 'lastMonth', value: [dayjs().subtract(1, 'month').startOf('month'), dayjs().subtract(1, 'month').endOf('month')] },
|
|
10
|
+
{ label: '近3个月', key: 'last3months', value: [dayjs().subtract(2, 'month').startOf('month'), dayjs().endOf('month')] },
|
|
11
|
+
{ label: '近半年', key: 'last6months', value: [dayjs().subtract(5, 'month').startOf('month'), dayjs().endOf('month')] },
|
|
12
|
+
{ label: '今年', key: 'thisMonth', value: [dayjs().startOf('year'), dayjs().endOf('month')] },
|
|
13
|
+
] as { label: string; key: string; value: [Dayjs, Dayjs] }[]
|
|
18
14
|
|
|
19
15
|
export const antdRangePickerShowTimeProps: ComponentProps<typeof RangePicker> = {
|
|
20
16
|
presets: antdRangePickerPresets,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<!-- eslint-disable jsdoc/no-multi-asterisks -->
|
|
2
2
|
|
|
3
3
|
<script setup lang="ts">
|
|
4
|
+
import { computed } from 'vue';
|
|
4
5
|
import type { BigNumber } from 'bignumber.js';
|
|
5
6
|
import bignumber from 'bignumber.js';
|
|
6
|
-
import CurrencyIcon from '../../currency/src/CurrencyIcon.vue';
|
|
7
|
+
import CurrencyIcon, {textIcons} from '../../currency/src/CurrencyIcon.vue';
|
|
7
8
|
import Num from './Num.vue';
|
|
8
9
|
|
|
9
10
|
// 由于 Vue 目前不支持 Props `interface AmountProps extends CurrencyIconProps, NumProps{}` 多继承写法,所以暂时这样写
|
|
@@ -95,10 +96,14 @@ const props = withDefaults(defineProps<AmountProps>(), {
|
|
|
95
96
|
useNumColor: false,
|
|
96
97
|
precision: 0,
|
|
97
98
|
});
|
|
99
|
+
|
|
100
|
+
const isTextIcon = computed(() => {
|
|
101
|
+
return props.iconType === 'text' || textIcons.value.includes(String(props.symbol));
|
|
102
|
+
});
|
|
98
103
|
</script>
|
|
99
104
|
|
|
100
105
|
<template>
|
|
101
|
-
<span class="amount flex-inline" :class="[
|
|
106
|
+
<span class="amount flex-inline" :class="[isTextIcon ? 'items-baseline' : 'items-center']">
|
|
102
107
|
<CurrencyIcon v-if="props.iconPos === 'left' && props.symbol && !props.useNumColor" v-bind="props" class="currency-icon" />
|
|
103
108
|
<Num v-bind="props" :value="bignumber(props.value ?? 0).dividedBy(10 ** props.precision)">
|
|
104
109
|
<template #signLeft>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { computed, reactive, ref
|
|
1
|
+
import { computed, reactive, ref } from 'vue';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
|
+
import { useTableColumns } from './useTableColumns'
|
|
3
4
|
import type { UseQueryReturnType } from '@tanstack/vue-query';
|
|
4
5
|
import type { Table, TableProps } from 'ant-design-vue';
|
|
5
6
|
import type { ColumnType, FilterValue } from 'ant-design-vue/es/table/interface';
|
|
@@ -10,6 +11,12 @@ interface ISorter {
|
|
|
10
11
|
order?: string
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
15
|
+
? D extends Api.PageData
|
|
16
|
+
? NonNullable<D['list']>[0]
|
|
17
|
+
: never
|
|
18
|
+
: never;
|
|
19
|
+
|
|
13
20
|
const defaultPageSizeOptions = ['10', '20', '50', '100'];
|
|
14
21
|
|
|
15
22
|
export function useAntdTable<
|
|
@@ -125,58 +132,3 @@ export function useAntdTable<
|
|
|
125
132
|
};
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
129
|
-
? D extends Api.PageData
|
|
130
|
-
? NonNullable<D['list']>[0]
|
|
131
|
-
: never
|
|
132
|
-
: never;
|
|
133
|
-
|
|
134
|
-
export type ColumnConfig = { title: string, dataIndex: string, visible: boolean, compact: boolean }
|
|
135
|
-
|
|
136
|
-
function useTableColumns<LCT extends any[]>() {
|
|
137
|
-
|
|
138
|
-
const columnsConfig = ref<Array<ColumnConfig> | null>(null);
|
|
139
|
-
let originalColumns: LCT | null = null;
|
|
140
|
-
|
|
141
|
-
const defineColumns = (columnsGetter: () => LCT) => {
|
|
142
|
-
originalColumns = toValue(columnsGetter) || [] as unknown as LCT;
|
|
143
|
-
|
|
144
|
-
return computed(() => {
|
|
145
|
-
const config = columnsConfig.value;
|
|
146
|
-
let columns = columnsGetter();
|
|
147
|
-
|
|
148
|
-
if (config?.length) {
|
|
149
|
-
columns = columns.map((col: any) => {
|
|
150
|
-
const x = config.find(c => c.dataIndex === col.dataIndex);
|
|
151
|
-
if (x) {
|
|
152
|
-
return { ...col, visible: x.visible, compact: x.compact,};
|
|
153
|
-
}
|
|
154
|
-
return col;
|
|
155
|
-
}) as LCT;
|
|
156
|
-
// 过滤掉不可见的列
|
|
157
|
-
// columns = columns.filter((col: any) => {
|
|
158
|
-
// const x = config.find(c => c.dataIndex === col.dataIndex);
|
|
159
|
-
// return x ? x.visible : true;
|
|
160
|
-
// }) as LCT;
|
|
161
|
-
// 基于 config 的顺序排序
|
|
162
|
-
columns = config.map(x => {
|
|
163
|
-
const col = columns.find(c => c.dataIndex === x.dataIndex);
|
|
164
|
-
return col ? col : null;
|
|
165
|
-
}).filter(Boolean) as LCT;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return columns;
|
|
169
|
-
})
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const setColumnsConfig = (columns: Array<ColumnConfig>) => {
|
|
173
|
-
columnsConfig.value = columns;
|
|
174
|
-
console.log('🤡 / columns:', columns);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
defineColumns,
|
|
180
|
-
setColumnsConfig
|
|
181
|
-
};
|
|
182
|
-
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { computed, reactive, ref, toValue, getCurrentInstance } from 'vue';
|
|
2
|
+
import { extendRef } from '@vueuse/core';
|
|
3
|
+
|
|
4
|
+
export type ColumnConfig = { title: string, dataIndex: string, visible: boolean, compact: boolean }
|
|
5
|
+
|
|
6
|
+
export function useTableColumns<LCT extends any[]>() {
|
|
7
|
+
const columnsConfig = ref<Array<ColumnConfig> | null>(null);
|
|
8
|
+
let originalColumns: LCT | null = null;
|
|
9
|
+
let tableId = ''
|
|
10
|
+
|
|
11
|
+
const _getTableId = () => {
|
|
12
|
+
if (!originalColumns)
|
|
13
|
+
throw new Error('请先调用 defineColumns() 方法定义 columns');
|
|
14
|
+
|
|
15
|
+
const indexsStr = originalColumns.map((col: any) => col.dataIndex).join(',');
|
|
16
|
+
if (!tableId) {
|
|
17
|
+
tableId = genTableId(indexsStr);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return tableId;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const defineColumns = (columnsGetter: () => LCT) => {
|
|
24
|
+
originalColumns = toValue(columnsGetter) || [] as unknown as LCT;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const columns = computed(() => {
|
|
28
|
+
const config = columnsConfig.value;
|
|
29
|
+
let columns = columnsGetter();
|
|
30
|
+
|
|
31
|
+
if (config?.length) {
|
|
32
|
+
columns = columns.map((col: any) => {
|
|
33
|
+
const x = config.find(c => c.dataIndex === col.dataIndex);
|
|
34
|
+
if (x) {
|
|
35
|
+
return { ...col, visible: x.visible, compact: x.compact, };
|
|
36
|
+
}
|
|
37
|
+
return col;
|
|
38
|
+
}) as LCT;
|
|
39
|
+
// 过滤掉不可见的列
|
|
40
|
+
// columns = columns.filter((col: any) => {
|
|
41
|
+
// const x = config.find(c => c.dataIndex === col.dataIndex);
|
|
42
|
+
// return x ? x.visible : true;
|
|
43
|
+
// }) as LCT;
|
|
44
|
+
// 基于 config 的顺序排序
|
|
45
|
+
columns = config.map(x => {
|
|
46
|
+
const col = columns.find(c => c.dataIndex === x.dataIndex);
|
|
47
|
+
return col ? col : null;
|
|
48
|
+
}).filter(Boolean) as LCT;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return columns;
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return extendRef(columns, {});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getColumnsConfig = () => {
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const setColumnsConfig = (columns: Array<ColumnConfig>) => {
|
|
62
|
+
columnsConfig.value = columns;
|
|
63
|
+
console.log('🤡 / columns:', columns);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
defineColumns,
|
|
68
|
+
setColumnsConfig
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class TableConfigurator {
|
|
73
|
+
private tableId: string | null = null;
|
|
74
|
+
private storeKeyPrefix = 'TABLE_CONFIG';
|
|
75
|
+
private _columnsConfig: Array<ColumnConfig> | null = null;
|
|
76
|
+
public originalColumns: any[] | null = null;
|
|
77
|
+
|
|
78
|
+
public setColumnsConfig() {
|
|
79
|
+
const tableId = this.genTableId();
|
|
80
|
+
const key = `${this.storeKeyPrefix}@${tableId}`;
|
|
81
|
+
const configStr = JSON.stringify(this._columnsConfig);
|
|
82
|
+
|
|
83
|
+
localStorage.setItem(key, configStr);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getColumnsConfig() {
|
|
87
|
+
const tableId = this.genTableId();
|
|
88
|
+
const key = `${this.storeKeyPrefix}@${tableId}`;
|
|
89
|
+
const configStr = localStorage.getItem(key);
|
|
90
|
+
|
|
91
|
+
if (configStr) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(configStr);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public genTableId() {
|
|
104
|
+
if (!this.originalColumns)
|
|
105
|
+
throw new Error('originalColumns 未设置');
|
|
106
|
+
|
|
107
|
+
if (this.tableId)
|
|
108
|
+
return this.tableId;
|
|
109
|
+
|
|
110
|
+
const str = this.originalColumns.map((col: any) => col.dataIndex).join('');
|
|
111
|
+
let hash = 0;
|
|
112
|
+
let len = 12;
|
|
113
|
+
|
|
114
|
+
for (let i = 0; i < str.length; i++) {
|
|
115
|
+
const ch = str.charCodeAt(i);
|
|
116
|
+
hash = (hash << 5) - hash + ch;
|
|
117
|
+
hash |= 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const base36 = (hash >>> 0).toString(36);
|
|
121
|
+
this.tableId = base36.length >= len ? base36.slice(0, len) : base36.padStart(len, '0');
|
|
122
|
+
return this.tableId;
|
|
123
|
+
}
|
|
124
|
+
}
|