bfg-common 1.4.288 → 1.4.290
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/assets/img/icons/icons-sprite-dark-1.svg +407 -407
- package/assets/img/icons/icons-sprite-dark-2.svg +343 -343
- package/assets/img/icons/icons-sprite-dark-3.svg +227 -227
- package/assets/img/icons/icons-sprite-dark-4.svg +255 -255
- package/assets/img/icons/icons-sprite-dark-5.svg +488 -488
- package/assets/img/icons/icons-sprite-dark-6.svg +94 -83
- package/assets/img/icons/icons-sprite-light-1.svg +407 -407
- package/assets/img/icons/icons-sprite-light-2.svg +343 -343
- package/assets/img/icons/icons-sprite-light-3.svg +227 -227
- package/assets/img/icons/icons-sprite-light-4.svg +255 -255
- package/assets/img/icons/icons-sprite-light-5.svg +488 -488
- package/assets/img/icons/icons-sprite-light-6.svg +94 -83
- package/assets/localization/local_be.json +2 -56
- package/assets/localization/local_en.json +2 -56
- package/assets/localization/local_hy.json +2 -56
- package/assets/localization/local_kk.json +2 -56
- package/assets/localization/local_ru.json +2 -56
- package/assets/localization/local_zh.json +2 -56
- package/assets/scss/common/icons/icons-6.scss +12 -0
- package/components/atoms/TheIcon3.vue +50 -50
- package/components/atoms/modal/bySteps/BySteps.vue +253 -253
- package/components/atoms/stack/StackBlock.vue +185 -185
- package/components/atoms/wizard/lib/utils/utils.ts +0 -104
- package/components/common/browse/blocks/Title.vue +91 -91
- package/components/common/browse/blocks/info/Date.vue +21 -21
- package/components/common/context/lib/models/interfaces.ts +30 -30
- package/components/common/context/recursion/Recursion.vue +86 -86
- package/components/common/context/recursion/RecursionNew.vue +199 -199
- package/components/common/context/recursion/RecursionOld.vue +213 -213
- package/components/common/modals/confirmation/Confirmation.vue +65 -65
- package/components/common/vm/actions/add/Add.vue +617 -617
- package/components/common/vm/actions/clone/lib/config/steps.ts +129 -129
- package/components/common/vm/actions/common/customizeHardware/virtualHardware/bus/lib/config/options.ts +20 -20
- package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/Cpu.vue +403 -403
- package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/Hv.vue +99 -99
- package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/order/Order.vue +201 -201
- package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/streamingMode/StreamingMode.vue +85 -85
- package/composables/productNameLocal.ts +30 -30
- package/package.json +1 -1
- package/plugins/date.ts +181 -181
- package/plugins/recursion.ts +311 -311
- package/public/spice-console/lib/images/bitmap.js +203 -203
- package/public/spice-console/network/spicechannel.js +383 -383
- package/store/tasks/mappers/recentTasks.ts +45 -45
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="">
|
|
3
|
-
<atoms-stack-block :has-children="false">
|
|
4
|
-
<template #stackBlockKey>
|
|
5
|
-
{{ localization.common.streamingMode }}
|
|
6
|
-
</template>
|
|
7
|
-
<template #stackBlockContent>
|
|
8
|
-
<atoms-tooltip-error
|
|
9
|
-
:has-error="!!apiError"
|
|
10
|
-
selector="#vm-wizard-streaming-mode-field"
|
|
11
|
-
@remove="onRemoveValidationError"
|
|
12
|
-
>
|
|
13
|
-
<template #elem>
|
|
14
|
-
<div class="select">
|
|
15
|
-
<select
|
|
16
|
-
id="vm-wizard-streaming-mode-field"
|
|
17
|
-
v-model="streamingModeLocal"
|
|
18
|
-
data-id="vm-wizard-streaming-mode-select"
|
|
19
|
-
:disabled="props.disabled"
|
|
20
|
-
>
|
|
21
|
-
<option
|
|
22
|
-
v-for="(item, key) in streamingModeOptions"
|
|
23
|
-
:key="key"
|
|
24
|
-
:value="item.value"
|
|
25
|
-
>
|
|
26
|
-
{{ item.text }}
|
|
27
|
-
</option>
|
|
28
|
-
</select>
|
|
29
|
-
</div>
|
|
30
|
-
</template>
|
|
31
|
-
<template #content>
|
|
32
|
-
{{ apiError }}
|
|
33
|
-
</template>
|
|
34
|
-
</atoms-tooltip-error>
|
|
35
|
-
</template>
|
|
36
|
-
</atoms-stack-block>
|
|
37
|
-
</div>
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
<script setup lang="ts">
|
|
41
|
-
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
42
|
-
import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
|
|
43
|
-
import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
|
|
44
|
-
import { streamingModeOptionsFunc } from '~/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/streamingMode/lib/config/config'
|
|
45
|
-
|
|
46
|
-
const localization = computed<UI_I_Localization>(() => useLocal())
|
|
47
|
-
|
|
48
|
-
const props = defineProps<{
|
|
49
|
-
streamingMode: string
|
|
50
|
-
errorValidationFields: UI_I_ErrorValidationField[]
|
|
51
|
-
disabled: boolean
|
|
52
|
-
}>()
|
|
53
|
-
const emits = defineEmits<{
|
|
54
|
-
(event: 'update:streaming-mode', value: string): void
|
|
55
|
-
(event: 'remove-error-by-title', value: string): void
|
|
56
|
-
}>()
|
|
57
|
-
|
|
58
|
-
const streamingModeOptions = ref<UI_I_OptionItem[]>(
|
|
59
|
-
streamingModeOptionsFunc(localization.value)
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
const streamingModeLocal = computed<string>({
|
|
63
|
-
get() {
|
|
64
|
-
return props.streamingMode
|
|
65
|
-
},
|
|
66
|
-
set(newValue) {
|
|
67
|
-
emits('update:streaming-mode', newValue)
|
|
68
|
-
},
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const typeError = 'options.remote_console.spice.streaming_mode'
|
|
72
|
-
|
|
73
|
-
const apiError = computed<string>(() => {
|
|
74
|
-
return (
|
|
75
|
-
props.errorValidationFields?.find((message) => message.field === typeError)
|
|
76
|
-
?.error_message || ''
|
|
77
|
-
)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const onRemoveValidationError = (): void => {
|
|
81
|
-
emits('remove-error-by-title', typeError)
|
|
82
|
-
}
|
|
83
|
-
</script>
|
|
84
|
-
|
|
85
|
-
<style scoped></style>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="">
|
|
3
|
+
<atoms-stack-block :has-children="false">
|
|
4
|
+
<template #stackBlockKey>
|
|
5
|
+
{{ localization.common.streamingMode }}
|
|
6
|
+
</template>
|
|
7
|
+
<template #stackBlockContent>
|
|
8
|
+
<atoms-tooltip-error
|
|
9
|
+
:has-error="!!apiError"
|
|
10
|
+
selector="#vm-wizard-streaming-mode-field"
|
|
11
|
+
@remove="onRemoveValidationError"
|
|
12
|
+
>
|
|
13
|
+
<template #elem>
|
|
14
|
+
<div class="select">
|
|
15
|
+
<select
|
|
16
|
+
id="vm-wizard-streaming-mode-field"
|
|
17
|
+
v-model="streamingModeLocal"
|
|
18
|
+
data-id="vm-wizard-streaming-mode-select"
|
|
19
|
+
:disabled="props.disabled"
|
|
20
|
+
>
|
|
21
|
+
<option
|
|
22
|
+
v-for="(item, key) in streamingModeOptions"
|
|
23
|
+
:key="key"
|
|
24
|
+
:value="item.value"
|
|
25
|
+
>
|
|
26
|
+
{{ item.text }}
|
|
27
|
+
</option>
|
|
28
|
+
</select>
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
<template #content>
|
|
32
|
+
{{ apiError }}
|
|
33
|
+
</template>
|
|
34
|
+
</atoms-tooltip-error>
|
|
35
|
+
</template>
|
|
36
|
+
</atoms-stack-block>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup lang="ts">
|
|
41
|
+
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
42
|
+
import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
|
|
43
|
+
import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
|
|
44
|
+
import { streamingModeOptionsFunc } from '~/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/streamingMode/lib/config/config'
|
|
45
|
+
|
|
46
|
+
const localization = computed<UI_I_Localization>(() => useLocal())
|
|
47
|
+
|
|
48
|
+
const props = defineProps<{
|
|
49
|
+
streamingMode: string
|
|
50
|
+
errorValidationFields: UI_I_ErrorValidationField[]
|
|
51
|
+
disabled: boolean
|
|
52
|
+
}>()
|
|
53
|
+
const emits = defineEmits<{
|
|
54
|
+
(event: 'update:streaming-mode', value: string): void
|
|
55
|
+
(event: 'remove-error-by-title', value: string): void
|
|
56
|
+
}>()
|
|
57
|
+
|
|
58
|
+
const streamingModeOptions = ref<UI_I_OptionItem[]>(
|
|
59
|
+
streamingModeOptionsFunc(localization.value)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const streamingModeLocal = computed<string>({
|
|
63
|
+
get() {
|
|
64
|
+
return props.streamingMode
|
|
65
|
+
},
|
|
66
|
+
set(newValue) {
|
|
67
|
+
emits('update:streaming-mode', newValue)
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const typeError = 'options.remote_console.spice.streaming_mode'
|
|
72
|
+
|
|
73
|
+
const apiError = computed<string>(() => {
|
|
74
|
+
return (
|
|
75
|
+
props.errorValidationFields?.find((message) => message.field === typeError)
|
|
76
|
+
?.error_message || ''
|
|
77
|
+
)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const onRemoveValidationError = (): void => {
|
|
81
|
+
emits('remove-error-by-title', typeError)
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<style scoped></style>
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
2
|
-
import type { UI_T_LanguageKey } from '~/lib/models/types'
|
|
3
|
-
|
|
4
|
-
export function productNameLocal(
|
|
5
|
-
localization: UI_I_Localization
|
|
6
|
-
): UI_I_Localization {
|
|
7
|
-
const config = useRuntimeConfig()
|
|
8
|
-
|
|
9
|
-
const productName =
|
|
10
|
-
config.public.LOCALIZATION_CODE === 'ru'
|
|
11
|
-
? config.public.PRODUCT_NAME_RU
|
|
12
|
-
: config.public.PRODUCT_NAME_EN
|
|
13
|
-
|
|
14
|
-
return replaceProductNameRecursion(localization, productName)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const replaceProductNameRecursion = (
|
|
18
|
-
localization: UI_I_Localization,
|
|
19
|
-
productName: any
|
|
20
|
-
): UI_I_Localization => {
|
|
21
|
-
for (const key of Object.keys(localization)) {
|
|
22
|
-
let item = localization[key as UI_T_LanguageKey]
|
|
23
|
-
|
|
24
|
-
for (const key2 of Object.keys(item)) {
|
|
25
|
-
item[key2] = item[key2].replaceAll('{productName}', productName)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return localization
|
|
30
|
-
}
|
|
1
|
+
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
2
|
+
import type { UI_T_LanguageKey } from '~/lib/models/types'
|
|
3
|
+
|
|
4
|
+
export function productNameLocal(
|
|
5
|
+
localization: UI_I_Localization
|
|
6
|
+
): UI_I_Localization {
|
|
7
|
+
const config = useRuntimeConfig()
|
|
8
|
+
|
|
9
|
+
const productName =
|
|
10
|
+
config.public.LOCALIZATION_CODE === 'ru'
|
|
11
|
+
? config.public.PRODUCT_NAME_RU
|
|
12
|
+
: config.public.PRODUCT_NAME_EN
|
|
13
|
+
|
|
14
|
+
return replaceProductNameRecursion(localization, productName)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const replaceProductNameRecursion = (
|
|
18
|
+
localization: UI_I_Localization,
|
|
19
|
+
productName: any
|
|
20
|
+
): UI_I_Localization => {
|
|
21
|
+
for (const key of Object.keys(localization)) {
|
|
22
|
+
let item = localization[key as UI_T_LanguageKey]
|
|
23
|
+
|
|
24
|
+
for (const key2 of Object.keys(item)) {
|
|
25
|
+
item[key2] = item[key2].replaceAll('{productName}', productName)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return localization
|
|
30
|
+
}
|
package/package.json
CHANGED
package/plugins/date.ts
CHANGED
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from '#app'
|
|
2
|
-
import { format } from 'date-fns'
|
|
3
|
-
import * as localizations from 'date-fns/locale'
|
|
4
|
-
import type { UI_T_DateFormat } from '~/lib/models/plugins/date/types'
|
|
5
|
-
import type { UI_I_Dateformat } from '~/lib/models/plugins/date/interfaces'
|
|
6
|
-
|
|
7
|
-
export default defineNuxtPlugin(() => {
|
|
8
|
-
// Проверяем переданое является датой
|
|
9
|
-
const isDate = (date: string | number) => {
|
|
10
|
-
return new Date(date).toString() !== 'Invalid Date'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Проверяем формат времени браузера равно 24h
|
|
14
|
-
const isBrowserLocale24h = () =>
|
|
15
|
-
!new Intl.DateTimeFormat(undefined, { hour: 'numeric' })
|
|
16
|
-
.format(0)
|
|
17
|
-
.match(/AM/)
|
|
18
|
-
|
|
19
|
-
// Получаем переводы для даты
|
|
20
|
-
const getDateLocalization = (lang?: string) => {
|
|
21
|
-
const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
|
|
22
|
-
const { be, enUS, hy, kk, ru, zhCN } = localizations
|
|
23
|
-
let localization
|
|
24
|
-
|
|
25
|
-
switch (currentLanguage) {
|
|
26
|
-
case 'be_BY':
|
|
27
|
-
localization = be
|
|
28
|
-
break
|
|
29
|
-
case 'en_US':
|
|
30
|
-
localization = enUS
|
|
31
|
-
break
|
|
32
|
-
case 'hy_AM':
|
|
33
|
-
localization = hy
|
|
34
|
-
break
|
|
35
|
-
case 'kk_KZ':
|
|
36
|
-
localization = kk
|
|
37
|
-
break
|
|
38
|
-
case 'ru_RU':
|
|
39
|
-
localization = ru
|
|
40
|
-
break
|
|
41
|
-
case 'zh_CHS':
|
|
42
|
-
localization = zhCN
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return localization
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Получаем формат даты
|
|
50
|
-
const getDateFormat = (lang?: string): UI_T_DateFormat => {
|
|
51
|
-
const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
|
|
52
|
-
const dateFormats: UI_I_Dateformat = {
|
|
53
|
-
be_BY: 'yyyy-MM-dd',
|
|
54
|
-
en_US: 'MM-dd-yyyy',
|
|
55
|
-
hy_AM: 'yyyy-MM-dd',
|
|
56
|
-
kk_KZ: 'dd/MM/yyyy',
|
|
57
|
-
ru_RU: 'dd/MM/yyyy',
|
|
58
|
-
zh_CHS: 'yyyy-MM-dd',
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const dateFormat = ref(dateFormats[currentLanguage])
|
|
62
|
-
|
|
63
|
-
window.addEventListener('timeFormatStorageChanged', function handler() {
|
|
64
|
-
dateFormat.value = dateFormats[lang || useLocalStorage('lang') || 'en_US'] // TODO нужно проверить когда будем работать без useLocalStorage
|
|
65
|
-
|
|
66
|
-
window.removeEventListener('timeFormatStorageChanged', handler)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
return dateFormat.value
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Получаем формат времени
|
|
73
|
-
const getTimeFormat = (hasSeconds: boolean, timeFormat?: string) => {
|
|
74
|
-
let appTimeFormat = timeFormat || useLocalStorage('timeFormat') || 'DEFAULT'
|
|
75
|
-
let timeFormatLocal = ''
|
|
76
|
-
|
|
77
|
-
if (appTimeFormat === 'DEFAULT') {
|
|
78
|
-
const isBrowserTimeFormat24 = isBrowserLocale24h()
|
|
79
|
-
|
|
80
|
-
appTimeFormat = isBrowserTimeFormat24 ? '24H' : appTimeFormat
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (appTimeFormat === '24H') {
|
|
84
|
-
timeFormatLocal = 'HH:mm'
|
|
85
|
-
} else {
|
|
86
|
-
timeFormatLocal = 'h:mm aa'
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
hasSeconds && (timeFormatLocal = timeFormatLocal.replace(':mm', ':mm:ss'))
|
|
90
|
-
|
|
91
|
-
return timeFormatLocal
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Форматирование даты из английского в стандартный
|
|
95
|
-
const enFormatToStandardFormat = (date: string): string => {
|
|
96
|
-
const splitDate = date.split('-')
|
|
97
|
-
return [splitDate[2], splitDate[0], splitDate[1]].join('/')
|
|
98
|
-
}
|
|
99
|
-
const getUnixByDate = (dateTime: string, lang?: string): number => {
|
|
100
|
-
const currentFormat: UI_T_DateFormat = getDateFormat(lang)
|
|
101
|
-
|
|
102
|
-
const [date, time] = dateTime.split(' ')
|
|
103
|
-
|
|
104
|
-
let standardDate = ''
|
|
105
|
-
switch (currentFormat) {
|
|
106
|
-
case 'dd/MM/yyyy':
|
|
107
|
-
standardDate = date.split('/').reverse().join('/')
|
|
108
|
-
break
|
|
109
|
-
case 'yyyy-MM-dd':
|
|
110
|
-
standardDate = date.replaceAll('-', '/')
|
|
111
|
-
break
|
|
112
|
-
case 'MM-dd-yyyy':
|
|
113
|
-
standardDate = enFormatToStandardFormat(date)
|
|
114
|
-
break
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const standard = time ? standardDate + ' ' + time : standardDate
|
|
118
|
-
return new Date(standard).getTime()
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Форматирование даты без временим
|
|
122
|
-
const formattedDate = (
|
|
123
|
-
date: number | string | Date,
|
|
124
|
-
formatDate = '',
|
|
125
|
-
lang?: string
|
|
126
|
-
) => {
|
|
127
|
-
const formatDateLocal = formatDate || getDateFormat(lang)
|
|
128
|
-
|
|
129
|
-
return format(new Date(date), formatDateLocal, {
|
|
130
|
-
locale: getDateLocalization(lang),
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
// Форматирование временим
|
|
134
|
-
const formattedTime = (
|
|
135
|
-
date: number | string | Date,
|
|
136
|
-
formatDate = '',
|
|
137
|
-
hasSeconds = false,
|
|
138
|
-
timeFormat?: string
|
|
139
|
-
) => {
|
|
140
|
-
const formatDateLocal = formatDate || getTimeFormat(hasSeconds, timeFormat)
|
|
141
|
-
|
|
142
|
-
return format(new Date(date), formatDateLocal)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Форматирование даты с временим
|
|
146
|
-
const formattedDatetime = (
|
|
147
|
-
date: number | string | Date,
|
|
148
|
-
formatDate = '',
|
|
149
|
-
hasSeconds = false,
|
|
150
|
-
lang?: string,
|
|
151
|
-
timeFormat?: string
|
|
152
|
-
) => {
|
|
153
|
-
const formatDateLocal = ref(formatDate || getDateFormat(lang))
|
|
154
|
-
const formatDatetime = ref(
|
|
155
|
-
formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
window.addEventListener('timeFormatStorageChanged', function handler() {
|
|
159
|
-
formatDatetime.value =
|
|
160
|
-
formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
|
|
161
|
-
|
|
162
|
-
window.removeEventListener('timeFormatStorageChanged', handler)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
return format(new Date(date), formatDatetime.value, {
|
|
166
|
-
locale: getDateLocalization(lang),
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
provide: {
|
|
172
|
-
isDate,
|
|
173
|
-
getTimeFormat,
|
|
174
|
-
getDateFormat,
|
|
175
|
-
formattedTime,
|
|
176
|
-
formattedDate,
|
|
177
|
-
formattedDatetime,
|
|
178
|
-
getUnixByDate,
|
|
179
|
-
},
|
|
180
|
-
}
|
|
181
|
-
})
|
|
1
|
+
import { defineNuxtPlugin } from '#app'
|
|
2
|
+
import { format } from 'date-fns'
|
|
3
|
+
import * as localizations from 'date-fns/locale'
|
|
4
|
+
import type { UI_T_DateFormat } from '~/lib/models/plugins/date/types'
|
|
5
|
+
import type { UI_I_Dateformat } from '~/lib/models/plugins/date/interfaces'
|
|
6
|
+
|
|
7
|
+
export default defineNuxtPlugin(() => {
|
|
8
|
+
// Проверяем переданое является датой
|
|
9
|
+
const isDate = (date: string | number) => {
|
|
10
|
+
return new Date(date).toString() !== 'Invalid Date'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Проверяем формат времени браузера равно 24h
|
|
14
|
+
const isBrowserLocale24h = () =>
|
|
15
|
+
!new Intl.DateTimeFormat(undefined, { hour: 'numeric' })
|
|
16
|
+
.format(0)
|
|
17
|
+
.match(/AM/)
|
|
18
|
+
|
|
19
|
+
// Получаем переводы для даты
|
|
20
|
+
const getDateLocalization = (lang?: string) => {
|
|
21
|
+
const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
|
|
22
|
+
const { be, enUS, hy, kk, ru, zhCN } = localizations
|
|
23
|
+
let localization
|
|
24
|
+
|
|
25
|
+
switch (currentLanguage) {
|
|
26
|
+
case 'be_BY':
|
|
27
|
+
localization = be
|
|
28
|
+
break
|
|
29
|
+
case 'en_US':
|
|
30
|
+
localization = enUS
|
|
31
|
+
break
|
|
32
|
+
case 'hy_AM':
|
|
33
|
+
localization = hy
|
|
34
|
+
break
|
|
35
|
+
case 'kk_KZ':
|
|
36
|
+
localization = kk
|
|
37
|
+
break
|
|
38
|
+
case 'ru_RU':
|
|
39
|
+
localization = ru
|
|
40
|
+
break
|
|
41
|
+
case 'zh_CHS':
|
|
42
|
+
localization = zhCN
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return localization
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Получаем формат даты
|
|
50
|
+
const getDateFormat = (lang?: string): UI_T_DateFormat => {
|
|
51
|
+
const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
|
|
52
|
+
const dateFormats: UI_I_Dateformat = {
|
|
53
|
+
be_BY: 'yyyy-MM-dd',
|
|
54
|
+
en_US: 'MM-dd-yyyy',
|
|
55
|
+
hy_AM: 'yyyy-MM-dd',
|
|
56
|
+
kk_KZ: 'dd/MM/yyyy',
|
|
57
|
+
ru_RU: 'dd/MM/yyyy',
|
|
58
|
+
zh_CHS: 'yyyy-MM-dd',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const dateFormat = ref(dateFormats[currentLanguage])
|
|
62
|
+
|
|
63
|
+
window.addEventListener('timeFormatStorageChanged', function handler() {
|
|
64
|
+
dateFormat.value = dateFormats[lang || useLocalStorage('lang') || 'en_US'] // TODO нужно проверить когда будем работать без useLocalStorage
|
|
65
|
+
|
|
66
|
+
window.removeEventListener('timeFormatStorageChanged', handler)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return dateFormat.value
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Получаем формат времени
|
|
73
|
+
const getTimeFormat = (hasSeconds: boolean, timeFormat?: string) => {
|
|
74
|
+
let appTimeFormat = timeFormat || useLocalStorage('timeFormat') || 'DEFAULT'
|
|
75
|
+
let timeFormatLocal = ''
|
|
76
|
+
|
|
77
|
+
if (appTimeFormat === 'DEFAULT') {
|
|
78
|
+
const isBrowserTimeFormat24 = isBrowserLocale24h()
|
|
79
|
+
|
|
80
|
+
appTimeFormat = isBrowserTimeFormat24 ? '24H' : appTimeFormat
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (appTimeFormat === '24H') {
|
|
84
|
+
timeFormatLocal = 'HH:mm'
|
|
85
|
+
} else {
|
|
86
|
+
timeFormatLocal = 'h:mm aa'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
hasSeconds && (timeFormatLocal = timeFormatLocal.replace(':mm', ':mm:ss'))
|
|
90
|
+
|
|
91
|
+
return timeFormatLocal
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Форматирование даты из английского в стандартный
|
|
95
|
+
const enFormatToStandardFormat = (date: string): string => {
|
|
96
|
+
const splitDate = date.split('-')
|
|
97
|
+
return [splitDate[2], splitDate[0], splitDate[1]].join('/')
|
|
98
|
+
}
|
|
99
|
+
const getUnixByDate = (dateTime: string, lang?: string): number => {
|
|
100
|
+
const currentFormat: UI_T_DateFormat = getDateFormat(lang)
|
|
101
|
+
|
|
102
|
+
const [date, time] = dateTime.split(' ')
|
|
103
|
+
|
|
104
|
+
let standardDate = ''
|
|
105
|
+
switch (currentFormat) {
|
|
106
|
+
case 'dd/MM/yyyy':
|
|
107
|
+
standardDate = date.split('/').reverse().join('/')
|
|
108
|
+
break
|
|
109
|
+
case 'yyyy-MM-dd':
|
|
110
|
+
standardDate = date.replaceAll('-', '/')
|
|
111
|
+
break
|
|
112
|
+
case 'MM-dd-yyyy':
|
|
113
|
+
standardDate = enFormatToStandardFormat(date)
|
|
114
|
+
break
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const standard = time ? standardDate + ' ' + time : standardDate
|
|
118
|
+
return new Date(standard).getTime()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Форматирование даты без временим
|
|
122
|
+
const formattedDate = (
|
|
123
|
+
date: number | string | Date,
|
|
124
|
+
formatDate = '',
|
|
125
|
+
lang?: string
|
|
126
|
+
) => {
|
|
127
|
+
const formatDateLocal = formatDate || getDateFormat(lang)
|
|
128
|
+
|
|
129
|
+
return format(new Date(date), formatDateLocal, {
|
|
130
|
+
locale: getDateLocalization(lang),
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
// Форматирование временим
|
|
134
|
+
const formattedTime = (
|
|
135
|
+
date: number | string | Date,
|
|
136
|
+
formatDate = '',
|
|
137
|
+
hasSeconds = false,
|
|
138
|
+
timeFormat?: string
|
|
139
|
+
) => {
|
|
140
|
+
const formatDateLocal = formatDate || getTimeFormat(hasSeconds, timeFormat)
|
|
141
|
+
|
|
142
|
+
return format(new Date(date), formatDateLocal)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Форматирование даты с временим
|
|
146
|
+
const formattedDatetime = (
|
|
147
|
+
date: number | string | Date,
|
|
148
|
+
formatDate = '',
|
|
149
|
+
hasSeconds = false,
|
|
150
|
+
lang?: string,
|
|
151
|
+
timeFormat?: string
|
|
152
|
+
) => {
|
|
153
|
+
const formatDateLocal = ref(formatDate || getDateFormat(lang))
|
|
154
|
+
const formatDatetime = ref(
|
|
155
|
+
formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
window.addEventListener('timeFormatStorageChanged', function handler() {
|
|
159
|
+
formatDatetime.value =
|
|
160
|
+
formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
|
|
161
|
+
|
|
162
|
+
window.removeEventListener('timeFormatStorageChanged', handler)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
return format(new Date(date), formatDatetime.value, {
|
|
166
|
+
locale: getDateLocalization(lang),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
provide: {
|
|
172
|
+
isDate,
|
|
173
|
+
getTimeFormat,
|
|
174
|
+
getDateFormat,
|
|
175
|
+
formattedTime,
|
|
176
|
+
formattedDate,
|
|
177
|
+
formattedDatetime,
|
|
178
|
+
getUnixByDate,
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
})
|