adminforth 3.21.1 → 3.22.0
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.
|
@@ -115,10 +115,7 @@
|
|
|
115
115
|
|
|
116
116
|
<script setup lang="ts">
|
|
117
117
|
|
|
118
|
-
import
|
|
119
|
-
import utc from 'dayjs/plugin/utc';
|
|
120
|
-
import timezone from 'dayjs/plugin/timezone';
|
|
121
|
-
import {checkEmptyValues} from '@/utils';
|
|
118
|
+
import {checkEmptyValues, formatDate, formatDateTime, formatTime} from '@/utils';
|
|
122
119
|
import { useRoute, useRouter } from 'vue-router';
|
|
123
120
|
import "vue3-json-viewer/dist/vue3-json-viewer.css";
|
|
124
121
|
import { computed, defineAsyncComponent } from 'vue';
|
|
@@ -131,10 +128,6 @@ import type { any } from 'zod';
|
|
|
131
128
|
const coreStore = useCoreStore();
|
|
132
129
|
const route = useRoute();
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
dayjs.extend(utc);
|
|
136
|
-
dayjs.extend(timezone);
|
|
137
|
-
|
|
138
131
|
const props = defineProps<{
|
|
139
132
|
column: any,
|
|
140
133
|
record: any
|
|
@@ -150,21 +143,6 @@ const canShowForeignRecord = computed(() => {
|
|
|
150
143
|
)?.allowedActions?.show;
|
|
151
144
|
});
|
|
152
145
|
|
|
153
|
-
function formatDateTime(date: string) {
|
|
154
|
-
if (!date) return '';
|
|
155
|
-
return dayjs.utc(date).local().format(`${coreStore.config?.datesFormat} ${coreStore.config?.timeFormat}` || 'YYYY-MM-DD HH:mm:ss');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function formatDate(date: string) {
|
|
159
|
-
if (!date) return '';
|
|
160
|
-
return dayjs.utc(date).local().format(coreStore.config?.datesFormat || 'YYYY-MM-DD');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function formatTime(time: string) {
|
|
164
|
-
if (!time) return '';
|
|
165
|
-
return dayjs(`0000-00-00 ${time}`).format(coreStore.config?.timeFormat || 'HH:mm:ss');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
146
|
function getArrayItemDisplayValue(value: any, column: AdminForthResourceColumnCommon) {
|
|
169
147
|
if (column.isArray?.itemType === 'datetime') {
|
|
170
148
|
return formatDateTime(value);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import utc from 'dayjs/plugin/utc';
|
|
3
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
4
|
+
import { useCoreStore } from '../stores/core';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(utc);
|
|
7
|
+
dayjs.extend(timezone);
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_DATES_FORMAT = 'YYYY-MM-DD';
|
|
10
|
+
export const DEFAULT_TIME_FORMAT = 'HH:mm:ss';
|
|
11
|
+
|
|
12
|
+
type DateLike = string | number | Date | null | undefined;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Date format configured in customization.datesFormat (or a sane default).
|
|
16
|
+
*/
|
|
17
|
+
export function getDatesFormat(): string {
|
|
18
|
+
return useCoreStore().config?.datesFormat || DEFAULT_DATES_FORMAT;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Time format configured in customization.timeFormat (or a sane default).
|
|
23
|
+
*/
|
|
24
|
+
export function getTimeFormat(): string {
|
|
25
|
+
return useCoreStore().config?.timeFormat || DEFAULT_TIME_FORMAT;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Formats UTC datetime into user's local time using formats from customization settings.
|
|
30
|
+
* Use it instead of toLocaleString() everywhere, so all dates in admin look the same.
|
|
31
|
+
*/
|
|
32
|
+
export function formatDateTime(date: DateLike): string {
|
|
33
|
+
if (!date) return '';
|
|
34
|
+
return dayjs.utc(date).local().format(`${getDatesFormat()} ${getTimeFormat()}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Formats date using format from customization settings.
|
|
39
|
+
*/
|
|
40
|
+
export function formatDate(date: DateLike): string {
|
|
41
|
+
if (!date) return '';
|
|
42
|
+
return dayjs.utc(date).local().format(getDatesFormat());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Formats standalone time value (e.g. "13:45:00") using format from customization settings.
|
|
47
|
+
*/
|
|
48
|
+
export function formatTime(time: string | null | undefined): string {
|
|
49
|
+
if (!time) return '';
|
|
50
|
+
return dayjs(`0000-00-00 ${time}`).format(getTimeFormat());
|
|
51
|
+
}
|
package/dist/spa/src/utils.ts
CHANGED