@peng_kai/kit 0.3.0-beta.13 → 0.3.0-beta.14
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.
- package/admin/components/date/helpers.ts +28 -19
- package/admin/components/filter/src/FilterReset.vue +7 -1
- package/admin/components/filter/src/more/TableSetting.vue +14 -0
- package/admin/layout/large/Notice.vue +2 -2
- package/antd/hooks/useAntdModal.ts +9 -7
- package/antd/hooks/useAntdTable.ts +18 -14
- package/package.json +1 -1
|
@@ -48,20 +48,20 @@ export const datetime = {
|
|
|
48
48
|
* 将日期范围转换为 API 参数格式的时间戳范围
|
|
49
49
|
* @param days 时间范围元组,包含开始和结束时间
|
|
50
50
|
* @param unit 时间单位,默认为 'day'
|
|
51
|
-
* @param
|
|
51
|
+
* @param useAppTz 是否使用时区,默认为 true
|
|
52
52
|
* @param keys 可选的键名元组,默认为 ['start_time', 'end_time']
|
|
53
53
|
* @returns 返回一个对象,包含开始和结束时间的时间戳
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
toRangeForApiParams<KS extends readonly [string, string] = ['start_time', 'end_time']>(
|
|
56
56
|
days: Array<OfDayType | undefined | null> | undefined | null,
|
|
57
57
|
unit: UnitType = 'day',
|
|
58
|
-
|
|
58
|
+
useAppTz: boolean = true,
|
|
59
59
|
keys?: KS
|
|
60
60
|
) {
|
|
61
61
|
if (!days || !days[0] || !days[1])
|
|
62
62
|
return undefined;
|
|
63
63
|
|
|
64
|
-
const tz =
|
|
64
|
+
const tz = useAppTz ? getTtaTimeZone().value : dayjs.tz.guess();
|
|
65
65
|
const _keys = (Array.isArray(keys) && keys?.length > 1) ? keys : ['start_time', 'end_time'];
|
|
66
66
|
|
|
67
67
|
type RetType = KS extends readonly [string, string]
|
|
@@ -76,48 +76,58 @@ export const datetime = {
|
|
|
76
76
|
/**
|
|
77
77
|
* 将日期范围转换为表单使用的时间范围
|
|
78
78
|
* @param days 时间范围元组,包含开始和结束时间
|
|
79
|
-
* @param
|
|
80
|
-
* @
|
|
79
|
+
* @param defaultRangeUnit 默认的时间范围单位,如果未提供,则返回 undefined
|
|
80
|
+
* @return 返回一个包含开始和结束时间的元组,格式为 dayjs 对象
|
|
81
81
|
*/
|
|
82
82
|
toRangeForForm(
|
|
83
83
|
days: Array<OfDayType | string | undefined | null>,
|
|
84
|
-
|
|
84
|
+
defaultRangeUnit?: UnitType,
|
|
85
85
|
) {
|
|
86
|
+
const getDefaultRange = () => {
|
|
87
|
+
const now = dayjs();
|
|
88
|
+
return defaultRangeUnit
|
|
89
|
+
? [now.startOf(defaultRangeUnit), now.endOf(defaultRangeUnit)] as [dayjs.Dayjs, dayjs.Dayjs]
|
|
90
|
+
: undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
if (!days || !days[0] || !days[1])
|
|
87
|
-
return
|
|
94
|
+
return getDefaultRange();
|
|
88
95
|
|
|
89
|
-
const sDay = dayjs(typeof days[0] === 'string' ? Number(days[0]) : days[0].valueOf());
|
|
90
|
-
const eDay = dayjs(typeof days[1] === 'string' ? Number(days[1]) : days[1].valueOf());
|
|
96
|
+
// const sDay = dayjs(typeof days[0] === 'string' ? Number(days[0]) : days[0].valueOf());
|
|
97
|
+
// const eDay = dayjs(typeof days[1] === 'string' ? Number(days[1]) : days[1].valueOf());
|
|
98
|
+
const [sDay, eDay] = days.map(d => dayjs(typeof d === 'string' ? Number(d) : d?.valueOf()));
|
|
91
99
|
|
|
92
100
|
if (!sDay.isValid() || !eDay.isValid())
|
|
93
|
-
return
|
|
101
|
+
return getDefaultRange();
|
|
94
102
|
|
|
95
|
-
return [sDay
|
|
103
|
+
return [sDay, eDay] as [dayjs.Dayjs, dayjs.Dayjs];
|
|
96
104
|
},
|
|
97
105
|
/**
|
|
98
106
|
* 获取指定日期的开始时间
|
|
99
107
|
* @param unit 时间单位
|
|
100
108
|
* @param day 日期对象
|
|
109
|
+
* @param useAppTz 是否使用应用时区,默认为 true
|
|
101
110
|
* @returns 返回指定日期的开始时间,格式为 dayjs 对象
|
|
102
111
|
*/
|
|
103
|
-
ofStart(unit: UnitType, day: OfDayType) {
|
|
112
|
+
ofStart(unit: UnitType, day: OfDayType, useAppTz = true) {
|
|
104
113
|
if (!day)
|
|
105
114
|
return undefined;
|
|
106
115
|
|
|
107
|
-
const tz = getTtaTimeZone().value;
|
|
116
|
+
const tz = useAppTz ? getTtaTimeZone().value : dayjs.tz.guess();
|
|
108
117
|
return dayjs(day.valueOf()).tz(tz).startOf(unit);
|
|
109
118
|
},
|
|
110
119
|
/**
|
|
111
120
|
* 获取指定日期的结束时间
|
|
112
121
|
* @param unit 时间单位
|
|
113
122
|
* @param day 日期对象
|
|
123
|
+
* @param useAppTz 是否使用应用时区,默认为 true
|
|
114
124
|
* @returns 返回指定日期的结束时间,格式为 dayjs 对象
|
|
115
125
|
*/
|
|
116
|
-
ofEnd(unit: UnitType, day: OfDayType) {
|
|
126
|
+
ofEnd(unit: UnitType, day: OfDayType, useAppTz = true) {
|
|
117
127
|
if (!day)
|
|
118
128
|
return undefined;
|
|
119
129
|
|
|
120
|
-
const tz = getTtaTimeZone().value;
|
|
130
|
+
const tz = useAppTz ? getTtaTimeZone().value : dayjs.tz.guess();
|
|
121
131
|
return dayjs(day.valueOf()).tz(tz).endOf(unit);
|
|
122
132
|
},
|
|
123
133
|
}
|
|
@@ -201,10 +211,9 @@ export function useRangePickerPropsForTz(
|
|
|
201
211
|
const newTzOffset = dayjs().tz(newV).utcOffset();
|
|
202
212
|
const oldTzOffset = dayjs().tz(oldV).utcOffset();
|
|
203
213
|
value.value = [
|
|
204
|
-
dayjs(v[0]).add((oldTzOffset - newTzOffset) * 60 * 1000),
|
|
205
|
-
dayjs(v[1]).add((oldTzOffset - newTzOffset) * 60 * 1000),
|
|
214
|
+
dayjs(v[0].valueOf()).add((oldTzOffset - newTzOffset) * 60 * 1000),
|
|
215
|
+
dayjs(v[1].valueOf()).add((oldTzOffset - newTzOffset) * 60 * 1000),
|
|
206
216
|
]
|
|
207
|
-
console.log('🤡 / value.value:', value.value[0].valueOf())
|
|
208
217
|
});
|
|
209
218
|
|
|
210
219
|
return reactive({
|
|
@@ -16,6 +16,7 @@ const props = withDefaults(defineProps<{
|
|
|
16
16
|
const emits = defineEmits<{
|
|
17
17
|
(e: 'filter'): void
|
|
18
18
|
(e: 'reset'): void
|
|
19
|
+
(e: 'setColumnsConfig', columnsConfig: any): void
|
|
19
20
|
}>();
|
|
20
21
|
|
|
21
22
|
const loading = computed(() => {
|
|
@@ -48,7 +49,12 @@ function openTableSettingModal() {
|
|
|
48
49
|
title: typeof x.title === 'string' ? x.title : x.dataIndex || '',
|
|
49
50
|
})) || [];
|
|
50
51
|
|
|
51
|
-
TableSettingModal.open({ tableColumns })
|
|
52
|
+
TableSettingModal.open({ tableColumns })?.then((res) => {
|
|
53
|
+
TableSettingModal.close();
|
|
54
|
+
if (res) {
|
|
55
|
+
emits('setColumnsConfig', res);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
onTtaTimeZone(() => {
|
|
@@ -3,6 +3,7 @@ import { RadioGroup,type TableColumnsType } from 'ant-design-vue';
|
|
|
3
3
|
import { reactive, defineAsyncComponent, ref } from 'vue';
|
|
4
4
|
import { useDragAndDrop } from "fluid-dnd/vue";
|
|
5
5
|
import { useAntdModal } from '../../../../../antd/hooks/useAntdModal';
|
|
6
|
+
import { type ColumnConfig } from '../../../../../antd/hooks/useAntdTable';
|
|
6
7
|
|
|
7
8
|
export const TableSettingModal = useAntdModal(
|
|
8
9
|
// eslint-disable-next-line import/no-self-import
|
|
@@ -24,6 +25,7 @@ const columnsConfig = ref(props.tableColumns.map((col: any) => ({
|
|
|
24
25
|
title: col.title as string,
|
|
25
26
|
dataIndex: col.dataIndex as string,
|
|
26
27
|
visible: col.visible !== false,
|
|
28
|
+
compact: col.compact === true,
|
|
27
29
|
})));
|
|
28
30
|
const columnsShowOptions = reactive(Object.fromEntries(props.tableColumns.map((col: any) => {
|
|
29
31
|
const options = [{ label: '显示', value: 'show' }, { label: '隐藏', value: 'hidden' }];
|
|
@@ -40,6 +42,18 @@ const [$ctn] = useDragAndDrop(columnsConfig, {
|
|
|
40
42
|
draggingClass: 'op-50',
|
|
41
43
|
direction: 'vertical',
|
|
42
44
|
});
|
|
45
|
+
|
|
46
|
+
defineExpose({
|
|
47
|
+
confirm(_: any, resolve: (data: any) => void) {
|
|
48
|
+
const newColumnsConfig = columnsConfig.value.map((col) => ({
|
|
49
|
+
...col,
|
|
50
|
+
visible: columnsShowValue[col.dataIndex] !== 'hidden',
|
|
51
|
+
compact: columnsShowValue[col.dataIndex] === 'compact',
|
|
52
|
+
})) as ColumnConfig[];
|
|
53
|
+
resolve(newColumnsConfig);
|
|
54
|
+
return true;
|
|
55
|
+
},
|
|
56
|
+
})
|
|
43
57
|
</script>
|
|
44
58
|
|
|
45
59
|
<template>
|
|
@@ -5,7 +5,7 @@ import { type UseQueryReturnType } from '@tanstack/vue-query'
|
|
|
5
5
|
import { watch, ref, computed } from 'vue'
|
|
6
6
|
import dayjs from '../../../libs/dayjs';
|
|
7
7
|
import { useRouter } from 'vue-router';
|
|
8
|
-
import audioURL from './y682.mp3';
|
|
8
|
+
import audioURL from './y682.mp3?url';
|
|
9
9
|
|
|
10
10
|
const noticeAudio = new Audio(audioURL);
|
|
11
11
|
noticeAudio.src = audioURL;
|
|
@@ -88,7 +88,7 @@ useIntervalFn(() => {
|
|
|
88
88
|
<i class="i-ri:notification-4-line block text-5" :class="{ shake: !!noticeNum }" />
|
|
89
89
|
</div>
|
|
90
90
|
<template #overlay>
|
|
91
|
-
<Menu v-if="noticeNum" @click="visible = false">
|
|
91
|
+
<Menu v-if="noticeNum" @click="visible = false" class="max-h-100 overflow-y-auto">
|
|
92
92
|
<MenuItem v-for="(item, i) of noticesQry.data.value" :key="i" @click="operate(item)">
|
|
93
93
|
<div class="min-w-50">
|
|
94
94
|
<div>{{ item.title }}</div>
|
|
@@ -53,8 +53,10 @@ export function useAntdModal<Comp extends Component>(
|
|
|
53
53
|
...defaultModalProps,
|
|
54
54
|
...isProxy(modalProps) ? toRefs(modalProps) : modalProps,
|
|
55
55
|
confirmLoading: toRef(() => (refs.comp as any)?.loading),
|
|
56
|
-
onOk: (e: MouseEvent) => {
|
|
57
|
-
|
|
56
|
+
onOk: async (e: MouseEvent) => {
|
|
57
|
+
const comp = refs.comp as any;
|
|
58
|
+
const isClosed = await comp?.confirm?.(e, (data: any) => promiseResolvers?.resolve(data));
|
|
59
|
+
// isClosed === true && (_modalProps.open = false);
|
|
58
60
|
modalProps.onOk?.(e);
|
|
59
61
|
},
|
|
60
62
|
});
|
|
@@ -96,11 +98,11 @@ export function useAntdModal<Comp extends Component>(
|
|
|
96
98
|
|
|
97
99
|
return promiseResolvers.promise;
|
|
98
100
|
};
|
|
99
|
-
const
|
|
101
|
+
const onConfirm = (ev: any) => {
|
|
100
102
|
_modalProps.open = false;
|
|
101
103
|
promiseResolvers.resolve(ev);
|
|
102
104
|
};
|
|
103
|
-
const
|
|
105
|
+
const onClose = (reason?: any) => {
|
|
104
106
|
_modalProps.open = false;
|
|
105
107
|
_onClose(reason);
|
|
106
108
|
};
|
|
@@ -122,8 +124,8 @@ export function useAntdModal<Comp extends Component>(
|
|
|
122
124
|
!visiable && _onClose();
|
|
123
125
|
};
|
|
124
126
|
(compProps as any).ref = setRefs.comp;
|
|
125
|
-
(compProps as any).onClose =
|
|
126
|
-
(compProps as any).onConfirm =
|
|
127
|
+
(compProps as any).onClose = onClose;
|
|
128
|
+
(compProps as any).onConfirm = onConfirm;
|
|
127
129
|
|
|
128
130
|
tryOnBeforeUnmount(_onClose);
|
|
129
131
|
onDeactivated(_onClose);
|
|
@@ -136,6 +138,6 @@ export function useAntdModal<Comp extends Component>(
|
|
|
136
138
|
return refs.comp;
|
|
137
139
|
},
|
|
138
140
|
open,
|
|
139
|
-
close,
|
|
141
|
+
close: onClose,
|
|
140
142
|
};
|
|
141
143
|
}
|
|
@@ -54,7 +54,7 @@ export function useAntdTable<
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
const { defineColumns } = useTableColumns<LocalColumnsType>();
|
|
57
|
+
const { defineColumns, setColumnsConfig } = useTableColumns<LocalColumnsType>();
|
|
58
58
|
const defineRowSelection = (rowSelectionGetter: () => LocalTableRowSelection = () => ({})) => {
|
|
59
59
|
const rowSelection = reactive(rowSelectionGetter());
|
|
60
60
|
|
|
@@ -114,8 +114,10 @@ export function useAntdTable<
|
|
|
114
114
|
dataIndexs,
|
|
115
115
|
/** 【类型辅助】bodyCell 插槽数据的精确类型描述 */
|
|
116
116
|
bodyCellType,
|
|
117
|
-
/**
|
|
117
|
+
/** 用于定义 columns */
|
|
118
118
|
defineColumns,
|
|
119
|
+
/** 用于设置 columns 的配置 */
|
|
120
|
+
setColumnsConfig,
|
|
119
121
|
/** 【类型辅助】用于定义出类型精确的 rowSelection */
|
|
120
122
|
defineRowSelection,
|
|
121
123
|
/** 内置的 ATable onChange 事件,默认在 `tableProps` 中 */
|
|
@@ -129,8 +131,9 @@ type GetRecordType<T> = T extends UseQueryReturnType<infer D, any>
|
|
|
129
131
|
: never
|
|
130
132
|
: never;
|
|
131
133
|
|
|
134
|
+
export type ColumnConfig = { title: string, dataIndex: string, visible: boolean, compact: boolean }
|
|
135
|
+
|
|
132
136
|
function useTableColumns<LCT extends any[]>() {
|
|
133
|
-
type ColumnConfig = {title: string, dataIndex: string, visible: boolean}
|
|
134
137
|
|
|
135
138
|
const columnsConfig = ref<Array<ColumnConfig> | null>(null);
|
|
136
139
|
let originalColumns: LCT | null = null;
|
|
@@ -143,11 +146,18 @@ function useTableColumns<LCT extends any[]>() {
|
|
|
143
146
|
let columns = columnsGetter();
|
|
144
147
|
|
|
145
148
|
if (config?.length) {
|
|
146
|
-
|
|
147
|
-
columns = columns.filter((col: any) => {
|
|
149
|
+
columns = columns.map((col: any) => {
|
|
148
150
|
const x = config.find(c => c.dataIndex === col.dataIndex);
|
|
149
|
-
|
|
151
|
+
if (x) {
|
|
152
|
+
return { ...col, visible: x.visible, compact: x.compact,};
|
|
153
|
+
}
|
|
154
|
+
return col;
|
|
150
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;
|
|
151
161
|
// 基于 config 的顺序排序
|
|
152
162
|
columns = config.map(x => {
|
|
153
163
|
const col = columns.find(c => c.dataIndex === x.dataIndex);
|
|
@@ -161,18 +171,12 @@ function useTableColumns<LCT extends any[]>() {
|
|
|
161
171
|
|
|
162
172
|
const setColumnsConfig = (columns: Array<ColumnConfig>) => {
|
|
163
173
|
columnsConfig.value = columns;
|
|
164
|
-
|
|
165
|
-
// if (!columnsConfig.value) {
|
|
166
|
-
// columnsConfig.value = originalColumns?.map(col => ({
|
|
167
|
-
// title: col.title,
|
|
168
|
-
// dataIndex: col.dataIndex as string,
|
|
169
|
-
// visible: true,
|
|
170
|
-
// })) || [];
|
|
171
|
-
// }
|
|
174
|
+
console.log('🤡 / columns:', columns);
|
|
172
175
|
};
|
|
173
176
|
|
|
174
177
|
|
|
175
178
|
return {
|
|
176
179
|
defineColumns,
|
|
180
|
+
setColumnsConfig
|
|
177
181
|
};
|
|
178
182
|
}
|