|
12 | 12 | <!-- table -->
|
13 | 13 | <a-table
|
14 | 14 | :class="['ant-table-striped', { border: hasBordered }]"
|
15 |
| - :rowClassName="(_, index) => (index % 2 === 1 ? 'table-striped' : null)" |
| 15 | + :rowClassName="(_, index) => (index % 2 === 1 ? 'table-striped' : '')" |
16 | 16 | :dataSource="dataSource"
|
17 | 17 | :columns="columns"
|
18 | 18 | :rowKey="(record) => record.id"
|
|
25 | 25 | <!-- <template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
|
26 | 26 | <slot :name="item" v-bind="data || {}"></slot>
|
27 | 27 | </template> -->
|
28 |
| - <template #toDate="{ text }"> |
29 |
| - <span>{{ text ? formatDate(text) : '-' }}</span> |
30 |
| - </template> |
31 |
| - <template #toDateTime="{ text }"> |
32 |
| - <span>{{ text ? formatDate(text, 'time') : '-' }}</span> |
33 |
| - </template> |
34 |
| - <!-- 函数式写法自定义 操作列 --> |
35 |
| - <template #action="{ record }"> |
36 |
| - <template v-for="(action, index) in getActions" :key="`${index}-${action.label}`"> |
37 |
| - <!-- 气泡确认框 --> |
38 |
| - <a-popconfirm |
39 |
| - v-if="action.enable" |
40 |
| - :title="action?.title" |
41 |
| - @confirm="action?.onConfirm(record)" |
42 |
| - @cancel="action?.onCancel(record)" |
43 |
| - > |
44 |
| - <a @click.prevent="() => {}" :type="action.type">{{ action.label }}</a> |
45 |
| - </a-popconfirm> |
46 |
| - <span v-else-if="!action.permission">——</span> |
47 |
| - <!-- 按钮 --> |
48 |
| - <a v-else @click="action?.onClick(record)" :type="action.type">{{ action.label }}</a> |
49 |
| - <!-- 分割线 --> |
50 |
| - <a-divider type="vertical" v-if="index < getActions.length - 1" /> |
| 28 | + <template #bodyCell="{ column, text, record }"> |
| 29 | + <template v-if="column.slots?.customRender === 'toDate'"> |
| 30 | + <span>{{ text ? formatDate(text) : '-' }}</span> |
| 31 | + </template> |
| 32 | + <template v-if="column.slots?.customRender === 'toDateTime'"> |
| 33 | + <span>{{ text ? formatDate(text, 'time') : '-' }}</span> |
| 34 | + </template> |
| 35 | + <!-- 函数式写法自定义 操作列 --> |
| 36 | + <template v-if="column.slots?.customRender === 'action'"> |
| 37 | + <template v-for="(action, index) in getActions" :key="`${index}-${action.label}`"> |
| 38 | + <!-- 气泡确认框 --> |
| 39 | + <a-popconfirm |
| 40 | + v-if="action.enable" |
| 41 | + :title="action?.title" |
| 42 | + @confirm="action?.onConfirm(record)" |
| 43 | + @cancel="action?.onCancel(record)" |
| 44 | + > |
| 45 | + <a @click.prevent="() => {}" :type="action.type">{{ action.label }}</a> |
| 46 | + </a-popconfirm> |
| 47 | + <span v-else-if="!action.permission">——</span> |
| 48 | + <!-- 按钮 --> |
| 49 | + <a v-else @click="action?.onClick(record)" :type="action.type">{{ action.label }}</a> |
| 50 | + <!-- 分割线 --> |
| 51 | + <a-divider type="vertical" v-if="index < getActions.length - 1" /> |
| 52 | + </template> |
51 | 53 | </template>
|
52 | 54 | </template>
|
53 | 55 | </a-table>
|
54 | 56 | </div>
|
55 | 57 | </template>
|
56 | 58 | <script lang="ts">
|
57 |
| - import { TableStateFilters } from 'ant-design-vue/es/table/interface'; |
58 |
| - import moment from 'moment'; |
| 59 | + import { FilterValue } from 'ant-design-vue/es/table/interface'; |
| 60 | + // import moment from 'moment'; |
| 61 | + import dayjs from 'dayjs'; |
59 | 62 | import { usePagination } from 'vue-request';
|
60 | 63 | import { formatToDate, formatToDateTime } from '/@/utils/dateUtil';
|
61 | 64 | import { usePermission } from '/@/hooks/usePermission';
|
62 | 65 | import { useRole } from '/@/hooks/useRole';
|
| 66 | + import { TablePaginationConfig } from 'ant-design-vue/lib/table/interface'; |
63 | 67 |
|
64 | 68 | // const req = () => new Promise((resolve) => resolve({ total: 0, list: [] }));
|
65 | 69 |
|
|
111 | 115 | showTotal: () => h('span', {}, `共 ${total.value} 条`),
|
112 | 116 | }));
|
113 | 117 |
|
114 |
| - const handleTableChange = (pag, filters: TableStateFilters, sorter: any) => { |
| 118 | + const handleTableChange = ( |
| 119 | + pag: TablePaginationConfig, |
| 120 | + filters: Record<string, FilterValue | null>, |
| 121 | + sorter: any, |
| 122 | + ) => { |
115 | 123 | run({
|
116 | 124 | limit: pag!.pageSize!,
|
117 | 125 | page: pag?.current,
|
|
149 | 157 | // 日期格式处理
|
150 | 158 | if (args) {
|
151 | 159 | Object.keys(args).map((key) => {
|
152 |
| - if (args[key] && moment.isMoment(args[key])) { |
| 160 | + if (args[key] && dayjs.isDayjs(args[key])) { |
153 | 161 | args[key] = formatToDate(args[key]);
|
154 | 162 | }
|
155 | 163 | });
|
|
0 commit comments