Browse Source

Merge pull request #795 from colinin/enhanced-table-props

feat(table): enhanced table props
pull/802/head
yx lin 3 years ago
committed by GitHub
parent
commit
3fa5089a44
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      apps/vue/src/components/Excel/src/ImportExcel.vue
  2. 2
      apps/vue/src/components/Table/src/components/AdvancedSearch.vue
  3. 115
      apps/vue/src/components/Table/src/components/settings/TableExport.vue
  4. 6
      apps/vue/src/components/Table/src/hooks/useTableAlert.ts
  5. 8
      apps/vue/src/components/Table/src/props.ts
  6. 2
      apps/vue/src/hooks/abp/useSettings.ts

22
apps/vue/src/components/Excel/src/ImportExcel.vue

@ -32,10 +32,11 @@
default: 8, default: 8,
}, },
}, },
emits: ['success', 'error'], emits: ['success', 'error', 'cancel'],
setup(props, { emit }) { setup(props, { emit }) {
const inputRef = ref<HTMLInputElement | null>(null); const inputRef = ref<HTMLInputElement | null>(null);
const loadingRef = ref<Boolean>(false); const loadingRef = ref<Boolean>(false);
const cancelRef = ref<Boolean>(true);
/** /**
* @description: 第一行作为头部 * @description: 第一行作为头部
@ -115,7 +116,7 @@
resolve(''); resolve('');
} catch (error) { } catch (error) {
reject(error); reject(error);
emit('error'); emit('error', error);
} finally { } finally {
loadingRef.value = false; loadingRef.value = false;
} }
@ -142,15 +143,30 @@
const rawFile = files && files[0]; // only setting files[0] const rawFile = files && files[0]; // only setting files[0]
target.value = ''; target.value = '';
if (!rawFile) return; if (!rawFile) return;
cancelRef.value = false;
upload(rawFile); upload(rawFile);
} }
function handleFocusChange() {
const timeId = setInterval(() => {
if (cancelRef.value === true) {
emit('cancel');
}
clearInterval(timeId);
window.removeEventListener('focus', handleFocusChange);
}, 1000);
}
/** /**
* @description: 点击上传按钮 * @description: 点击上传按钮
*/ */
function handleUpload() { function handleUpload() {
const inputRefDom = unref(inputRef); const inputRefDom = unref(inputRef);
inputRefDom && inputRefDom.click(); if (inputRefDom) {
cancelRef.value = true;
inputRefDom.click();
window.addEventListener('focus', handleFocusChange);
}
} }
return { handleUpload, handleInputClick, inputRef }; return { handleUpload, handleInputClick, inputRef };

2
apps/vue/src/components/Table/src/components/AdvancedSearch.vue

@ -136,6 +136,7 @@
dataIndex: 'comparison', dataIndex: 'comparison',
key: 'comparison', key: 'comparison',
title: t('component.table.advancedSearch.comparison'), title: t('component.table.advancedSearch.comparison'),
width: 120,
}, },
{ {
dataIndex: 'value', dataIndex: 'value',
@ -151,6 +152,7 @@
title: t('table.action'), title: t('table.action'),
dataIndex: 'actions', dataIndex: 'actions',
align: 'center', align: 'center',
width: 120,
}, },
]); ]);

115
apps/vue/src/components/Table/src/components/settings/TableExport.vue

@ -3,78 +3,69 @@
<template #title> <template #title>
<span>{{ t('common.export') }}</span> <span>{{ t('common.export') }}</span>
</template> </template>
<ExportOutlined @click="exportData" /> <DownloadOutlined @click="exportData" />
<ExpExcelModal @register="registerModal" @success="handleExport" /> <ExpExcelModal @register="registerModal" @success="handleExport" />
</Tooltip> </Tooltip>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue';
import { Tooltip } from 'ant-design-vue'; import { Tooltip } from 'ant-design-vue';
import { ExportOutlined } from '@ant-design/icons-vue'; import { DownloadOutlined } from '@ant-design/icons-vue';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { useTableContext } from '../../hooks/useTableContext'; import { useTableContext } from '../../hooks/useTableContext';
import { ExpExcelModal, jsonToSheetXlsx } from '/@/components/Excel'; import { ExpExcelModal, jsonToSheetXlsx } from '/@/components/Excel';
import { useModal } from '/@/components/Modal'; import { useModal } from '/@/components/Modal';
import { isString } from '/@/utils/is'; import { isString } from '/@/utils/is';
export default defineComponent({ const table = useTableContext();
name: 'TableExport', const { t } = useI18n();
components: { const [registerModal, { openModal }] = useModal();
ExpExcelModal,
ExportOutlined,
Tooltip,
},
setup() {
const table = useTableContext();
const { t } = useI18n();
const [registerModal, { openModal }] = useModal();
function exportData() { function exportData() {
openModal(true); openModal(true);
} }
function handleExport(options) { function handleExport(options) {
const dataSource = table.getDataSource(); table.setLoading(true);
// try {
const columns = table.getColumns() exportDataToExcel(options);
.filter((col) => !col.flag || col.flag === 'DEFAULT') } finally {
.filter((col) => isString(col.title) && isString(col.dataIndex)); table.setLoading(false);
// }
const header: {[key:string]: string} = {}; }
columns.forEach((col) => {
header[String(col.dataIndex)] = String(col.title);
});
//
const rows: {[key:string]: string}[] = [];
dataSource.forEach((data) => {
const row: {[key:string]: string} = {};
columns.forEach((col) => {
const colName = String(col.dataIndex);
if (Reflect.has(data, colName)) {
row[colName] = data[colName];
}
});
if (Object.keys(row).length > 0) {
rows.push(row);
}
});
// excel
jsonToSheetXlsx({
data: rows,
header: header,
filename: options.filename,
write2excelOpts: {
bookType: options.bookType,
},
});
}
return { function exportDataToExcel(options) {
registerModal, const dataSource = table.getDataSource();
exportData, //
handleExport, const columns = table.getColumns()
t, .filter((col) => !col.flag || col.flag === 'DEFAULT')
}; .filter((col) => isString(col.title) && isString(col.dataIndex));
}, //
}); const header: {[key:string]: string} = {};
columns.forEach((col) => {
header[String(col.dataIndex)] = String(col.title);
});
//
const rows: {[key:string]: string}[] = [];
dataSource.forEach((data) => {
const row: {[key:string]: string} = {};
columns.forEach((col) => {
const colName = String(col.dataIndex);
if (Reflect.has(data, colName)) {
row[colName] = data[colName];
}
});
if (Object.keys(row).length > 0) {
rows.push(row);
}
});
// excel
jsonToSheetXlsx({
data: rows,
header: header,
filename: options.filename,
write2excelOpts: {
bookType: options.bookType,
},
});
}
</script> </script>

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

@ -21,11 +21,7 @@ export function useTableAlert(
const getAlertEnabled = computed(() => { const getAlertEnabled = computed(() => {
const props = unref(propsRef); const props = unref(propsRef);
if (!props.useSelectedAlert) { return props.useSelectedAlert === true;
return false;
}
return unref(getSelectRowKeysCount) > 0;
}); });
const getAlertMessage = computed(() => { const getAlertMessage = computed(() => {

8
apps/vue/src/components/Table/src/props.ts

@ -12,6 +12,7 @@ import type {
import type { FormProps } from '/@/components/Form'; import type { FormProps } from '/@/components/Form';
import { DEFAULT_FILTER_FN, DEFAULT_SORT_FN, FETCH_SETTING, DEFAULT_SIZE } from './const'; import { DEFAULT_FILTER_FN, DEFAULT_SORT_FN, FETCH_SETTING, DEFAULT_SIZE } from './const';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
import { AdvanceSearchProps } from './types/advancedSearch';
export const basicProps = { export const basicProps = {
clickToRowSelect: { type: Boolean, default: true }, clickToRowSelect: { type: Boolean, default: true },
@ -82,6 +83,13 @@ export const basicProps = {
type: Object as PropType<Partial<FormProps>>, type: Object as PropType<Partial<FormProps>>,
default: null, default: null,
}, },
// 展示选择提示
useSelectedAlert: propTypes.bool,
// 使用高级搜索
advancedSearchConfig: {
type: Object as PropType<Partial<AdvanceSearchProps>>,
default: null,
},
columns: { columns: {
type: Array as PropType<BasicColumn[]>, type: Array as PropType<BasicColumn[]>,
default: () => [], default: () => [],

2
apps/vue/src/hooks/abp/useSettings.ts

@ -5,7 +5,7 @@ type SettingValue = NameValue<string>;
/** /**
* *
*/ */
interface ISettingProvider { export interface ISettingProvider {
/** /**
* number * number
* @param name * @param name

Loading…
Cancel
Save