@dt-frames/ui 1.0.2 → 1.0.5

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 (233) hide show
  1. package/README.md +1 -15
  2. package/es/assets/imgs/header/avatar.png +0 -0
  3. package/es/assets/style/reset.less +0 -3
  4. package/es/components/curd/src/components/dialog.d.ts +21 -58
  5. package/es/components/curd/src/types/curd.type.d.ts +2 -1
  6. package/es/components/dialog/index.d.ts +2 -0
  7. package/es/components/dialog/src/hooks/useDialog.d.ts +3 -0
  8. package/es/components/forms/index.d.ts +2 -2
  9. package/es/components/forms/src/components/formIcon.d.ts +4 -47
  10. package/es/components/forms/src/index.d.ts +2 -6
  11. package/es/components/iframe/index.d.ts +2 -2
  12. package/es/components/index.d.ts +3 -2
  13. package/es/components/modal/src/components/close-icon.d.ts +0 -43
  14. package/es/components/modal/src/index.d.ts +0 -43
  15. package/es/components/source/src/types/table.type.d.ts +1 -1
  16. package/es/components/table/index.d.ts +1 -1
  17. package/es/components/table/src/components/setting/Column.d.ts +6 -5
  18. package/es/components/table/src/hooks/useColumns.d.ts +1 -1
  19. package/es/components/table/src/hooks/useDataSource.d.ts +1 -3
  20. package/es/components/table/src/hooks/useHeaderCode.d.ts +2 -0
  21. package/es/components/table/src/hooks/useRowSelection.d.ts +2 -3
  22. package/es/components/table/src/index.d.ts +15 -3
  23. package/es/components/table/src/props.d.ts +7 -1
  24. package/es/index.js +284 -271
  25. package/es/style/assets/style/reset.less +0 -3
  26. package/es/style/components/forms/{src/index.less → index.less} +2 -0
  27. package/es/style/components/icons/index.less +1 -0
  28. package/es/style/components/iframe/index.less +3 -0
  29. package/es/style/components/modal/{src/index.less → index.less} +0 -0
  30. package/es/style/components/table/{src/index.less → index.less} +12 -1
  31. package/es/style/theme/header/index.less +8 -4
  32. package/es/style/theme/sider/index.less +25 -25
  33. package/es/style/theme/theme.less +2 -1
  34. package/es/theme/header/components/logo.d.ts +43 -0
  35. package/es/theme/header/components/notify.d.ts +0 -1
  36. package/package.json +50 -40
  37. package/src/assets/data/icons/actions.ts +427 -0
  38. package/src/assets/data/icons/code.ts +10 -0
  39. package/src/assets/data/icons/commuticate.ts +190 -0
  40. package/src/assets/data/icons/currency.ts +46 -0
  41. package/src/assets/data/icons/devices.ts +128 -0
  42. package/src/assets/data/icons/edit.ts +165 -0
  43. package/src/assets/data/icons/file.ts +104 -0
  44. package/src/assets/data/icons/math.ts +53 -0
  45. package/src/assets/data/icons/message.ts +75 -0
  46. package/src/assets/data/icons/navigate.ts +181 -0
  47. package/src/assets/data/icons/other.ts +333 -0
  48. package/src/assets/data/icons.ts +58 -0
  49. package/src/assets/imgs/header/avatar.png +0 -0
  50. package/src/assets/imgs/logo/logo.png +0 -0
  51. package/src/assets/locales/en_US.json +3 -0
  52. package/src/assets/locales/zh_CN.json +3 -0
  53. package/src/assets/style/index.less +10 -0
  54. package/src/assets/style/reset.less +17 -0
  55. package/src/components/container/index.less +85 -0
  56. package/src/components/container/index.ts +8 -0
  57. package/src/components/container/src/bar.ts +107 -0
  58. package/src/components/container/src/lazy-container.vue +9 -0
  59. package/src/components/container/src/scroll-bar.vue +117 -0
  60. package/src/components/container/src/scroll-container.vue +61 -0
  61. package/src/components/curd/index.ts +5 -0
  62. package/src/components/curd/src/components/dialog.vue +71 -0
  63. package/src/components/curd/src/components/props.ts +32 -0
  64. package/src/components/curd/src/hooks/useCurd.tsx +87 -0
  65. package/src/components/curd/src/types/curd.type.ts +31 -0
  66. package/src/components/dialog/index.ts +5 -0
  67. package/src/components/dialog/src/hooks/useDialog.ts +85 -0
  68. package/src/components/excel/index.ts +6 -0
  69. package/src/components/excel/src/export2Excel.ts +44 -0
  70. package/src/components/forms/index.less +84 -0
  71. package/src/components/forms/index.ts +11 -0
  72. package/src/components/forms/src/componentMap.ts +44 -0
  73. package/src/components/forms/src/components/formButton.vue +150 -0
  74. package/src/components/forms/src/components/formIcon.vue +50 -0
  75. package/src/components/forms/src/components/formItem.vue +407 -0
  76. package/src/components/forms/src/components/radioButton.vue +58 -0
  77. package/src/components/forms/src/const/form.const.ts +7 -0
  78. package/src/components/forms/src/hooks/helper.ts +70 -0
  79. package/src/components/forms/src/hooks/useForm.ts +130 -0
  80. package/src/components/forms/src/hooks/useFormActions.ts +63 -0
  81. package/src/components/forms/src/hooks/useFormEvents.ts +247 -0
  82. package/src/components/forms/src/hooks/useFormValue.ts +49 -0
  83. package/src/components/forms/src/hooks/useFormValues.ts +131 -0
  84. package/src/components/forms/src/hooks/useLabelWidth.ts +57 -0
  85. package/src/components/forms/src/index.vue +306 -0
  86. package/src/components/forms/src/prop.ts +80 -0
  87. package/src/components/forms/src/types/form.type.ts +269 -0
  88. package/{es/style/components/icons/src → src/components/icons}/index.less +1 -0
  89. package/src/components/icons/index.ts +7 -0
  90. package/src/components/icons/src/pick-icon.vue +117 -0
  91. package/src/components/icons/src/svg-icon.vue +117 -0
  92. package/src/components/iframe/index.less +3 -0
  93. package/src/components/iframe/index.ts +5 -0
  94. package/src/components/iframe/src/index.less +3 -0
  95. package/src/components/iframe/src/index.vue +38 -0
  96. package/src/components/index.ts +48 -0
  97. package/src/components/modal/index.less +60 -0
  98. package/src/components/modal/index.ts +8 -0
  99. package/src/components/modal/src/components/close-icon.vue +47 -0
  100. package/src/components/modal/src/components/modal-wrap.vue +118 -0
  101. package/src/components/modal/src/components/modal.tsx +30 -0
  102. package/src/components/modal/src/components/modalFooter.vue +38 -0
  103. package/src/components/modal/src/hooks/useDrag.ts +107 -0
  104. package/src/components/modal/src/hooks/useFullScreen.ts +27 -0
  105. package/src/components/modal/src/hooks/useModal.ts +176 -0
  106. package/src/components/modal/src/index.vue +173 -0
  107. package/src/components/modal/src/props.ts +43 -0
  108. package/src/components/modal/src/types/modal.type.ts +27 -0
  109. package/src/components/router/base-router.vue +11 -0
  110. package/src/components/router/index.ts +3 -0
  111. package/src/components/source/index.ts +1 -0
  112. package/src/components/source/src/hooks/useFetch.ts +69 -0
  113. package/src/components/source/src/hooks/usePage.ts +3 -0
  114. package/src/components/source/src/hooks/useSource.ts +179 -0
  115. package/src/components/source/src/index.ts +5 -0
  116. package/src/components/source/src/types/source.type.ts +68 -0
  117. package/src/components/source/src/types/table.type.ts +8 -0
  118. package/src/components/table/index.less +173 -0
  119. package/src/components/table/index.ts +7 -0
  120. package/src/components/table/src/components/TableActions.vue +108 -0
  121. package/src/components/table/src/components/TableHeader.vue +77 -0
  122. package/src/components/table/src/components/TableRender.vue +76 -0
  123. package/src/components/table/src/components/setting/Column.vue +354 -0
  124. package/src/components/table/src/components/setting/Download.vue +55 -0
  125. package/src/components/table/src/components/setting/Fullscreen.vue +43 -0
  126. package/src/components/table/src/components/setting/Size.vue +42 -0
  127. package/src/components/table/src/components/setting/index.vue +64 -0
  128. package/src/components/table/src/const.ts +13 -0
  129. package/src/components/table/src/hooks/useColumns.ts +319 -0
  130. package/{es/assets/app-antd-dark-theme-style.e3b0c442.css → src/components/table/src/hooks/useCustomRow.ts} +0 -0
  131. package/src/components/table/src/hooks/useDataSource.ts +99 -0
  132. package/src/components/table/src/hooks/useHeaderCode.ts +82 -0
  133. package/src/components/table/src/hooks/useLoading.ts +29 -0
  134. package/src/components/table/src/hooks/usePagination.ts +76 -0
  135. package/src/components/table/src/hooks/useRowSelection.ts +145 -0
  136. package/src/components/table/src/hooks/useRows.ts +30 -0
  137. package/src/components/table/src/hooks/useTable.ts +89 -0
  138. package/src/components/table/src/hooks/useTableHeader.ts +48 -0
  139. package/src/components/table/src/hooks/useTableInstance.ts +29 -0
  140. package/src/components/table/src/hooks/useTableScroll.ts +229 -0
  141. package/src/components/table/src/index.vue +197 -0
  142. package/src/components/table/src/props.ts +157 -0
  143. package/src/components/table/src/types/table.type.ts +133 -0
  144. package/src/components/table/src/types/tableHeader.type.ts +27 -0
  145. package/{es/assets/app-theme-style.e3b0c442.css → src/components/type.ts} +0 -0
  146. package/src/directives/icon.ts +36 -0
  147. package/src/directives/index.ts +26 -0
  148. package/src/directives/permission.ts +20 -0
  149. package/src/global.d.ts +8 -0
  150. package/src/index.ts +4 -0
  151. package/src/theme/content/index.vue +37 -0
  152. package/src/theme/feature/back-top.vue +11 -0
  153. package/src/theme/feature/index.vue +7 -0
  154. package/src/theme/footer/index.less +16 -0
  155. package/src/theme/footer/index.vue +24 -0
  156. package/src/theme/header/components/bread-crumb.vue +26 -0
  157. package/src/theme/header/components/fullscreen.vue +12 -0
  158. package/src/theme/header/components/handler.ts +81 -0
  159. package/src/theme/header/components/index.ts +21 -0
  160. package/src/theme/header/components/lang-picker.vue +36 -0
  161. package/src/theme/header/components/logo.vue +35 -0
  162. package/src/theme/header/components/menu-search.vue +62 -0
  163. package/src/theme/header/components/notify.vue +22 -0
  164. package/src/theme/header/components/setting-theme.vue +123 -0
  165. package/src/theme/header/components/theme-drawer/enum.ts +12 -0
  166. package/src/theme/header/components/theme-drawer/feature.vue +75 -0
  167. package/src/theme/header/components/theme-drawer/index.ts +7 -0
  168. package/src/theme/header/components/theme-drawer/menu-type.vue +40 -0
  169. package/src/theme/header/components/theme-drawer/select-item.vue +46 -0
  170. package/src/theme/header/components/theme-drawer/switch-item.vue +39 -0
  171. package/src/theme/header/components/theme-drawer/theme-color.vue +26 -0
  172. package/src/theme/header/components/trigger.vue +14 -0
  173. package/src/theme/header/components/user-info.vue +60 -0
  174. package/src/theme/header/const/index.ts +40 -0
  175. package/src/theme/header/helper/menu-tree.ts +64 -0
  176. package/src/theme/header/index.less +442 -0
  177. package/{es/theme/theme.d.ts → src/theme/header/index.ts} +0 -0
  178. package/src/theme/header/index.vue +96 -0
  179. package/src/theme/header/multiple-header.vue +67 -0
  180. package/src/theme/header/set-theme.less +68 -0
  181. package/src/theme/index.ts +3 -0
  182. package/src/theme/sider/components/basic-menu/basic-menu-item.vue +14 -0
  183. package/src/theme/sider/components/basic-menu/basic-menu.vue +122 -0
  184. package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +46 -0
  185. package/src/theme/sider/components/basic-menu/menu-item-content.vue +13 -0
  186. package/src/theme/sider/components/drag-bar.vue +26 -0
  187. package/src/theme/sider/components/layout-menu.vue +132 -0
  188. package/src/theme/sider/components/props.ts +97 -0
  189. package/src/theme/sider/components/sider-trigger.vue +24 -0
  190. package/src/theme/sider/helper/sider.ts +52 -0
  191. package/src/theme/sider/helper/split-menu.ts +146 -0
  192. package/src/theme/sider/hooks/useDragLine.ts +86 -0
  193. package/src/theme/sider/hooks/useOpenKeys.ts +57 -0
  194. package/src/theme/sider/index.less +203 -0
  195. package/src/theme/sider/index.vue +88 -0
  196. package/src/theme/tabs/components/TabContent.vue +36 -0
  197. package/src/theme/tabs/components/TabRedo.vue +18 -0
  198. package/src/theme/tabs/hooks/useMultifyTabs.ts +96 -0
  199. package/src/theme/tabs/hooks/useTabDropdown.ts +89 -0
  200. package/src/theme/tabs/index.less +165 -0
  201. package/src/theme/tabs/index.vue +98 -0
  202. package/src/theme/tabs/types/tabs.type.ts +8 -0
  203. package/src/theme/theme.less +67 -0
  204. package/src/theme/theme.vue +90 -0
  205. package/src/theme/transition.less +99 -0
  206. package/es/assets/data/icon.d.ts +0 -4
  207. package/es/assets/data/icon.ts +0 -69
  208. package/es/assets/data/icon11.ts +0 -69
  209. package/es/assets/style/var.less +0 -42
  210. package/es/components/icons/pick-icon.d.ts +0 -529
  211. package/es/components/icons/svg-icon.d.ts +0 -44
  212. package/es/components/table/src/hooks/useFormat.d.ts +0 -2
  213. package/es/components/table/src/hooks/useVirtualScroll.d.ts +0 -5
  214. package/es/components/table/src/utils/format.d.ts +0 -1
  215. package/es/index.css +0 -1
  216. package/es/style/assets/style/var.less +0 -42
  217. package/es/theme/content/index.d.ts +0 -29
  218. package/es/theme/header/components/menu-search.d.ts +0 -528
  219. package/es/theme/header/components/setting-theme.d.ts +0 -2550
  220. package/es/theme/header/components/user-info.d.ts +0 -452
  221. package/es/theme/header/index.d.ts +0 -4369
  222. package/es/theme/header/multiple-header.d.ts +0 -2001
  223. package/es/theme/styles/hooks/changeTheme.d.ts +0 -1
  224. package/es/theme/styles/hooks/generate.d.ts +0 -13
  225. package/es/theme/styles/index.d.ts +0 -2
  226. package/es/theme/tabs/components/TabRedo.d.ts +0 -49
  227. package/es/theme/tabs/index.d.ts +0 -1399
  228. package/es/theme/theme/initTheme.d.ts +0 -3
  229. package/es/theme/theme/util.d.ts +0 -5
  230. package/es/themes/generate.ts +0 -74
  231. package/es/themes/index.ts +0 -10
  232. package/es/themes/modifyVars.ts +0 -33
  233. 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,82 @@
1
+ import { error, http, Recordable, useAppStore } from "@dt-frames/core"
2
+ import { BasicColumn, CellFormat } from "../types/table.type"
3
+
4
+
5
+ // 解析header
6
+ export function useHeaderCode(code: string, templates: CellFormat = {}, changeColumns: ( rows: BasicColumn[] ) => void) {
7
+ const { appConf } = useAppStore()
8
+
9
+ if( !appConf.pages.queryColumnApi ) {
10
+ error('请在init.config.ts中配置queryColumnApi!')
11
+ return
12
+ }
13
+
14
+
15
+ // 设置文字对齐方式
16
+ const getAlign = ( key: number | null ) => key === 0 ? 'center' : key === 2 ? 'right' : 'left'
17
+
18
+
19
+ // 渲染单元格
20
+ const renderCell = ( type: number, ctx: string ): Recordable => {
21
+ switch( type ) {
22
+ // 时间
23
+ case 0: return { date: ctx }
24
+
25
+ // 字典
26
+ case 1: return { dict: ctx }
27
+
28
+ // 百分比
29
+ case 5: return { percent: ctx }
30
+
31
+ // structure
32
+ case 7:
33
+ if( !appConf.structure[ctx] ) {
34
+ error(`未找到structure: ${ ctx } !`)
35
+ return { }
36
+ }
37
+ return { dict: appConf.structure[ctx] }
38
+
39
+ // 自定义模板
40
+ case 10: return templates[ctx]
41
+
42
+ // 数字
43
+ case 11: return { number: ctx }
44
+ }
45
+ }
46
+
47
+
48
+ function getColumns() {
49
+ http.post(
50
+ appConf.pages.queryColumnApi,
51
+ { tableCode: code }
52
+ ).then( rsp => {
53
+ handleData(rsp)
54
+ } )
55
+ }
56
+
57
+ function handleData(data: Recordable[]) {
58
+ let rows: BasicColumn[] = []
59
+
60
+ data.forEach( it => {
61
+ let obj: BasicColumn = {
62
+ title: it.cloumnName,
63
+ dataIndex: it.cloumnCode,
64
+ sorter: it.ifOrder,
65
+ align: getAlign(it.textAlign),
66
+ ifShow: Boolean( it.ifDisplay ),
67
+ defaultHidden: !Boolean( it.ifDisplay )
68
+ }
69
+
70
+ if( it.cloumnType !== undefined ) obj.render = renderCell( it.cloumnType, it.dictCode )
71
+
72
+ if( it.width ) obj.width = Number(it.width)
73
+
74
+ rows.push(obj)
75
+ } )
76
+
77
+ changeColumns( rows )
78
+ }
79
+
80
+ getColumns()
81
+
82
+ }
@@ -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
+ }