@dt-frames/ui 1.0.2 → 1.0.3

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 (183) hide show
  1. package/README.md +1 -15
  2. package/es/assets/style/reset.less +0 -3
  3. package/es/index.css +1 -1
  4. package/es/index.js +1 -0
  5. package/es/style/assets/style/reset.less +0 -3
  6. package/es/style/theme/sider/index.less +25 -25
  7. package/es/theme/content/index.d.ts +27 -29
  8. package/es/theme/header/components/menu-search.d.ts +528 -528
  9. package/es/theme/header/components/setting-theme.d.ts +2580 -2550
  10. package/es/theme/header/index.d.ts +4369 -4369
  11. package/es/theme/tabs/components/TabRedo.d.ts +7 -49
  12. package/es/theme/tabs/index.d.ts +2478 -1399
  13. package/es/theme/theme/initTheme.d.ts +3 -3
  14. package/es/theme/theme.d.ts +22 -0
  15. package/package.json +50 -40
  16. package/src/assets/data/icons/actions.ts +427 -0
  17. package/src/assets/data/icons/code.ts +10 -0
  18. package/src/assets/data/icons/commuticate.ts +190 -0
  19. package/src/assets/data/icons/currency.ts +46 -0
  20. package/src/assets/data/icons/devices.ts +128 -0
  21. package/src/assets/data/icons/edit.ts +165 -0
  22. package/src/assets/data/icons/file.ts +104 -0
  23. package/src/assets/data/icons/math.ts +53 -0
  24. package/src/assets/data/icons/message.ts +75 -0
  25. package/src/assets/data/icons/navigate.ts +181 -0
  26. package/src/assets/data/icons/other.ts +333 -0
  27. package/src/assets/data/icons.ts +58 -0
  28. package/src/assets/imgs/logo/logo.png +0 -0
  29. package/src/assets/locales/en_US.json +3 -0
  30. package/src/assets/locales/zh_CN.json +3 -0
  31. package/src/assets/style/index.less +10 -0
  32. package/src/assets/style/reset.less +17 -0
  33. package/src/components/container/index.less +85 -0
  34. package/src/components/container/index.ts +8 -0
  35. package/src/components/container/src/bar.ts +107 -0
  36. package/src/components/container/src/lazy-container.vue +9 -0
  37. package/src/components/container/src/scroll-bar.vue +117 -0
  38. package/src/components/container/src/scroll-container.vue +61 -0
  39. package/src/components/curd/index.ts +5 -0
  40. package/src/components/curd/src/components/dialog.vue +65 -0
  41. package/src/components/curd/src/components/props.ts +32 -0
  42. package/src/components/curd/src/hooks/useCurd.tsx +72 -0
  43. package/src/components/curd/src/types/curd.type.ts +29 -0
  44. package/src/components/excel/index.ts +6 -0
  45. package/src/components/excel/src/export2Excel.ts +44 -0
  46. package/src/components/forms/index.ts +12 -0
  47. package/src/components/forms/src/componentMap.ts +44 -0
  48. package/src/components/forms/src/components/formButton.vue +150 -0
  49. package/src/components/forms/src/components/formIcon.vue +50 -0
  50. package/src/components/forms/src/components/formItem.vue +407 -0
  51. package/src/components/forms/src/components/radioButton.vue +58 -0
  52. package/src/components/forms/src/const/form.const.ts +7 -0
  53. package/src/components/forms/src/hooks/helper.ts +70 -0
  54. package/src/components/forms/src/hooks/useForm.ts +130 -0
  55. package/src/components/forms/src/hooks/useFormActions.ts +63 -0
  56. package/src/components/forms/src/hooks/useFormEvents.ts +247 -0
  57. package/src/components/forms/src/hooks/useFormValue.ts +49 -0
  58. package/src/components/forms/src/hooks/useFormValues.ts +131 -0
  59. package/src/components/forms/src/hooks/useLabelWidth.ts +57 -0
  60. package/src/components/forms/src/index.less +82 -0
  61. package/src/components/forms/src/index.vue +306 -0
  62. package/src/components/forms/src/prop.ts +80 -0
  63. package/src/components/forms/src/types/form.type.ts +269 -0
  64. package/src/components/icons/index.ts +7 -0
  65. package/src/components/icons/src/index.less +96 -0
  66. package/src/components/icons/src/pick-icon.vue +117 -0
  67. package/src/components/icons/src/svg-icon.vue +117 -0
  68. package/src/components/iframe/index.ts +5 -0
  69. package/src/components/iframe/src/index.less +3 -0
  70. package/src/components/iframe/src/index.vue +38 -0
  71. package/src/components/index.ts +46 -0
  72. package/src/components/modal/index.ts +8 -0
  73. package/src/components/modal/src/components/close-icon.vue +47 -0
  74. package/src/components/modal/src/components/modal-wrap.vue +118 -0
  75. package/src/components/modal/src/components/modal.tsx +30 -0
  76. package/src/components/modal/src/components/modalFooter.vue +38 -0
  77. package/src/components/modal/src/hooks/useDrag.ts +107 -0
  78. package/src/components/modal/src/hooks/useFullScreen.ts +27 -0
  79. package/src/components/modal/src/hooks/useModal.ts +177 -0
  80. package/src/components/modal/src/index.less +60 -0
  81. package/src/components/modal/src/index.vue +173 -0
  82. package/src/components/modal/src/props.ts +43 -0
  83. package/src/components/modal/src/types/modal.type.ts +27 -0
  84. package/src/components/router/base-router.vue +11 -0
  85. package/src/components/router/index.ts +3 -0
  86. package/src/components/source/index.ts +1 -0
  87. package/src/components/source/src/hooks/useFetch.ts +70 -0
  88. package/src/components/source/src/hooks/usePage.ts +3 -0
  89. package/src/components/source/src/hooks/useSource.ts +178 -0
  90. package/src/components/source/src/index.ts +5 -0
  91. package/src/components/source/src/types/source.type.ts +68 -0
  92. package/src/components/source/src/types/table.type.ts +8 -0
  93. package/src/components/table/index.ts +7 -0
  94. package/src/components/table/src/components/TableActions.vue +108 -0
  95. package/src/components/table/src/components/TableHeader.vue +77 -0
  96. package/src/components/table/src/components/TableRender.vue +76 -0
  97. package/src/components/table/src/components/setting/Column.vue +355 -0
  98. package/src/components/table/src/components/setting/Download.vue +55 -0
  99. package/src/components/table/src/components/setting/Fullscreen.vue +43 -0
  100. package/src/components/table/src/components/setting/Size.vue +42 -0
  101. package/src/components/table/src/components/setting/index.vue +64 -0
  102. package/src/components/table/src/const.ts +13 -0
  103. package/src/components/table/src/hooks/useColumns.ts +319 -0
  104. package/src/components/table/src/hooks/useCustomRow.ts +0 -0
  105. package/src/components/table/src/hooks/useDataSource.ts +99 -0
  106. package/src/components/table/src/hooks/useLoading.ts +29 -0
  107. package/src/components/table/src/hooks/usePagination.ts +76 -0
  108. package/src/components/table/src/hooks/useRowSelection.ts +146 -0
  109. package/src/components/table/src/hooks/useRows.ts +30 -0
  110. package/src/components/table/src/hooks/useTable.ts +77 -0
  111. package/src/components/table/src/hooks/useTableHeader.ts +48 -0
  112. package/src/components/table/src/hooks/useTableInstance.ts +29 -0
  113. package/src/components/table/src/hooks/useTableScroll.ts +227 -0
  114. package/src/components/table/src/index.less +162 -0
  115. package/src/components/table/src/index.vue +198 -0
  116. package/src/components/table/src/props.ts +152 -0
  117. package/src/components/table/src/types/table.type.ts +133 -0
  118. package/src/components/table/src/types/tableHeader.type.ts +27 -0
  119. package/src/components/type.ts +0 -0
  120. package/src/directives/icon.ts +36 -0
  121. package/src/directives/index.ts +27 -0
  122. package/src/directives/permission.ts +21 -0
  123. package/src/global.d.ts +8 -0
  124. package/src/index.ts +4 -0
  125. package/src/theme/content/index.vue +37 -0
  126. package/src/theme/feature/back-top.vue +11 -0
  127. package/src/theme/feature/index.vue +7 -0
  128. package/src/theme/footer/index.less +16 -0
  129. package/src/theme/footer/index.vue +24 -0
  130. package/src/theme/header/components/bread-crumb.vue +26 -0
  131. package/src/theme/header/components/fullscreen.vue +14 -0
  132. package/src/theme/header/components/handler.ts +81 -0
  133. package/src/theme/header/components/index.ts +21 -0
  134. package/src/theme/header/components/lang-picker.vue +36 -0
  135. package/src/theme/header/components/logo.vue +33 -0
  136. package/src/theme/header/components/menu-search.vue +62 -0
  137. package/src/theme/header/components/notify.vue +23 -0
  138. package/src/theme/header/components/setting-theme.vue +123 -0
  139. package/src/theme/header/components/theme-drawer/enum.ts +12 -0
  140. package/src/theme/header/components/theme-drawer/feature.vue +75 -0
  141. package/src/theme/header/components/theme-drawer/index.ts +7 -0
  142. package/src/theme/header/components/theme-drawer/menu-type.vue +40 -0
  143. package/src/theme/header/components/theme-drawer/select-item.vue +46 -0
  144. package/src/theme/header/components/theme-drawer/switch-item.vue +39 -0
  145. package/src/theme/header/components/theme-drawer/theme-color.vue +26 -0
  146. package/src/theme/header/components/trigger.vue +14 -0
  147. package/src/theme/header/components/user-info.vue +43 -0
  148. package/src/theme/header/const/index.ts +40 -0
  149. package/src/theme/header/helper/menu-tree.ts +67 -0
  150. package/src/theme/header/index.less +438 -0
  151. package/src/theme/header/index.ts +0 -0
  152. package/src/theme/header/index.vue +96 -0
  153. package/src/theme/header/multiple-header.vue +67 -0
  154. package/src/theme/header/set-theme.less +68 -0
  155. package/src/theme/index.ts +3 -0
  156. package/src/theme/sider/components/basic-menu/basic-menu-item.vue +14 -0
  157. package/src/theme/sider/components/basic-menu/basic-menu.vue +122 -0
  158. package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +46 -0
  159. package/src/theme/sider/components/basic-menu/menu-item-content.vue +13 -0
  160. package/src/theme/sider/components/drag-bar.vue +26 -0
  161. package/src/theme/sider/components/layout-menu.vue +132 -0
  162. package/src/theme/sider/components/props.ts +97 -0
  163. package/src/theme/sider/components/sider-trigger.vue +24 -0
  164. package/src/theme/sider/helper/sider.ts +52 -0
  165. package/src/theme/sider/helper/split-menu.ts +147 -0
  166. package/src/theme/sider/hooks/useDragLine.ts +86 -0
  167. package/src/theme/sider/hooks/useOpenKeys.ts +57 -0
  168. package/src/theme/sider/index.less +203 -0
  169. package/src/theme/sider/index.vue +88 -0
  170. package/src/theme/tabs/components/TabContent.vue +37 -0
  171. package/src/theme/tabs/components/TabRedo.vue +18 -0
  172. package/src/theme/tabs/hooks/useMultifyTabs.ts +96 -0
  173. package/src/theme/tabs/hooks/useTabDropdown.ts +89 -0
  174. package/src/theme/tabs/index.less +165 -0
  175. package/src/theme/tabs/index.vue +98 -0
  176. package/src/theme/tabs/types/tabs.type.ts +8 -0
  177. package/src/theme/theme.less +66 -0
  178. package/src/theme/theme.vue +89 -0
  179. package/src/theme/transition.less +99 -0
  180. package/es/themes/generate.ts +0 -74
  181. package/es/themes/index.ts +0 -10
  182. package/es/themes/modifyVars.ts +0 -33
  183. package/es/themes/themePlugiin.ts +0 -74
@@ -0,0 +1,43 @@
1
+ <template>
2
+ <Tooltip placement="top">
3
+ <template #title>
4
+ <span v-if="!isFullscreen">全屏</span>
5
+ </template>
6
+
7
+ <span @click="toggle">
8
+ <span v-if="!isFullscreen" v-icon="'ic:baseline-fullscreen'"></span>
9
+ <span v-else v-icon="'ic:baseline-fullscreen-exit'"></span>
10
+ </span>
11
+ </Tooltip>
12
+ </template>
13
+
14
+ <script lang="ts" setup>
15
+ import { ref, watch } from 'vue'
16
+ import { useFullscreen } from '@vueuse/core';
17
+ import { Tooltip } from 'ant-design-vue'
18
+ import { DtIcon } from '../../../../icons/index'
19
+ import { getTableInstance } from '../../hooks/useTableInstance';
20
+
21
+ const table = getTableInstance()
22
+ const wrapEl = ref(null)
23
+
24
+ const { toggle, isFullscreen } = useFullscreen(wrapEl)
25
+
26
+ watch(
27
+ () => table.tableElRef.value,
28
+ ( v: any ) => {
29
+ const getParent = ( el ) => {
30
+ if( !el || !el.parentNode ) return null
31
+
32
+ // 找到路由的下一层 进行全屏
33
+ if(el.parentNode.className.indexOf('dt-layout-content') !== -1) {
34
+ wrapEl.value = el.parentNode
35
+ } else {
36
+ getParent( el.parentNode )
37
+ }
38
+ }
39
+
40
+ getParent(v.$el)
41
+ }
42
+ )
43
+ </script>
@@ -0,0 +1,42 @@
1
+ <template>
2
+ <Tooltip>
3
+ <template #title>密度</template>
4
+
5
+ <Dropdown
6
+ placement="bottom"
7
+ :trigger="['click']"
8
+ :getPopupContainer="getPopupContainer"
9
+ >
10
+ <span v-icon="'ant-design:column-height-outlined'"></span>
11
+
12
+ <template #overlay>
13
+ <Menu
14
+ @click="handleTitleClick"
15
+ selectable
16
+ v-model:selectedKeys="selectedKeysRef"
17
+ >
18
+ <MenuItem key="default"> <span>默认</span> </MenuItem>
19
+ <MenuItem key="middle"> <span>中等</span> </MenuItem>
20
+ <MenuItem key="small"> <span>紧凑</span> </MenuItem>
21
+ </Menu>
22
+ </template>
23
+ </Dropdown>
24
+ </Tooltip>
25
+ </template>
26
+
27
+ <script lang="ts" setup>
28
+ import { getPopupContainer } from '@dt-frames/core';
29
+ import { Tooltip, Dropdown, Menu, MenuItem } from 'ant-design-vue'
30
+ import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
31
+ import { ref } from 'vue'
32
+ import { getTableInstance } from '../../hooks/useTableInstance';
33
+ import { SizeType } from '../../types/table.type';
34
+
35
+ const table = getTableInstance()
36
+ const selectedKeysRef = ref<SizeType[]>([table.getSize()])
37
+
38
+ function handleTitleClick({ key }: MenuInfo) {
39
+ selectedKeysRef.value = [key as SizeType]
40
+ table.setProps({ size: key as SizeType })
41
+ }
42
+ </script>
@@ -0,0 +1,64 @@
1
+ <template>
2
+ <Download></Download>
3
+ <SizeSetting v-if="getSetting.size" />
4
+ <ColumnSetting
5
+ v-if="getSetting.setting"
6
+ @columns-change="handleColumnChange"
7
+ />
8
+
9
+ <FullscreenSetting v-if="getSetting.fullscreen"></FullscreenSetting>
10
+
11
+ </template>
12
+
13
+ <script lang="ts">
14
+ import { computed, defineComponent, unref } from "vue"
15
+ import type { PropType } from 'vue'
16
+ import { TableSetting } from "../../types/table.type"
17
+ import ColumnSetting from './Column.vue'
18
+ import FullscreenSetting from './Fullscreen.vue'
19
+ import SizeSetting from './Size.vue'
20
+ import Download from './Download.vue'
21
+
22
+ type ColumnChangeParam = {
23
+ dataIndex: string;
24
+ fixed: boolean | 'left' | 'right' | undefined;
25
+ visible: boolean;
26
+ }
27
+
28
+ export default defineComponent({
29
+ name: 'table-setting',
30
+ components: {
31
+ ColumnSetting,
32
+ FullscreenSetting,
33
+ SizeSetting,
34
+ Download
35
+ },
36
+ props: {
37
+ setting: {
38
+ type: Object as PropType<TableSetting>,
39
+ default: () => ({}),
40
+ },
41
+ },
42
+ emits: ['columns-change'],
43
+ setup(props, { emit }) {
44
+ const getSetting = computed((): TableSetting => {
45
+ return {
46
+ redo: true,
47
+ size: true,
48
+ setting: true,
49
+ fullscreen: true,
50
+ ...props.setting,
51
+ };
52
+ })
53
+
54
+ function handleColumnChange(data: ColumnChangeParam[]) {
55
+ emit('columns-change', data);
56
+ }
57
+
58
+ return {
59
+ getSetting,
60
+ handleColumnChange
61
+ }
62
+ }
63
+ })
64
+ </script>
@@ -0,0 +1,13 @@
1
+ export const DEFAULT_SORT_FN = (sortInfo) => {
2
+ const { field, order } = sortInfo
3
+
4
+ return field && order
5
+ ? { field, order }
6
+ : { }
7
+ }
8
+
9
+ export const TABLE_SIZE_HEIGHT = {
10
+ default: 56,
11
+ middle: 47,
12
+ small: 32
13
+ }
@@ -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
+ }
File without changes
@@ -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
+ }