222
schangxiang@126.com
2025-04-30 9bec4dcae002f36aa23231da11cb03a156b40110
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { TableData } from '@arco-design/web-vue'
import { useVModels } from '@vueuse/core'
import { computed, inject, provide, ref, SetupContext } from 'vue'
import { useUtils } from './useUtils'
import { TablePropsItemType } from './BaseTable.d'
 
const KEY = Symbol('BaseTable')
 
const useStore = (props: TablePropsItemType, ctx: SetupContext) => {
  const currentRow = ref<TableData>()
 
  const { dataSource } = useVModels(props, ctx.emit)
  const { columns, columnSeq } = useUtils(props, ctx)
  const rowId = computed(() => props.id || 'id')
  const baseTableRef = ref()
  const currentHeight = ref<number>(0)
 
  const store = {
    currentRow,
    dataSource,
    columns,
    columnSeq,
    rowId,
    baseTableRef,
    currentHeight,
  }
  return store
}
 
export type StoreType = ReturnType<typeof useStore>
 
let store = {}
 
export const createState = (props: TablePropsItemType, ctx: SetupContext) => {
  store = useStore(props, ctx)
  provide(KEY, store)
  return store as StoreType
}
 
export const injectState = () => {
  const injectStore = inject(KEY, '')
  if (!injectStore) {
    return store as StoreType
  }
  return inject(KEY) as StoreType
}