v-nuxt-ui 0.1.25 → 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 CHANGED
@@ -7,7 +7,7 @@
7
7
  "dependencies": [
8
8
  "@nuxt/ui"
9
9
  ],
10
- "version": "0.1.25",
10
+ "version": "0.1.27",
11
11
  "builder": {
12
12
  "@nuxt/module-builder": "1.0.2",
13
13
  "unbuild": "3.6.1"
@@ -12,7 +12,7 @@ const props = defineProps({
12
12
  loading: { type: Boolean, required: false },
13
13
  range: { type: Boolean, required: false },
14
14
  placeholder: { type: String, required: false },
15
- timeUnit: { type: String, required: false },
15
+ timeUnit: { type: null, required: false },
16
16
  leadingIcon: { type: null, required: false },
17
17
  shortcuts: { type: Array, required: false },
18
18
  peerButtons: { type: Array, required: false }
@@ -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;
@@ -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
+ ]);
@@ -4,3 +4,4 @@ export * from './options.js';
4
4
  export * from './time.js';
5
5
  export * from './menu.js';
6
6
  export * from './user.js';
7
+ export * from './calendar.js';
@@ -4,3 +4,4 @@ export * from "./options.js";
4
4
  export * from "./time.js";
5
5
  export * from "./menu.js";
6
6
  export * from "./user.js";
7
+ export * from "./calendar.js";
@@ -5,4 +5,3 @@ export declare const weekEnLabels: string[];
5
5
  export declare const weekCnLabels: string[];
6
6
  export declare const dateFormat = "YYYY-MM-DD";
7
7
  export declare const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
8
- export type TimeUnit = 'day' | 'week' | 'month' | 'quarter' | 'year';
@@ -0,0 +1,4 @@
1
+ export type CalendarsSavePayload = {
2
+ dates: string[];
3
+ type: number;
4
+ };
File without changes
@@ -1,3 +1,4 @@
1
1
  export * from './login.js';
2
2
  export * from './sys.js';
3
3
  export * from './user.js';
4
+ export * from './calendar.js';
@@ -1,3 +1,4 @@
1
1
  export * from "./login.js";
2
2
  export * from "./sys.js";
3
3
  export * from "./user.js";
4
+ export * from "./calendar.js";
@@ -7,6 +7,7 @@ export * from './locale.js';
7
7
  export * from './request.js';
8
8
  export * from './query.js';
9
9
  export * from './storage.js';
10
+ export * from './time.js';
10
11
  export type Size = import('@nuxt/ui').ButtonProps['size'];
11
12
  export type SelectOption = {
12
13
  label: string;
@@ -6,3 +6,4 @@ export * from "./locale.js";
6
6
  export * from "./request.js";
7
7
  export * from "./query.js";
8
8
  export * from "./storage.js";
9
+ export * from "./time.js";
@@ -82,3 +82,7 @@ export type RowRecord = {
82
82
  oldValue?: string;
83
83
  newValue?: string;
84
84
  } & BaseModel;
85
+ export type Calendar = {
86
+ date?: string;
87
+ type?: number;
88
+ } & BaseModel;
@@ -0,0 +1 @@
1
+ export type TimeUnit = 'day' | 'week' | 'month' | 'quarter' | 'year';
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v-nuxt-ui",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "Veken UI Component Library - Reusable Nuxt UI components, composables, and utilities for enterprise applications",
5
5
  "type": "module",
6
6
  "style": "./dist/runtime/index.css",