shared-ritm 1.2.129 → 1.2.131

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 (136) hide show
  1. package/README.md +103 -103
  2. package/dist/index.css +1 -1
  3. package/dist/shared-ritm.es.js +3045 -2991
  4. package/dist/shared-ritm.umd.js +146 -146
  5. package/dist/types/api/services/PhotoService.d.ts +40 -0
  6. package/dist/types/api/services/ProjectsService.d.ts +1 -0
  7. package/dist/types/api/services/ScheduleService.d.ts +13 -0
  8. package/dist/types/api/services/VideoService.d.ts +18 -9
  9. package/dist/types/api/types/Api_Schedule.d.ts +26 -0
  10. package/dist/types/api/types/Api_Video.d.ts +4 -0
  11. package/dist/types/index.d.ts +3 -1
  12. package/package.json +64 -64
  13. package/src/App.vue +2461 -2461
  14. package/src/api/services/AuthService.ts +53 -53
  15. package/src/api/services/BrigadesService.ts +32 -32
  16. package/src/api/services/CommentsService.ts +24 -24
  17. package/src/api/services/ControlsService.ts +73 -73
  18. package/src/api/services/EquipmentService.ts +29 -29
  19. package/src/api/services/FileService.ts +17 -17
  20. package/src/api/services/GanttService.ts +17 -17
  21. package/src/api/services/InstrumentsService.ts +63 -63
  22. package/src/api/services/MetricsService.ts +110 -110
  23. package/src/api/services/ModulesService.ts +27 -27
  24. package/src/api/services/ProjectsService.ts +83 -79
  25. package/src/api/services/RepairsService.ts +123 -123
  26. package/src/api/services/ScheduleService.ts +34 -0
  27. package/src/api/services/SearchService.ts +22 -22
  28. package/src/api/services/TasksService.ts +145 -145
  29. package/src/api/services/UserService.ts +101 -101
  30. package/src/api/services/VideoService.ts +103 -71
  31. package/src/api/settings/ApiService.ts +124 -124
  32. package/src/api/types/Api_Auth.ts +86 -86
  33. package/src/api/types/Api_Brigades.ts +36 -36
  34. package/src/api/types/Api_Comment.ts +40 -40
  35. package/src/api/types/Api_Controls.ts +93 -93
  36. package/src/api/types/Api_Equipment.ts +3 -3
  37. package/src/api/types/Api_Files.ts +7 -7
  38. package/src/api/types/Api_Instruments.ts +136 -136
  39. package/src/api/types/Api_Modules.ts +21 -21
  40. package/src/api/types/Api_Projects.ts +60 -60
  41. package/src/api/types/Api_Repairs.ts +117 -117
  42. package/src/api/types/Api_Schedule.ts +29 -0
  43. package/src/api/types/Api_Search.ts +77 -77
  44. package/src/api/types/Api_Service.ts +9 -9
  45. package/src/api/types/Api_Tasks.ts +319 -319
  46. package/src/api/types/Api_User.ts +117 -117
  47. package/src/api/types/Api_Video.ts +145 -140
  48. package/src/common/app-button/AppButton.vue +173 -173
  49. package/src/common/app-checkbox/AppCheckbox.vue +26 -26
  50. package/src/common/app-date-picker/AppDatePicker.vue +81 -81
  51. package/src/common/app-datepicker/AppDatepicker.vue +165 -165
  52. package/src/common/app-dialogs/AppConfirmDialog.vue +99 -99
  53. package/src/common/app-dropdown/AppDropdown.vue +37 -37
  54. package/src/common/app-icon/AppIcon.vue +108 -108
  55. package/src/common/app-input/AppInput.vue +148 -148
  56. package/src/common/app-input-new/AppInputNew.vue +175 -175
  57. package/src/common/app-input-search/AppInputSearch.vue +174 -174
  58. package/src/common/app-layout/AppLayout.vue +84 -84
  59. package/src/common/app-layout/components/AppLayoutHeader.vue +273 -273
  60. package/src/common/app-layout/components/AppLayoutPage.vue +16 -16
  61. package/src/common/app-loader/index.vue +43 -43
  62. package/src/common/app-page-layout/AppPageLayout.vue +122 -122
  63. package/src/common/app-select/AppSelect.vue +157 -157
  64. package/src/common/app-sheet/AppSheet.vue +120 -120
  65. package/src/common/app-sheet-new/AppSheetNew.vue +246 -246
  66. package/src/common/app-sidebar/AppSidebar.vue +168 -168
  67. package/src/common/app-sidebar/components/SidebarMenu.vue +37 -37
  68. package/src/common/app-sidebar/components/SidebarMenuItem.vue +148 -148
  69. package/src/common/app-table/AppTable.vue +308 -308
  70. package/src/common/app-table/AppTableLayout.vue +137 -137
  71. package/src/common/app-table/components/ModalSelect.vue +281 -281
  72. package/src/common/app-table/components/TableModal.vue +356 -356
  73. package/src/common/app-table/components/TablePagination.vue +152 -152
  74. package/src/common/app-table/controllers/useBaseTable.ts +45 -45
  75. package/src/common/app-table/controllers/useColumnSelector.ts +38 -38
  76. package/src/common/app-table/controllers/useTableModel.ts +102 -102
  77. package/src/common/app-toggle/AppToggle.vue +24 -24
  78. package/src/common/app-wrapper/AppWrapper.vue +28 -28
  79. package/src/global.d.ts +1 -1
  80. package/src/icons/components/arrow-down-icon.vue +25 -25
  81. package/src/icons/components/arrow-frame-icon.vue +19 -19
  82. package/src/icons/components/arrow-square.vue +22 -22
  83. package/src/icons/components/table-filter-icon.vue +30 -30
  84. package/src/icons/dialogs/RemoveIcon.vue +12 -12
  85. package/src/icons/dialogs/SafetyIcon.vue +12 -12
  86. package/src/icons/header/NotificationIcon.vue +18 -18
  87. package/src/icons/header/PersonIcon.vue +11 -11
  88. package/src/icons/header/SettingIcon.vue +14 -14
  89. package/src/icons/header/flashIcon.vue +24 -24
  90. package/src/icons/header/searchStatusIcon.vue +24 -24
  91. package/src/icons/header/smallCapsIcon.vue +34 -34
  92. package/src/icons/sidebar/assign-module-icon.vue +36 -36
  93. package/src/icons/sidebar/instrument-history-icon.vue +32 -32
  94. package/src/icons/sidebar/instrument-order-icon.vue +38 -38
  95. package/src/icons/sidebar/instrument-work-zone-icon.vue +18 -18
  96. package/src/icons/sidebar/instruments-icon.vue +45 -45
  97. package/src/icons/sidebar/logo-icon.vue +15 -15
  98. package/src/icons/sidebar/logout-icon.vue +13 -13
  99. package/src/icons/sidebar/modules-icon.vue +16 -16
  100. package/src/icons/sidebar/notifications-icon.vue +24 -24
  101. package/src/icons/sidebar/order-icon.vue +44 -44
  102. package/src/icons/sidebar/pass-icon.vue +38 -38
  103. package/src/icons/sidebar/positions-icon.vue +42 -42
  104. package/src/icons/sidebar/preorder-icon.vue +19 -19
  105. package/src/icons/sidebar/projects-icon.vue +31 -31
  106. package/src/icons/sidebar/repair-object-icon.vue +18 -18
  107. package/src/icons/sidebar/repairs-icon.vue +20 -20
  108. package/src/icons/sidebar/roles-icon.vue +26 -26
  109. package/src/icons/sidebar/status-history-icon.vue +24 -24
  110. package/src/icons/sidebar/tasks-icon.vue +28 -28
  111. package/src/icons/sidebar/tasks_tasks-icon.vue +39 -39
  112. package/src/icons/sidebar/tasks_today-icon.vue +27 -27
  113. package/src/icons/sidebar/teams-icon.vue +32 -32
  114. package/src/icons/sidebar/user-icon.vue +18 -18
  115. package/src/icons/sidebar/users-icon.vue +46 -46
  116. package/src/icons/sidebar/videosources-icon.vue +19 -19
  117. package/src/icons/sidebar/videowall-icon.vue +13 -13
  118. package/src/icons/sidebar/videozones-icon.vue +21 -21
  119. package/src/icons/sidebar/warehouses-icon.vue +43 -43
  120. package/src/icons/sidebar/workshop-icon.vue +100 -100
  121. package/src/icons/sidebar/workzones-icon.vue +22 -22
  122. package/src/icons/task/attention-icon.vue +13 -13
  123. package/src/icons/task/clock-icon.vue +10 -10
  124. package/src/icons/task/delete-icon.vue +10 -10
  125. package/src/icons/task/fire-icon.vue +16 -16
  126. package/src/index.ts +126 -123
  127. package/src/main.ts +28 -28
  128. package/src/quasar-user-options.ts +17 -17
  129. package/src/router/index.ts +10 -10
  130. package/src/shared/styles/general.css +124 -124
  131. package/src/shims-vue.d.ts +5 -5
  132. package/src/styles/variables.sass +12 -12
  133. package/src/utils/confirm.ts +12 -12
  134. package/src/utils/faceApiHelper.ts +132 -132
  135. package/src/utils/helpers.ts +59 -59
  136. package/src/utils/notification.ts +9 -9
@@ -1,152 +1,152 @@
1
- <template>
2
- <div class="table-pagination">
3
- <button class="arrow-button" :disabled="modelValue <= 1" @click="prevPage">
4
- <q-icon name="mdi-chevron-left" :color="modelValue <= 1 ? 'grey-4' : 'primary'" />
5
- </button>
6
-
7
- <div class="pages">
8
- <button
9
- v-for="page in pageArray"
10
- :key="page"
11
- class="page-button"
12
- :class="{ selected: page === modelValue, ellipsis: page === '...' }"
13
- :disabled="page === modelValue || page === '...'"
14
- @click="changePage(page)"
15
- >
16
- {{ page }}
17
- </button>
18
- </div>
19
-
20
- <button class="arrow-button" :disabled="modelValue >= totalPages" @click="nextPage">
21
- <q-icon name="mdi-chevron-right" :color="modelValue >= totalPages ? 'grey-4' : 'primary'" />
22
- </button>
23
- </div>
24
- </template>
25
- <script setup lang="ts">
26
- import { computed } from 'vue'
27
- import { defineProps, defineEmits } from 'vue'
28
-
29
- const props = defineProps<{
30
- modelValue: number
31
- totalPages: number
32
- }>()
33
-
34
- const emit = defineEmits<{
35
- (e: 'update:modelValue', value: number): void
36
- (e: 'page-change', value: number): void
37
- }>()
38
-
39
- const currentPage = computed({
40
- get: () => props.modelValue,
41
- set: (val: number) => {
42
- emit('update:modelValue', val)
43
- emit('page-change', val)
44
- },
45
- })
46
-
47
- const pageArray = computed(() => {
48
- const maxPagesToShow = 5
49
- let startPage = 1
50
- let endPage = props.totalPages
51
- const pages: (number | string)[] = []
52
-
53
- if (props.totalPages <= maxPagesToShow) {
54
- for (let i = 1; i <= props.totalPages; i++) pages.push(i)
55
- } else {
56
- if (props.modelValue <= 3) {
57
- startPage = 1
58
- endPage = maxPagesToShow - 1
59
- } else if (props.modelValue + 2 >= props.totalPages) {
60
- startPage = props.totalPages - (maxPagesToShow - 2)
61
- endPage = props.totalPages
62
- } else {
63
- startPage = props.modelValue - 2
64
- endPage = props.modelValue + 2
65
- }
66
-
67
- for (let i = startPage; i <= endPage; i++) pages.push(i)
68
-
69
- if (startPage > 1) {
70
- pages.unshift('...')
71
- pages.unshift(1)
72
- }
73
- if (endPage < props.totalPages) {
74
- pages.push('...')
75
- pages.push(props.totalPages)
76
- }
77
- }
78
-
79
- return pages
80
- })
81
-
82
- function changePage(page: number | string) {
83
- if (typeof page === 'number' && page !== props.modelValue) {
84
- currentPage.value = page
85
- }
86
- }
87
-
88
- function prevPage() {
89
- if (props.modelValue > 1) currentPage.value = props.modelValue - 1
90
- }
91
-
92
- function nextPage() {
93
- if (props.modelValue < props.totalPages) currentPage.value = props.modelValue + 1
94
- }
95
- </script>
96
-
97
- <style scoped lang="scss">
98
- .pages {
99
- display: flex;
100
- gap: 20px;
101
- }
102
- .table-pagination {
103
- display: flex;
104
- justify-content: start;
105
- align-items: center;
106
- gap: 20px;
107
- flex-wrap: wrap;
108
-
109
- .arrow-button,
110
- .page-button {
111
- display: flex;
112
- justify-content: center;
113
- align-items: center;
114
- width: 34px;
115
- height: 34px;
116
- border-radius: 4px;
117
- background: white;
118
- border: none;
119
- cursor: pointer;
120
- font-weight: 500;
121
- color: #3f8cff;
122
- font-size: 16px;
123
- transition: all 0.2s ease;
124
- }
125
-
126
- .page-button.selected {
127
- background: #3f8cff;
128
- color: white;
129
- cursor: not-allowed;
130
- }
131
-
132
- .page-button.ellipsis {
133
- cursor: default;
134
- color: #aab2c8;
135
- font-weight: 400;
136
- }
137
-
138
- .arrow-button:disabled {
139
- cursor: not-allowed;
140
- background: white;
141
- }
142
-
143
- @media (max-width: 768px) {
144
- .arrow-button,
145
- .page-button {
146
- width: 32px;
147
- height: 32px;
148
- font-size: 14px;
149
- }
150
- }
151
- }
152
- </style>
1
+ <template>
2
+ <div class="table-pagination">
3
+ <button class="arrow-button" :disabled="modelValue <= 1" @click="prevPage">
4
+ <q-icon name="mdi-chevron-left" :color="modelValue <= 1 ? 'grey-4' : 'primary'" />
5
+ </button>
6
+
7
+ <div class="pages">
8
+ <button
9
+ v-for="page in pageArray"
10
+ :key="page"
11
+ class="page-button"
12
+ :class="{ selected: page === modelValue, ellipsis: page === '...' }"
13
+ :disabled="page === modelValue || page === '...'"
14
+ @click="changePage(page)"
15
+ >
16
+ {{ page }}
17
+ </button>
18
+ </div>
19
+
20
+ <button class="arrow-button" :disabled="modelValue >= totalPages" @click="nextPage">
21
+ <q-icon name="mdi-chevron-right" :color="modelValue >= totalPages ? 'grey-4' : 'primary'" />
22
+ </button>
23
+ </div>
24
+ </template>
25
+ <script setup lang="ts">
26
+ import { computed } from 'vue'
27
+ import { defineProps, defineEmits } from 'vue'
28
+
29
+ const props = defineProps<{
30
+ modelValue: number
31
+ totalPages: number
32
+ }>()
33
+
34
+ const emit = defineEmits<{
35
+ (e: 'update:modelValue', value: number): void
36
+ (e: 'page-change', value: number): void
37
+ }>()
38
+
39
+ const currentPage = computed({
40
+ get: () => props.modelValue,
41
+ set: (val: number) => {
42
+ emit('update:modelValue', val)
43
+ emit('page-change', val)
44
+ },
45
+ })
46
+
47
+ const pageArray = computed(() => {
48
+ const maxPagesToShow = 5
49
+ let startPage = 1
50
+ let endPage = props.totalPages
51
+ const pages: (number | string)[] = []
52
+
53
+ if (props.totalPages <= maxPagesToShow) {
54
+ for (let i = 1; i <= props.totalPages; i++) pages.push(i)
55
+ } else {
56
+ if (props.modelValue <= 3) {
57
+ startPage = 1
58
+ endPage = maxPagesToShow - 1
59
+ } else if (props.modelValue + 2 >= props.totalPages) {
60
+ startPage = props.totalPages - (maxPagesToShow - 2)
61
+ endPage = props.totalPages
62
+ } else {
63
+ startPage = props.modelValue - 2
64
+ endPage = props.modelValue + 2
65
+ }
66
+
67
+ for (let i = startPage; i <= endPage; i++) pages.push(i)
68
+
69
+ if (startPage > 1) {
70
+ pages.unshift('...')
71
+ pages.unshift(1)
72
+ }
73
+ if (endPage < props.totalPages) {
74
+ pages.push('...')
75
+ pages.push(props.totalPages)
76
+ }
77
+ }
78
+
79
+ return pages
80
+ })
81
+
82
+ function changePage(page: number | string) {
83
+ if (typeof page === 'number' && page !== props.modelValue) {
84
+ currentPage.value = page
85
+ }
86
+ }
87
+
88
+ function prevPage() {
89
+ if (props.modelValue > 1) currentPage.value = props.modelValue - 1
90
+ }
91
+
92
+ function nextPage() {
93
+ if (props.modelValue < props.totalPages) currentPage.value = props.modelValue + 1
94
+ }
95
+ </script>
96
+
97
+ <style scoped lang="scss">
98
+ .pages {
99
+ display: flex;
100
+ gap: 20px;
101
+ }
102
+ .table-pagination {
103
+ display: flex;
104
+ justify-content: start;
105
+ align-items: center;
106
+ gap: 20px;
107
+ flex-wrap: wrap;
108
+
109
+ .arrow-button,
110
+ .page-button {
111
+ display: flex;
112
+ justify-content: center;
113
+ align-items: center;
114
+ width: 34px;
115
+ height: 34px;
116
+ border-radius: 4px;
117
+ background: white;
118
+ border: none;
119
+ cursor: pointer;
120
+ font-weight: 500;
121
+ color: #3f8cff;
122
+ font-size: 16px;
123
+ transition: all 0.2s ease;
124
+ }
125
+
126
+ .page-button.selected {
127
+ background: #3f8cff;
128
+ color: white;
129
+ cursor: not-allowed;
130
+ }
131
+
132
+ .page-button.ellipsis {
133
+ cursor: default;
134
+ color: #aab2c8;
135
+ font-weight: 400;
136
+ }
137
+
138
+ .arrow-button:disabled {
139
+ cursor: not-allowed;
140
+ background: white;
141
+ }
142
+
143
+ @media (max-width: 768px) {
144
+ .arrow-button,
145
+ .page-button {
146
+ width: 32px;
147
+ height: 32px;
148
+ font-size: 14px;
149
+ }
150
+ }
151
+ }
152
+ </style>
@@ -1,45 +1,45 @@
1
- import { ref, watch, onMounted, Ref } from 'vue'
2
-
3
- export function useBaseTable(model: {
4
- initialize: (params: { search: string; page: number }) => Promise<void>
5
- loading: Ref<boolean>
6
- columnFilters: Ref<Record<string, any>>
7
- }) {
8
- const search = ref('')
9
- const currentPage = ref(1)
10
-
11
- const loadTable = async (searchVal = '', pageVal = 1) => {
12
- await model.initialize({ search: searchVal, page: pageVal })
13
- }
14
-
15
- const handleSearch = async (val: string) => {
16
- search.value = val
17
- currentPage.value = 1
18
- await loadTable(val, currentPage.value)
19
- }
20
-
21
- const handlePageChange = async (page: number) => {
22
- currentPage.value = page
23
- await loadTable(search.value, page)
24
- }
25
-
26
- watch(
27
- () => model.columnFilters.value,
28
- async () => {
29
- currentPage.value = 1
30
- await loadTable(search.value, currentPage.value)
31
- },
32
- { deep: true },
33
- )
34
-
35
- onMounted(() => loadTable(search.value, currentPage.value))
36
-
37
- return {
38
- search,
39
- currentPage,
40
- loading: model.loading,
41
- handleSearch,
42
- handlePageChange,
43
- loadTable,
44
- }
45
- }
1
+ import { ref, watch, onMounted, Ref } from 'vue'
2
+
3
+ export function useBaseTable(model: {
4
+ initialize: (params: { search: string; page: number }) => Promise<void>
5
+ loading: Ref<boolean>
6
+ columnFilters: Ref<Record<string, any>>
7
+ }) {
8
+ const search = ref('')
9
+ const currentPage = ref(1)
10
+
11
+ const loadTable = async (searchVal = '', pageVal = 1) => {
12
+ await model.initialize({ search: searchVal, page: pageVal })
13
+ }
14
+
15
+ const handleSearch = async (val: string) => {
16
+ search.value = val
17
+ currentPage.value = 1
18
+ await loadTable(val, currentPage.value)
19
+ }
20
+
21
+ const handlePageChange = async (page: number) => {
22
+ currentPage.value = page
23
+ await loadTable(search.value, page)
24
+ }
25
+
26
+ watch(
27
+ () => model.columnFilters.value,
28
+ async () => {
29
+ currentPage.value = 1
30
+ await loadTable(search.value, currentPage.value)
31
+ },
32
+ { deep: true },
33
+ )
34
+
35
+ onMounted(() => loadTable(search.value, currentPage.value))
36
+
37
+ return {
38
+ search,
39
+ currentPage,
40
+ loading: model.loading,
41
+ handleSearch,
42
+ handlePageChange,
43
+ loadTable,
44
+ }
45
+ }
@@ -1,38 +1,38 @@
1
- import { computed, ref } from 'vue'
2
-
3
- export interface ColumnConfig {
4
- name: string
5
- label: string
6
- [key: string]: any
7
- }
8
-
9
- export function useColumnSelector(allColumns: ColumnConfig[], fixedColumnNames: string[] = []) {
10
- const selectedColumnNames = ref<string[]>([...new Set([...fixedColumnNames, ...allColumns.map(col => col.name)])])
11
-
12
- const visibleColumns = computed(() => allColumns.filter(col => selectedColumnNames.value.includes(col.name)))
13
-
14
- function openColumnSelectorDialog($q: any) {
15
- $q.dialog({
16
- title: 'Выберите колонки',
17
- options: {
18
- type: 'checkbox',
19
- model: [...selectedColumnNames.value],
20
- items: allColumns.map(col => ({
21
- label: col.label,
22
- value: col.name,
23
- disable: fixedColumnNames.includes(col.name),
24
- })),
25
- },
26
- cancel: true,
27
- persistent: true,
28
- }).onOk((val: string[]) => {
29
- selectedColumnNames.value = Array.from(new Set([...val, ...fixedColumnNames]))
30
- })
31
- }
32
-
33
- return {
34
- selectedColumnNames,
35
- visibleColumns,
36
- openColumnSelectorDialog,
37
- }
38
- }
1
+ import { computed, ref } from 'vue'
2
+
3
+ export interface ColumnConfig {
4
+ name: string
5
+ label: string
6
+ [key: string]: any
7
+ }
8
+
9
+ export function useColumnSelector(allColumns: ColumnConfig[], fixedColumnNames: string[] = []) {
10
+ const selectedColumnNames = ref<string[]>([...new Set([...fixedColumnNames, ...allColumns.map(col => col.name)])])
11
+
12
+ const visibleColumns = computed(() => allColumns.filter(col => selectedColumnNames.value.includes(col.name)))
13
+
14
+ function openColumnSelectorDialog($q: any) {
15
+ $q.dialog({
16
+ title: 'Выберите колонки',
17
+ options: {
18
+ type: 'checkbox',
19
+ model: [...selectedColumnNames.value],
20
+ items: allColumns.map(col => ({
21
+ label: col.label,
22
+ value: col.name,
23
+ disable: fixedColumnNames.includes(col.name),
24
+ })),
25
+ },
26
+ cancel: true,
27
+ persistent: true,
28
+ }).onOk((val: string[]) => {
29
+ selectedColumnNames.value = Array.from(new Set([...val, ...fixedColumnNames]))
30
+ })
31
+ }
32
+
33
+ return {
34
+ selectedColumnNames,
35
+ visibleColumns,
36
+ openColumnSelectorDialog,
37
+ }
38
+ }
@@ -1,102 +1,102 @@
1
- import { Ref, computed, ref } from 'vue'
2
-
3
- export interface TableColumn {
4
- name: string
5
- label: string
6
- style?: string
7
- headerStyle?: string
8
- field?: string | ((row: any) => any)
9
- sortable?: boolean
10
- filterType?: 'single' | 'multi' | null
11
- align?: 'left' | 'center' | 'right'
12
- badge?: {
13
- true?: string
14
- false?: string
15
- colorTrue?: string
16
- colorFalse?: string
17
- }
18
- format?: (val: any) => any
19
- html?: boolean
20
- }
21
-
22
- export interface FilterOption {
23
- id: string
24
- name: string
25
- }
26
-
27
- export interface TableModel<T = any> {
28
- columns: TableColumn[]
29
- rows: T[] | Ref<T[]>
30
- filtersOptions?: Ref<Record<string, FilterOption[]>>
31
- }
32
-
33
- export const useTableModel = <T = any>(model: TableModel<T>) => {
34
- const columnFilters = ref<Record<string, string | string[] | undefined>>({})
35
- const filterMenus = ref<Record<string, boolean>>({})
36
-
37
- model.columns.forEach(({ name, filterType }) => {
38
- if (filterType) {
39
- columnFilters.value[name] = filterType === 'multi' ? [] : undefined
40
- filterMenus.value[name] = false
41
- }
42
- })
43
-
44
- const resolvedRows = computed(() => (Array.isArray(model.rows) ? model.rows : model.rows.value))
45
-
46
- const toggleFilterValue = (colName: string, value: string) => {
47
- const col = model.columns.find(c => c.name === colName)
48
- if (col?.filterType === 'multi') {
49
- const current = columnFilters.value[colName] as string[]
50
- const index = current.indexOf(value)
51
- index > -1 ? current.splice(index, 1) : current.push(value)
52
- columnFilters.value[colName] = [...current]
53
- } else {
54
- columnFilters.value[colName] = value
55
- filterMenus.value[colName] = false
56
- }
57
- }
58
-
59
- const selectedFilters = computed(() => {
60
- const result: Record<string, string[]> = {}
61
- for (const col of model.columns) {
62
- const filter = columnFilters.value[col.name]
63
- const options = model.filtersOptions?.value[col.name] || []
64
-
65
- if (filter) {
66
- let selectedIds: string[] = []
67
- if (Array.isArray(filter)) {
68
- selectedIds = options
69
- .filter(opt => filter.includes(opt.name))
70
- .map(opt => opt.id)
71
- } else {
72
- selectedIds = options
73
- .filter(opt => opt.name === filter)
74
- .map(opt => opt.id)
75
- }
76
- result[col.name] = Array.from(new Set(selectedIds))
77
- }
78
- }
79
- return result
80
- })
81
-
82
-
83
- const clearFilter = (colName: string) => {
84
- const col = model.columns.find(c => c.name === colName)
85
- columnFilters.value[colName] = col?.filterType === 'multi' ? [] : undefined
86
- }
87
-
88
- const openFilterMenu = (colName: string, isOpen: boolean) => {
89
- filterMenus.value[colName] = isOpen
90
- }
91
-
92
- return {
93
- rows: resolvedRows,
94
- columns: computed(() => model.columns),
95
- columnFilters,
96
- filterMenus,
97
- toggleFilterValue,
98
- clearFilter,
99
- openFilterMenu,
100
- selectedFilters,
101
- }
102
- }
1
+ import { Ref, computed, ref } from 'vue'
2
+
3
+ export interface TableColumn {
4
+ name: string
5
+ label: string
6
+ style?: string
7
+ headerStyle?: string
8
+ field?: string | ((row: any) => any)
9
+ sortable?: boolean
10
+ filterType?: 'single' | 'multi' | null
11
+ align?: 'left' | 'center' | 'right'
12
+ badge?: {
13
+ true?: string
14
+ false?: string
15
+ colorTrue?: string
16
+ colorFalse?: string
17
+ }
18
+ format?: (val: any) => any
19
+ html?: boolean
20
+ }
21
+
22
+ export interface FilterOption {
23
+ id: string
24
+ name: string
25
+ }
26
+
27
+ export interface TableModel<T = any> {
28
+ columns: TableColumn[]
29
+ rows: T[] | Ref<T[]>
30
+ filtersOptions?: Ref<Record<string, FilterOption[]>>
31
+ }
32
+
33
+ export const useTableModel = <T = any>(model: TableModel<T>) => {
34
+ const columnFilters = ref<Record<string, string | string[] | undefined>>({})
35
+ const filterMenus = ref<Record<string, boolean>>({})
36
+
37
+ model.columns.forEach(({ name, filterType }) => {
38
+ if (filterType) {
39
+ columnFilters.value[name] = filterType === 'multi' ? [] : undefined
40
+ filterMenus.value[name] = false
41
+ }
42
+ })
43
+
44
+ const resolvedRows = computed(() => (Array.isArray(model.rows) ? model.rows : model.rows.value))
45
+
46
+ const toggleFilterValue = (colName: string, value: string) => {
47
+ const col = model.columns.find(c => c.name === colName)
48
+ if (col?.filterType === 'multi') {
49
+ const current = columnFilters.value[colName] as string[]
50
+ const index = current.indexOf(value)
51
+ index > -1 ? current.splice(index, 1) : current.push(value)
52
+ columnFilters.value[colName] = [...current]
53
+ } else {
54
+ columnFilters.value[colName] = value
55
+ filterMenus.value[colName] = false
56
+ }
57
+ }
58
+
59
+ const selectedFilters = computed(() => {
60
+ const result: Record<string, string[]> = {}
61
+ for (const col of model.columns) {
62
+ const filter = columnFilters.value[col.name]
63
+ const options = model.filtersOptions?.value[col.name] || []
64
+
65
+ if (filter) {
66
+ let selectedIds: string[] = []
67
+ if (Array.isArray(filter)) {
68
+ selectedIds = options
69
+ .filter(opt => filter.includes(opt.name))
70
+ .map(opt => opt.id)
71
+ } else {
72
+ selectedIds = options
73
+ .filter(opt => opt.name === filter)
74
+ .map(opt => opt.id)
75
+ }
76
+ result[col.name] = Array.from(new Set(selectedIds))
77
+ }
78
+ }
79
+ return result
80
+ })
81
+
82
+
83
+ const clearFilter = (colName: string) => {
84
+ const col = model.columns.find(c => c.name === colName)
85
+ columnFilters.value[colName] = col?.filterType === 'multi' ? [] : undefined
86
+ }
87
+
88
+ const openFilterMenu = (colName: string, isOpen: boolean) => {
89
+ filterMenus.value[colName] = isOpen
90
+ }
91
+
92
+ return {
93
+ rows: resolvedRows,
94
+ columns: computed(() => model.columns),
95
+ columnFilters,
96
+ filterMenus,
97
+ toggleFilterValue,
98
+ clearFilter,
99
+ openFilterMenu,
100
+ selectedFilters,
101
+ }
102
+ }