Commit da12da9d8caeba0e7732551cfbad9b0da3baaac4

Authored by 无木
1 parent 30c5fc63

perf(table): fixed code style

修复一些代码检查警告,并且为table的canResize属性添加不兼容场景警告

close: #1070
src/components/Page/index.ts
... ... @@ -5,3 +5,5 @@ import pageWrapper from './src/PageWrapper.vue';
5 5  
6 6 export const PageFooter = withInstall(pageFooter);
7 7 export const PageWrapper = withInstall(pageWrapper);
  8 +
  9 +export const PageWrapperFixedHeightKey = 'PageWrapperFixedHeight';
... ...
src/components/Page/src/PageWrapper.vue
... ... @@ -33,7 +33,7 @@
33 33 </div>
34 34 </template>
35 35 <script lang="ts">
36   - import type { CSSProperties, PropType } from 'vue';
  36 + import { CSSProperties, PropType, provide } from 'vue';
37 37  
38 38 import { defineComponent, computed, watch, ref, unref } from 'vue';
39 39 import PageFooter from './PageFooter.vue';
... ... @@ -43,6 +43,7 @@
43 43 import { omit } from 'lodash-es';
44 44 import { PageHeader } from 'ant-design-vue';
45 45 import { useContentHeight } from '/@/hooks/web/useContentHeight';
  46 + import { PageWrapperFixedHeightKey } from '..';
46 47  
47 48 export default defineComponent({
48 49 name: 'PageWrapper',
... ... @@ -68,6 +69,11 @@
68 69 const footerRef = ref(null);
69 70 const { prefixCls } = useDesign('page-wrapper');
70 71  
  72 + provide(
  73 + PageWrapperFixedHeightKey,
  74 + computed(() => props.fixedHeight)
  75 + );
  76 +
71 77 const getIsContentFullHeight = computed(() => {
72 78 return props.contentFullHeight;
73 79 });
... ...
src/components/Table/src/BasicTable.vue
... ... @@ -39,9 +39,10 @@
39 39 ColumnChangeParam,
40 40 } from './types/table';
41 41  
42   - import { defineComponent, ref, computed, unref, toRaw } from 'vue';
  42 + import { defineComponent, ref, computed, unref, toRaw, inject, watchEffect } from 'vue';
43 43 import { Table } from 'ant-design-vue';
44 44 import { BasicForm, useForm } from '/@/components/Form/index';
  45 + import { PageWrapperFixedHeightKey } from '/@/components/Page';
45 46 import expandIcon from './components/ExpandIcon';
46 47 import HeaderCell from './components/HeaderCell.vue';
47 48 import { InnerHandlers } from './types/table';
... ... @@ -64,6 +65,7 @@
64 65 import { omit } from 'lodash-es';
65 66 import { basicProps } from './props';
66 67 import { isFunction } from '/@/utils/is';
  68 + import { warn } from '/@/utils/log';
67 69  
68 70 export default defineComponent({
69 71 components: {
... ... @@ -104,6 +106,13 @@
104 106 return { ...props, ...unref(innerPropsRef) } as BasicTableProps;
105 107 });
106 108  
  109 + const isFixedHeightPage = inject(PageWrapperFixedHeightKey);
  110 + watchEffect(() => {
  111 + unref(isFixedHeightPage) &&
  112 + props.canResize &&
  113 + warn("[BasicTable] 'canRize' not worked with PageWrapper while 'fixedHeight' is true");
  114 + });
  115 +
107 116 const { getLoading, setLoading } = useLoading(getProps);
108 117 const {
109 118 getPaginationInfo,
... ... @@ -380,9 +389,9 @@
380 389 align-items: center;
381 390 }
382 391  
383   - .ant-table-tbody > tr.ant-table-row-selected td {
384   - //background-color: fade(@primary-color, 8%) !important;
385   - }
  392 + //.ant-table-tbody > tr.ant-table-row-selected td {
  393 + //background-color: fade(@primary-color, 8%) !important;
  394 + //}
386 395 }
387 396  
388 397 .ant-pagination {
... ...
src/components/Table/src/hooks/useTableForm.ts
... ... @@ -21,9 +21,11 @@ export function useTableForm(
21 21 };
22 22 });
23 23  
24   - const getFormSlotKeys = computed(() => {
  24 + const getFormSlotKeys: ComputedRef<string[]> = computed(() => {
25 25 const keys = Object.keys(slots);
26   - return keys.map((item) => (item.startsWith('form-') ? item : null)).filter(Boolean);
  26 + return keys
  27 + .map((item) => (item.startsWith('form-') ? item : null))
  28 + .filter((item) => !!item) as string[];
27 29 });
28 30  
29 31 function replaceFormSlotKey(key: string) {
... ...
src/views/demo/table/FetchTable.vue
1 1 <template>
2   - <div class="p-4">
  2 + <PageWrapper contentBackground contentClass="flex" dense contentFullHeight fixedHeight>
3 3 <BasicTable @register="registerTable">
4 4 <template #toolbar>
5 5 <a-button type="primary" @click="handleReloadCurrent"> 刷新当前页 </a-button>
6 6 <a-button type="primary" @click="handleReload"> 刷新并返回第一页 </a-button>
7 7 </template>
8 8 </BasicTable>
9   - </div>
  9 + </PageWrapper>
10 10 </template>
11 11 <script lang="ts">
12 12 import { defineComponent } from 'vue';
13 13 import { BasicTable, useTable } from '/@/components/Table';
14 14 import { getBasicColumns } from './tableData';
  15 + import { PageWrapper } from '/@/components/Page';
15 16  
16 17 import { demoListApi } from '/@/api/demo/table';
17 18 export default defineComponent({
18   - components: { BasicTable },
  19 + components: { BasicTable, PageWrapper },
19 20 setup() {
20 21 const [registerTable, { reload }] = useTable({
21 22 title: '远程加载示例',
... ...