bfg-common 1.5.199 → 1.5.200

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.
Files changed (125) hide show
  1. package/CODE_STYLE.md +109 -109
  2. package/components/atoms/TheIcon3.vue +50 -50
  3. package/components/atoms/perPage/PerPage.vue +58 -58
  4. package/components/atoms/table/dataGrid/lib/config/settingsTable.ts +94 -94
  5. package/components/atoms/table/dataGrid/lib/utils/export.ts +16 -16
  6. package/components/atoms/tabs/VerticalTabs.vue +105 -105
  7. package/components/common/browse/blocks/contents/filesNew/Skeleton.vue +18 -18
  8. package/components/common/context/lib/models/interfaces.ts +31 -31
  9. package/components/common/context/recursion/RecursionNew.vue +238 -238
  10. package/components/common/diagramMain/DiagramMain.vue +897 -897
  11. package/components/common/diagramMain/Header.vue +214 -214
  12. package/components/common/graph/GraphOld.vue +50 -50
  13. package/components/common/graph/graphNew/GraphNew.vue +194 -194
  14. package/components/common/layout/theHeader/helpMenu/About.vue +82 -82
  15. package/components/common/layout/theHeader/userMenu/modals/preferences/view/ViewOld.vue +112 -112
  16. package/components/common/monitor/advanced/tools/chartOptionsModal/counters/table/lib/config/utils.ts +1040 -1040
  17. package/components/common/monitor/overview/OverviewOld.vue +139 -139
  18. package/components/common/pages/home/headline/Headline.vue +45 -45
  19. package/components/common/pages/home/headline/HeadlineOld.vue +42 -42
  20. package/components/common/pages/home/lib/models/interfaces.ts +48 -48
  21. package/components/common/pages/home/widgets/Widgets.vue +49 -49
  22. package/components/common/pages/home/widgets/WidgetsNew.vue +86 -86
  23. package/components/common/pages/home/widgets/WidgetsOld.vue +34 -34
  24. package/components/common/pages/home/widgets/hosts/Hosts.vue +27 -27
  25. package/components/common/pages/home/widgets/hosts/lib/config/items.ts +23 -23
  26. package/components/common/pages/home/widgets/vms/Vms.vue +26 -26
  27. package/components/common/pages/home/widgets/vms/VmsOld.vue +35 -35
  28. package/components/common/pages/home/widgets/vms/lib/config/items.ts +19 -19
  29. package/components/common/pages/packages/Packages.vue +208 -208
  30. package/components/common/pages/shortcuts/block/BlockOld.vue +68 -68
  31. package/components/common/readyToComplete/ReadyToComplete.vue +17 -17
  32. package/components/common/recursionTree/RecursionTree.vue +223 -223
  33. package/components/common/select/button/ButtonDropdown.vue +108 -108
  34. package/components/common/spiceConsole/lib/models/interfaces.ts +5 -5
  35. package/components/common/vm/actions/add/folderTreeView/FolderTreeView.vue +72 -72
  36. package/components/common/vm/actions/add/folderTreeView/New.vue +40 -40
  37. package/components/common/vm/actions/add/folderTreeView/Old.vue +50 -50
  38. package/components/common/vm/actions/add/lib/config/steps.ts +263 -263
  39. package/components/common/vm/actions/clone/lib/config/steps.ts +291 -291
  40. package/components/common/vm/actions/clone/toTemplate/lib/config/steps.ts +116 -116
  41. package/components/common/vm/actions/common/customizeHardware/CustomizeHardwareNew.vue +337 -337
  42. package/components/common/vm/actions/common/customizeHardware/virtualHardware/VirtualHardwareNew.vue +480 -480
  43. package/components/common/vm/actions/common/customizeHardware/virtualHardware/VirtualHardwareOld.vue +319 -319
  44. package/components/common/vm/actions/common/customizeHardware/virtualHardware/browseView/BrowseView.vue +219 -219
  45. package/components/common/vm/actions/common/customizeHardware/virtualHardware/bus/Bus.vue +100 -100
  46. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cdDvdDrive/CdDvdDrive.vue +232 -232
  47. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cdDvdDrive/CdDvdDriveOld.vue +168 -168
  48. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cdDvdDrive/media/Media.vue +25 -25
  49. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cdDvdDrive/media/MediaNew.vue +78 -78
  50. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cdDvdDrive/media/MediaOld.vue +50 -50
  51. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/Cpu.vue +2 -17
  52. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/CpuNew.vue +190 -190
  53. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/model/ModelNew.vue +237 -237
  54. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/shares/Shares.vue +140 -140
  55. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/shares/lib/config/options.ts +28 -28
  56. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/tooltip/TooltipNew.vue +154 -154
  57. package/components/common/vm/actions/common/customizeHardware/virtualHardware/limit/Limit.vue +220 -220
  58. package/components/common/vm/actions/common/customizeHardware/virtualHardware/memory/Memory.vue +288 -304
  59. package/components/common/vm/actions/common/customizeHardware/virtualHardware/memory/MemoryNew.vue +154 -154
  60. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/NewHardDisk.vue +375 -382
  61. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/NewHardDiskNew.vue +289 -289
  62. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/location/Location.vue +151 -151
  63. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/location/LocationNew.vue +73 -73
  64. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/location/LocationOld.vue +83 -83
  65. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newNetwork/NewNetwork.vue +288 -288
  66. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newNetwork/location/new/table/lib/config/config.ts +94 -94
  67. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newNetwork/macAddress/MacAddress.vue +119 -119
  68. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/NewPciDevice.vue +205 -205
  69. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/directPathIo/DirectPathIoNew.vue +66 -66
  70. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/directPathIo/DirectPathIoOld.vue +62 -62
  71. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/dynamicDirectPathIo/DynamicDirectPathIo.vue +31 -31
  72. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/dynamicDirectPathIo/DynamicDirectPathIoOld.vue +76 -76
  73. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/note/Note.vue +15 -15
  74. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/note/NoteNew.vue +42 -42
  75. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/note/NoteOld.vue +30 -30
  76. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/nvidiaGrid/NvidiaGridOld.vue +84 -84
  77. package/components/common/vm/actions/common/customizeHardware/virtualHardware/other/Other.vue +16 -16
  78. package/components/common/vm/actions/common/customizeHardware/virtualHardware/other/OtherNew.vue +30 -30
  79. package/components/common/vm/actions/common/customizeHardware/virtualHardware/other/inputDevices/InputDevicesNew.vue +40 -40
  80. package/components/common/vm/actions/common/customizeHardware/vmoptions/Vmoptions.vue +145 -145
  81. package/components/common/vm/actions/common/customizeHardware/vmoptions/VmoptionsNew.vue +106 -106
  82. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/BootOptionsNew.vue +81 -81
  83. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/delay/Delay.vue +32 -32
  84. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/firmware/Firmware.vue +60 -60
  85. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/order/Order.vue +174 -174
  86. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/order/OrderNew.vue +67 -67
  87. package/components/common/vm/actions/common/customizeHardware/vmoptions/generalOptions/GeneralOptionsNew.vue +149 -149
  88. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/New.vue +140 -140
  89. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/copyPaste/CopyPasteNew.vue +31 -31
  90. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/fileTransfer/FileTransferNew.vue +31 -31
  91. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/keymap/Keymap.vue +32 -32
  92. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/password/PasswordNew.vue +128 -128
  93. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/usbRedirection/UsbRedirection.vue +28 -28
  94. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/usbRedirection/UsbRedirectionNew.vue +39 -39
  95. package/components/common/vm/actions/common/customizeHardware/vmoptions/remoteConsoleOptions/usbRedirection/UsbRedirectionOld.vue +44 -44
  96. package/components/common/vm/actions/common/lib/utils/capabilities.ts +52 -52
  97. package/components/common/vm/actions/common/select/compatibility/Old.vue +107 -107
  98. package/components/common/vm/actions/common/select/computeResource/ComputeResource.vue +134 -134
  99. package/components/common/vm/actions/common/select/computeResource/treeView/New.vue +44 -44
  100. package/components/common/vm/actions/common/select/computeResource/treeView/TreeView.vue +118 -118
  101. package/components/common/vm/actions/common/select/createType/CreateType.vue +38 -38
  102. package/components/common/vm/actions/common/select/createType/New.vue +84 -84
  103. package/components/common/vm/actions/common/select/createType/lib/models/interfaces.ts +5 -5
  104. package/components/common/vm/actions/common/select/name/Name.vue +167 -167
  105. package/components/common/vm/actions/common/select/os/New.vue +122 -122
  106. package/components/common/vm/actions/common/select/os/Old.vue +152 -152
  107. package/components/common/vm/actions/common/select/os/Os.vue +139 -139
  108. package/components/common/vm/actions/common/select/storage/new/lib/models/interfaces.ts +5 -5
  109. package/components/common/vm/actions/common/select/storage/new/lib/utils/utils.ts +21 -21
  110. package/components/common/vm/actions/editSettings/new/Skeleton.vue +88 -88
  111. package/components/common/wizards/vm/migrate/lib/config/constructDataReady.ts +220 -220
  112. package/components/common/wizards/vm/migrate/lib/config/steps.ts +157 -157
  113. package/components/common/wizards/vm/migrate/lib/validations.ts +68 -68
  114. package/components/common/wizards/vm/migrate/select/computeResource/tableView/TableView.vue +137 -137
  115. package/components/common/wizards/vm/migrate/select/network/Network.vue +103 -103
  116. package/components/common/wizards/vm/migrate/select/network/table/network/lib/config/advancedTable.ts +91 -91
  117. package/composables/productNameLocal.ts +30 -30
  118. package/composables/useAppVersion.ts +21 -21
  119. package/package.json +2 -2
  120. package/plugins/date.ts +233 -233
  121. package/public/spice-console/lib/images/bitmap.js +203 -203
  122. package/public/spice-console/network/spicechannel.js +383 -383
  123. package/store/main/mutations.ts +7 -7
  124. package/store/main/state.ts +7 -7
  125. package/store/tasks/mappers/recentTasks.ts +64 -64
@@ -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
+ }
@@ -1,21 +1,21 @@
1
- import type { UI_I_UseAppVersionReturnType } from '~/lib/models/composables/useAppVersion/interfaces'
2
-
3
- export function useAppVersion(): UI_I_UseAppVersionReturnType {
4
- const config = useRuntimeConfig()
5
- const version = config.public.APP_VERSION as string
6
-
7
- // const regexHasDot = /\./
8
- // const regexHasDotAndB = /\.\d*b$/
9
- // const regexHasDotAndD = /\..*d/
10
-
11
- // const isBeta = regexHasDotAndB.test(version)
12
- // const isDev =
13
- // regexHasDotAndD.test(version) ||
14
- // (!regexHasDot.test(version) && version.length < 8)
15
-
16
- return {
17
- version,
18
- // isBeta,
19
- // isDev,
20
- }
21
- }
1
+ import type { UI_I_UseAppVersionReturnType } from '~/lib/models/composables/useAppVersion/interfaces'
2
+
3
+ export function useAppVersion(): UI_I_UseAppVersionReturnType {
4
+ const config = useRuntimeConfig()
5
+ const version = config.public.APP_VERSION as string
6
+
7
+ // const regexHasDot = /\./
8
+ // const regexHasDotAndB = /\.\d*b$/
9
+ // const regexHasDotAndD = /\..*d/
10
+
11
+ // const isBeta = regexHasDotAndB.test(version)
12
+ // const isDev =
13
+ // regexHasDotAndD.test(version) ||
14
+ // (!regexHasDot.test(version) && version.length < 8)
15
+
16
+ return {
17
+ version,
18
+ // isBeta,
19
+ // isDev,
20
+ }
21
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.5.199",
4
+ "version": "1.5.200",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
@@ -34,7 +34,7 @@
34
34
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
35
35
  "@vueuse/components": "^10.1.2",
36
36
  "date-fns": "^2.29.3",
37
- "bfg-nuxt-3-graph": "1.0.25",
37
+ "bfg-nuxt-3-graph": "1.0.26",
38
38
  "bfg-uikit": "1.0.430",
39
39
  "html2canvas": "^1.4.1",
40
40
  "prettier-eslint": "^15.0.1"
package/plugins/date.ts CHANGED
@@ -1,233 +1,233 @@
1
- import { defineNuxtPlugin } from '#app'
2
- import {
3
- format,
4
- // differenceInYears,
5
- // differenceInMonths,
6
- // differenceInDays,
7
- // differenceInHours,
8
- // differenceInMinutes,
9
- // differenceInSeconds,
10
- } from 'date-fns'
11
- import * as localizations from 'date-fns/locale'
12
- import type { UI_T_DateFormat } from '~/lib/models/plugins/date/types'
13
- import type { UI_I_Dateformat } from '~/lib/models/plugins/date/interfaces'
14
- import type { UI_I_ArbitraryObject } from '~/lib/models/interfaces'
15
-
16
- export default defineNuxtPlugin(() => {
17
- // Проверяем переданое является датой
18
- const isDate = (date: string | number) => {
19
- return new Date(date).toString() !== 'Invalid Date'
20
- }
21
-
22
- // Проверяем формат времени браузера равно 24h
23
- const isBrowserLocale24h = () =>
24
- !new Intl.DateTimeFormat(undefined, { hour: 'numeric' })
25
- .format(0)
26
- .match(/AM/)
27
-
28
- // Получаем переводы для даты
29
- const getDateLocalization = (lang?: string) => {
30
- const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
31
- const { be, enUS, hy, kk, ru, zhCN } = localizations
32
- let localization
33
-
34
- switch (currentLanguage) {
35
- case 'be_BY':
36
- localization = be
37
- break
38
- case 'en_US':
39
- localization = enUS
40
- break
41
- case 'hy_AM':
42
- localization = hy
43
- break
44
- case 'kk_KZ':
45
- localization = kk
46
- break
47
- case 'ru_RU':
48
- localization = ru
49
- break
50
- case 'zh_CHS':
51
- localization = zhCN
52
- break
53
- }
54
-
55
- return localization
56
- }
57
-
58
- // Получаем формат даты
59
- const getDateFormat = (lang?: string): UI_T_DateFormat => {
60
- const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
61
- const dateFormats: UI_I_Dateformat = {
62
- be_BY: 'yyyy-MM-dd',
63
- en_US: 'MM-dd-yyyy',
64
- hy_AM: 'yyyy-MM-dd',
65
- kk_KZ: 'dd/MM/yyyy',
66
- ru_RU: 'dd/MM/yyyy',
67
- zh_CHS: 'yyyy-MM-dd',
68
- }
69
-
70
- const dateFormat = ref(dateFormats[currentLanguage])
71
-
72
- window.addEventListener('timeFormatStorageChanged', function handler() {
73
- dateFormat.value = dateFormats[lang || useLocalStorage('lang') || 'en_US'] // TODO нужно проверить когда будем работать без useLocalStorage
74
-
75
- window.removeEventListener('timeFormatStorageChanged', handler)
76
- })
77
-
78
- return dateFormat.value
79
- }
80
-
81
- // Получаем формат времени
82
- const getTimeFormat = (hasSeconds: boolean, timeFormat?: string) => {
83
- let appTimeFormat = timeFormat || useLocalStorage('timeFormat') || 'DEFAULT'
84
- let timeFormatLocal = ''
85
-
86
- if (appTimeFormat === 'DEFAULT') {
87
- const isBrowserTimeFormat24 = isBrowserLocale24h()
88
-
89
- appTimeFormat = isBrowserTimeFormat24 ? '24H' : appTimeFormat
90
- }
91
-
92
- if (appTimeFormat === '24H') {
93
- timeFormatLocal = 'HH:mm'
94
- } else {
95
- timeFormatLocal = 'h:mm aa'
96
- }
97
-
98
- hasSeconds && (timeFormatLocal = timeFormatLocal.replace(':mm', ':mm:ss'))
99
-
100
- return timeFormatLocal
101
- }
102
-
103
- // Форматирование даты из английского в стандартный
104
- const enFormatToStandardFormat = (date: string): string => {
105
- const splitDate = date.split('-')
106
- return [splitDate[2], splitDate[0], splitDate[1]].join('/')
107
- }
108
- const getUnixByDate = (dateTime: string, lang?: string): number => {
109
- const currentFormat: UI_T_DateFormat = getDateFormat(lang)
110
-
111
- const [date, time] = dateTime.split(' ')
112
-
113
- let standardDate = ''
114
- switch (currentFormat) {
115
- case 'dd/MM/yyyy':
116
- standardDate = date.split('/').reverse().join('/')
117
- break
118
- case 'yyyy-MM-dd':
119
- standardDate = date.replaceAll('-', '/')
120
- break
121
- case 'MM-dd-yyyy':
122
- standardDate = enFormatToStandardFormat(date)
123
- break
124
- }
125
-
126
- const standard = time ? standardDate + ' ' + time : standardDate
127
- return new Date(standard).getTime()
128
- }
129
-
130
- // Форматирование даты без временим
131
- const formattedDate = (
132
- date: number | string | Date,
133
- formatDate = '',
134
- lang?: string
135
- ) => {
136
- const formatDateLocal = formatDate || getDateFormat(lang)
137
-
138
- return format(new Date(date), formatDateLocal, {
139
- locale: getDateLocalization(lang),
140
- })
141
- }
142
- // Форматирование временим
143
- const formattedTime = (
144
- date: number | string | Date,
145
- formatDate = '',
146
- hasSeconds = false,
147
- timeFormat?: string
148
- ) => {
149
- const formatDateLocal = formatDate || getTimeFormat(hasSeconds, timeFormat)
150
-
151
- return format(new Date(date), formatDateLocal)
152
- }
153
-
154
- // Форматирование даты с временим
155
- const formattedDatetime = (
156
- date: number | string | Date,
157
- formatDate = '',
158
- hasSeconds = false,
159
- lang?: string,
160
- timeFormat?: string
161
- ) => {
162
- const formatDateLocal = ref(formatDate || getDateFormat(lang))
163
- const formatDatetime = ref(
164
- formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
165
- )
166
-
167
- window.addEventListener('timeFormatStorageChanged', function handler() {
168
- formatDatetime.value =
169
- formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
170
-
171
- window.removeEventListener('timeFormatStorageChanged', handler)
172
- })
173
-
174
- return format(new Date(date), formatDatetime.value, {
175
- locale: getDateLocalization(lang),
176
- })
177
- }
178
-
179
- const correctRuUnit = (value: number, type: string): string => {
180
- let result = ''
181
-
182
- const forms: UI_I_ArbitraryObject<string[]> = {
183
- second: ['Секунда', 'Секунды', 'Секунд'],
184
- minute: ['Минута', 'Минуты', 'Минут'],
185
- hour: ['Час', 'Часа', 'Часов'],
186
- day: ['День', 'Дня', 'Дней'],
187
- week: ['Неделя', 'Недели', 'Недель'],
188
- month: ['Месяц', 'Месяца', 'Месяцев'],
189
- year: ['Год', 'Года', 'Лет'],
190
- }
191
-
192
- const isFirstType = value % 10 === 1 && value % 100 !== 11
193
- const isSecondType =
194
- [2, 3, 4].includes(value % 10) && ![12, 13, 14].includes(value % 100)
195
-
196
- if (isFirstType) {
197
- result = forms[type][0]
198
- } else if (isSecondType) {
199
- result = forms[type][1]
200
- } else {
201
- result = forms[type][2]
202
- }
203
-
204
- return result
205
- }
206
-
207
- // Определяем сколько времени осталось
208
- // time = seconds
209
- const timeToTimeLeft = (time: number): number[] => {
210
- const seconds = Math.floor(time % 60)
211
- const minutes = Math.floor((time / 60) % 60)
212
- const hours = Math.floor((time / 60 / 60) % 24)
213
- const days = Math.floor((time / 60 / 60 / 24) % 30)
214
- const months = Math.floor((time / 60 / 60 / 24 / 30) % 12)
215
- const years = Math.floor(time / 60 / 60 / 24 / 30 / 12)
216
-
217
- return [years, months, days, hours, minutes, seconds]
218
- }
219
-
220
- return {
221
- provide: {
222
- isDate,
223
- getTimeFormat,
224
- getDateFormat,
225
- formattedTime,
226
- formattedDate,
227
- formattedDatetime,
228
- getUnixByDate,
229
- correctRuUnit,
230
- timeToTimeLeft,
231
- },
232
- }
233
- })
1
+ import { defineNuxtPlugin } from '#app'
2
+ import {
3
+ format,
4
+ // differenceInYears,
5
+ // differenceInMonths,
6
+ // differenceInDays,
7
+ // differenceInHours,
8
+ // differenceInMinutes,
9
+ // differenceInSeconds,
10
+ } from 'date-fns'
11
+ import * as localizations from 'date-fns/locale'
12
+ import type { UI_T_DateFormat } from '~/lib/models/plugins/date/types'
13
+ import type { UI_I_Dateformat } from '~/lib/models/plugins/date/interfaces'
14
+ import type { UI_I_ArbitraryObject } from '~/lib/models/interfaces'
15
+
16
+ export default defineNuxtPlugin(() => {
17
+ // Проверяем переданое является датой
18
+ const isDate = (date: string | number) => {
19
+ return new Date(date).toString() !== 'Invalid Date'
20
+ }
21
+
22
+ // Проверяем формат времени браузера равно 24h
23
+ const isBrowserLocale24h = () =>
24
+ !new Intl.DateTimeFormat(undefined, { hour: 'numeric' })
25
+ .format(0)
26
+ .match(/AM/)
27
+
28
+ // Получаем переводы для даты
29
+ const getDateLocalization = (lang?: string) => {
30
+ const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
31
+ const { be, enUS, hy, kk, ru, zhCN } = localizations
32
+ let localization
33
+
34
+ switch (currentLanguage) {
35
+ case 'be_BY':
36
+ localization = be
37
+ break
38
+ case 'en_US':
39
+ localization = enUS
40
+ break
41
+ case 'hy_AM':
42
+ localization = hy
43
+ break
44
+ case 'kk_KZ':
45
+ localization = kk
46
+ break
47
+ case 'ru_RU':
48
+ localization = ru
49
+ break
50
+ case 'zh_CHS':
51
+ localization = zhCN
52
+ break
53
+ }
54
+
55
+ return localization
56
+ }
57
+
58
+ // Получаем формат даты
59
+ const getDateFormat = (lang?: string): UI_T_DateFormat => {
60
+ const currentLanguage = lang || useLocalStorage('lang') || 'en_US'
61
+ const dateFormats: UI_I_Dateformat = {
62
+ be_BY: 'yyyy-MM-dd',
63
+ en_US: 'MM-dd-yyyy',
64
+ hy_AM: 'yyyy-MM-dd',
65
+ kk_KZ: 'dd/MM/yyyy',
66
+ ru_RU: 'dd/MM/yyyy',
67
+ zh_CHS: 'yyyy-MM-dd',
68
+ }
69
+
70
+ const dateFormat = ref(dateFormats[currentLanguage])
71
+
72
+ window.addEventListener('timeFormatStorageChanged', function handler() {
73
+ dateFormat.value = dateFormats[lang || useLocalStorage('lang') || 'en_US'] // TODO нужно проверить когда будем работать без useLocalStorage
74
+
75
+ window.removeEventListener('timeFormatStorageChanged', handler)
76
+ })
77
+
78
+ return dateFormat.value
79
+ }
80
+
81
+ // Получаем формат времени
82
+ const getTimeFormat = (hasSeconds: boolean, timeFormat?: string) => {
83
+ let appTimeFormat = timeFormat || useLocalStorage('timeFormat') || 'DEFAULT'
84
+ let timeFormatLocal = ''
85
+
86
+ if (appTimeFormat === 'DEFAULT') {
87
+ const isBrowserTimeFormat24 = isBrowserLocale24h()
88
+
89
+ appTimeFormat = isBrowserTimeFormat24 ? '24H' : appTimeFormat
90
+ }
91
+
92
+ if (appTimeFormat === '24H') {
93
+ timeFormatLocal = 'HH:mm'
94
+ } else {
95
+ timeFormatLocal = 'h:mm aa'
96
+ }
97
+
98
+ hasSeconds && (timeFormatLocal = timeFormatLocal.replace(':mm', ':mm:ss'))
99
+
100
+ return timeFormatLocal
101
+ }
102
+
103
+ // Форматирование даты из английского в стандартный
104
+ const enFormatToStandardFormat = (date: string): string => {
105
+ const splitDate = date.split('-')
106
+ return [splitDate[2], splitDate[0], splitDate[1]].join('/')
107
+ }
108
+ const getUnixByDate = (dateTime: string, lang?: string): number => {
109
+ const currentFormat: UI_T_DateFormat = getDateFormat(lang)
110
+
111
+ const [date, time] = dateTime.split(' ')
112
+
113
+ let standardDate = ''
114
+ switch (currentFormat) {
115
+ case 'dd/MM/yyyy':
116
+ standardDate = date.split('/').reverse().join('/')
117
+ break
118
+ case 'yyyy-MM-dd':
119
+ standardDate = date.replaceAll('-', '/')
120
+ break
121
+ case 'MM-dd-yyyy':
122
+ standardDate = enFormatToStandardFormat(date)
123
+ break
124
+ }
125
+
126
+ const standard = time ? standardDate + ' ' + time : standardDate
127
+ return new Date(standard).getTime()
128
+ }
129
+
130
+ // Форматирование даты без временим
131
+ const formattedDate = (
132
+ date: number | string | Date,
133
+ formatDate = '',
134
+ lang?: string
135
+ ) => {
136
+ const formatDateLocal = formatDate || getDateFormat(lang)
137
+
138
+ return format(new Date(date), formatDateLocal, {
139
+ locale: getDateLocalization(lang),
140
+ })
141
+ }
142
+ // Форматирование временим
143
+ const formattedTime = (
144
+ date: number | string | Date,
145
+ formatDate = '',
146
+ hasSeconds = false,
147
+ timeFormat?: string
148
+ ) => {
149
+ const formatDateLocal = formatDate || getTimeFormat(hasSeconds, timeFormat)
150
+
151
+ return format(new Date(date), formatDateLocal)
152
+ }
153
+
154
+ // Форматирование даты с временим
155
+ const formattedDatetime = (
156
+ date: number | string | Date,
157
+ formatDate = '',
158
+ hasSeconds = false,
159
+ lang?: string,
160
+ timeFormat?: string
161
+ ) => {
162
+ const formatDateLocal = ref(formatDate || getDateFormat(lang))
163
+ const formatDatetime = ref(
164
+ formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
165
+ )
166
+
167
+ window.addEventListener('timeFormatStorageChanged', function handler() {
168
+ formatDatetime.value =
169
+ formatDateLocal.value + ' ' + getTimeFormat(hasSeconds, timeFormat)
170
+
171
+ window.removeEventListener('timeFormatStorageChanged', handler)
172
+ })
173
+
174
+ return format(new Date(date), formatDatetime.value, {
175
+ locale: getDateLocalization(lang),
176
+ })
177
+ }
178
+
179
+ const correctRuUnit = (value: number, type: string): string => {
180
+ let result = ''
181
+
182
+ const forms: UI_I_ArbitraryObject<string[]> = {
183
+ second: ['Секунда', 'Секунды', 'Секунд'],
184
+ minute: ['Минута', 'Минуты', 'Минут'],
185
+ hour: ['Час', 'Часа', 'Часов'],
186
+ day: ['День', 'Дня', 'Дней'],
187
+ week: ['Неделя', 'Недели', 'Недель'],
188
+ month: ['Месяц', 'Месяца', 'Месяцев'],
189
+ year: ['Год', 'Года', 'Лет'],
190
+ }
191
+
192
+ const isFirstType = value % 10 === 1 && value % 100 !== 11
193
+ const isSecondType =
194
+ [2, 3, 4].includes(value % 10) && ![12, 13, 14].includes(value % 100)
195
+
196
+ if (isFirstType) {
197
+ result = forms[type][0]
198
+ } else if (isSecondType) {
199
+ result = forms[type][1]
200
+ } else {
201
+ result = forms[type][2]
202
+ }
203
+
204
+ return result
205
+ }
206
+
207
+ // Определяем сколько времени осталось
208
+ // time = seconds
209
+ const timeToTimeLeft = (time: number): number[] => {
210
+ const seconds = Math.floor(time % 60)
211
+ const minutes = Math.floor((time / 60) % 60)
212
+ const hours = Math.floor((time / 60 / 60) % 24)
213
+ const days = Math.floor((time / 60 / 60 / 24) % 30)
214
+ const months = Math.floor((time / 60 / 60 / 24 / 30) % 12)
215
+ const years = Math.floor(time / 60 / 60 / 24 / 30 / 12)
216
+
217
+ return [years, months, days, hours, minutes, seconds]
218
+ }
219
+
220
+ return {
221
+ provide: {
222
+ isDate,
223
+ getTimeFormat,
224
+ getDateFormat,
225
+ formattedTime,
226
+ formattedDate,
227
+ formattedDatetime,
228
+ getUnixByDate,
229
+ correctRuUnit,
230
+ timeToTimeLeft,
231
+ },
232
+ }
233
+ })