@dt-frames/ui 1.0.1 → 1.0.4

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 (207) hide show
  1. package/README.md +1 -15
  2. package/es/assets/style/reset.less +0 -3
  3. package/es/components/iframe/index.d.ts +2 -2
  4. package/es/components/index.d.ts +2 -2
  5. package/es/index.css +1 -1
  6. package/es/index.js +34 -392
  7. package/es/style/assets/style/reset.less +0 -3
  8. package/es/style/components/forms/index.less +84 -0
  9. package/es/style/components/iframe/index.less +3 -0
  10. package/es/style/components/modal/index.less +63 -0
  11. package/es/style/components/table/index.less +162 -0
  12. package/es/style/theme/sider/index.less +25 -25
  13. package/es/style/theme/theme.less +2 -1
  14. package/es/theme/header/components/notify.d.ts +0 -1
  15. package/es/theme/header/components/user-info.d.ts +1 -1
  16. package/package.json +47 -40
  17. package/src/assets/data/icons/actions.ts +427 -0
  18. package/src/assets/data/icons/code.ts +10 -0
  19. package/src/assets/data/icons/commuticate.ts +190 -0
  20. package/src/assets/data/icons/currency.ts +46 -0
  21. package/src/assets/data/icons/devices.ts +128 -0
  22. package/src/assets/data/icons/edit.ts +165 -0
  23. package/src/assets/data/icons/file.ts +104 -0
  24. package/src/assets/data/icons/math.ts +53 -0
  25. package/src/assets/data/icons/message.ts +75 -0
  26. package/src/assets/data/icons/navigate.ts +181 -0
  27. package/src/assets/data/icons/other.ts +333 -0
  28. package/src/assets/data/icons.ts +58 -0
  29. package/src/assets/imgs/logo/logo.png +0 -0
  30. package/src/assets/locales/en_US.json +3 -0
  31. package/src/assets/locales/zh_CN.json +3 -0
  32. package/src/assets/style/index.less +10 -0
  33. package/src/assets/style/reset.less +17 -0
  34. package/src/components/container/index.less +85 -0
  35. package/src/components/container/index.ts +8 -0
  36. package/src/components/container/src/bar.ts +107 -0
  37. package/src/components/container/src/lazy-container.vue +9 -0
  38. package/src/components/container/src/scroll-bar.vue +117 -0
  39. package/src/components/container/src/scroll-container.vue +61 -0
  40. package/src/components/curd/index.ts +5 -0
  41. package/src/components/curd/src/components/dialog.vue +65 -0
  42. package/src/components/curd/src/components/props.ts +32 -0
  43. package/src/components/curd/src/hooks/useCurd.tsx +72 -0
  44. package/src/components/curd/src/types/curd.type.ts +29 -0
  45. package/src/components/excel/index.ts +6 -0
  46. package/src/components/excel/src/export2Excel.ts +44 -0
  47. package/src/components/forms/index.less +84 -0
  48. package/src/components/forms/index.ts +12 -0
  49. package/src/components/forms/src/componentMap.ts +44 -0
  50. package/src/components/forms/src/components/formButton.vue +150 -0
  51. package/src/components/forms/src/components/formIcon.vue +50 -0
  52. package/src/components/forms/src/components/formItem.vue +407 -0
  53. package/src/components/forms/src/components/radioButton.vue +58 -0
  54. package/src/components/forms/src/const/form.const.ts +7 -0
  55. package/src/components/forms/src/hooks/helper.ts +70 -0
  56. package/src/components/forms/src/hooks/useForm.ts +130 -0
  57. package/src/components/forms/src/hooks/useFormActions.ts +63 -0
  58. package/src/components/forms/src/hooks/useFormEvents.ts +247 -0
  59. package/src/components/forms/src/hooks/useFormValue.ts +49 -0
  60. package/src/components/forms/src/hooks/useFormValues.ts +131 -0
  61. package/src/components/forms/src/hooks/useLabelWidth.ts +57 -0
  62. package/src/components/forms/src/index.vue +306 -0
  63. package/src/components/forms/src/prop.ts +80 -0
  64. package/src/components/forms/src/types/form.type.ts +269 -0
  65. package/src/components/icons/index.less +96 -0
  66. package/src/components/icons/index.ts +7 -0
  67. package/src/components/icons/src/pick-icon.vue +117 -0
  68. package/src/components/icons/src/svg-icon.vue +117 -0
  69. package/src/components/iframe/index.less +3 -0
  70. package/src/components/iframe/index.ts +5 -0
  71. package/src/components/iframe/src/index.vue +38 -0
  72. package/src/components/index.ts +46 -0
  73. package/src/components/modal/index.less +63 -0
  74. package/src/components/modal/index.ts +8 -0
  75. package/src/components/modal/src/components/close-icon.vue +47 -0
  76. package/src/components/modal/src/components/modal-wrap.vue +118 -0
  77. package/src/components/modal/src/components/modal.tsx +30 -0
  78. package/src/components/modal/src/components/modalFooter.vue +38 -0
  79. package/src/components/modal/src/hooks/useDrag.ts +107 -0
  80. package/src/components/modal/src/hooks/useFullScreen.ts +27 -0
  81. package/src/components/modal/src/hooks/useModal.ts +177 -0
  82. package/src/components/modal/src/index.vue +173 -0
  83. package/src/components/modal/src/props.ts +43 -0
  84. package/src/components/modal/src/types/modal.type.ts +27 -0
  85. package/src/components/router/base-router.vue +11 -0
  86. package/src/components/router/index.ts +3 -0
  87. package/src/components/source/index.ts +1 -0
  88. package/src/components/source/src/hooks/useFetch.ts +70 -0
  89. package/src/components/source/src/hooks/usePage.ts +3 -0
  90. package/src/components/source/src/hooks/useSource.ts +178 -0
  91. package/src/components/source/src/index.ts +5 -0
  92. package/src/components/source/src/types/source.type.ts +68 -0
  93. package/src/components/source/src/types/table.type.ts +8 -0
  94. package/src/components/table/index.less +162 -0
  95. package/src/components/table/index.ts +7 -0
  96. package/src/components/table/src/components/TableActions.vue +108 -0
  97. package/src/components/table/src/components/TableHeader.vue +77 -0
  98. package/src/components/table/src/components/TableRender.vue +76 -0
  99. package/src/components/table/src/components/setting/Column.vue +355 -0
  100. package/src/components/table/src/components/setting/Download.vue +55 -0
  101. package/src/components/table/src/components/setting/Fullscreen.vue +43 -0
  102. package/src/components/table/src/components/setting/Size.vue +42 -0
  103. package/src/components/table/src/components/setting/index.vue +64 -0
  104. package/src/components/table/src/const.ts +13 -0
  105. package/src/components/table/src/hooks/useColumns.ts +319 -0
  106. package/{es/assets/app-antd-dark-theme-style.e3b0c442.css → src/components/table/src/hooks/useCustomRow.ts} +0 -0
  107. package/src/components/table/src/hooks/useDataSource.ts +99 -0
  108. package/src/components/table/src/hooks/useLoading.ts +29 -0
  109. package/src/components/table/src/hooks/usePagination.ts +76 -0
  110. package/src/components/table/src/hooks/useRowSelection.ts +146 -0
  111. package/src/components/table/src/hooks/useRows.ts +30 -0
  112. package/src/components/table/src/hooks/useTable.ts +77 -0
  113. package/src/components/table/src/hooks/useTableHeader.ts +48 -0
  114. package/src/components/table/src/hooks/useTableInstance.ts +29 -0
  115. package/src/components/table/src/hooks/useTableScroll.ts +227 -0
  116. package/src/components/table/src/index.vue +198 -0
  117. package/src/components/table/src/props.ts +152 -0
  118. package/src/components/table/src/types/table.type.ts +133 -0
  119. package/src/components/table/src/types/tableHeader.type.ts +27 -0
  120. package/{es/assets/app-theme-style.e3b0c442.css → src/components/type.ts} +0 -0
  121. package/src/directives/icon.ts +36 -0
  122. package/src/directives/index.ts +26 -0
  123. package/src/directives/permission.ts +20 -0
  124. package/src/global.d.ts +8 -0
  125. package/src/index.ts +4 -0
  126. package/src/theme/content/index.vue +37 -0
  127. package/src/theme/feature/back-top.vue +11 -0
  128. package/src/theme/feature/index.vue +7 -0
  129. package/src/theme/footer/index.less +16 -0
  130. package/src/theme/footer/index.vue +24 -0
  131. package/src/theme/header/components/bread-crumb.vue +26 -0
  132. package/src/theme/header/components/fullscreen.vue +12 -0
  133. package/src/theme/header/components/handler.ts +81 -0
  134. package/src/theme/header/components/index.ts +21 -0
  135. package/src/theme/header/components/lang-picker.vue +36 -0
  136. package/src/theme/header/components/logo.vue +33 -0
  137. package/src/theme/header/components/menu-search.vue +62 -0
  138. package/src/theme/header/components/notify.vue +22 -0
  139. package/src/theme/header/components/setting-theme.vue +123 -0
  140. package/src/theme/header/components/theme-drawer/enum.ts +12 -0
  141. package/src/theme/header/components/theme-drawer/feature.vue +75 -0
  142. package/src/theme/header/components/theme-drawer/index.ts +7 -0
  143. package/src/theme/header/components/theme-drawer/menu-type.vue +40 -0
  144. package/src/theme/header/components/theme-drawer/select-item.vue +46 -0
  145. package/src/theme/header/components/theme-drawer/switch-item.vue +39 -0
  146. package/src/theme/header/components/theme-drawer/theme-color.vue +26 -0
  147. package/src/theme/header/components/trigger.vue +14 -0
  148. package/src/theme/header/components/user-info.vue +43 -0
  149. package/src/theme/header/const/index.ts +40 -0
  150. package/src/theme/header/helper/menu-tree.ts +64 -0
  151. package/src/theme/header/index.less +438 -0
  152. package/src/theme/header/index.ts +0 -0
  153. package/src/theme/header/index.vue +96 -0
  154. package/src/theme/header/multiple-header.vue +67 -0
  155. package/src/theme/header/set-theme.less +68 -0
  156. package/src/theme/index.ts +3 -0
  157. package/src/theme/sider/components/basic-menu/basic-menu-item.vue +14 -0
  158. package/src/theme/sider/components/basic-menu/basic-menu.vue +122 -0
  159. package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +46 -0
  160. package/src/theme/sider/components/basic-menu/menu-item-content.vue +13 -0
  161. package/src/theme/sider/components/drag-bar.vue +26 -0
  162. package/src/theme/sider/components/layout-menu.vue +132 -0
  163. package/src/theme/sider/components/props.ts +97 -0
  164. package/src/theme/sider/components/sider-trigger.vue +24 -0
  165. package/src/theme/sider/helper/sider.ts +52 -0
  166. package/src/theme/sider/helper/split-menu.ts +146 -0
  167. package/src/theme/sider/hooks/useDragLine.ts +86 -0
  168. package/src/theme/sider/hooks/useOpenKeys.ts +57 -0
  169. package/src/theme/sider/index.less +203 -0
  170. package/src/theme/sider/index.vue +88 -0
  171. package/src/theme/tabs/components/TabContent.vue +36 -0
  172. package/src/theme/tabs/components/TabRedo.vue +18 -0
  173. package/src/theme/tabs/hooks/useMultifyTabs.ts +96 -0
  174. package/src/theme/tabs/hooks/useTabDropdown.ts +89 -0
  175. package/src/theme/tabs/index.less +165 -0
  176. package/src/theme/tabs/index.vue +98 -0
  177. package/src/theme/tabs/types/tabs.type.ts +8 -0
  178. package/src/theme/theme.less +67 -0
  179. package/src/theme/theme.vue +90 -0
  180. package/src/theme/transition.less +99 -0
  181. package/es/assets/data/icon.d.ts +0 -4
  182. package/es/assets/data/icon.ts +0 -69
  183. package/es/assets/data/icon11.ts +0 -69
  184. package/es/assets/style/var.less +0 -42
  185. package/es/components/icons/pick-icon.d.ts +0 -529
  186. package/es/components/icons/svg-icon.d.ts +0 -44
  187. package/es/components/table/src/hooks/useFormat.d.ts +0 -2
  188. package/es/components/table/src/hooks/useVirtualScroll.d.ts +0 -5
  189. package/es/components/table/src/utils/format.d.ts +0 -1
  190. package/es/style/assets/style/var.less +0 -42
  191. package/es/theme/content/index.d.ts +0 -29
  192. package/es/theme/header/components/menu-search.d.ts +0 -528
  193. package/es/theme/header/components/setting-theme.d.ts +0 -2550
  194. package/es/theme/header/index.d.ts +0 -4369
  195. package/es/theme/header/multiple-header.d.ts +0 -2001
  196. package/es/theme/styles/hooks/changeTheme.d.ts +0 -1
  197. package/es/theme/styles/hooks/generate.d.ts +0 -13
  198. package/es/theme/styles/index.d.ts +0 -2
  199. package/es/theme/tabs/components/TabRedo.d.ts +0 -49
  200. package/es/theme/tabs/index.d.ts +0 -1399
  201. package/es/theme/theme/initTheme.d.ts +0 -3
  202. package/es/theme/theme/util.d.ts +0 -5
  203. package/es/theme/theme.d.ts +0 -4911
  204. package/es/themes/generate.ts +0 -74
  205. package/es/themes/index.ts +0 -10
  206. package/es/themes/modifyVars.ts +0 -33
  207. package/es/themes/themePlugiin.ts +0 -74
@@ -0,0 +1,319 @@
1
+ import type { PaginationProps } from 'ant-design-vue/lib/pagination'
2
+ import { computed, ComputedRef, Ref, ref, unref, toRaw, watch, h } from "vue";
3
+ import { cloneDeep, isEqual } from 'lodash-es'
4
+ import { BasicColumn, BasicTableProps, CellFormat } from "../types/table.type";
5
+ import { SetColumnsParams } from '../types/tableHeader.type';
6
+ import { isArray, isBoolean, isFunction, isObject, isString, Recordable, useAppStore, getDictValueByCode } from '@dt-frames/core';
7
+ import TableAction from '../components/TableActions.vue'
8
+
9
+ // 索引列及操作列标识
10
+ const INDEX_FLAG = 'INDEX'
11
+ const ACTION_COLUMN = 'ACTION'
12
+
13
+ // 处理单条数据的ellipsis 对齐方式
14
+ function handleItem(item: BasicColumn, ellipsis: boolean) {
15
+ const { appConf } = useAppStore();
16
+ const { align } = appConf.ui.table
17
+
18
+ const { key, dataIndex, children } = item
19
+ item.align = item.align || align
20
+
21
+ if( ellipsis ) {
22
+ if (!key) item.key = dataIndex && dataIndex.toString()
23
+
24
+ if (!isBoolean(item.ellipsis)) {
25
+ item = Object.assign(item, {
26
+ ellipsis,
27
+ })
28
+ }
29
+ }
30
+
31
+ if (children && children.length) {
32
+ handleChildren(children, !!ellipsis);
33
+ }
34
+ }
35
+
36
+ function handleChildren(children: BasicColumn[] | undefined, ellipsis: boolean) {
37
+ if (!children) return
38
+
39
+ children.forEach((item) => {
40
+ const { children } = item
41
+ handleItem(item, ellipsis)
42
+ handleChildren(children, ellipsis)
43
+ })
44
+ }
45
+
46
+ // 重新排序列
47
+ function sortFixedColumn(columns: BasicColumn[]) {
48
+ const fixedLeftColumn: BasicColumn[] = []
49
+ const fixedRightColumn: BasicColumn[] = []
50
+ const defaultColumn: BasicColumn[] = []
51
+
52
+ for( let column of columns ) {
53
+ if( column.defaultHidden ) continue
54
+
55
+ if( column.fixed === 'left' ) {
56
+ fixedLeftColumn.push( column )
57
+ continue
58
+ }
59
+
60
+ if( column.fixed === 'right' ) {
61
+ fixedRightColumn.push( column )
62
+ continue
63
+ }
64
+
65
+ defaultColumn.push( column )
66
+ }
67
+
68
+ return [
69
+ ...fixedLeftColumn,
70
+ ...defaultColumn,
71
+ ...fixedRightColumn
72
+ ]
73
+ }
74
+
75
+ // 处理序号
76
+ function handleIndexColumn(
77
+ propsRef: ComputedRef<BasicTableProps>,
78
+ getPaginationRef: ComputedRef<boolean | PaginationProps>,
79
+ columns: BasicColumn[]
80
+ ) {
81
+ const { showIndexColumn, indexColumnProps, isTreeTable } = unref(propsRef)
82
+
83
+ let pushIndexColumns = false
84
+ if (unref(isTreeTable)) {
85
+ return;
86
+ }
87
+
88
+ columns.forEach(() => {
89
+ const indIndex = columns.findIndex((column) => column.flag === INDEX_FLAG);
90
+ if (showIndexColumn) {
91
+ pushIndexColumns = indIndex === -1;
92
+ } else if (!showIndexColumn && indIndex !== -1) {
93
+ columns.splice(indIndex, 1);
94
+ }
95
+ })
96
+
97
+ if (!pushIndexColumns) return
98
+
99
+ const isFixedLeft = columns.some((item) => item.fixed === 'left')
100
+
101
+ columns.unshift({
102
+ flag: INDEX_FLAG,
103
+ width: 50,
104
+ title: '序号',
105
+ align: 'center',
106
+ customRender: ( { index } ) => {
107
+ const getPagination = unref(getPaginationRef)
108
+
109
+ const { appConf } = useAppStore()
110
+ const { defaultPageSize } = appConf.ui.table
111
+
112
+ if (isBoolean(getPagination)) {
113
+ return `${index + 1}`;
114
+ }
115
+
116
+ const { current = 1, pageSize = defaultPageSize } = getPagination;
117
+ return ((current < 1 ? 1 : current) - 1) * pageSize + index + 1
118
+ },
119
+ ...(isFixedLeft
120
+ ? {
121
+ fixed: 'left',
122
+ }
123
+ : {}),
124
+ ...indexColumnProps,
125
+ })
126
+ }
127
+
128
+ // 处理操作栏的列
129
+ function handleActionColumn(propsRef: ComputedRef<BasicTableProps>, columns: BasicColumn[]) {
130
+ const { operations } = unref(propsRef)
131
+
132
+ if (
133
+ !operations
134
+ || (isObject( operations ) && !operations?.btns )
135
+ || ( isArray(operations) && !operations )
136
+ ) return
137
+
138
+ const hasIndex = columns.findIndex((column) => column.flag === ACTION_COLUMN)
139
+
140
+ if( hasIndex === -1 ) {
141
+ let column = isObject( operations ) ? operations
142
+ : isArray( operations ) ? { btns: operations } : {}
143
+
144
+ let expand = column.expand ? column.expand : false
145
+ let columnObj = {
146
+ fixed: 'right',
147
+ title: '操作',
148
+ align: 'center',
149
+ expand,
150
+ width: (expand ? (column.btns.length * 30 + 40) : 70) + 'px',
151
+ ...column,
152
+ flag: ACTION_COLUMN,
153
+ }
154
+
155
+ columns.push({
156
+ ...(columnObj as any),
157
+ customRender: ({ record, index}) => {
158
+ return h(
159
+ TableAction as any,
160
+ {
161
+ ...columnObj,
162
+ record,
163
+ align: null,
164
+ index
165
+ }
166
+ )
167
+ }
168
+ })
169
+ }
170
+ }
171
+
172
+
173
+ export function useColumns(
174
+ propsRef: ComputedRef<BasicTableProps>,
175
+ getPaginationRef: ComputedRef<boolean | PaginationProps>,
176
+ ) {
177
+
178
+ const columnsRef = ref(unref(propsRef).columns) as unknown as Ref<BasicColumn[]>
179
+ let cacheColumns = unref(propsRef).columns
180
+
181
+ const getColumnsRef = computed(() => {
182
+ const columns = cloneDeep(unref(columnsRef)) as BasicColumn[]
183
+ if (!columns) return []
184
+
185
+ const { ellipsis, resizable, minWidth = 50, maxWidth = 700 } = unref(propsRef)
186
+
187
+ columns.forEach( (it, index) => {
188
+ const { slots } = it
189
+ it.width = it.width || (index === columns.length - 1 ? 119.9 : 120)
190
+ if( Reflect.has(it, 'resizable') ? !!it.resizable : resizable ) {
191
+ it.resizable = true
192
+ it.minWidth = it.minWidth || minWidth
193
+ it.maxWidth = it.maxWidth || maxWidth
194
+ }
195
+
196
+ handleItem(
197
+ it,
198
+ Reflect.has(it, 'ellipsis') ? !!it.ellipsis : !!ellipsis && !slots
199
+ )
200
+ } )
201
+
202
+ handleIndexColumn(propsRef, getPaginationRef, columns)
203
+ handleActionColumn(propsRef, columns)
204
+
205
+ return columns
206
+ })
207
+
208
+ const getViewColumns = computed(() => {
209
+ const viewColumns = sortFixedColumn(unref(getColumnsRef))
210
+ const columns: BasicColumn[] = cloneDeep(viewColumns)
211
+
212
+ return columns
213
+ .filter( column => isIfShow(column) )
214
+
215
+ })
216
+
217
+ function isIfShow( column: BasicColumn ): boolean {
218
+ const ifShow = column.ifShow
219
+
220
+ return isBoolean(ifShow)
221
+ ? ifShow
222
+ : isFunction(ifShow) ? ifShow(column) : true
223
+
224
+ }
225
+
226
+ watch(
227
+ () => unref(propsRef).columns,
228
+ columns => {
229
+ columnsRef.value = columns
230
+ cacheColumns = columns.filter( it => !it.flag ) ?? []
231
+ }
232
+ )
233
+
234
+
235
+ // 获取列信息
236
+ function getColumns(opt?: SetColumnsParams) {
237
+ const { ignoreIndex, ignoreAction, sort } = opt || {}
238
+
239
+ let columns = toRaw(unref(getColumnsRef))
240
+
241
+ if( ignoreIndex ) {
242
+ columns = columns.filter( it => it.flag !== INDEX_FLAG )
243
+ }
244
+
245
+ if( ignoreAction ) {
246
+ columns = columns.filter( it => it.flag !== ACTION_COLUMN )
247
+ }
248
+
249
+ // 重新排序
250
+ if( sort ) {
251
+ columns = sortFixedColumn( columns )
252
+ }
253
+
254
+ return columns
255
+ }
256
+
257
+
258
+ // 设置列信息
259
+ function setColumns(columnList: Partial<BasicColumn>[] | string[]) {
260
+ const columns = cloneDeep(columnList)
261
+
262
+ if( !isArray( columns ) ) return
263
+
264
+ // 重置所有的列
265
+ if( !columns.length ) {
266
+ columnsRef.value = []
267
+ return
268
+ }
269
+
270
+ const cacheKeys = cacheColumns.map((item) => item.dataIndex)
271
+
272
+ if( !isString( columns[0] ) ) {
273
+ columnsRef.value = columns as BasicColumn[]
274
+ } else {
275
+ const columnKeys = columns as string[]
276
+ const newColumns: BasicColumn[] = []
277
+
278
+ cacheColumns.forEach( it => {
279
+ newColumns.push({
280
+ ...it,
281
+ defaultHidden: !columnKeys.includes((it.dataIndex! || it.key) as string),
282
+ })
283
+ } )
284
+
285
+
286
+ if( !isEqual(cacheKeys, columns) ) {
287
+ newColumns.sort((prev, next) => {
288
+ return columnKeys.indexOf(prev.dataIndex as string) - columnKeys.indexOf(next.dataIndex as string)
289
+ })
290
+ }
291
+
292
+ columnsRef.value = newColumns
293
+ }
294
+ }
295
+
296
+ function setCacheColumnsByField(dataIndex: string | undefined, value: Partial<BasicColumn>) {
297
+ if (!dataIndex || !value) return
298
+
299
+ cacheColumns.forEach((item) => {
300
+ if (item.dataIndex === dataIndex) {
301
+ Object.assign(item, value);
302
+ return;
303
+ }
304
+ })
305
+ }
306
+
307
+ function getCacheColumns() {
308
+ return cacheColumns;
309
+ }
310
+
311
+ return {
312
+ getViewColumns,
313
+ getColumnsRef,
314
+ getColumns,
315
+ setColumns,
316
+ setCacheColumnsByField,
317
+ getCacheColumns
318
+ }
319
+ }
@@ -0,0 +1,99 @@
1
+ import { ComputedRef, ref, Ref, unref, toRaw, watch, computed, onMounted } from "vue"
2
+ import type { PaginationProps } from 'ant-design-vue/lib/pagination'
3
+ import { BasicTableProps, SorterResult } from "../types/table.type"
4
+ import { isFunction, Recordable, useAppStore, useTimeoutFn } from "@dt-frames/core"
5
+
6
+ /**
7
+ * 处理表格数据
8
+ */
9
+ type ActionsType = {
10
+ getPaginationInfo: ComputedRef<boolean | PaginationProps>
11
+ setPagination: (info: Partial<PaginationProps>) => void
12
+ clearSelectedRowKeys: () => void
13
+ }
14
+
15
+ export function useDataSource(
16
+ propsRef: ComputedRef<BasicTableProps>,
17
+ {
18
+ getPaginationInfo,
19
+ setPagination,
20
+ clearSelectedRowKeys,
21
+ }: ActionsType,
22
+ emit
23
+ ) {
24
+ // 拷贝一份表格数据 然后再做数据处理
25
+ const dataSourceRef = ref<Recordable[]>([])
26
+
27
+ watch(
28
+ () => unref(propsRef).dataSource,
29
+ (dataSource) => {
30
+ dataSource && (dataSourceRef.value = dataSource)
31
+ },
32
+ {
33
+ immediate: true
34
+ }
35
+ )
36
+
37
+ const getDataSourceRef = computed( () => {
38
+ return unref(dataSourceRef)
39
+ } )
40
+
41
+ // 表单改变事件
42
+ function handleTableChange(
43
+ pagination: PaginationProps,
44
+ filters: Partial<Recordable<string[]>>,
45
+ sorter: SorterResult,
46
+ ) {
47
+ const { sortFn, filterFn, onTableChange } = unref( propsRef )
48
+ const { appConf } = useAppStore()
49
+ const { current = 1, pageSize = appConf.ui.table.defaultPageSize } = pagination
50
+
51
+ // clearSelectedRowKeys()
52
+
53
+ setPagination( pagination )
54
+
55
+ const params: Recordable = {}
56
+
57
+ if( sorter && isFunction(sortFn) ) {
58
+ params.sortInfo = sortFn(sorter)
59
+ }
60
+
61
+ if (filters && isFunction(filterFn)) {
62
+ params.filterInfo = filterFn( filters )
63
+ }
64
+
65
+
66
+ return onTableChange({
67
+ pagination: {
68
+ current,
69
+ pageSize
70
+ },
71
+ sort: unref( params.sortInfo ),
72
+ filter: toRaw(unref( params.filterInfo )),
73
+ showBtnLoading: false
74
+ })
75
+ }
76
+
77
+
78
+ onMounted(() => {
79
+ const { defSort, onTableChange } = unref( propsRef )
80
+ const { appConf } = useAppStore()
81
+
82
+ onTableChange({
83
+ pagination: {
84
+ current: 1,
85
+ pageSize: appConf.ui.table.defaultPageSize
86
+ },
87
+ sort:defSort,
88
+ filter: null,
89
+ showBtnLoading: false
90
+ }, false)
91
+ })
92
+
93
+
94
+ return {
95
+ getDataSourceRef,
96
+ handleTableChange
97
+ }
98
+
99
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 设置表格的loading状态
3
+ * 这里做二次封装 主要原因是暴露一个方法 外面可以调用这个方法 从而改变loading状态
4
+ */
5
+
6
+ import { ComputedRef, ref, unref, watch, computed } from "vue"
7
+ import { BasicTableProps } from "../types/table.type"
8
+
9
+ export function useLoading(props: ComputedRef<BasicTableProps>) {
10
+ const loadingRef = ref( unref(props).loading )
11
+
12
+ watch(
13
+ () => unref(props).loading,
14
+ (v) => {
15
+ loadingRef.value = v
16
+ }
17
+ )
18
+
19
+ const getLoading = computed(() => unref(loadingRef))
20
+
21
+ function setLoading( loading: boolean ) {
22
+ loadingRef.value = loading
23
+ }
24
+
25
+ return {
26
+ getLoading,
27
+ setLoading
28
+ }
29
+ }
@@ -0,0 +1,76 @@
1
+ import { computed, ComputedRef, ref, unref, watch } from "vue"
2
+ import type { PaginationProps } from 'ant-design-vue/lib/pagination'
3
+ import { BasicTableProps } from "../types/table.type"
4
+ import { isBoolean, useAppStore } from "@dt-frames/core"
5
+
6
+
7
+ export function usePagination(props: ComputedRef<BasicTableProps>) {
8
+ const paginationRef = ref<PaginationProps>({})
9
+ const show = ref(true)
10
+
11
+ watch(
12
+ () => unref(props).pagination,
13
+ (pagination) => {
14
+ if( !isBoolean(pagination) && pagination ) {
15
+ paginationRef.value = {
16
+ ...unref(paginationRef),
17
+ ...(pagination ?? {})
18
+ }
19
+ }
20
+ }
21
+ )
22
+
23
+ // 获取分页数据
24
+ const getPaginationInfo = computed((): PaginationProps | boolean => {
25
+ const { pagination } = unref( props )
26
+
27
+ if( !unref(show) || isBoolean( pagination ) && !pagination ) {
28
+ return false
29
+ }
30
+
31
+ const { appConf } = useAppStore()
32
+ const { defaultPageSize, pageSizeOptions, size } = appConf.ui.table
33
+
34
+ return {
35
+ current: 1,
36
+ pageSize: defaultPageSize,
37
+ size: size === 'small' ? 'small' : 'default',
38
+ defaultPageSize,
39
+ showTotal: (total, range) => `总共${ total }页`,
40
+ showSizeChanger: true,
41
+ pageSizeOptions,
42
+ showQuickJumper: true,
43
+ ...(isBoolean(pagination) ? {} : pagination),
44
+ ...unref(paginationRef),
45
+ }
46
+ })
47
+
48
+ function setPagination(info: Partial<PaginationProps>) {
49
+ const paginationInfo = unref( getPaginationInfo )
50
+
51
+ paginationRef.value = {
52
+ ...(!isBoolean(paginationInfo) ? paginationInfo : {}),
53
+ ...info
54
+ }
55
+ }
56
+
57
+ function getPagination() {
58
+ return unref( getPaginationInfo )
59
+ }
60
+
61
+ function getShowPagination() {
62
+ return unref(show);
63
+ }
64
+
65
+ async function setShowPagination(flag: boolean) {
66
+ show.value = flag;
67
+ }
68
+
69
+ return {
70
+ getPaginationInfo,
71
+ setPagination,
72
+ getPagination,
73
+ getShowPagination,
74
+ setShowPagination
75
+ }
76
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * 处理表格选中事件
3
+ */
4
+
5
+ import { isFunction, Recordable } from "@dt-frames/core";
6
+ import type { TableRowSelection } from 'ant-design-vue/lib/table/interface'
7
+ import { computed, ComputedRef, ref, Ref, toRaw, unref, watch, nextTick } from "vue";
8
+ import { BasicTableProps } from "../types/table.type";
9
+ import { omit } from 'lodash-es'
10
+
11
+ interface TreeHelperConfig {
12
+ id: string;
13
+ children: string;
14
+ pid: string;
15
+ }
16
+
17
+ const DEFAULT_CONFIG: TreeHelperConfig = {
18
+ id: 'id',
19
+ children: 'children',
20
+ pid: 'pid',
21
+ }
22
+
23
+ export function useRowSelection(
24
+ propsRef: ComputedRef<BasicTableProps>,
25
+ emit
26
+ ) {
27
+ // 选中的节点 不包含子节点
28
+ const selectedRowKeysRef = ref<string[]>([])
29
+ // 选中的节点 包含子节点
30
+ const selectedRowRef = ref<Recordable[]>([])
31
+
32
+ // 获取选中的行数据
33
+ const getRowSelectionRef = computed((): TableRowSelection | null => {
34
+ const { rowSelection } = unref(propsRef)
35
+
36
+ if (!rowSelection) {
37
+ return null;
38
+ }
39
+
40
+ return {
41
+ ...rowSelection,
42
+ selectedRowKeys: toRaw(unref(selectedRowKeysRef)),
43
+ onChange: (selectedRowKeys: string[]) => {
44
+ setSelectedRowKeys(selectedRowKeys)
45
+ },
46
+ }
47
+ })
48
+
49
+ watch(
50
+ () => unref(propsRef).rowSelection?.selectedRowKeys,
51
+ (v: string[]) => {
52
+ setSelectedRowKeys(v);
53
+ },
54
+ )
55
+
56
+ watch(
57
+ () => unref(selectedRowKeysRef),
58
+ () => {
59
+ nextTick(() => {
60
+ const { rowSelection } = unref(propsRef)
61
+
62
+ if (rowSelection){
63
+ const { onChange } = rowSelection
64
+ if (onChange && isFunction(onChange)) onChange(getSelectRowKeys(), getSelectRows())
65
+ }
66
+
67
+ emit('selection-change', {
68
+ keys: getSelectRowKeys(),
69
+ rows: getSelectRows(),
70
+ })
71
+ })
72
+ },
73
+ { deep: true }
74
+ )
75
+
76
+ // 设置树节点的选中
77
+ function findeNodeAll(
78
+ tree: any,
79
+ func: Function,
80
+ config: Partial<TreeHelperConfig> = {}
81
+ ) {
82
+ config = Object.assign({}, DEFAULT_CONFIG, config)
83
+ const { children } = config
84
+
85
+ const result: any[] = []
86
+ const list = [...tree]
87
+
88
+ for (const node of list) {
89
+ func(node) && result.push(node);
90
+ node.children && list.push(...node.children);
91
+ }
92
+
93
+ return result
94
+ }
95
+
96
+ // 设置选中的key
97
+ function setSelectedRowKeys( rowKeys: string[] ) {
98
+ selectedRowKeysRef.value = rowKeys
99
+
100
+ const allSelectedRows = findeNodeAll(
101
+ toRaw(unref(propsRef).dataSource).concat(toRaw(unref(selectedRowRef))),
102
+ (item) => rowKeys.includes(item[ unref( propsRef ).rowKey]),
103
+ {
104
+ children: propsRef.value.childrenColumnName ?? 'children',
105
+ },
106
+ )
107
+
108
+ const trueSelectedRows: any[] = []
109
+
110
+ rowKeys.forEach( (key: string) => {
111
+ const found = allSelectedRows.find((item) => item[ unref( propsRef ).rowKey] === key)
112
+ found && trueSelectedRows.push(found)
113
+ } )
114
+
115
+ selectedRowRef.value = trueSelectedRows
116
+ }
117
+
118
+
119
+ // 清除所有的选中数据
120
+ function clearSelectedRowKeys() {
121
+ selectedRowKeysRef.value = []
122
+ selectedRowRef.value = []
123
+ }
124
+
125
+ // 获取选中的行数据
126
+ function getRowSelection() {
127
+ return unref( getRowSelectionRef )
128
+ }
129
+
130
+ function getSelectRowKeys() {
131
+ return unref(selectedRowKeysRef);
132
+ }
133
+
134
+ function getSelectRows() {
135
+ return unref(selectedRowRef)
136
+ }
137
+
138
+ return {
139
+ getRowSelectionRef,
140
+ clearSelectedRowKeys,
141
+ getRowSelection,
142
+ getSelectRowKeys,
143
+ getSelectRows,
144
+ setSelectedRowKeys
145
+ }
146
+ }
@@ -0,0 +1,30 @@
1
+ import { isFunction } from "@dt-frames/core";
2
+ import { ComputedRef, unref } from "vue";
3
+ import { BasicTableProps } from "../types/table.type";
4
+
5
+
6
+ export function useRows(propsRef: ComputedRef<BasicTableProps>) {
7
+ /**
8
+ * 获取行的class
9
+ */
10
+ function getRowClassName(record: any, index: number) {
11
+
12
+ const { striped, rowClassName } = unref(propsRef)
13
+ const classNames: string[] = []
14
+
15
+ if( striped ) {
16
+ classNames.push( index % 2 === 1 ? 'table-striped' : '' )
17
+ }
18
+
19
+ if( rowClassName && isFunction(rowClassName) ) {
20
+ classNames.push( rowClassName( record, index ) )
21
+ }
22
+
23
+ return classNames.join(' ')
24
+ }
25
+
26
+ return {
27
+ getRowClassName
28
+ }
29
+
30
+ }