@peng_kai/kit 0.3.0-beta.12 → 0.3.0-beta.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.
@@ -3,6 +3,10 @@ import { tryOnScopeDispose } from '@vueuse/core';
3
3
  import { computed, reactive, watch, ref, type Ref } from 'vue';
4
4
  import type { Simplify } from 'type-fest';
5
5
 
6
+ /**
7
+ * 获取应用的时区,默认使用浏览器的时区
8
+ * @returns 返回一个响应式的时区字符串
9
+ */
6
10
  export function getTtaTimeZone() {
7
11
  const win = window as any;
8
12
  const key = '__APP_TZ__';
@@ -10,6 +14,9 @@ export function getTtaTimeZone() {
10
14
  return (win[key] || (win[key] = ref(dayjs.tz.guess()))) as Ref<string>;
11
15
  }
12
16
 
17
+ /**
18
+ * 监听应用的时区变化的函数
19
+ */
13
20
  export const onTtaTimeZone = (() => {
14
21
  const ttaTz = getTtaTimeZone();
15
22
  const cbList: any[] = [];
@@ -34,47 +41,85 @@ export const onTtaTimeZone = (() => {
34
41
  }
35
42
  })();
36
43
 
37
- type OfDayType = Dayjs | undefined | null;
44
+ type OfDayType = dayjs.Dayjs | undefined | null;
38
45
  type UnitType = dayjs.QUnitType | dayjs.OpUnitType;
39
- export const dayOf = {
40
- rangeTs<KS extends readonly [string, string] = ['start_time', 'end_time']>(
41
- unit: UnitType,
42
- day: Array<OfDayType> | undefined | null,
46
+ export const datetime = {
47
+ /**
48
+ * 将日期范围转换为 API 参数格式的时间戳范围
49
+ * @param days 时间范围元组,包含开始和结束时间
50
+ * @param unit 时间单位,默认为 'day'
51
+ * @param useTz 是否使用时区,默认为 true
52
+ * @param keys 可选的键名元组,默认为 ['start_time', 'end_time']
53
+ * @returns 返回一个对象,包含开始和结束时间的时间戳
54
+ */
55
+ toTsRangeForApiParams<KS extends readonly [string, string] = ['start_time', 'end_time']>(
56
+ days: Array<OfDayType | undefined | null> | undefined | null,
57
+ unit: UnitType = 'day',
58
+ useTz: boolean = true,
43
59
  keys?: KS
44
- ): KS extends readonly [string, string]
45
- ? Simplify<{ [K in KS[0]]: number } & { [K in KS[1]]: number }>
46
- : { start_time: number; end_time: number } {
47
- if (!day || !day[0] || !day[1])
48
- return undefined as any;
60
+ ) {
61
+ if (!days || !days[0] || !days[1])
62
+ return undefined;
49
63
 
50
- const tz = getTtaTimeZone().value;
64
+ const tz = useTz ? getTtaTimeZone().value : dayjs.tz.guess();
51
65
  const _keys = (Array.isArray(keys) && keys?.length > 1) ? keys : ['start_time', 'end_time'];
52
66
 
67
+ type RetType = KS extends readonly [string, string]
68
+ ? Simplify<{ [K in KS[0]]: number } & { [K in KS[1]]: number }>
69
+ : { start_time: number; end_time: number };
70
+
53
71
  return {
54
- [_keys[0]]: dayjs(day[0].valueOf()).tz(tz).startOf(unit).valueOf(),
55
- [_keys[1]]: dayjs(day[1].valueOf()).tz(tz).endOf(unit).valueOf(),
56
- } as any;
72
+ [_keys[0]]: dayjs(days[0].valueOf()).tz(tz).startOf(unit).valueOf(),
73
+ [_keys[1]]: dayjs(days[1].valueOf()).tz(tz).endOf(unit).valueOf(),
74
+ } as RetType;
57
75
  },
58
- start(unit: UnitType, day: OfDayType) {
76
+ /**
77
+ * 将日期范围转换为表单使用的时间范围
78
+ * @param days 时间范围元组,包含开始和结束时间
79
+ * @param unit 时间单位,默认为 'day'
80
+ * @returns 返回一个包含开始和结束时间的元组,格式为 [start, end],其中 start 和 end 是 dayjs 对象
81
+ */
82
+ toRangeForForm(
83
+ days: Array<OfDayType | string | undefined | null>,
84
+ unit: UnitType = 'day',
85
+ ) {
86
+ if (!days || !days[0] || !days[1])
87
+ return undefined;
88
+
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());
91
+
92
+ if (!sDay.isValid() || !eDay.isValid())
93
+ return undefined;
94
+
95
+ return [sDay.startOf(unit), eDay.endOf(unit)] as [dayjs.Dayjs, dayjs.Dayjs];
96
+ },
97
+ /**
98
+ * 获取指定日期的开始时间
99
+ * @param unit 时间单位
100
+ * @param day 日期对象
101
+ * @returns 返回指定日期的开始时间,格式为 dayjs 对象
102
+ */
103
+ ofStart(unit: UnitType, day: OfDayType) {
59
104
  if (!day)
60
105
  return undefined;
61
106
 
62
107
  const tz = getTtaTimeZone().value;
63
108
  return dayjs(day.valueOf()).tz(tz).startOf(unit);
64
109
  },
65
- startTs(unit: UnitType, day: OfDayType) {
66
- this.start(unit, day);
67
- },
68
- end(unit: UnitType, day: OfDayType) {
110
+ /**
111
+ * 获取指定日期的结束时间
112
+ * @param unit 时间单位
113
+ * @param day 日期对象
114
+ * @returns 返回指定日期的结束时间,格式为 dayjs 对象
115
+ */
116
+ ofEnd(unit: UnitType, day: OfDayType) {
69
117
  if (!day)
70
118
  return undefined;
71
119
 
72
120
  const tz = getTtaTimeZone().value;
73
121
  return dayjs(day.valueOf()).tz(tz).endOf(unit);
74
122
  },
75
- endTs(unit: UnitType, day: OfDayType) {
76
- this.end(unit, day);
77
- },
78
123
  }
79
124
 
80
125
  /** 为 DatePicker 组件提供响应式时区支持,当时区更新时,自动调整时间戳 */
@@ -1,4 +1,4 @@
1
1
  export { default as TimeFieldSelectForLabel } from './TimeFieldSelectForLabel.vue';
2
2
  export { default as TtaTimeZone } from './TtaTimeZone.vue';
3
3
  export { default as PeriodPicker } from './PeriodPicker.vue';
4
- export { useDatePickerPropsForTz, useRangePickerPropsForTz, getTtaTimeZone, onTtaTimeZone, dayOf } from './helpers';
4
+ export { useDatePickerPropsForTz, useRangePickerPropsForTz, getTtaTimeZone, onTtaTimeZone, datetime } from './helpers';
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { Button, Switch, Divider, Select, type TableColumnsType } from 'ant-design-vue';
2
+ 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';
@@ -10,17 +10,10 @@ export const TableSettingModal = useAntdModal(
10
10
  {
11
11
  title: '表格设置',
12
12
  width: 500,
13
- // footer: null,
14
13
  centered: true,
15
14
  maskClosable: false,
16
15
  }
17
16
  );
18
-
19
- const showTypeOptions = [
20
- { label: '显示', value: 'show' },
21
- { label: '简略', value: 'simple' },
22
- { label: '隐藏', value: 'hidden' },
23
- ];
24
17
  </script>
25
18
 
26
19
  <script lang="ts" setup>
@@ -32,6 +25,15 @@ const columnsConfig = ref(props.tableColumns.map((col: any) => ({
32
25
  dataIndex: col.dataIndex as string,
33
26
  visible: col.visible !== false,
34
27
  })));
28
+ const columnsShowOptions = reactive(Object.fromEntries(props.tableColumns.map((col: any) => {
29
+ const options = [{ label: '显示', value: 'show' }, { label: '隐藏', value: 'hidden' }];
30
+ col.compactable === true && options.unshift({ label: '简略', value: 'compact' });
31
+ return [col.dataIndex, options];
32
+ })) as Record<string, { value: string; options: string }[]>);
33
+ const columnsShowValue = reactive(Object.fromEntries(props.tableColumns.map((col: any) => {
34
+ const value = col.visible === false ? 'hidden' : (col.compact === true && col.compactable === true) ? 'compact' : 'show';
35
+ return [col.dataIndex, value]
36
+ })) as Record<string, string>);
35
37
 
36
38
  const [$ctn] = useDragAndDrop(columnsConfig, {
37
39
  handlerSelector: '.drag-handler',
@@ -43,21 +45,24 @@ const [$ctn] = useDragAndDrop(columnsConfig, {
43
45
  <template>
44
46
  <div>
45
47
  <div>
46
- <Divider>列设置</Divider>
48
+ <!-- <Divider>列设置</Divider> -->
47
49
  <div ref="$ctn">
48
- <div v-for="(col, i) in columnsConfig" :key="col.dataIndex" :index="i" class="flex items-center gap-2 p-2 select-none">
49
- <div class="drag-handler flex items-center justify-center cursor-move p-1 -m-2">
50
- <i class="i-material-symbols:drag-indicator" />
50
+ <div
51
+ v-for="(col, i) in columnsConfig" :key="col.dataIndex" :index="i"
52
+ class="flex items-center gap-2 p-2 select-none"
53
+ >
54
+ <div class="drag-handler flex items-center justify-center p-1 -m-2 mr-auto">
55
+ <i class="i-material-symbols:drag-indicator" />&nbsp;
56
+ <span >{{ col.title }}</span>
51
57
  </div>
52
- <span class="mr-auto">{{ col.title }}</span>
53
- <Select value="show" :options="showTypeOptions" />
54
- <!-- <Switch checked-children="简略" un-checked-children="简略" />
55
- <Switch checked-children="显示" un-checked-children="显示" />
56
- <Button>上</Button>
57
- <Button>下</Button> -->
58
+ <RadioGroup
59
+ v-model:value="columnsShowValue[col.dataIndex]"
60
+ :options="columnsShowOptions[col.dataIndex]"
61
+ optionType="button" buttonStyle="solid" size="small"
62
+ />
63
+ <!-- <Select v-model:value="columnsShowValue[col.dataIndex]" :options="columnsShowOptions[col.dataIndex]" /> -->
58
64
  </div>
59
65
  </div>
60
-
61
66
  </div>
62
67
  </div>
63
68
  </template>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.3.0-beta.12",
4
+ "version": "0.3.0-beta.13",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",