Commit 54d14056462566521f2528480c13fb24279156ae
1 parent
de499a14
fix: fix table column settings not displayed by setting
Showing
3 changed files
with
17 additions
and
8 deletions
CHANGELOG.zh_CN.md
@@ -31,6 +31,8 @@ | @@ -31,6 +31,8 @@ | ||
31 | - form: 修复表单校验先设置在校验及控制台错误信息问题 | 31 | - form: 修复表单校验先设置在校验及控制台错误信息问题 |
32 | - `modal`&`drawer` 修复组件传递数组参数问题 | 32 | - `modal`&`drawer` 修复组件传递数组参数问题 |
33 | - form: 修复`updateSchema`赋值含有`[]`时不生效 | 33 | - form: 修复`updateSchema`赋值含有`[]`时不生效 |
34 | +- table: 修复表格 `TableAction` 图标显示问题 | ||
35 | +- table: 修复表格列设置通过`setColumns`设置不显示 | ||
34 | 36 | ||
35 | ### 🎫 Chores | 37 | ### 🎫 Chores |
36 | 38 |
src/components/Table/src/components/TableSetting.vue
@@ -77,7 +77,7 @@ | @@ -77,7 +77,7 @@ | ||
77 | </div> | 77 | </div> |
78 | </template> | 78 | </template> |
79 | <script lang="ts"> | 79 | <script lang="ts"> |
80 | - import { defineComponent, ref, reactive, toRefs, PropType, computed } from 'vue'; | 80 | + import { defineComponent, ref, reactive, toRefs, PropType, computed, watchEffect } from 'vue'; |
81 | import { injectTable } from '../hooks/useProvinceTable'; | 81 | import { injectTable } from '../hooks/useProvinceTable'; |
82 | import { Tooltip, Divider, Dropdown, Menu, Popover, Checkbox } from 'ant-design-vue'; | 82 | import { Tooltip, Divider, Dropdown, Menu, Popover, Checkbox } from 'ant-design-vue'; |
83 | import { | 83 | import { |
@@ -132,7 +132,7 @@ | @@ -132,7 +132,7 @@ | ||
132 | const { toggleFullscreen, isFullscreenRef } = useFullscreen(table.wrapRef); | 132 | const { toggleFullscreen, isFullscreenRef } = useFullscreen(table.wrapRef); |
133 | const selectedKeysRef = ref<SizeType[]>([table.getSize()]); | 133 | const selectedKeysRef = ref<SizeType[]>([table.getSize()]); |
134 | 134 | ||
135 | - let plainOptions: Options[] = []; | 135 | + const plainOptions = ref<Options[]>([]); |
136 | const state = reactive<State>({ | 136 | const state = reactive<State>({ |
137 | indeterminate: false, | 137 | indeterminate: false, |
138 | checkAll: true, | 138 | checkAll: true, |
@@ -142,6 +142,12 @@ | @@ -142,6 +142,12 @@ | ||
142 | 142 | ||
143 | const { t } = useI18n('component.table'); | 143 | const { t } = useI18n('component.table'); |
144 | 144 | ||
145 | + watchEffect(() => { | ||
146 | + const columns = table.getColumns(); | ||
147 | + if (columns.length) { | ||
148 | + init(); | ||
149 | + } | ||
150 | + }); | ||
145 | function init() { | 151 | function init() { |
146 | let ret: Options[] = []; | 152 | let ret: Options[] = []; |
147 | table.getColumns({ ignoreIndex: true, ignoreAction: true }).forEach((item) => { | 153 | table.getColumns({ ignoreIndex: true, ignoreAction: true }).forEach((item) => { |
@@ -150,7 +156,8 @@ | @@ -150,7 +156,8 @@ | ||
150 | value: (item.dataIndex || item.title) as string, | 156 | value: (item.dataIndex || item.title) as string, |
151 | }); | 157 | }); |
152 | }); | 158 | }); |
153 | - plainOptions = ret; | 159 | + |
160 | + plainOptions.value = ret; | ||
154 | const checkList = table | 161 | const checkList = table |
155 | .getColumns() | 162 | .getColumns() |
156 | .map((item) => item.dataIndex || item.title) as string[]; | 163 | .map((item) => item.dataIndex || item.title) as string[]; |
@@ -171,7 +178,7 @@ | @@ -171,7 +178,7 @@ | ||
171 | 178 | ||
172 | function onCheckAllChange(e: ChangeEvent) { | 179 | function onCheckAllChange(e: ChangeEvent) { |
173 | state.indeterminate = false; | 180 | state.indeterminate = false; |
174 | - const checkList = plainOptions.map((item) => item.value); | 181 | + const checkList = plainOptions.value.map((item) => item.value); |
175 | if (e.target.checked) { | 182 | if (e.target.checked) { |
176 | state.checkedList = checkList; | 183 | state.checkedList = checkList; |
177 | table.setColumns(checkList); | 184 | table.setColumns(checkList); |
@@ -182,8 +189,9 @@ | @@ -182,8 +189,9 @@ | ||
182 | } | 189 | } |
183 | 190 | ||
184 | function onChange(checkedList: string[]) { | 191 | function onChange(checkedList: string[]) { |
185 | - state.indeterminate = !!checkedList.length && checkedList.length < plainOptions.length; | ||
186 | - state.checkAll = checkedList.length === plainOptions.length; | 192 | + const len = plainOptions.value.length; |
193 | + state.indeterminate = !!checkedList.length && checkedList.length < len; | ||
194 | + state.checkAll = checkedList.length === len; | ||
187 | table.setColumns(checkedList); | 195 | table.setColumns(checkedList); |
188 | } | 196 | } |
189 | 197 | ||
@@ -207,7 +215,6 @@ | @@ -207,7 +215,6 @@ | ||
207 | } | 215 | } |
208 | ); | 216 | ); |
209 | 217 | ||
210 | - init(); | ||
211 | return { | 218 | return { |
212 | redo: () => table.reload(), | 219 | redo: () => table.reload(), |
213 | handleTitleClick, | 220 | handleTitleClick, |
vite.config.ts
@@ -55,7 +55,7 @@ const viteConfig: UserConfig = { | @@ -55,7 +55,7 @@ const viteConfig: UserConfig = { | ||
55 | * Available options are 'terser' or 'esbuild'. | 55 | * Available options are 'terser' or 'esbuild'. |
56 | * @default 'terser' | 56 | * @default 'terser' |
57 | */ | 57 | */ |
58 | - minify: isDevFn() ? 'esbuild' : 'terser', | 58 | + minify: isDevFn() ? false : 'terser', |
59 | /** | 59 | /** |
60 | * Base public path when served in production. | 60 | * Base public path when served in production. |
61 | * @default '/' | 61 | * @default '/' |