v-nuxt-ui 0.1.26 → 0.1.27
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/dist/module.json +1 -1
- package/dist/runtime/components/sys/calendar/board.d.vue.ts +3 -0
- package/dist/runtime/components/sys/calendar/board.vue +221 -0
- package/dist/runtime/components/sys/calendar/board.vue.d.ts +3 -0
- package/dist/runtime/composables/api/sys/useCalendarApi.d.ts +0 -0
- package/dist/runtime/composables/api/sys/useCalendarApi.js +8 -0
- package/dist/runtime/composables/useDate.d.ts +2 -2
- package/dist/runtime/composables/useDate.js +5 -0
- package/dist/runtime/constants/calendar.d.ts +12 -0
- package/dist/runtime/constants/calendar.js +19 -0
- package/dist/runtime/constants/index.d.ts +1 -0
- package/dist/runtime/constants/index.js +1 -0
- package/dist/runtime/types/cmds/calendar.d.ts +4 -0
- package/dist/runtime/types/cmds/calendar.js +0 -0
- package/dist/runtime/types/cmds/index.d.ts +1 -0
- package/dist/runtime/types/cmds/index.js +1 -0
- package/dist/runtime/types/models/sys.d.ts +4 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useDate, useFetching, useSubmitting } from "#v/composables";
|
|
3
|
+
import { useCalendarApi } from "#v/composables/api/sys/useCalendarApi";
|
|
4
|
+
import { TIME_ZONE, CalendarEventType, dateFormat, calendarEventTypeOptions } from "#v/constants";
|
|
5
|
+
import { endOfMonth, now, startOfMonth } from "@internationalized/date";
|
|
6
|
+
import { useToast } from "@nuxt/ui/runtime/composables/useToast.js";
|
|
7
|
+
import { ref, computed, watch } from "vue";
|
|
8
|
+
const apiGroup = useCalendarApi();
|
|
9
|
+
const dateUtil = useDate();
|
|
10
|
+
const toast = useToast();
|
|
11
|
+
const panelDate = ref(now(TIME_ZONE));
|
|
12
|
+
const calendars = ref([]);
|
|
13
|
+
const calendarTypeMap = computed(() => {
|
|
14
|
+
const map = {};
|
|
15
|
+
for (const calendar of calendars.value) {
|
|
16
|
+
map[dateUtil.isoUtcStringToDayjs(calendar.date).format(dateFormat)] = calendar.type;
|
|
17
|
+
}
|
|
18
|
+
return map;
|
|
19
|
+
});
|
|
20
|
+
const { fetching, startFetching, endFetching } = useFetching();
|
|
21
|
+
const fetchCalendars = async () => {
|
|
22
|
+
const start = startOfMonth(panelDate.value).subtract({ days: 7 });
|
|
23
|
+
const end = endOfMonth(panelDate.value).add({ days: 7 });
|
|
24
|
+
try {
|
|
25
|
+
startFetching();
|
|
26
|
+
const { data } = await apiGroup.list({
|
|
27
|
+
whereQuery: {
|
|
28
|
+
items: [
|
|
29
|
+
{
|
|
30
|
+
field: "date",
|
|
31
|
+
opr: "range_gte_lte",
|
|
32
|
+
value: {
|
|
33
|
+
start: start.toAbsoluteString(),
|
|
34
|
+
end: end.toAbsoluteString()
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{ field: "type", opr: "ne", value: CalendarEventType.NONE }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (data.value.data) {
|
|
42
|
+
mergeCalendars(data.value.data.list);
|
|
43
|
+
}
|
|
44
|
+
} finally {
|
|
45
|
+
endFetching();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const mergeCalendars = (newModels) => {
|
|
49
|
+
const newCalendars = [...calendars.value];
|
|
50
|
+
for (const newModel of newModels) {
|
|
51
|
+
const index = newCalendars.findIndex((m) => m.date === newModel.date);
|
|
52
|
+
if (index !== -1) {
|
|
53
|
+
newCalendars[index] = newModel;
|
|
54
|
+
} else {
|
|
55
|
+
newCalendars.push(newModel);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
calendars.value = newCalendars.filter((calendar) => calendar.type !== CalendarEventType.NONE);
|
|
59
|
+
};
|
|
60
|
+
const selectedDates = ref();
|
|
61
|
+
const calendarEventType = ref(CalendarEventType.HOLIDAY);
|
|
62
|
+
const { submitting, startSubmitting, endSubmitting } = useSubmitting();
|
|
63
|
+
const onSubmit = async () => {
|
|
64
|
+
if (selectedDates.value?.length === 0 || calendarEventType.value === void 0) {
|
|
65
|
+
toast.add({
|
|
66
|
+
color: "warning",
|
|
67
|
+
title: "\u63D0\u4EA4\u5931\u8D25",
|
|
68
|
+
description: "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u65E5\u671F\u5E76\u9009\u62E9\u8282\u5047\u65E5\u7C7B\u578B"
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
startSubmitting();
|
|
74
|
+
const { data } = await apiGroup.batchSave({
|
|
75
|
+
dates: selectedDates.value?.map((date) => dateUtil.dateValueToDayjs(date)?.toISOString() ?? "") ?? [],
|
|
76
|
+
type: calendarEventType.value
|
|
77
|
+
});
|
|
78
|
+
if (data.value.data) {
|
|
79
|
+
mergeCalendars(data.value.data.list);
|
|
80
|
+
selectedDates.value = [];
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
endSubmitting();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
watch(
|
|
87
|
+
panelDate,
|
|
88
|
+
() => {
|
|
89
|
+
fetchCalendars();
|
|
90
|
+
},
|
|
91
|
+
{ immediate: true }
|
|
92
|
+
);
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<div class="flex flex-col items-center gap-3">
|
|
97
|
+
<div class="flex flex-col items-center">
|
|
98
|
+
<UButton
|
|
99
|
+
label="节假日设置"
|
|
100
|
+
size="xl"
|
|
101
|
+
icon="i-lucide-calendar-days"
|
|
102
|
+
variant="link"
|
|
103
|
+
color="primary"
|
|
104
|
+
/>
|
|
105
|
+
<div class="text-dimmed text-sm">
|
|
106
|
+
选择一个或多个日期并选择节假日类型,然后点提交
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<div class="flex flex-col md:flex-row items-center md:items-start gap-3 md:gap-4">
|
|
110
|
+
<UCard class="h-fit w-fit">
|
|
111
|
+
<UCalendar
|
|
112
|
+
v-model="selectedDates"
|
|
113
|
+
multiple
|
|
114
|
+
disable-days-outside-current-view
|
|
115
|
+
:fixed-weeks="false"
|
|
116
|
+
:disabled="fetching || submitting"
|
|
117
|
+
:next-year="{
|
|
118
|
+
onClick: () => {
|
|
119
|
+
panelDate = panelDate.add({ years: 1 });
|
|
120
|
+
}
|
|
121
|
+
}"
|
|
122
|
+
:prev-year="{
|
|
123
|
+
onClick: () => {
|
|
124
|
+
panelDate = panelDate.subtract({ years: 1 });
|
|
125
|
+
}
|
|
126
|
+
}"
|
|
127
|
+
:next-month="{
|
|
128
|
+
onClick: () => {
|
|
129
|
+
panelDate = panelDate.add({ months: 1 });
|
|
130
|
+
}
|
|
131
|
+
}"
|
|
132
|
+
:prev-month="{
|
|
133
|
+
onClick: () => {
|
|
134
|
+
panelDate = panelDate.subtract({ months: 1 });
|
|
135
|
+
}
|
|
136
|
+
}"
|
|
137
|
+
>
|
|
138
|
+
<template #day="{ day }">
|
|
139
|
+
<UChip
|
|
140
|
+
:show="calendarTypeMap[dateUtil.dateValueToDayjs(day)?.format(dateFormat) ?? ''] !== void 0"
|
|
141
|
+
size="2xs"
|
|
142
|
+
:color="calendarEventTypeOptions.find((item2) => item2.value === calendarTypeMap[dateUtil.dateValueToDayjs(day)?.format(dateFormat) ?? ''])?.color ?? 'primary'"
|
|
143
|
+
>
|
|
144
|
+
{{ day.day }}
|
|
145
|
+
</UChip>
|
|
146
|
+
</template>
|
|
147
|
+
</UCalendar>
|
|
148
|
+
</UCard>
|
|
149
|
+
<UCard class="min-w-64 h-fit">
|
|
150
|
+
<div class="flex flex-col gap-3 sm:gap-4">
|
|
151
|
+
<UFormField label="已选日期" required>
|
|
152
|
+
<div v-if="(selectedDates?.length ?? 0) > 0" class="grid grid-cols-3 gap-1">
|
|
153
|
+
<UBadge
|
|
154
|
+
v-for="(date, i) in selectedDates"
|
|
155
|
+
:key="i"
|
|
156
|
+
variant="subtle"
|
|
157
|
+
:label="dateUtil.dateValueToDayjs(date)?.format(dateFormat) ?? ''"
|
|
158
|
+
>
|
|
159
|
+
<template #trailing>
|
|
160
|
+
<UIcon
|
|
161
|
+
name="i-lucide-x"
|
|
162
|
+
class="cursor-pointer"
|
|
163
|
+
@click="() => {
|
|
164
|
+
const newValue = [...selectedDates ?? []];
|
|
165
|
+
newValue.splice(i, 1);
|
|
166
|
+
selectedDates = newValue;
|
|
167
|
+
}"
|
|
168
|
+
/>
|
|
169
|
+
</template>
|
|
170
|
+
</UBadge>
|
|
171
|
+
<UButton
|
|
172
|
+
label="清除"
|
|
173
|
+
variant="ghost"
|
|
174
|
+
size="xs"
|
|
175
|
+
icon="i-lucide-timer-reset"
|
|
176
|
+
@click="selectedDates = []"
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
<div v-else>
|
|
180
|
+
/
|
|
181
|
+
</div>
|
|
182
|
+
</UFormField>
|
|
183
|
+
<UFormField label="节假日类型" required>
|
|
184
|
+
<URadioGroup
|
|
185
|
+
v-model="calendarEventType"
|
|
186
|
+
:items="calendarEventTypeOptions"
|
|
187
|
+
>
|
|
188
|
+
<template #label="{ item }">
|
|
189
|
+
<div class="flex items-center gap-2">
|
|
190
|
+
<span>{{ item.label }}</span>
|
|
191
|
+
<span
|
|
192
|
+
v-if="item.value !== CalendarEventType.NONE"
|
|
193
|
+
class="inline-block size-2 rounded-full"
|
|
194
|
+
:class="`bg-(--color-light) dark:bg-(--color-dark)`"
|
|
195
|
+
:style="{
|
|
196
|
+
'--color-light': `var(--ui-${item.color})`,
|
|
197
|
+
'--color-dark': `var(--ui-${item.color})`
|
|
198
|
+
}"
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
</template>
|
|
202
|
+
</URadioGroup>
|
|
203
|
+
</UFormField>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<template #footer>
|
|
207
|
+
<div class="flex justify-end">
|
|
208
|
+
<UButton
|
|
209
|
+
label="提交"
|
|
210
|
+
color="primary"
|
|
211
|
+
icon="i-lucide-upload"
|
|
212
|
+
:loading="submitting"
|
|
213
|
+
:disabled="(selectedDates?.length ?? 0) === 0 || calendarEventType === void 0 || submitting"
|
|
214
|
+
@click="onSubmit"
|
|
215
|
+
/>
|
|
216
|
+
</div>
|
|
217
|
+
</template>
|
|
218
|
+
</UCard>
|
|
219
|
+
</div>
|
|
220
|
+
</div>
|
|
221
|
+
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createSharedComposable } from "@vueuse/core";
|
|
2
|
+
import { useApi, usePostFetch } from "../useApi.js";
|
|
3
|
+
export const useCalendarApi = createSharedComposable(() => ({
|
|
4
|
+
...useApi("/calendars"),
|
|
5
|
+
batchSave: (payload, customOptions = {}) => {
|
|
6
|
+
return usePostFetch(`/calendars/batch-save`, payload, customOptions);
|
|
7
|
+
}
|
|
8
|
+
}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type DateValue } from '@internationalized/date';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import type { TimeUnit } from '#v/constants';
|
|
4
3
|
import type { DateRange } from 'reka-ui';
|
|
5
|
-
import type { DateShortcut } from '#v/types';
|
|
4
|
+
import type { DateShortcut, TimeUnit } from '#v/types';
|
|
6
5
|
export declare const useDate: () => {
|
|
7
6
|
dayjsToDateValue: (date: dayjs.Dayjs | null | undefined) => DateValue | undefined;
|
|
8
7
|
isoUtcStringToDateValue: (isoString: string | null | undefined) => DateValue | undefined;
|
|
8
|
+
isoUtcStringToDayjs: (isoString: string | null | undefined) => dayjs.Dayjs | undefined;
|
|
9
9
|
dateValueToDayjs: (dateValue: DateValue | null | undefined) => dayjs.Dayjs | undefined;
|
|
10
10
|
formatTimeUnit: (dateValue: DateValue | null | undefined, unit: TimeUnit) => string;
|
|
11
11
|
getRecentDateRange: (days: number) => DateRange;
|
|
@@ -11,6 +11,10 @@ const _useDate = () => {
|
|
|
11
11
|
if (!isoString) return void 0;
|
|
12
12
|
return dayjsToDateValue(dayjs(isoString));
|
|
13
13
|
};
|
|
14
|
+
const isoUtcStringToDayjs = (isoString) => {
|
|
15
|
+
if (!isoString) return void 0;
|
|
16
|
+
return dayjs(isoString);
|
|
17
|
+
};
|
|
14
18
|
const dateValueToDayjs = (dateValue) => {
|
|
15
19
|
if (!dateValue) return void 0;
|
|
16
20
|
return dayjs(toZoned(dateValue, TIME_ZONE).toAbsoluteString()).tz(TIME_ZONE);
|
|
@@ -135,6 +139,7 @@ const _useDate = () => {
|
|
|
135
139
|
return {
|
|
136
140
|
dayjsToDateValue,
|
|
137
141
|
isoUtcStringToDateValue,
|
|
142
|
+
isoUtcStringToDayjs,
|
|
138
143
|
dateValueToDayjs,
|
|
139
144
|
formatTimeUnit,
|
|
140
145
|
getRecentDateRange,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum CalendarEventType {
|
|
2
|
+
NONE = 0,
|
|
3
|
+
HOLIDAY = 1,
|
|
4
|
+
ADJUSTRED = 2,
|
|
5
|
+
WEEKEND = 3
|
|
6
|
+
}
|
|
7
|
+
export declare const calendarEventTypeOptions: {
|
|
8
|
+
label: string;
|
|
9
|
+
value: CalendarEventType;
|
|
10
|
+
color: string;
|
|
11
|
+
}[];
|
|
12
|
+
export declare const calendarEventTypeShortNameMap: Map<CalendarEventType, string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export var CalendarEventType = /* @__PURE__ */ ((CalendarEventType2) => {
|
|
2
|
+
CalendarEventType2[CalendarEventType2["NONE"] = 0] = "NONE";
|
|
3
|
+
CalendarEventType2[CalendarEventType2["HOLIDAY"] = 1] = "HOLIDAY";
|
|
4
|
+
CalendarEventType2[CalendarEventType2["ADJUSTRED"] = 2] = "ADJUSTRED";
|
|
5
|
+
CalendarEventType2[CalendarEventType2["WEEKEND"] = 3] = "WEEKEND";
|
|
6
|
+
return CalendarEventType2;
|
|
7
|
+
})(CalendarEventType || {});
|
|
8
|
+
export const calendarEventTypeOptions = [
|
|
9
|
+
{ label: "\u56FD\u5BB6\u6CD5\u5B9A\u5047", value: 1 /* HOLIDAY */, color: "primary" },
|
|
10
|
+
{ label: "\u516C\u53F8\u8C03\u6574\u5047", value: 2 /* ADJUSTRED */, color: "warning" },
|
|
11
|
+
{ label: "\u5468\u672B\u4F11\u606F\u65E5", value: 3 /* WEEKEND */, color: "success" },
|
|
12
|
+
{ label: "\u65E0", value: 0 /* NONE */, color: "neutral" }
|
|
13
|
+
];
|
|
14
|
+
export const calendarEventTypeShortNameMap = /* @__PURE__ */ new Map([
|
|
15
|
+
[0 /* NONE */, "\u73ED"],
|
|
16
|
+
[1 /* HOLIDAY */, "\u5047"],
|
|
17
|
+
[2 /* ADJUSTRED */, "\u8C03"],
|
|
18
|
+
[3 /* WEEKEND */, "\u4F11"]
|
|
19
|
+
]);
|
|
File without changes
|
package/package.json
CHANGED