Browse Source

Fix the TableAlert component

Fix the TableAlert component at #723
pull/724/head
cKey 3 years ago
parent
commit
a8a5eb53d7
  1. 8
      apps/vue/src/components/Table/src/BasicTable.vue
  2. 33
      apps/vue/src/components/Table/src/components/TableAlert.vue
  3. 20
      apps/vue/src/components/Table/src/hooks/useTableAlert.ts

8
apps/vue/src/components/Table/src/BasicTable.vue

@ -78,11 +78,11 @@
import { useDataSource } from './hooks/useDataSource'; import { useDataSource } from './hooks/useDataSource';
import { useLoading } from './hooks/useLoading'; import { useLoading } from './hooks/useLoading';
import { useRowSelection } from './hooks/useRowSelection'; import { useRowSelection } from './hooks/useRowSelection';
import { useTableAlert } from './hooks/useTableAlert';
import { useTableScroll } from './hooks/useTableScroll'; import { useTableScroll } from './hooks/useTableScroll';
import { useTableScrollTo } from './hooks/useScrollTo'; import { useTableScrollTo } from './hooks/useScrollTo';
import { useCustomRow } from './hooks/useCustomRow'; import { useCustomRow } from './hooks/useCustomRow';
import { useTableStyle } from './hooks/useTableStyle'; import { useTableStyle } from './hooks/useTableStyle';
import { useTableAlert } from './hooks/useTableAlert';
import { useTableHeader } from './hooks/useTableHeader'; import { useTableHeader } from './hooks/useTableHeader';
import { useTableExpand } from './hooks/useTableExpand'; import { useTableExpand } from './hooks/useTableExpand';
import { createTableContext } from './hooks/useTableContext'; import { createTableContext } from './hooks/useTableContext';
@ -253,7 +253,7 @@
}, },
}; };
const { getAlertEnabled, getAlertMessage } = useTableAlert(getProps, getSelectRowKeys); const { getAlertEnabled, getAlertMessage } = useTableAlert(getProps, getRowSelectionRef);
const { getHeaderProps } = useTableHeader(getProps, slots, handlers, getAlertEnabled, getAlertMessage); const { getHeaderProps } = useTableHeader(getProps, slots, handlers, getAlertEnabled, getAlertMessage);
@ -446,6 +446,10 @@
} }
} }
.ant-alert {
margin-bottom: 16px;
}
.ant-tag { .ant-tag {
margin-right: 0; margin-right: 0;
} }

33
apps/vue/src/components/Table/src/components/TableAlert.vue

@ -1,7 +1,12 @@
<template> <template>
<Alert :class="prefixCls" type="info" :message="message"> <Alert :class="prefixCls" type="info">
<template #closeText> <template #message>
<Button type="link" @click="handleDeSelect">{{ t('component.table.deSelected') }}</Button> <div class="message-box">
<span class="message-content">{{ message }}</span>
<div class="message-button">
<Button type="link" @click="handleDeSelect">{{ t('component.table.deSelected') }}</Button>
</div>
</div>
</template> </template>
</Alert> </Alert>
</template> </template>
@ -17,13 +22,13 @@
default: '', default: '',
}, },
}); });
const emits = defineEmits(['onDeSelect']); const emits = defineEmits(['de-select']);
const { t } = useI18n(); const { t } = useI18n();
const { prefixCls } = useDesign('basic-table-alert'); const { prefixCls } = useDesign('basic-table-alert');
function handleDeSelect() { function handleDeSelect() {
emits('onDeSelect'); emits('de-select');
} }
</script> </script>
@ -32,5 +37,21 @@
.@{prefix-cls} { .@{prefix-cls} {
margin: 6px 0 3px 0; margin: 6px 0 3px 0;
.message-box {
position: relative;
display: flex;
align-items: center;
word-wrap: break-word;
.message-content {
flex: 1;
min-width: 0;
}
.message-button {
margin-right: 0px;
}
}
} }
</style> </style>

20
apps/vue/src/components/Table/src/hooks/useTableAlert.ts

@ -1,5 +1,5 @@
import type { ComputedRef } from 'vue'; import type { ComputedRef } from 'vue';
import type { BasicTableProps } from '../types/table'; import type { BasicTableProps, TableRowSelection } from '../types/table';
import { computed, unref } from 'vue'; import { computed, unref } from 'vue';
import {} from '/@/hooks/web/useI18n'; import {} from '/@/hooks/web/useI18n';
@ -7,23 +7,29 @@ import { useI18n } from 'vue-i18n';
export function useTableAlert( export function useTableAlert(
propsRef: ComputedRef<BasicTableProps>, propsRef: ComputedRef<BasicTableProps>,
getSelectRowKeys: () => string[] rowSelectionRef: ComputedRef<TableRowSelection | null>,
) { ) {
const { t } = useI18n(); const { t } = useI18n();
const getSelectRowKeysCount = computed(() => {
const rowSelection = unref(rowSelectionRef);
if (!rowSelection?.selectedRowKeys) {
return 0;
}
return rowSelection.selectedRowKeys.length;
});
const getAlertEnabled = computed(() => { const getAlertEnabled = computed(() => {
const props = unref(propsRef); const props = unref(propsRef);
if (!props.useSelectedAlert) { if (!props.useSelectedAlert) {
return false; return false;
} }
const selectedKeys = getSelectRowKeys();
return selectedKeys.length > 0; return unref(getSelectRowKeysCount) > 0;
}); });
const getAlertMessage = computed(() => { const getAlertMessage = computed(() => {
const selectedKeys = getSelectRowKeys(); return t('component.table.selectedRows', { count: unref(getSelectRowKeysCount) });
console.log(selectedKeys);
return t('component.table.selectedRows', { count: selectedKeys.length });
}); });
return { return {

Loading…
Cancel
Save