@hoenergy/hoenergy-template-pc 1.0.0

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 (63) hide show
  1. package/.i18n_extractor.json +13 -0
  2. package/dist/components/data/table/FormaxTable/index.d.ts +7 -0
  3. package/dist/components/data/table/FormaxTable/src/BasicTable.d.ts +6 -0
  4. package/dist/components/data/table/FormaxTable/src/Table.vue.d.ts +99 -0
  5. package/dist/components/data/table/FormaxTable/src/components/settings/ColumnSetting.vue.d.ts +31 -0
  6. package/dist/components/data/table/FormaxTable/src/const.d.ts +9 -0
  7. package/dist/components/data/table/FormaxTable/src/hooks/useColumns.d.ts +10 -0
  8. package/dist/components/data/table/FormaxTable/src/hooks/useDataSource.d.ts +20 -0
  9. package/dist/components/data/table/FormaxTable/src/hooks/useLoading.d.ts +6 -0
  10. package/dist/components/data/table/FormaxTable/src/hooks/usePagination.d.ts +10 -0
  11. package/dist/components/data/table/FormaxTable/src/hooks/useTableContext.d.ts +13 -0
  12. package/dist/components/data/table/FormaxTable/src/props.d.ts +1 -0
  13. package/dist/components/data/table/FormaxTable/src/types/componentType.d.ts +1 -0
  14. package/dist/components/data/table/FormaxTable/src/types/pagination.d.ts +10 -0
  15. package/dist/components/data/table/FormaxTable/src/types/table.d.ts +36 -0
  16. package/dist/components/data/table/FormaxTable/src/types/tableAction.d.ts +23 -0
  17. package/dist/components/data/table/FormaxTable/src/utils.d.ts +11 -0
  18. package/dist/components/general/button/FormaxButton/index.d.ts +2 -0
  19. package/dist/index.d.ts +41 -0
  20. package/dist/index.js +37 -0
  21. package/dist/index.mjs +1862 -0
  22. package/dist/mock.d.ts +13 -0
  23. package/dist/style.css +1 -0
  24. package/dist/types.d.ts +34 -0
  25. package/docs/i18n-stub.mjs +12 -0
  26. package/docs/index.html +314 -0
  27. package/docs/index.js +658 -0
  28. package/docs/index.mjs +113892 -0
  29. package/docs/tailwind.css +4 -0
  30. package/docs/tailwind.generated.css +1 -0
  31. package/package.json +51 -0
  32. package/playground/App.vue +60 -0
  33. package/playground/index.html +12 -0
  34. package/playground/main.ts +12 -0
  35. package/src/components/data/table/FormaxTable/index.ts +143 -0
  36. package/src/components/data/table/FormaxTable/src/BasicTable.ts +12 -0
  37. package/src/components/data/table/FormaxTable/src/Table.vue +412 -0
  38. package/src/components/data/table/FormaxTable/src/components/TableAction.vue +155 -0
  39. package/src/components/data/table/FormaxTable/src/components/settings/ColumnSetting.vue +248 -0
  40. package/src/components/data/table/FormaxTable/src/const.ts +11 -0
  41. package/src/components/data/table/FormaxTable/src/hooks/useColumns.ts +147 -0
  42. package/src/components/data/table/FormaxTable/src/hooks/useDataSource.ts +238 -0
  43. package/src/components/data/table/FormaxTable/src/hooks/useLoading.ts +21 -0
  44. package/src/components/data/table/FormaxTable/src/hooks/usePagination.ts +65 -0
  45. package/src/components/data/table/FormaxTable/src/hooks/useTableContext.ts +23 -0
  46. package/src/components/data/table/FormaxTable/src/props.ts +77 -0
  47. package/src/components/data/table/FormaxTable/src/types/componentType.ts +9 -0
  48. package/src/components/data/table/FormaxTable/src/types/pagination.ts +10 -0
  49. package/src/components/data/table/FormaxTable/src/types/table.ts +45 -0
  50. package/src/components/data/table/FormaxTable/src/types/tableAction.ts +25 -0
  51. package/src/components/data/table/FormaxTable/src/utils.ts +65 -0
  52. package/src/components/general/button/FormaxButton/index.ts +70 -0
  53. package/src/index.ts +66 -0
  54. package/src/locales/en.json +13 -0
  55. package/src/locales/zh-CN.json +13 -0
  56. package/src/mock.ts +17 -0
  57. package/src/shims-vue.d.ts +6 -0
  58. package/src/types/i18n-auto-extractor.d.ts +3 -0
  59. package/src/types.ts +40 -0
  60. package/tailwind.config.cjs +12 -0
  61. package/tsconfig.json +16 -0
  62. package/tsup.config.ts +16 -0
  63. package/vite.config.ts +59 -0
@@ -0,0 +1,248 @@
1
+ <template>
2
+ <n-tooltip trigger="hover">
3
+ <template #trigger>
4
+ <div class="cursor-pointer table-toolbar-right-icon flex items-center">
5
+ <n-popover trigger="click" class="toolbar-popover" placement="bottom-end">
6
+ <template #trigger>
7
+ <n-icon size="18">
8
+ <SettingOutlined />
9
+ </n-icon>
10
+ </template>
11
+ <template #header>
12
+ <div class="table-toolbar-inner-popover-title flex flex-row ">
13
+ <n-checkbox v-model:checked="checkAll" @update:checked="onCheckAll">
14
+ {{ $at('列展示') }}
15
+ </n-checkbox>
16
+ <n-button text type="info" size="small" class="mt-1 ml-auto" @click="resetColumns">
17
+ {{ $at('重置') }}
18
+ </n-button>
19
+ </div>
20
+ </template>
21
+ <div class="table-toolbar-inner">
22
+ <!-- :class="{
23
+ 'table-toolbar-inner-checkbox-dark': getDarkTheme === true,
24
+ 'no-draggable': element.draggable === false,
25
+ }" -->
26
+ <n-checkbox-group v-model:value="checkList" @update:value="onChange">
27
+ <div v-for="element in columnsList" :key="element.key">
28
+ <div class="table-toolbar-inner-checkbox">
29
+ <span class="drag-icon">
30
+ <n-icon size="18">
31
+ <DragOutlined />
32
+ </n-icon>
33
+ </span>
34
+ <n-checkbox :value="element.key" :label="element.title" />
35
+ </div>
36
+ </div>
37
+ </n-checkbox-group>
38
+ </div>
39
+ </n-popover>
40
+ </div>
41
+ </template>
42
+ <span>{{ $at('列设置') }}</span>
43
+ </n-tooltip>
44
+ </template>
45
+
46
+ <script lang="ts">
47
+ import { ref, defineComponent, reactive, unref, toRaw, computed, toRefs, watchEffect } from 'vue'
48
+ import { useTableContext } from '../../hooks/useTableContext'
49
+ import { cloneDeep } from 'lodash-es'
50
+ import { $at } from 'i18n-auto-extractor'
51
+ import {
52
+ SettingOutlined,
53
+ DragOutlined,
54
+ } from '@vicons/antd'
55
+
56
+ export interface Options {
57
+ title: string;
58
+ key: string;
59
+ fixed?: boolean | 'left' | 'right';
60
+ }
61
+
62
+ export default defineComponent({
63
+ name: 'ColumnSetting',
64
+ components: {
65
+ SettingOutlined,
66
+ DragOutlined,
67
+ },
68
+ setup() {
69
+ const table: any = useTableContext()
70
+ const columnsList = ref<Options[]>([])
71
+ const cacheColumnsList = ref<Options[]>([])
72
+
73
+ const state = reactive({
74
+ selection: false,
75
+ checkAll: true,
76
+ checkList: [],
77
+ defaultCheckList: [],
78
+ })
79
+
80
+ const getSelection = computed(() => {
81
+ return state.selection
82
+ })
83
+
84
+ watchEffect(() => {
85
+ if (!table) return
86
+ const columns = table.getColumns()
87
+ if (columns.length) {
88
+ init()
89
+ }
90
+ });
91
+
92
+ //初始化
93
+ function init() {
94
+ if (!table) return
95
+ const columns: any[] = getColumns()
96
+ const checkList: any = columns.map((item) => item.key)
97
+ state.checkList = checkList
98
+ state.defaultCheckList = checkList
99
+ const newColumns = columns.filter((item) => item.key != 'action' && item.title != $at('操作'))
100
+ if (!columnsList.value.length) {
101
+ columnsList.value = cloneDeep(newColumns)
102
+ cacheColumnsList.value = cloneDeep(newColumns)
103
+ }
104
+ }
105
+
106
+ //切换
107
+ function onChange(checkList: any) {
108
+ if (state.selection) {
109
+ checkList.unshift('selection')
110
+ }
111
+ setColumns(checkList)
112
+ }
113
+
114
+ //设置
115
+ function setColumns(columns: any) {
116
+ if (!table) return
117
+ table.setColumns(columns)
118
+ }
119
+
120
+ //获取
121
+ function getColumns() {
122
+ if (!table) return []
123
+ const newRet: any[] = []
124
+ table.getColumns().forEach((item: any) => {
125
+ newRet.push({ ...item })
126
+ })
127
+ return newRet
128
+ }
129
+
130
+ //重置
131
+ function resetColumns() {
132
+ if (!table) return
133
+ state.checkList = [...state.defaultCheckList]
134
+ state.checkAll = true
135
+ const cacheColumnsKeys: any[] = table.getCacheColumns()
136
+ const newColumns = cacheColumnsKeys.map((item) => {
137
+ return {
138
+ ...item,
139
+ fixed: undefined,
140
+ }
141
+ })
142
+ setColumns(newColumns)
143
+ columnsList.value = newColumns
144
+ }
145
+
146
+ //全选
147
+ function onCheckAll(e: any) {
148
+ if (!table) return
149
+ const checkList = table.getCacheColumns(true)
150
+ if (e) {
151
+ setColumns(checkList)
152
+ state.checkList = checkList
153
+ } else {
154
+ setColumns([])
155
+ state.checkList = []
156
+ }
157
+ }
158
+
159
+ //勾选列
160
+ function onSelection(e: any) {
161
+ if (!table) return
162
+ const checkList = table.getCacheColumns()
163
+ if (e) {
164
+ checkList.unshift({ type: 'selection', key: 'selection' })
165
+ setColumns(checkList)
166
+ } else {
167
+ checkList.splice(0, 1)
168
+ setColumns(checkList)
169
+ }
170
+ }
171
+
172
+ return {
173
+ ...toRefs(state),
174
+ columnsList,
175
+ onChange,
176
+ onCheckAll,
177
+ onSelection,
178
+ resetColumns,
179
+ getSelection,
180
+ $at,
181
+ };
182
+ },
183
+ });
184
+ </script>
185
+
186
+ <style lang="scss">
187
+ .table-toolbar {
188
+ &-inner-popover-title {
189
+ padding: 3px 0;
190
+ }
191
+
192
+ &-right {
193
+ &-icon {
194
+ margin-left: 12px;
195
+ font-size: 16px;
196
+ color: var(--text-color);
197
+ cursor: pointer;
198
+
199
+ :hover {
200
+ color: #1890ff;
201
+ }
202
+ }
203
+ }
204
+ }
205
+
206
+ .table-toolbar-inner {
207
+ &-checkbox {
208
+ display: flex;
209
+ align-items: center;
210
+ padding: 10px 14px;
211
+
212
+ &:hover {
213
+ background: rgba(19, 180, 151, 0.3);
214
+ }
215
+
216
+ .drag-icon {
217
+ display: inline-flex;
218
+ margin-right: 8px;
219
+ cursor: move;
220
+
221
+ &-hidden {
222
+ visibility: hidden;
223
+ cursor: default;
224
+ }
225
+ }
226
+
227
+ .ant-checkbox-wrapper {
228
+ flex: 1;
229
+
230
+ &:hover {
231
+ color: #1890ff !important;
232
+ }
233
+ }
234
+ }
235
+
236
+ &-checkbox-dark {
237
+ &:hover {
238
+ background: hsla(0, 0%, 100%, 0.08);
239
+ }
240
+ }
241
+ }
242
+
243
+ .toolbar-popover {
244
+ .n-popover__content {
245
+ padding: 0;
246
+ }
247
+ }
248
+ </style>
@@ -0,0 +1,11 @@
1
+ export const DEFAULTPAGESIZE = 50
2
+
3
+ export const APISETTING = {
4
+ pageField: 'pageNum',
5
+ sizeField: 'pageSize',
6
+ totalField: 'pages',
7
+ listField: 'list',
8
+ countField: 'total',
9
+ }
10
+
11
+ export const PAGESIZES = [10, 20, 50, 100]
@@ -0,0 +1,147 @@
1
+ import { ref, Ref, ComputedRef, unref, computed, watch, toRaw, h } from 'vue'
2
+ import type { BasicColumn, BasicTableProps } from '../types/table'
3
+ import { isEqual, cloneDeep } from 'lodash-es'
4
+ import type { ActionItem } from '../types/tableAction'
5
+ import { NTooltip } from 'naive-ui'
6
+
7
+ const isArray = (val: unknown): val is any[] => Array.isArray(val)
8
+ const isString = (val: unknown): val is string => typeof val === 'string'
9
+ const isBoolean = (val: unknown): val is boolean => typeof val === 'boolean'
10
+ const isFunction = (val: unknown): val is (...args: any[]) => any =>
11
+ typeof val === 'function'
12
+
13
+ export function useColumns(propsRef: ComputedRef<BasicTableProps>) {
14
+ const columnsRef = ref(unref(propsRef).columns) as unknown as Ref<
15
+ BasicColumn[]
16
+ >
17
+ let cacheColumns = unref(propsRef).columns
18
+
19
+ const getColumnsRef = computed(() => {
20
+ const columns = cloneDeep(unref(columnsRef))
21
+ handleActionColumn(propsRef, columns)
22
+ if (!columns) return []
23
+ return columns
24
+ })
25
+
26
+ function isIfShow(action: ActionItem): boolean {
27
+ const ifShow = action.ifShow
28
+ let show = true
29
+ if (isBoolean(ifShow)) {
30
+ show = ifShow
31
+ }
32
+ if (isFunction(ifShow)) {
33
+ show = ifShow(action)
34
+ }
35
+ return show
36
+ }
37
+
38
+ const renderTooltip = (trigger: any, content: any) => {
39
+ return h(NTooltip, null, {
40
+ trigger: () => trigger,
41
+ default: () => content,
42
+ })
43
+ }
44
+
45
+ const getPageColumns = computed(() => {
46
+ const pageColumns = unref(getColumnsRef)
47
+ const columns = cloneDeep(pageColumns)
48
+ return columns
49
+ .filter((column: any) => {
50
+ return isIfShow(column)
51
+ })
52
+ .map((column: any) => {
53
+ column.ellipsis =
54
+ typeof column.ellipsis === 'undefined' ? { tooltip: true } : false
55
+ return column
56
+ })
57
+ })
58
+
59
+ watch(
60
+ () => unref(propsRef).columns,
61
+ (columns) => {
62
+ columnsRef.value = columns
63
+ cacheColumns = columns
64
+ }
65
+ )
66
+
67
+ function handleActionColumn(
68
+ propsRef: ComputedRef<BasicTableProps>,
69
+ columns: BasicColumn[]
70
+ ) {
71
+ const { actionColumn } = unref(propsRef)
72
+ if (!actionColumn) return
73
+ const actionCol: any = actionColumn
74
+ if (!actionCol.ellipsis) actionCol.ellipsis = false
75
+ !columns.find((col) => col.key === 'action') &&
76
+ columns.push({
77
+ ...(actionCol as any),
78
+ })
79
+ }
80
+
81
+ function setColumns(columnList: string[] | BasicColumn[]) {
82
+ const columns: any[] = cloneDeep(columnList as any)
83
+ if (!isArray(columns)) return
84
+
85
+ if (!columns.length) {
86
+ columnsRef.value = []
87
+ return
88
+ }
89
+ const cacheKeys = cacheColumns.map((item) => item.key)
90
+ if (!isString(columns[0])) {
91
+ columnsRef.value = columns
92
+ } else {
93
+ const newColumns: any[] = []
94
+ cacheColumns.forEach((item) => {
95
+ if (columnList.includes(item.key)) {
96
+ newColumns.push({ ...item })
97
+ }
98
+ })
99
+ if (!isEqual(cacheKeys, columns)) {
100
+ newColumns.sort((prev, next) => {
101
+ return cacheKeys.indexOf(prev.key) - cacheKeys.indexOf(next.key)
102
+ })
103
+ }
104
+ columnsRef.value = newColumns
105
+ }
106
+ }
107
+
108
+ function getColumns(): BasicColumn[] {
109
+ const columns = toRaw(unref(getColumnsRef))
110
+ return columns.map((item: any) => {
111
+ return {
112
+ ...item,
113
+ title: item.title,
114
+ key: item.key,
115
+ fixed: item.fixed || undefined,
116
+ }
117
+ })
118
+ }
119
+
120
+ function getCacheColumns(isKey?: boolean): any[] {
121
+ return isKey ? cacheColumns.map((item) => item.key) : cacheColumns
122
+ }
123
+
124
+ function setCacheColumnsField(
125
+ key: string | undefined,
126
+ value: Partial<BasicColumn>
127
+ ) {
128
+ if (!key || !value) {
129
+ return
130
+ }
131
+ cacheColumns.forEach((item) => {
132
+ if (item.key === key) {
133
+ Object.assign(item, value)
134
+ return
135
+ }
136
+ })
137
+ }
138
+
139
+ return {
140
+ getColumnsRef,
141
+ getCacheColumns,
142
+ setCacheColumnsField,
143
+ setColumns,
144
+ getColumns,
145
+ getPageColumns,
146
+ }
147
+ }
@@ -0,0 +1,238 @@
1
+ import {
2
+ ComputedRef,
3
+ Ref,
4
+ computed,
5
+ onMounted,
6
+ ref,
7
+ unref,
8
+ watch,
9
+ watchEffect,
10
+ } from 'vue'
11
+ import { APISETTING } from '../const'
12
+ import type { PaginationProps } from '../types/pagination'
13
+ import type { BasicTableProps } from '../types/table'
14
+
15
+ const isBoolean = (val: unknown): val is boolean => typeof val === 'boolean'
16
+ const isFunction = (val: unknown): val is (...args: any[]) => any =>
17
+ typeof val === 'function'
18
+ const isArray = (val: unknown): val is any[] => Array.isArray(val)
19
+ const isObject = (val: unknown): val is Record<string, any> =>
20
+ val !== null && typeof val === 'object'
21
+
22
+ export function useDataSource(
23
+ propsRef: ComputedRef<BasicTableProps>,
24
+ {
25
+ getPaginationInfo,
26
+ setPagination,
27
+ setLoading,
28
+ tableData,
29
+ }: {
30
+ getPaginationInfo: ComputedRef<boolean | PaginationProps>
31
+ setPagination: (info: Partial<PaginationProps>) => void
32
+ tableData: Ref<any[]>
33
+ setLoading: (loading: boolean) => void
34
+ },
35
+ emit: {
36
+ (
37
+ event:
38
+ | 'fetch-success'
39
+ | 'fetch-error'
40
+ | 'update:checked-row-keys'
41
+ | 'edit-end'
42
+ | 'edit-cancel'
43
+ | 'edit-row-end'
44
+ | 'edit-change',
45
+ ...args: any[]
46
+ ): void
47
+ (arg0: string, arg1: unknown): void
48
+ }
49
+ ) {
50
+ const dataSourceRef = ref<any[]>([])
51
+
52
+ watchEffect(() => {
53
+ tableData.value = unref(dataSourceRef)
54
+ })
55
+
56
+ watch(
57
+ () => unref(propsRef).dataSource,
58
+ () => {
59
+ const { dataSource }: any = unref(propsRef)
60
+ dataSource && (dataSourceRef.value = dataSource)
61
+ },
62
+ {
63
+ immediate: true,
64
+ }
65
+ )
66
+
67
+ const getRowKey = computed(() => {
68
+ const { rowKey }: any = unref(propsRef)
69
+ return rowKey
70
+ ? typeof rowKey === 'function'
71
+ ? rowKey
72
+ : (record: any) => record[rowKey]
73
+ : () => {
74
+ return 'key'
75
+ }
76
+ })
77
+
78
+ const getDataSourceRef = computed(() => {
79
+ const dataSource = unref(dataSourceRef)
80
+ if (!dataSource || dataSource.length === 0) {
81
+ return unref(dataSourceRef)
82
+ }
83
+ return unref(dataSourceRef)
84
+ })
85
+ const getKeysList = computed(() => {
86
+ const rowKey = unref(getRowKey)
87
+ const dataSource = unref(getDataSourceRef)
88
+ let keysList: any = []
89
+ if (dataSource && dataSource.length > 0) {
90
+ keysList = getIdFromTreeArray(dataSource, rowKey)
91
+ }
92
+ return keysList
93
+ })
94
+ //获取数组中得key值
95
+ function getIdFromTreeArray(treeArray: any, rowKey: any) {
96
+ const { canExpand }: any = unref(propsRef)
97
+ let ids: any = []
98
+ function traverse(array: any) {
99
+ array.forEach((item: any) => {
100
+ if (item.children) {
101
+ traverse(item.children)
102
+ }
103
+ ids.push(rowKey(item))
104
+ })
105
+ }
106
+ if (canExpand) {
107
+ traverse(treeArray)
108
+ }
109
+ return ids
110
+ }
111
+ async function fetch(opt?: any) {
112
+ try {
113
+ setLoading(true)
114
+ const { request, pagination, beforeRequest, afterRequest }: any =
115
+ unref(propsRef)
116
+ if (!request) return
117
+ //组装分页信息
118
+ const pageField: any = APISETTING.pageField
119
+ const sizeField: any = APISETTING.sizeField
120
+ const totalField: any = APISETTING.totalField
121
+ const listField: any = APISETTING.listField
122
+ const itemCount: any = APISETTING.countField
123
+ let pageParams: any = {}
124
+ const { page = 1, pageSize = 10 } = unref(
125
+ getPaginationInfo
126
+ ) as PaginationProps
127
+
128
+ if (
129
+ (isBoolean(pagination) && !pagination) ||
130
+ isBoolean(getPaginationInfo)
131
+ ) {
132
+ pageParams = {}
133
+ } else {
134
+ pageParams[pageField] = (opt && opt[pageField]) || page
135
+ pageParams[sizeField] = pageSize
136
+ }
137
+
138
+ let params = {
139
+ ...pageParams,
140
+ ...opt,
141
+ }
142
+ if (beforeRequest && isFunction(beforeRequest)) {
143
+ // The params parameter can be modified by outsiders
144
+ params = (await beforeRequest(params)) || params
145
+ }
146
+ const res: any = await request(params)
147
+ if (res) {
148
+ const resultTotal = res[totalField]
149
+ const currentPage = res[pageField]
150
+ const total = res[itemCount]
151
+ // let results = null
152
+ // if (isObject(res)) {
153
+ // results = res[listField] ? res[listField] : [res]
154
+ // } else if (isArray(res)) {
155
+ // results = res[listField] ? res[listField] : res
156
+ // }
157
+ // 如果数据异常,需获取正确的页码再次执行
158
+ if (resultTotal) {
159
+ const currentTotalPage = Math.ceil(total / pageSize)
160
+ if (page > currentTotalPage) {
161
+ setPagination({
162
+ page: currentTotalPage,
163
+ itemCount: total,
164
+ })
165
+ return await fetch(opt)
166
+ }
167
+ }
168
+ let resultInfo = null
169
+ if (isObject(res)) {
170
+ resultInfo =
171
+ res[listField] || res[listField]?.length === 0
172
+ ? res[listField]
173
+ : [res]
174
+ } else if (isArray(res)) {
175
+ resultInfo = res[listField] ? res[listField] : res
176
+ }
177
+ // let resultInfo = res[listField] ? res[listField] : [res];
178
+ if (afterRequest && isFunction(afterRequest)) {
179
+ // can modify the data returned by the interface for processing
180
+ resultInfo = (await afterRequest(resultInfo)) || resultInfo
181
+ }
182
+ dataSourceRef.value = resultInfo
183
+ setPagination({
184
+ page: currentPage,
185
+ pageCount: resultTotal,
186
+ itemCount: total,
187
+ })
188
+ if (opt && opt[pageField]) {
189
+ setPagination({
190
+ page: opt[pageField] || 1,
191
+ })
192
+ }
193
+ emit('fetch-success', {
194
+ items: unref(resultInfo),
195
+ resultTotal,
196
+ })
197
+ } else {
198
+ return
199
+ }
200
+ } catch (error) {
201
+ emit('fetch-error', error)
202
+ dataSourceRef.value = []
203
+ setPagination({
204
+ pageCount: 0,
205
+ })
206
+ } finally {
207
+ setLoading(false)
208
+ }
209
+ }
210
+
211
+ onMounted(() => {
212
+ setTimeout(() => {
213
+ fetch()
214
+ }, 16)
215
+ })
216
+
217
+ function setTableData(values: any) {
218
+ dataSourceRef.value = values
219
+ }
220
+
221
+ function getDataSource(): any[] {
222
+ return getDataSourceRef.value
223
+ }
224
+
225
+ async function reload(opt?: any) {
226
+ await fetch(opt)
227
+ }
228
+
229
+ return {
230
+ fetch,
231
+ getRowKey,
232
+ getDataSourceRef,
233
+ getDataSource,
234
+ setTableData,
235
+ getKeysList,
236
+ reload,
237
+ }
238
+ }
@@ -0,0 +1,21 @@
1
+ import { ref, ComputedRef, unref, computed, watch } from 'vue';
2
+ import type { BasicTableProps } from '../types/table';
3
+
4
+ export function useLoading(props: ComputedRef<BasicTableProps>) {
5
+ const loadingRef = ref(unref(props).loading);
6
+
7
+ watch(
8
+ () => unref(props).loading,
9
+ (loading) => {
10
+ loadingRef.value = loading;
11
+ }
12
+ );
13
+
14
+ const getLoading = computed(() => unref(loadingRef));
15
+
16
+ function setLoading(loading: boolean) {
17
+ loadingRef.value = loading;
18
+ }
19
+
20
+ return { getLoading, setLoading };
21
+ }