From 3ef5087be64ed98d84429a1a111182f761e0ffa9 Mon Sep 17 00:00:00 2001 From: zuihou <244387066@qq.com> Date: Sat, 22 May 2021 18:08:53 +0800 Subject: [PATCH] style: formatting code --- .../src/components/editable/EditableCell.vue | 16 ++--- .../Table/src/components/settings/index.vue | 20 +++--- src/components/Table/src/hooks/useColumns.ts | 2 +- .../Table/src/hooks/useDataSource.ts | 11 +-- src/components/Table/src/hooks/useTable.ts | 6 +- .../Table/src/hooks/useTableForm.ts | 22 +++--- .../Table/src/hooks/useTableHeader.ts | 68 +++++++++---------- 7 files changed, 64 insertions(+), 81 deletions(-) diff --git a/src/components/Table/src/components/editable/EditableCell.vue b/src/components/Table/src/components/editable/EditableCell.vue index 0b92ebf6..326ba501 100644 --- a/src/components/Table/src/components/editable/EditableCell.vue +++ b/src/components/Table/src/components/editable/EditableCell.vue @@ -131,16 +131,14 @@ return option?.label ?? value; }); - const getWrapperStyle = computed( - (): CSSProperties => { - if (unref(getIsCheckComp) || unref(getRowEditable)) { - return {}; - } - return { - width: 'calc(100% - 48px)', - }; + const getWrapperStyle = computed((): CSSProperties => { + if (unref(getIsCheckComp) || unref(getRowEditable)) { + return {}; } - ); + return { + width: 'calc(100% - 48px)', + }; + }); const getRowEditable = computed(() => { const { editable } = props.record || {}; diff --git a/src/components/Table/src/components/settings/index.vue b/src/components/Table/src/components/settings/index.vue index 71e55412..ed079993 100644 --- a/src/components/Table/src/components/settings/index.vue +++ b/src/components/Table/src/components/settings/index.vue @@ -36,17 +36,15 @@ setup(props) { const { t } = useI18n(); - const getSetting = computed( - (): TableSetting => { - return { - redo: true, - size: true, - setting: true, - fullScreen: false, - ...props.setting, - }; - } - ); + const getSetting = computed((): TableSetting => { + return { + redo: true, + size: true, + setting: true, + fullScreen: false, + ...props.setting, + }; + }); return { getSetting, t }; }, diff --git a/src/components/Table/src/hooks/useColumns.ts b/src/components/Table/src/hooks/useColumns.ts index 24f6f45c..7172486e 100644 --- a/src/components/Table/src/hooks/useColumns.ts +++ b/src/components/Table/src/hooks/useColumns.ts @@ -109,7 +109,7 @@ export function useColumns( propsRef: ComputedRef, getPaginationRef: ComputedRef ) { - const columnsRef = (ref(unref(propsRef).columns) as unknown) as Ref; + const columnsRef = ref(unref(propsRef).columns) as unknown as Ref; let cacheColumns = unref(propsRef).columns; const getColumnsRef = computed(() => { diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index b68866c4..1d161abd 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -150,15 +150,8 @@ export function useDataSource( } async function fetch(opt?: FetchParams) { - const { - api, - searchInfo, - fetchSetting, - beforeFetch, - afterFetch, - useSearchForm, - pagination, - } = unref(propsRef); + const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = + unref(propsRef); if (!api || !isFunction(api)) return; try { setLoading(true); diff --git a/src/components/Table/src/hooks/useTable.ts b/src/components/Table/src/hooks/useTable.ts index 1afd34b2..740420a5 100644 --- a/src/components/Table/src/hooks/useTable.ts +++ b/src/components/Table/src/hooks/useTable.ts @@ -15,9 +15,7 @@ type UseTableMethod = TableActionType & { getForm: () => FormActionType; }; -export function useTable( - tableProps?: Props -): [ +export function useTable(tableProps?: Props): [ (instance: TableActionType, formInstance: UseTableMethod) => void, TableActionType & { getForm: () => FormActionType; @@ -129,7 +127,7 @@ export function useTable( return toRaw(getTableInstance().getCacheColumns()); }, getForm: () => { - return (unref(formRef) as unknown) as FormActionType; + return unref(formRef) as unknown as FormActionType; }, setShowPagination: async (show: boolean) => { getTableInstance().setShowPagination(show); diff --git a/src/components/Table/src/hooks/useTableForm.ts b/src/components/Table/src/hooks/useTableForm.ts index 500aa0b8..09d2d777 100644 --- a/src/components/Table/src/hooks/useTableForm.ts +++ b/src/components/Table/src/hooks/useTableForm.ts @@ -9,18 +9,16 @@ export function useTableForm( fetch: (opt?: FetchParams | undefined) => Promise, getLoading: ComputedRef ) { - const getFormProps = computed( - (): Partial => { - const { formConfig } = unref(propsRef); - const { submitButtonOptions } = formConfig || {}; - return { - showAdvancedButton: true, - ...formConfig, - submitButtonOptions: { loading: unref(getLoading), ...submitButtonOptions }, - compact: true, - }; - } - ); + const getFormProps = computed((): Partial => { + const { formConfig } = unref(propsRef); + const { submitButtonOptions } = formConfig || {}; + return { + showAdvancedButton: true, + ...formConfig, + submitButtonOptions: { loading: unref(getLoading), ...submitButtonOptions }, + compact: true, + }; + }); const getFormSlotKeys = computed(() => { const keys = Object.keys(slots); diff --git a/src/components/Table/src/hooks/useTableHeader.ts b/src/components/Table/src/hooks/useTableHeader.ts index 515fc86d..93c3ef4a 100644 --- a/src/components/Table/src/hooks/useTableHeader.ts +++ b/src/components/Table/src/hooks/useTableHeader.ts @@ -8,41 +8,39 @@ import { isString } from '/@/utils/is'; import { getSlot } from '/@/utils/helper/tsxHelper'; export function useTableHeader(propsRef: ComputedRef, slots: Slots) { - const getHeaderProps = computed( - (): Recordable => { - const { title, showTableSetting, titleHelpMessage, tableSetting } = unref(propsRef); - const hideTitle = !slots.tableTitle && !title && !slots.toolbar && !showTableSetting; - if (hideTitle && !isString(title)) { - return {}; - } - - return { - title: hideTitle - ? null - : () => - h( - TableHeader, - { - title, - titleHelpMessage, - showTableSetting, - tableSetting, - } as Recordable, - { - ...(slots.toolbar - ? { - toolbar: () => getSlot(slots, 'toolbar'), - } - : {}), - ...(slots.tableTitle - ? { - tableTitle: () => getSlot(slots, 'tableTitle'), - } - : {}), - } - ), - }; + const getHeaderProps = computed((): Recordable => { + const { title, showTableSetting, titleHelpMessage, tableSetting } = unref(propsRef); + const hideTitle = !slots.tableTitle && !title && !slots.toolbar && !showTableSetting; + if (hideTitle && !isString(title)) { + return {}; } - ); + + return { + title: hideTitle + ? null + : () => + h( + TableHeader, + { + title, + titleHelpMessage, + showTableSetting, + tableSetting, + } as Recordable, + { + ...(slots.toolbar + ? { + toolbar: () => getSlot(slots, 'toolbar'), + } + : {}), + ...(slots.tableTitle + ? { + tableTitle: () => getSlot(slots, 'tableTitle'), + } + : {}), + } + ), + }; + }); return { getHeaderProps }; } -- GitLab