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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| import { getScopeT, globalT } from '@/libs/Language/Language'
| import { computed, h, inject, SetupContext } from 'vue'
| import { ScopeType, TablePropsItemType } from './BaseTable.d'
| import styles from './BaseTable.module.scss'
| import { useVModels } from '@vueuse/core'
| import { TableData } from '@arco-design/web-vue'
| import { isFunction } from 'lodash'
|
| export const useUtils = (props: TablePropsItemType, { emit }: SetupContext) => {
| const LanguageScopeKey =
| props.LanguageScopeKey || inject('LanguageScopeKey', '')
| const _t = LanguageScopeKey ? getScopeT(LanguageScopeKey) : globalT
|
| const getCellStyle = (data: ScopeType) =>
| isFunction(props.cellStyle)
| ? props.cellStyle({ ...data, row: data.record })
| : {}
|
| const columns = computed(() => {
| return props.columns.map((item) => {
| const render = item.render
| delete item.render
| const column = {
| tooltip: true,
| ellipsis: true,
| ...item,
| // 自定义render
| customRender: render,
| title: _t(item.title),
| dataIndex: item.field,
| slotName: item.field || item.slotName,
| headerCellClass: 'selector-ignore',
| width: item.width ? parseInt(String(item.width)) : item.width,
| }
| return column
| })
| })
| /**
| * 设置序号
| */
| const columnSeq = computed(() => {
| const seq = columns.value.find((column) => column.type === 'seq')
| if (seq && props.isSeq) {
| return {
| ...seq,
| seq: ({ column, record, rowIndex }: TableData) => {
| const cellStyle = getCellStyle({ column, record, rowIndex })
| return h(
| 'div',
| {
| class: styles.bodyCell,
| style: cellStyle,
| },
| rowIndex + 1
| )
| },
| }
| }
| return {}
| })
|
| return {
| _t,
| LanguageScopeKey,
| columns,
| columnSeq,
| // slotsMap,
| }
| }
|
|