@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,77 @@
1
+ import { DynamicProps, Nullable, getDynamicProps, error } from '@dt-frames/core'
2
+ import { onUnmounted, ref, toRaw, unref, watch } from 'vue'
3
+ import { BasicColumn, BasicTableProps, TableActionType } from '../types/table.type'
4
+
5
+
6
+ type Props = Partial<DynamicProps<BasicTableProps>>
7
+
8
+ export function useTable(tableProps?: Props) {
9
+ const tableRef = ref<Nullable<TableActionType>>(null)
10
+ const loadedRef = ref<Nullable<boolean>>(false)
11
+
12
+ function registerTable( instance: TableActionType ) {
13
+ onUnmounted(() => {
14
+ tableRef.value = null;
15
+ loadedRef.value = null;
16
+ })
17
+
18
+ if( unref(loadedRef) && instance === unref(tableRef) ) return
19
+
20
+ tableRef.value = instance
21
+ tableProps && instance.setProps(getDynamicProps(tableProps))
22
+
23
+ watch(
24
+ () => tableProps,
25
+ () => {
26
+ tableProps && instance.setProps(getDynamicProps(tableProps));
27
+ },
28
+ {
29
+ immediate: true,
30
+ deep: true,
31
+ },
32
+ )
33
+
34
+ }
35
+
36
+ function getTableInstance(): TableActionType {
37
+ const table = unref(tableRef);
38
+ if (!table) {
39
+ error('没有table表单实例');
40
+ }
41
+
42
+ return table as TableActionType;
43
+ }
44
+
45
+ const methods: TableActionType = {
46
+ setProps: (props: Partial<BasicTableProps>) => {
47
+ getTableInstance().setProps(props);
48
+ },
49
+ setLoading: (loading: boolean) => {
50
+ getTableInstance().setLoading( loading )
51
+ },
52
+ getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => {
53
+ const columns = getTableInstance().getColumns({ ignoreIndex }) || []
54
+ return toRaw(columns);
55
+ },
56
+ setColumns: (columns: BasicColumn[]) => {
57
+ getTableInstance().setColumns(columns)
58
+ },
59
+ getRowSelection: () => {
60
+ return toRaw(getTableInstance().getRowSelection())
61
+ },
62
+ getCacheColumns: () => {
63
+ return toRaw(getTableInstance().getCacheColumns())
64
+ },
65
+ getSize: () => {
66
+ return toRaw(getTableInstance().getSize())
67
+ },
68
+ getSelectRowKeys: () => {
69
+ return getTableInstance().getSelectRowKeys()
70
+ },
71
+ getSelectRows: () => {
72
+ return getTableInstance().getSelectRows()
73
+ }
74
+ }
75
+
76
+ return [registerTable as any, methods]
77
+ }
@@ -0,0 +1,48 @@
1
+ import { Recordable, useSlots } from "@dt-frames/core"
2
+ import { computed, ComputedRef, h, Slots, unref } from "vue"
3
+ import TableHeader from '../components/TableHeader.vue'
4
+ import { BasicTableProps, ColumnChangeParam } from "../types/table.type";
5
+
6
+ export function useTableHeader(
7
+ propsRef: ComputedRef<BasicTableProps>,
8
+ slots: Slots,
9
+ handlers: { onColumnsChange: (data: ColumnChangeParam[]) => void }
10
+ ) {
11
+ const getHeaderProps = computed((): Recordable => {
12
+ const { tableSetting, toolbar } = unref(propsRef)
13
+
14
+ const { getSlot } = useSlots()
15
+ const hideTitle = !slots.toolbar && !slots.headerTop && (!tableSetting || !tableSetting.length)
16
+
17
+ return {
18
+ title: hideTitle
19
+ ? null
20
+ : () =>
21
+ h(
22
+ TableHeader,
23
+ {
24
+ tableSetting,
25
+ toolbar,
26
+ onColumnsChange: handlers.onColumnsChange
27
+ } as Recordable,
28
+ {
29
+ ...(slots.toolbar
30
+ ? {
31
+ toolbar: () => getSlot(slots, 'toolbar'),
32
+ }
33
+ : {}),
34
+ ...(slots.headerTop
35
+ ? {
36
+ headerTop: () => getSlot(slots, 'headerTop'),
37
+ }
38
+ : {}),
39
+ },
40
+ )
41
+ }
42
+
43
+ })
44
+
45
+ return {
46
+ getHeaderProps
47
+ }
48
+ }
@@ -0,0 +1,29 @@
1
+ /** ======================================
2
+ * 保存table实例对象
3
+ * ======================================*/
4
+
5
+ import { Nullable, Recordable } from "@dt-frames/core"
6
+ import { ComputedRef, inject, provide, Ref } from "vue"
7
+ import { BasicTableProps, TableActionType } from "../types/table.type"
8
+
9
+
10
+ const tableKey = Symbol('dt-page')
11
+
12
+ type Instance = TableActionType & {
13
+ tableElRef: Ref<Nullable<HTMLElement>>
14
+ getBind: ComputedRef<Recordable>
15
+ }
16
+
17
+ type RetInstance = Omit<Instance, 'getBind'> & {
18
+ getBind: ComputedRef<BasicTableProps>
19
+ }
20
+
21
+ // 创建table实例
22
+ export function createTableInstance(instance: Instance) {
23
+ provide(tableKey, instance)
24
+ }
25
+
26
+ // 获取table实例
27
+ export function getTableInstance(): RetInstance {
28
+ return inject(tableKey) as RetInstance
29
+ }
@@ -0,0 +1,227 @@
1
+ import { isBoolean, windowResizeFn } from "@dt-frames/core"
2
+ import { useDebounceFn } from "@vueuse/core"
3
+ import { ComputedRef, ref, Ref, nextTick, watch, computed, unref, onMounted, h } from "vue"
4
+ import { TABLE_SIZE_HEIGHT } from "../const"
5
+ import { BasicColumn, BasicTableProps, TableRowSelection } from "../types/table.type"
6
+
7
+ /**
8
+ * 计算table横向和纵向的滚动条
9
+ */
10
+ export function useTableScroll(
11
+ propsRef: ComputedRef<BasicTableProps>,
12
+ tableElRef: Ref<HTMLDivElement & {$el: any} | null>,
13
+ columnsRef: ComputedRef<BasicColumn[]>,
14
+ rowSelectionRef: ComputedRef<TableRowSelection | null>
15
+ ) {
16
+ // 默认表格的高度
17
+ const tableHeightRef = ref(0)
18
+ const filterSource = ref([])
19
+
20
+ const debounceRedoHeight = useDebounceFn( redoHeight, 100 )
21
+
22
+ watch(
23
+ () => unref(propsRef)?.dataSource?.length,
24
+ () => {
25
+ debounceRedoHeight()
26
+ },
27
+ {
28
+ flush: 'post' // 在dom渲染之后监听
29
+ }
30
+ )
31
+
32
+ windowResizeFn(calcTableHeight, 280)
33
+
34
+ function redoHeight() {
35
+ nextTick(() => {
36
+ calcTableHeight()
37
+ })
38
+ }
39
+
40
+ let footerEl: HTMLElement | null
41
+ let bodyEl: HTMLElement | null
42
+
43
+ function setHeight(height: number) {
44
+ tableHeightRef.value = height
45
+ }
46
+
47
+ async function calcTableHeight() {
48
+ const { pagination, virtual } = unref(propsRef)
49
+
50
+ const table = unref(tableElRef)
51
+
52
+ if( !table ) return
53
+
54
+ const tableEl = table?.$el
55
+
56
+ if( !bodyEl ) {
57
+ bodyEl = tableEl.querySelector('.ant-table-body')
58
+ if( !bodyEl ) return
59
+ }
60
+
61
+ const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight
62
+ const hasScrollBarX = bodyEl.scrollWidth > bodyEl.clientWidth
63
+
64
+ if( hasScrollBarY ) {
65
+ tableEl.classList.contains('hide-scrollbar-y') && tableEl.classList.remove('hide-scrollbar-y')
66
+ } else {
67
+ !tableEl.classList.contains('hide-scrollbar-y') && tableEl.classList.add('hide-scrollbar-y')
68
+ }
69
+
70
+ if (hasScrollBarX) {
71
+ tableEl.classList.contains('hide-scrollbar-x') && tableEl.classList.remove('hide-scrollbar-x')
72
+ } else {
73
+ !tableEl.classList.contains('hide-scrollbar-x') && tableEl.classList.add('hide-scrollbar-x')
74
+ }
75
+
76
+ bodyEl!.style.height = 'unset'
77
+ if( unref(propsRef).dataSource.length === 0 ) return
78
+
79
+ await nextTick()
80
+
81
+ let
82
+ headerHeight = 0,
83
+ paginationHeight = 2,
84
+ footerHeight = 0,
85
+ titleHeight = (tableEl.querySelector('.ant-table-title') as HTMLElement)?.offsetHeight ?? 0,
86
+ marginHeight = 15
87
+
88
+ const headEl = tableEl.querySelector('.ant-table-thead ')
89
+ if( headEl ) {
90
+ headerHeight = (headEl as HTMLElement).offsetHeight
91
+ }
92
+
93
+ if( !isBoolean(pagination) ) {
94
+ let paginationEl = tableEl.querySelector('.ant-pagination') as HTMLElement
95
+
96
+ if( paginationEl ) {
97
+ const offsetHeight = paginationEl.offsetHeight
98
+ paginationHeight += offsetHeight || 0
99
+ } else {
100
+ paginationHeight += 24
101
+ }
102
+
103
+ if( !footerEl ) {
104
+ footerEl = tableEl.querySelector('.ant-table-footer') as HTMLElement
105
+ } else {
106
+ const offsetHeight = footerEl.offsetHeight
107
+ footerHeight += offsetHeight || 0
108
+ }
109
+
110
+ } else {
111
+ paginationHeight = -8
112
+ }
113
+
114
+ const tableHeight = table?.$el?.offsetHeight ?? 0
115
+
116
+ let height = tableHeight - paginationHeight - footerHeight - headerHeight - titleHeight - marginHeight
117
+ height = Math.max(height, 167)
118
+
119
+ setHeight(height)
120
+
121
+ bodyEl!.style.height = `${height}px`
122
+
123
+ // 表格虚拟滚动
124
+ virtual ? calcTableScroll( ) : filterSource.value = unref(propsRef)?.dataSource
125
+ }
126
+
127
+ onMounted(() => {
128
+ calcTableHeight();
129
+ nextTick(() => {
130
+ debounceRedoHeight();
131
+ });
132
+ });
133
+
134
+ const getScrollX = computed(() => {
135
+ let width = 0
136
+
137
+ // 如果有复选框或者单选框
138
+ if( unref(rowSelectionRef) ) {
139
+ width += 32
140
+ }
141
+
142
+ const NORMAL_WIDTH = 120
143
+
144
+ const columns = unref(columnsRef).filter((item) => !item.defaultHidden)
145
+
146
+ columns.forEach( item => {
147
+ width += Number.parseInt(item.width as string) || NORMAL_WIDTH
148
+ } )
149
+
150
+ const table = unref(tableElRef)
151
+ const tableWidth = table?.$el?.offsetWidth ?? 0
152
+
153
+ return tableWidth > width ? '100%' : width
154
+ })
155
+
156
+ const getScrollRef = computed(() => {
157
+ const tableHeight = unref(tableHeightRef)
158
+ const { scroll } = unref(propsRef)
159
+
160
+ return {
161
+ x: unref(getScrollX),
162
+ y: tableHeight,
163
+ scrollToFirstRowOnChange: false,
164
+ ...scroll,
165
+ };
166
+ })
167
+
168
+ // 创建滚动元素
169
+ function createScrollWrap(el: Element) {
170
+ let data = unref(propsRef)?.dataSource?.length
171
+ const { size } = unref(propsRef)
172
+ const rowHeight = TABLE_SIZE_HEIGHT[size]
173
+
174
+ let scrollWrap = el.querySelector('.tableScrollWrap')
175
+ let wrapHeight = data * rowHeight + 'px'
176
+
177
+ if( scrollWrap ) {
178
+ (scrollWrap as any).style.height = wrapHeight
179
+ } else {
180
+ let div = document.createElement('div')
181
+ div.className = 'tableScrollWrap'
182
+ div.style.height = wrapHeight
183
+ el.insertBefore(div, el.querySelector('table')[0])
184
+ }
185
+ }
186
+
187
+ async function calcTableScroll() {
188
+ const tableEl = unref(tableElRef)?.$el
189
+ bodyEl = tableEl.querySelector('.ant-table-body')
190
+
191
+ // 添加一个滚动div元素
192
+ createScrollWrap(bodyEl)
193
+
194
+ calcScroll(bodyEl)
195
+
196
+ bodyEl.addEventListener('scroll', (e) => {
197
+ calcScroll(bodyEl)
198
+ })
199
+ }
200
+
201
+ async function calcScroll(el: Element) {
202
+ const { size } = unref(propsRef)
203
+ const rowHeight = TABLE_SIZE_HEIGHT[size]
204
+ const scrollTop = el.scrollTop
205
+
206
+ // 留闲高度,默认留3个表格高度
207
+ const remainCount = 3
208
+ const remainH = remainCount * rowHeight
209
+
210
+ // 最小高度
211
+ const minItemHeight = scrollTop > remainH ? Math.floor((scrollTop - remainH) / rowHeight) * rowHeight : 0
212
+
213
+ // 最小索引
214
+ const minIndex = minItemHeight / rowHeight
215
+ // 最大索引
216
+ const maxIndex = minIndex + Math.ceil(tableHeightRef.value / rowHeight) + (minItemHeight && remainCount) + remainCount * 2
217
+
218
+ bodyEl.querySelector('table').style.transform = `translateY(${minItemHeight}px)`
219
+
220
+ filterSource.value = unref(propsRef)?.dataSource.slice(minIndex, maxIndex)
221
+ }
222
+
223
+ return {
224
+ getScrollRef,
225
+ filterSource
226
+ }
227
+ }
@@ -0,0 +1,198 @@
1
+
2
+
3
+ <template>
4
+ <Table
5
+ ref="tableElRef"
6
+ class="dt-table"
7
+ v-bind="getBind"
8
+ :rowClassName="getRowClassName"
9
+ @change="handleTableChange"
10
+ @resizeColumn="handleResizeColumn"
11
+ >
12
+ <template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
13
+ <slot :name="item" v-bind="data || {}"></slot>
14
+ </template>
15
+
16
+ <template #bodyCell="{ column, record, index }">
17
+ <template v-if="column.render">
18
+ <TableRender :column="column" :record="record" :index="index"></TableRender>
19
+ </template>
20
+ </template>
21
+ </Table>
22
+ </template>
23
+
24
+ <script lang="ts">
25
+ import { defineComponent, ref, unref, computed, ExtractPropTypes, toRaw } from "vue"
26
+ import { Table } from 'ant-design-vue'
27
+ import { TableProps } from './props'
28
+ import { BasicTableProps, SizeType, TableActionType } from "./types/table.type"
29
+ import { useRows } from './hooks/useRows'
30
+ import { Recordable } from "@dt-frames/core"
31
+ import { useLoading } from "./hooks/useLoading"
32
+ import { usePagination } from "./hooks/usePagination"
33
+ import { useDataSource } from "./hooks/useDataSource"
34
+ import { useRowSelection } from "./hooks/useRowSelection"
35
+ import TableHeader from './components/TableHeader.vue'
36
+ import TableRender from './components/TableRender.vue'
37
+ import { createTableInstance } from "./hooks/useTableInstance"
38
+ import { useColumns } from "./hooks/useColumns"
39
+ import { useTableHeader } from "./hooks/useTableHeader"
40
+ import { useTableScroll } from "./hooks/useTableScroll"
41
+
42
+
43
+ export default defineComponent({
44
+ name: 'dt-table',
45
+ props: TableProps,
46
+ components: {
47
+ Table,
48
+ TableHeader,
49
+ TableRender
50
+ },
51
+ emits: [
52
+ 'register',
53
+ 'columns-change',
54
+ 'selection-change'
55
+ ],
56
+ setup(props, { emit, attrs, slots }) {
57
+ // table实例
58
+ const tableElRef = ref(null)
59
+ const tableData = ref<Recordable[]>([])
60
+
61
+ // 修改后的props属性
62
+ const innerPropsRef = ref<BasicTableProps>()
63
+
64
+ const getProps = computed(() => {
65
+ return { ...props, ...unref(innerPropsRef) } as BasicTableProps
66
+ })
67
+
68
+
69
+ /**
70
+ * 重构loading状态
71
+ */
72
+ const { getLoading, setLoading } = useLoading( getProps )
73
+
74
+
75
+ /**
76
+ * 重构分页数据
77
+ */
78
+ const { getPaginationInfo, setPagination, getPagination, getShowPagination, setShowPagination } = usePagination( getProps )
79
+
80
+ // 关于列的控制
81
+ const {
82
+ getViewColumns,
83
+ getColumnsRef,
84
+ getColumns,
85
+ setColumns,
86
+ setCacheColumnsByField,
87
+ getCacheColumns
88
+ } = useColumns(getProps, getPaginationInfo)
89
+
90
+ const {
91
+ getRowSelectionRef,
92
+ clearSelectedRowKeys,
93
+ getRowSelection,
94
+ getSelectRows,
95
+ getSelectRowKeys,
96
+
97
+ } = useRowSelection(getProps, emit)
98
+
99
+ // 关于滚动条的设置
100
+ const { getScrollRef, filterSource } = useTableScroll(
101
+ getProps,
102
+ tableElRef,
103
+ getColumnsRef,
104
+ getRowSelectionRef,
105
+ )
106
+
107
+ function setProps(props: Partial<BasicTableProps>) {
108
+ innerPropsRef.value = { ...unref(innerPropsRef), ...props };
109
+ }
110
+
111
+ const tableAction: TableActionType = {
112
+ setProps,
113
+ setLoading,
114
+ getColumns,
115
+ setColumns,
116
+ getRowSelection,
117
+ setCacheColumnsByField,
118
+ getCacheColumns,
119
+ getSelectRows,
120
+ getSelectRowKeys,
121
+ getSize: () => {
122
+ return unref(getBind).size as SizeType;
123
+ }
124
+ }
125
+
126
+ const {
127
+ getRowClassName
128
+ } = useRows( getProps )
129
+
130
+
131
+ const getBind = computed(() => {
132
+ return {
133
+ ...attrs,
134
+ ...unref(getProps),
135
+ ...unref(getHeaderProps),
136
+ scroll: unref(getScrollRef),
137
+ loading: unref( getLoading ),
138
+ dataSource: toRaw(unref(filterSource)),
139
+ pagination: toRaw(unref(getPaginationInfo)),
140
+ rowSelection: unref(getRowSelectionRef),
141
+ rowKey: unref(getProps).rowKey,
142
+ columns: toRaw(unref(getViewColumns)),
143
+ tableLayout: 'fixed'
144
+ }
145
+ })
146
+
147
+ // 创建实例
148
+ createTableInstance({ ...tableAction, tableElRef, getBind })
149
+
150
+ /**
151
+ * 处理表格头部内容
152
+ */
153
+ const handlers = {
154
+ onColumnsChange: (data: {
155
+ dataIndex: string
156
+ fixed: boolean | 'left' | 'right' | undefined
157
+ visible: boolean
158
+ }[]) => {
159
+ emit('columns-change', data)
160
+
161
+ unref(getProps).onColumnsChange?.(data)
162
+ }
163
+ }
164
+ const { getHeaderProps } = useTableHeader(getProps, slots, handlers)
165
+
166
+
167
+ /**
168
+ * 表格改变
169
+ */
170
+ const {
171
+ handleTableChange
172
+ } = useDataSource(
173
+ getProps,
174
+ {
175
+ getPaginationInfo,
176
+ setPagination,
177
+ clearSelectedRowKeys
178
+ },
179
+ emit
180
+ )
181
+
182
+ emit('register', tableAction)
183
+
184
+ return {
185
+ tableElRef,
186
+ getBind,
187
+ getRowClassName,
188
+ handleTableChange,
189
+ getSelectRows,
190
+ handleResizeColumn: (w, col) => {
191
+ col.width = w;
192
+ setCacheColumnsByField(col.dataIndex, col)
193
+ }
194
+ }
195
+ }
196
+ })
197
+ </script>
198
+