@@ -9,6 +9,19 @@ defineOptions({
99const columns = defineModel <NaiveUI .TableColumnCheck []>(' columns' , {
1010 required: true
1111});
12+
13+ const tooltipRecord: Record <NaiveUI .TableColumnFixed , App .I18n .I18nKey > = {
14+ left: ' datatable.fixed.right' ,
15+ right: ' datatable.fixed.unFixed' ,
16+ unFixed: ' datatable.fixed.left'
17+ };
18+
19+ function handleFixed(column : NaiveUI .TableColumnCheck ) {
20+ const fixedOptions: NaiveUI .TableColumnFixed [] = [' left' , ' right' , ' unFixed' ];
21+ const index = fixedOptions .findIndex (item => item === column .fixed );
22+ const nextIndex = index === fixedOptions .length - 1 ? 0 : index + 1 ;
23+ column .fixed = fixedOptions [nextIndex ];
24+ }
1225 </script >
1326
1427<template >
@@ -25,16 +38,29 @@ const columns = defineModel<NaiveUI.TableColumnCheck[]>('columns', {
2538 <div
2639 v-for =" item in columns"
2740 :key =" item.key"
28- class =" h-36px flex-y-center rd-4px hover:(bg-primary bg-opacity-20) "
41+ class =" h-36px flex-y-center justify-between gap-6px "
2942 :class =" { hidden: !item.visible }"
3043 >
31- <icon-mdi-drag class =" mr-8px h-full cursor-move text-icon" />
32- <NCheckbox v-model:checked =" item.checked" class =" none_draggable flex-1" >
33- <template v-if =" typeof item .title === ' function' " >
34- <component :is =" item.title" />
35- </template >
36- <template v-else >{{ item.title }}</template >
37- </NCheckbox >
44+ <div class =" flex-y-center rd-4px hover:(bg-primary bg-opacity-20)" >
45+ <icon-mdi-drag class =" mr-8px h-full cursor-move text-icon" />
46+ <NCheckbox v-model:checked =" item.checked" class =" none_draggable flex-1" >
47+ <template v-if =" typeof item .title === ' function' " >
48+ <component :is =" item.title" />
49+ </template >
50+ <template v-else >{{ item.title }}</template >
51+ </NCheckbox >
52+ </div >
53+ <ButtonIcon
54+ :disabled =" !item.checked"
55+ text
56+ :focusable =" false"
57+ :tooltip-content =" $t(tooltipRecord[item.fixed!])"
58+ @click =" handleFixed(item)"
59+ >
60+ <icon-octicon-pin-16 v-if =" item.fixed === 'unFixed'" />
61+ <icon-octicon-pin-16 v-else-if =" item.fixed === 'left'" class =" rotate-270" />
62+ <icon-octicon-pin-slash-16 v-else />
63+ </ButtonIcon >
3864 </div >
3965 </VueDraggable >
4066 </NPopover >
0 commit comments