@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.
- package/.i18n_extractor.json +13 -0
- package/dist/components/data/table/FormaxTable/index.d.ts +7 -0
- package/dist/components/data/table/FormaxTable/src/BasicTable.d.ts +6 -0
- package/dist/components/data/table/FormaxTable/src/Table.vue.d.ts +99 -0
- package/dist/components/data/table/FormaxTable/src/components/settings/ColumnSetting.vue.d.ts +31 -0
- package/dist/components/data/table/FormaxTable/src/const.d.ts +9 -0
- package/dist/components/data/table/FormaxTable/src/hooks/useColumns.d.ts +10 -0
- package/dist/components/data/table/FormaxTable/src/hooks/useDataSource.d.ts +20 -0
- package/dist/components/data/table/FormaxTable/src/hooks/useLoading.d.ts +6 -0
- package/dist/components/data/table/FormaxTable/src/hooks/usePagination.d.ts +10 -0
- package/dist/components/data/table/FormaxTable/src/hooks/useTableContext.d.ts +13 -0
- package/dist/components/data/table/FormaxTable/src/props.d.ts +1 -0
- package/dist/components/data/table/FormaxTable/src/types/componentType.d.ts +1 -0
- package/dist/components/data/table/FormaxTable/src/types/pagination.d.ts +10 -0
- package/dist/components/data/table/FormaxTable/src/types/table.d.ts +36 -0
- package/dist/components/data/table/FormaxTable/src/types/tableAction.d.ts +23 -0
- package/dist/components/data/table/FormaxTable/src/utils.d.ts +11 -0
- package/dist/components/general/button/FormaxButton/index.d.ts +2 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +37 -0
- package/dist/index.mjs +1862 -0
- package/dist/mock.d.ts +13 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +34 -0
- package/docs/i18n-stub.mjs +12 -0
- package/docs/index.html +314 -0
- package/docs/index.js +658 -0
- package/docs/index.mjs +113892 -0
- package/docs/tailwind.css +4 -0
- package/docs/tailwind.generated.css +1 -0
- package/package.json +51 -0
- package/playground/App.vue +60 -0
- package/playground/index.html +12 -0
- package/playground/main.ts +12 -0
- package/src/components/data/table/FormaxTable/index.ts +143 -0
- package/src/components/data/table/FormaxTable/src/BasicTable.ts +12 -0
- package/src/components/data/table/FormaxTable/src/Table.vue +412 -0
- package/src/components/data/table/FormaxTable/src/components/TableAction.vue +155 -0
- package/src/components/data/table/FormaxTable/src/components/settings/ColumnSetting.vue +248 -0
- package/src/components/data/table/FormaxTable/src/const.ts +11 -0
- package/src/components/data/table/FormaxTable/src/hooks/useColumns.ts +147 -0
- package/src/components/data/table/FormaxTable/src/hooks/useDataSource.ts +238 -0
- package/src/components/data/table/FormaxTable/src/hooks/useLoading.ts +21 -0
- package/src/components/data/table/FormaxTable/src/hooks/usePagination.ts +65 -0
- package/src/components/data/table/FormaxTable/src/hooks/useTableContext.ts +23 -0
- package/src/components/data/table/FormaxTable/src/props.ts +77 -0
- package/src/components/data/table/FormaxTable/src/types/componentType.ts +9 -0
- package/src/components/data/table/FormaxTable/src/types/pagination.ts +10 -0
- package/src/components/data/table/FormaxTable/src/types/table.ts +45 -0
- package/src/components/data/table/FormaxTable/src/types/tableAction.ts +25 -0
- package/src/components/data/table/FormaxTable/src/utils.ts +65 -0
- package/src/components/general/button/FormaxButton/index.ts +70 -0
- package/src/index.ts +66 -0
- package/src/locales/en.json +13 -0
- package/src/locales/zh-CN.json +13 -0
- package/src/mock.ts +17 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/types/i18n-auto-extractor.d.ts +3 -0
- package/src/types.ts +40 -0
- package/tailwind.config.cjs +12 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +16 -0
- package/vite.config.ts +59 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<div class="table-toolbar">
|
|
4
|
+
<!--顶部左侧区域-->
|
|
5
|
+
<div v-if="title || $slots.tableTitle" class="flex items-center table-toolbar-left pb-[16px]">
|
|
6
|
+
<template v-if="title">
|
|
7
|
+
<div class="table-toolbar-left-title">
|
|
8
|
+
{{ title }}
|
|
9
|
+
<n-tooltip trigger="hover" v-if="titleTooltip">
|
|
10
|
+
<template #trigger>
|
|
11
|
+
<n-icon size="18" class="ml-1 text-gray-400 cursor-pointer">
|
|
12
|
+
<QuestionCircleOutlined />
|
|
13
|
+
</n-icon>
|
|
14
|
+
</template>
|
|
15
|
+
{{ titleTooltip }}
|
|
16
|
+
</n-tooltip>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
<slot name="tableTitle"></slot>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<div class="flex items-center table-toolbar-right pb-[16px]" v-if="toolbarShow">
|
|
23
|
+
<!--顶部右侧区域-->
|
|
24
|
+
<slot name="toolbar"></slot>
|
|
25
|
+
|
|
26
|
+
<!--斑马纹-->
|
|
27
|
+
<n-tooltip trigger="hover">
|
|
28
|
+
<template #trigger>
|
|
29
|
+
<div class="flex items-center table-toolbar-right-icon" @click="setStriped(isStriped)">
|
|
30
|
+
<n-icon size="18">
|
|
31
|
+
<PicCenterOutlined />
|
|
32
|
+
</n-icon>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
35
|
+
<span>{{ $at('表格斑马纹') }}</span>
|
|
36
|
+
</n-tooltip>
|
|
37
|
+
|
|
38
|
+
<!--刷新-->
|
|
39
|
+
<n-tooltip trigger="hover">
|
|
40
|
+
<template #trigger>
|
|
41
|
+
<div class="flex items-center table-toolbar-right-icon" @click="reload">
|
|
42
|
+
<n-icon size="18">
|
|
43
|
+
<ReloadOutlined />
|
|
44
|
+
</n-icon>
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
<span>{{ $at('刷新') }}</span>
|
|
48
|
+
</n-tooltip>
|
|
49
|
+
|
|
50
|
+
<!--密度-->
|
|
51
|
+
<n-tooltip trigger="hover">
|
|
52
|
+
<template #trigger>
|
|
53
|
+
<div class="flex items-center table-toolbar-right-icon">
|
|
54
|
+
<n-dropdown @select="densitySelect" trigger="click" :options="densityOptions" v-model:value="tableSize">
|
|
55
|
+
<n-icon size="18">
|
|
56
|
+
<ColumnHeightOutlined />
|
|
57
|
+
</n-icon>
|
|
58
|
+
</n-dropdown>
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
61
|
+
<span>{{ $at('密度') }}</span>
|
|
62
|
+
</n-tooltip>
|
|
63
|
+
|
|
64
|
+
<!--表格设置单独抽离成组件-->
|
|
65
|
+
<div class="flex items-center h-full">
|
|
66
|
+
<ColumnSetting />
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<div class="s-table">
|
|
72
|
+
<n-data-table ref="tableElRef" v-bind="getBindValues" :striped="isStriped" :pagination="pagination"
|
|
73
|
+
:bordered="getBordered" @update:page="updatePage" @update:page-size="updatePageSize"
|
|
74
|
+
@update:expanded-row-keys="updateExpendKeys">
|
|
75
|
+
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
|
|
76
|
+
<slot :name="item" v-bind="data"></slot>
|
|
77
|
+
</template>
|
|
78
|
+
</n-data-table>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script lang="ts">
|
|
85
|
+
import {
|
|
86
|
+
ref,
|
|
87
|
+
defineComponent,
|
|
88
|
+
reactive,
|
|
89
|
+
unref,
|
|
90
|
+
toRaw,
|
|
91
|
+
computed,
|
|
92
|
+
toRefs,
|
|
93
|
+
onMounted,
|
|
94
|
+
nextTick,
|
|
95
|
+
watch
|
|
96
|
+
} from 'vue';
|
|
97
|
+
import { ReloadOutlined, PicCenterOutlined, ColumnHeightOutlined, QuestionCircleOutlined } from '@vicons/antd';
|
|
98
|
+
import { createTableContext } from './hooks/useTableContext';
|
|
99
|
+
import { $at } from 'i18n-auto-extractor';
|
|
100
|
+
|
|
101
|
+
import ColumnSetting from './components/settings/ColumnSetting.vue';
|
|
102
|
+
|
|
103
|
+
import { useLoading } from './hooks/useLoading';
|
|
104
|
+
import { useColumns } from './hooks/useColumns';
|
|
105
|
+
import { useDataSource } from './hooks/useDataSource';
|
|
106
|
+
import { usePagination } from './hooks/usePagination';
|
|
107
|
+
|
|
108
|
+
import { basicProps } from './props';
|
|
109
|
+
import { BasicTableProps } from './types/table';
|
|
110
|
+
import { isBoolean, useWindowSizeFn, getViewportOffset } from './utils';
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const densityOptions = [
|
|
114
|
+
{
|
|
115
|
+
type: 'menu',
|
|
116
|
+
label: $at('紧凑'),
|
|
117
|
+
key: 'small',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: 'menu',
|
|
121
|
+
label: $at('默认'),
|
|
122
|
+
key: 'medium',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'menu',
|
|
126
|
+
label: $at('宽松'),
|
|
127
|
+
key: 'large',
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
export default defineComponent({
|
|
132
|
+
name: 'FormaxTable',
|
|
133
|
+
components: {
|
|
134
|
+
ReloadOutlined,
|
|
135
|
+
ColumnHeightOutlined,
|
|
136
|
+
PicCenterOutlined,
|
|
137
|
+
ColumnSetting,
|
|
138
|
+
QuestionCircleOutlined,
|
|
139
|
+
},
|
|
140
|
+
props: {
|
|
141
|
+
...basicProps,
|
|
142
|
+
},
|
|
143
|
+
emits: [
|
|
144
|
+
'fetch-success',
|
|
145
|
+
'fetch-error',
|
|
146
|
+
'update:checked-row-keys',
|
|
147
|
+
'edit-end',
|
|
148
|
+
'edit-cancel',
|
|
149
|
+
'edit-row-end',
|
|
150
|
+
'edit-change',
|
|
151
|
+
],
|
|
152
|
+
setup(props, { emit }) {
|
|
153
|
+
const deviceHeight = ref(150);
|
|
154
|
+
const tableElRef = ref<any>(null);
|
|
155
|
+
const wrapRef = ref<any>(null);
|
|
156
|
+
let paginationEl: HTMLElement | null;
|
|
157
|
+
const isStriped = ref(false);
|
|
158
|
+
const tableData = ref<any[]>([]);
|
|
159
|
+
const innerPropsRef = ref<Partial<BasicTableProps>>();
|
|
160
|
+
const getProps = computed(() => {
|
|
161
|
+
return { ...props, ...unref(innerPropsRef) } as BasicTableProps;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const tableHeight = ref<any>(0)
|
|
165
|
+
const formNum = ref(1)
|
|
166
|
+
window.addEventListener('resize', () => {
|
|
167
|
+
tableHeight.value = document.getElementById('basicForm')?.offsetHeight
|
|
168
|
+
});
|
|
169
|
+
document.addEventListener("heightChange", e => {
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
tableHeight.value = document.getElementById('basicForm')?.offsetHeight
|
|
172
|
+
}, 10);
|
|
173
|
+
|
|
174
|
+
})
|
|
175
|
+
watch(() => tableHeight.value, (newVal) => {
|
|
176
|
+
formNum.value = (newVal / 58)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
const { getLoading, setLoading } = useLoading(getProps);
|
|
180
|
+
|
|
181
|
+
const { getPaginationInfo, setPagination } = usePagination(getProps);
|
|
182
|
+
|
|
183
|
+
const { getDataSourceRef, getDataSource, getRowKey, reload, getKeysList } = useDataSource(
|
|
184
|
+
getProps,
|
|
185
|
+
{
|
|
186
|
+
getPaginationInfo,
|
|
187
|
+
setPagination,
|
|
188
|
+
tableData,
|
|
189
|
+
setLoading,
|
|
190
|
+
},
|
|
191
|
+
emit
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const { getPageColumns, setColumns, getColumns, getCacheColumns, setCacheColumnsField } =
|
|
195
|
+
useColumns(getProps);
|
|
196
|
+
|
|
197
|
+
const state = reactive({
|
|
198
|
+
tableSize: unref(getProps as any).size || 'medium',
|
|
199
|
+
isColumnSetting: false,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
//页码切换
|
|
203
|
+
function updatePage(page: any) {
|
|
204
|
+
setPagination({ page: page });
|
|
205
|
+
reload();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//分页数量切换
|
|
209
|
+
function updatePageSize(size: any) {
|
|
210
|
+
setPagination({ page: 1, pageSize: size });
|
|
211
|
+
reload();
|
|
212
|
+
}
|
|
213
|
+
function updateExpendKeys(keys: any) {
|
|
214
|
+
expandedKeysList.value = keys
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//密度切换
|
|
218
|
+
function densitySelect(e: any) {
|
|
219
|
+
state.tableSize = e;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//选中行
|
|
223
|
+
function updateCheckedRowKeys(rowKeys: any) {
|
|
224
|
+
emit('update:checked-row-keys', rowKeys);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//获取表格大小
|
|
228
|
+
const getTableSize = computed(() => state.tableSize);
|
|
229
|
+
|
|
230
|
+
//组装表格信息
|
|
231
|
+
const expandedKeysList = ref([]);
|
|
232
|
+
const keyList = computed(() => getKeysList.value);
|
|
233
|
+
watch(keyList,
|
|
234
|
+
(v) => {
|
|
235
|
+
// expandedKeysList.value = v
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
const getBindValues = computed(() => {
|
|
239
|
+
const tableData = unref(getDataSourceRef);
|
|
240
|
+
const maxHeight = tableData.length ? `${unref(deviceHeight)}` : 'auto';
|
|
241
|
+
return {
|
|
242
|
+
...unref(getProps),
|
|
243
|
+
loading: unref(getLoading),
|
|
244
|
+
columns: toRaw(unref(getPageColumns)),
|
|
245
|
+
rowKey: unref(getRowKey),
|
|
246
|
+
data: tableData,
|
|
247
|
+
size: unref(getTableSize),
|
|
248
|
+
expandedRowKeys: expandedKeysList,
|
|
249
|
+
remote: true,
|
|
250
|
+
defaultExpandAll: true,
|
|
251
|
+
'max-height': maxHeight,
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
//获取分页信息
|
|
255
|
+
const pagination = computed(() => toRaw(unref(getPaginationInfo)));
|
|
256
|
+
|
|
257
|
+
function setProps(props: Partial<BasicTableProps>) {
|
|
258
|
+
innerPropsRef.value = { ...unref(innerPropsRef), ...props };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const setStriped = (value: boolean) => (isStriped.value = !value);
|
|
262
|
+
|
|
263
|
+
const tableAction = {
|
|
264
|
+
reload,
|
|
265
|
+
setColumns,
|
|
266
|
+
setLoading,
|
|
267
|
+
setProps,
|
|
268
|
+
getColumns,
|
|
269
|
+
getPageColumns,
|
|
270
|
+
getCacheColumns,
|
|
271
|
+
setCacheColumnsField,
|
|
272
|
+
emit,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const getCanResize = computed(() => {
|
|
276
|
+
const { canResize } = unref(getProps);
|
|
277
|
+
return canResize;
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const getBordered = computed(() => {
|
|
281
|
+
const { bordered } = unref(getProps);
|
|
282
|
+
return !!bordered;
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
async function computeTableHeight() {
|
|
286
|
+
const table = unref(tableElRef);
|
|
287
|
+
if (!table) return;
|
|
288
|
+
if (!unref(getCanResize)) return;
|
|
289
|
+
const tableEl: any = table?.$el;
|
|
290
|
+
const headEl = tableEl.querySelector('.n-data-table-thead ');
|
|
291
|
+
const { bottomIncludeBody } = getViewportOffset(headEl);
|
|
292
|
+
const headerH = 64;
|
|
293
|
+
let paginationH = 2;
|
|
294
|
+
let marginH = 24;
|
|
295
|
+
if (!isBoolean(unref(pagination))) {
|
|
296
|
+
paginationEl = tableEl.querySelector('.n-data-table__pagination') as HTMLElement;
|
|
297
|
+
if (paginationEl) {
|
|
298
|
+
const offsetHeight = paginationEl.offsetHeight;
|
|
299
|
+
paginationH += offsetHeight || 0;
|
|
300
|
+
} else {
|
|
301
|
+
paginationH += 28;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
let height =
|
|
305
|
+
bottomIncludeBody - (headerH + paginationH + marginH + (props.resizeHeightOffset || 0));
|
|
306
|
+
const maxHeight = props.maxHeight;
|
|
307
|
+
height = maxHeight && maxHeight < height ? maxHeight : height;
|
|
308
|
+
deviceHeight.value = height;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
useWindowSizeFn(computeTableHeight, 280);
|
|
312
|
+
|
|
313
|
+
onMounted(() => {
|
|
314
|
+
nextTick(() => {
|
|
315
|
+
computeTableHeight();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
createTableContext({ ...tableAction, wrapRef, getBindValues });
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
...toRefs(state),
|
|
323
|
+
tableHeight,
|
|
324
|
+
formNum,
|
|
325
|
+
tableElRef,
|
|
326
|
+
getBindValues,
|
|
327
|
+
getDataSource,
|
|
328
|
+
densityOptions,
|
|
329
|
+
reload,
|
|
330
|
+
densitySelect,
|
|
331
|
+
updatePage,
|
|
332
|
+
updatePageSize,
|
|
333
|
+
updateExpendKeys,
|
|
334
|
+
updateCheckedRowKeys,
|
|
335
|
+
pagination,
|
|
336
|
+
tableAction,
|
|
337
|
+
setStriped,
|
|
338
|
+
isStriped,
|
|
339
|
+
getBordered,
|
|
340
|
+
$at
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
</script>
|
|
345
|
+
<style lang="scss" scoped>
|
|
346
|
+
.table-toolbar {
|
|
347
|
+
display: flex;
|
|
348
|
+
justify-content: space-between;
|
|
349
|
+
// padding: 0 0 16px 0;
|
|
350
|
+
|
|
351
|
+
&-left {
|
|
352
|
+
display: flex;
|
|
353
|
+
align-items: center;
|
|
354
|
+
justify-content: flex-start;
|
|
355
|
+
flex: 1;
|
|
356
|
+
|
|
357
|
+
&-title {
|
|
358
|
+
display: flex;
|
|
359
|
+
align-items: center;
|
|
360
|
+
justify-content: flex-start;
|
|
361
|
+
font-size: 16px;
|
|
362
|
+
font-weight: 600;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
&-right {
|
|
367
|
+
display: flex;
|
|
368
|
+
justify-content: flex-end;
|
|
369
|
+
flex: 1;
|
|
370
|
+
|
|
371
|
+
&-icon {
|
|
372
|
+
margin-left: 12px;
|
|
373
|
+
font-size: 16px;
|
|
374
|
+
cursor: pointer;
|
|
375
|
+
color: var(--text-color);
|
|
376
|
+
|
|
377
|
+
:hover {
|
|
378
|
+
color: #1890ff;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
::v-deep(.n-data-table-base-table) {
|
|
385
|
+
height: 95% !important;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ::v-deep(.n-data-table-thead){
|
|
389
|
+
// border-radius: 20px ;
|
|
390
|
+
// }
|
|
391
|
+
::v-deep(.n-data-table-base-table-header) {
|
|
392
|
+
// border-radius: 8px 8px 0 0 !important;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.table-toolbar-inner-popover-title {
|
|
396
|
+
padding: 2px 0;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
.s-table {
|
|
400
|
+
border-radius: 8px 8px 0 0;
|
|
401
|
+
// @include fetch-bg-color('s-table');
|
|
402
|
+
transition: all 0.4s;
|
|
403
|
+
|
|
404
|
+
::v-deep(.n-data-table .n-data-table-th .n-data-table-resize-button::after) {
|
|
405
|
+
background-color: #6E7D8B;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
::v-deep(.n-data-table .n-data-table-th .n-data-table-resize-button:hover::after) {
|
|
409
|
+
background-color: var(--n-th-icon-color-active) !important;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
</style>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="tableAction">
|
|
3
|
+
<div class="flex items-center ">
|
|
4
|
+
<template v-for="(action, index) in getActions" :key="`${index}-${action.label}`">
|
|
5
|
+
<n-button v-if="!action.isPopConfirm" v-bind="action" class="mx-1 p-0">
|
|
6
|
+
{{ action.label }}
|
|
7
|
+
<template #icon v-if="action.hasOwnProperty('icon')">
|
|
8
|
+
<n-icon :component="action.icon" />
|
|
9
|
+
</template>
|
|
10
|
+
</n-button>
|
|
11
|
+
|
|
12
|
+
<n-popconfirm v-else @positive-click="action.confirm" @negative-click="action.cancel">
|
|
13
|
+
<template #trigger>
|
|
14
|
+
<n-button v-bind="action" class="mx-1">
|
|
15
|
+
{{ action.label }}
|
|
16
|
+
<template #icon v-if="action.hasOwnProperty('icon')">
|
|
17
|
+
<n-icon :component="action.icon" />
|
|
18
|
+
</template>
|
|
19
|
+
</n-button>
|
|
20
|
+
</template>
|
|
21
|
+
{{ action.title }}
|
|
22
|
+
</n-popconfirm>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<n-dropdown v-if="dropDownActions && getDropdownList.length" trigger="hover" :options="getDropdownList"
|
|
26
|
+
@select="select">
|
|
27
|
+
<slot name="more"></slot>
|
|
28
|
+
<n-button v-bind="getMoreProps" class="mx-1" v-if="!$slots.more" icon-placement="right">
|
|
29
|
+
<div class="flex items-center">
|
|
30
|
+
<span>{{ $at('更多') }}</span>
|
|
31
|
+
<n-icon size="14" class="ml-1">
|
|
32
|
+
<DownOutlined />
|
|
33
|
+
</n-icon>
|
|
34
|
+
</div>
|
|
35
|
+
</n-button>
|
|
36
|
+
</n-dropdown>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script lang="ts">
|
|
42
|
+
import { defineComponent, PropType, computed, toRaw } from 'vue'
|
|
43
|
+
import type { ActionItem } from '../../types/tableAction'
|
|
44
|
+
import { DownOutlined } from '@vicons/antd'
|
|
45
|
+
import { $at } from 'i18n-auto-extractor'
|
|
46
|
+
|
|
47
|
+
const isBoolean = (val: unknown): val is boolean => typeof val === 'boolean'
|
|
48
|
+
const isFunction = (val: unknown): val is (...args: any[]) => any => typeof val === 'function'
|
|
49
|
+
|
|
50
|
+
export default defineComponent({
|
|
51
|
+
name: 'TableAction',
|
|
52
|
+
components: { DownOutlined },
|
|
53
|
+
props: {
|
|
54
|
+
actions: {
|
|
55
|
+
type: Array as PropType<ActionItem[]>,
|
|
56
|
+
default: null,
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
dropDownActions: {
|
|
60
|
+
type: Array as PropType<ActionItem[]>,
|
|
61
|
+
default: null,
|
|
62
|
+
},
|
|
63
|
+
style: {
|
|
64
|
+
type: String as PropType<string>,
|
|
65
|
+
default: 'button',
|
|
66
|
+
},
|
|
67
|
+
select: {
|
|
68
|
+
type: Function as PropType<Function>,
|
|
69
|
+
default: () => {},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
setup(props) {
|
|
73
|
+
const actionType =
|
|
74
|
+
props.style === 'button' ? 'default' : props.style === 'text' ? 'primary' : 'default'
|
|
75
|
+
const actionText =
|
|
76
|
+
props.style === 'button' ? undefined : props.style === 'text' ? true : undefined
|
|
77
|
+
|
|
78
|
+
const getMoreProps = computed(() => {
|
|
79
|
+
return {
|
|
80
|
+
text: actionText,
|
|
81
|
+
type: actionType,
|
|
82
|
+
size: 'small',
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
function isIfShow(action: ActionItem): boolean {
|
|
87
|
+
const ifShow = action.ifShow
|
|
88
|
+
let show = true
|
|
89
|
+
if (isBoolean(ifShow)) {
|
|
90
|
+
show = ifShow
|
|
91
|
+
}
|
|
92
|
+
if (isFunction(ifShow)) {
|
|
93
|
+
show = ifShow(action)
|
|
94
|
+
}
|
|
95
|
+
return show
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const getDropdownList = computed(() => {
|
|
99
|
+
return (toRaw(props.dropDownActions) || [])
|
|
100
|
+
.filter((action) => isIfShow(action))
|
|
101
|
+
.map((action) => {
|
|
102
|
+
const { popConfirm } = action
|
|
103
|
+
return {
|
|
104
|
+
size: 'small',
|
|
105
|
+
text: actionText,
|
|
106
|
+
type: actionType,
|
|
107
|
+
...action,
|
|
108
|
+
...popConfirm,
|
|
109
|
+
onConfirm: popConfirm?.confirm,
|
|
110
|
+
onCancel: popConfirm?.cancel,
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const getActions = computed(() => {
|
|
116
|
+
return (toRaw(props.actions) || [])
|
|
117
|
+
.filter((action) => isIfShow(action))
|
|
118
|
+
.map((action) => {
|
|
119
|
+
const { popConfirm } = action
|
|
120
|
+
return {
|
|
121
|
+
size: 'small',
|
|
122
|
+
text: actionText,
|
|
123
|
+
type: actionType,
|
|
124
|
+
...action,
|
|
125
|
+
...(popConfirm || {}),
|
|
126
|
+
onConfirm: popConfirm?.confirm,
|
|
127
|
+
onCancel: popConfirm?.cancel,
|
|
128
|
+
enable: !!popConfirm,
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
getActions,
|
|
135
|
+
getDropdownList,
|
|
136
|
+
getMoreProps,
|
|
137
|
+
$at,
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
</script>
|
|
142
|
+
<style lang="scss">
|
|
143
|
+
.n-popconfirm__action {
|
|
144
|
+
.n-button {
|
|
145
|
+
height: 24px !important;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
.n-popover:not(.n-popover--raw):not(.n-popover--scrollable):not(.n-popover--show-header-or-footer){
|
|
149
|
+
// border: 1px solid #636363!important;
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
.n-popover-shared .n-popover-arrow-wrapper .n-popover-arrow{
|
|
153
|
+
// background-color:#13B497!important;
|
|
154
|
+
}
|
|
155
|
+
</style>
|