提交 116a1f77 作者: vben

wip(table): perf table #136,146,134

上级 405d7466
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
- useForm: 支持动态改变参数。可以传入`Ref`类型与`Computed`类型进行动态更改 - useForm: 支持动态改变参数。可以传入`Ref`类型与`Computed`类型进行动态更改
- table: 新增`clickToRowSelect`属性。用于控制点击行是否选中勾选狂 - table: 新增`clickToRowSelect`属性。用于控制点击行是否选中勾选狂
- table: 监听行点击事件 - table: 监听行点击事件
- table: 表格列配置按钮增加 列拖拽,列固定功能。
- table:表格列配置新增`defaultHidden` 属性。用于默认隐藏。可在表格列配置勾选显示
### ✨ Refactor
- 重构表单,解决已知 bug
### ⚡ Performance Improvements ### ⚡ Performance Improvements
......
...@@ -63,11 +63,11 @@ ...@@ -63,11 +63,11 @@
"@types/sortablejs": "^1.10.6", "@types/sortablejs": "^1.10.6",
"@types/yargs": "^15.0.12", "@types/yargs": "^15.0.12",
"@types/zxcvbn": "^4.4.0", "@types/zxcvbn": "^4.4.0",
"@typescript-eslint/eslint-plugin": "^4.11.0", "@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.0", "@typescript-eslint/parser": "^4.11.1",
"@vue/compiler-sfc": "^3.0.4", "@vue/compiler-sfc": "^3.0.4",
"@vuedx/typecheck": "^0.2.4-0", "@vuedx/typecheck": "^0.4.0",
"@vuedx/typescript-plugin-vue": "^0.2.4-0", "@vuedx/typescript-plugin-vue": "^0.4.0",
"autoprefixer": "^9.8.6", "autoprefixer": "^9.8.6",
"commitizen": "^4.2.2", "commitizen": "^4.2.2",
"conventional-changelog-cli": "^2.1.1", "conventional-changelog-cli": "^2.1.1",
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
"vite-plugin-html": "^1.0.0-beta.2", "vite-plugin-html": "^1.0.0-beta.2",
"vite-plugin-mock": "^1.0.9", "vite-plugin-mock": "^1.0.9",
"vite-plugin-purge-icons": "^0.4.5", "vite-plugin-purge-icons": "^0.4.5",
"vite-plugin-pwa": "^0.2.0", "vite-plugin-pwa": "^0.2.1",
"vue-eslint-parser": "^7.3.0", "vue-eslint-parser": "^7.3.0",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
......
<template> <template>
<ConfigProvider <ConfigProvider v-bind="lockEvent" :locale="antConfigLocale">
v-bind="lockEvent"
:locale="antConfigLocale"
:transform-cell-text="transformCellText"
>
<AppProvider> <AppProvider>
<router-view /> <router-view />
</AppProvider> </AppProvider>
...@@ -14,7 +10,7 @@ ...@@ -14,7 +10,7 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { ConfigProvider } from 'ant-design-vue'; import { ConfigProvider } from 'ant-design-vue';
import { getConfigProvider, initAppConfigStore } from '/@/setup/App'; import { initAppConfigStore } from '/@/setup/App';
import { useLockPage } from '/@/hooks/web/useLockPage'; import { useLockPage } from '/@/hooks/web/useLockPage';
import { useLocale } from '/@/hooks/web/useLocale'; import { useLocale } from '/@/hooks/web/useLocale';
...@@ -28,9 +24,6 @@ ...@@ -28,9 +24,6 @@
// Initialize vuex internal system configuration // Initialize vuex internal system configuration
initAppConfigStore(); initAppConfigStore();
// Get ConfigProvider configuration
const { transformCellText } = getConfigProvider();
// Create a lock screen monitor // Create a lock screen monitor
const lockEvent = useLockPage(); const lockEvent = useLockPage();
...@@ -38,7 +31,6 @@ ...@@ -38,7 +31,6 @@
const { antConfigLocale } = useLocale(); const { antConfigLocale } = useLocale();
return { return {
transformCellText,
antConfigLocale, antConfigLocale,
lockEvent, lockEvent,
}; };
......
import Button from './src/BasicButton.vue'; import Button from './src/BasicButton.vue';
import PopConfirmButton from './src/PopConfirmButton.vue';
import { withInstall } from '../util'; import { withInstall } from '../util';
withInstall(Button); withInstall(Button, PopConfirmButton);
export { Button }; export { Button, PopConfirmButton };
<script lang="ts">
import { defineComponent, h, unref } from 'vue';
import { Popconfirm } from 'ant-design-vue';
import BasicButton from './BasicButton.vue';
import { propTypes } from '/@/utils/propTypes';
import { useI18n } from '/@/hooks/web/useI18n';
import { extendSlots } from '/@/utils/helper/tsxHelper';
import { omit } from 'lodash-es';
const { t } = useI18n();
export default defineComponent({
name: 'PopButton',
inheritAttrs: false,
components: { Popconfirm, BasicButton },
props: {
enable: propTypes.bool.def(true),
okText: propTypes.string.def(t('component.drawer.okText')),
cancelText: propTypes.string.def(t('component.drawer.cancelText')),
},
setup(props, { slots, attrs }) {
return () => {
const popValues = { ...props, ...unref(attrs) };
const Button = h(BasicButton, omit(unref(attrs), 'icon'), extendSlots(slots));
if (!props.enable) {
return Button;
}
return h(Popconfirm, omit(popValues, 'icon'), { default: () => Button });
};
},
});
</script>
<template> <template>
<Scrollbar <Scrollbar ref="scrollbarRef" class="scroll-container" v-bind="$attrs">
ref="scrollbarRef"
:wrapClass="`scrollbar__wrap`"
:viewClass="`scrollbar__view`"
class="scroll-container"
v-bind="$attrs"
>
<slot /> <slot />
</Scrollbar> </Scrollbar>
</template> </template>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<template #overlay> <template #overlay>
<a-menu :selectedKeys="selectedKeys"> <a-menu :selectedKeys="selectedKeys">
<template v-for="item in getMenuList" :key="`${item.event}`"> <template v-for="item in getMenuList" :key="`${item.event}`">
<a-menu-item @click="handleClickMenu({ key: item.event })" :disabled="item.disabled"> <a-menu-item @click="handleClickMenu(item)" :disabled="item.disabled">
<Icon :icon="item.icon" v-if="item.icon" /> <Icon :icon="item.icon" v-if="item.icon" />
<span class="ml-1">{{ item.text }}</span> <span class="ml-1">{{ item.text }}</span>
</a-menu-item> </a-menu-item>
...@@ -59,9 +59,11 @@ ...@@ -59,9 +59,11 @@
setup(props, { emit }) { setup(props, { emit }) {
const getMenuList = computed(() => props.dropMenuList); const getMenuList = computed(() => props.dropMenuList);
function handleClickMenu({ key }: { key: string }) { function handleClickMenu(item: DropMenu) {
const menu = unref(getMenuList).find((item) => `${item.event}` === `${key}`); const { event } = item;
const menu = unref(getMenuList).find((item) => `${item.event}` === `${event}`);
emit('menuEvent', menu); emit('menuEvent', menu);
item.onClick?.();
} }
return { handleClickMenu, getMenuList }; return { handleClickMenu, getMenuList };
......
export interface DropMenu { export interface DropMenu {
onClick?: Fn;
to?: string; to?: string;
icon?: string; icon?: string;
event: string | number; event: string | number;
......
<template> <template>
<Select v-bind="attrs" :options="options" v-model:value="state"> <Select v-bind="attrs" :options="getOptions" v-model:value="state">
<template #[item]="data" v-for="item in Object.keys($slots)"> <template #[item]="data" v-for="item in Object.keys($slots)">
<slot :name="item" v-bind="data" /> <slot :name="item" v-bind="data" />
</template> </template>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</Select> </Select>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType, ref, watchEffect } from 'vue'; import { defineComponent, PropType, ref, watchEffect, computed, unref } from 'vue';
import { Select } from 'ant-design-vue'; import { Select } from 'ant-design-vue';
import { isFunction } from '/@/utils/is'; import { isFunction } from '/@/utils/is';
import { useRuleFormItem } from '/@/hooks/component/useFormItem'; import { useRuleFormItem } from '/@/hooks/component/useFormItem';
...@@ -24,31 +24,31 @@ ...@@ -24,31 +24,31 @@
import { LoadingOutlined } from '@ant-design/icons-vue'; import { LoadingOutlined } from '@ant-design/icons-vue';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { propTypes } from '/@/utils/propTypes';
type OptionsItem = { label: string; value: string; disabled?: boolean }; type OptionsItem = { label: string; value: string; disabled?: boolean };
export default defineComponent({ export default defineComponent({
name: 'RadioButtonGroup', name: 'ApiSelect',
components: { components: {
Select, Select,
LoadingOutlined, LoadingOutlined,
}, },
props: { props: {
value: { value: propTypes.string,
type: String as PropType<string>,
},
api: { api: {
type: Function as PropType<(arg?: Recordable) => Promise<OptionsItem[]>>, type: Function as PropType<(arg?: Recordable) => Promise<OptionsItem[]>>,
default: null, default: null,
}, },
// api params
params: { params: {
type: Object as PropType<Recordable>, type: Object as PropType<Recordable>,
default: () => {}, default: () => {},
}, },
resultField: { // support xxx.xxx.xx
type: String as PropType<string>, resultField: propTypes.string.def(''),
default: '', labelField: propTypes.string.def('label'),
}, valueField: propTypes.string.def('value'),
}, },
setup(props) { setup(props) {
const options = ref<OptionsItem[]>([]); const options = ref<OptionsItem[]>([]);
...@@ -59,6 +59,20 @@ ...@@ -59,6 +59,20 @@
// Embedded in the form, just use the hook binding to perform form verification // Embedded in the form, just use the hook binding to perform form verification
const [state] = useRuleFormItem(props); const [state] = useRuleFormItem(props);
const getOptions = computed(() => {
const { labelField, valueField } = props;
return unref(options).reduce((prev, next: Recordable) => {
if (next) {
prev.push({
label: next[labelField],
value: next[valueField],
});
}
return prev;
}, [] as OptionsItem[]);
});
watchEffect(() => { watchEffect(() => {
fetch(); fetch();
}); });
...@@ -83,7 +97,7 @@ ...@@ -83,7 +97,7 @@
loading.value = false; loading.value = false;
} }
} }
return { state, attrs, options, loading, t }; return { state, attrs, getOptions, loading, t };
}, },
}); });
</script> </script>
...@@ -117,7 +117,7 @@ export function useFormEvents({ ...@@ -117,7 +117,7 @@ export function useFormEvents({
const schemaList: FormSchema[] = cloneDeep(unref(getSchema)); const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
const index = schemaList.findIndex((schema) => schema.field === prefixField); const index = schemaList.findIndex((schema) => schema.field === prefixField);
const hasInList = schemaList.some((item) => item.field === prefixField); const hasInList = schemaList.some((item) => item.field === prefixField || schema.field);
if (!hasInList) return; if (!hasInList) return;
...@@ -147,6 +147,7 @@ export function useFormEvents({ ...@@ -147,6 +147,7 @@ export function useFormEvents({
error( error(
'All children of the form Schema array that need to be updated must contain the `field` field' 'All children of the form Schema array that need to be updated must contain the `field` field'
); );
return;
} }
const schema: FormSchema[] = []; const schema: FormSchema[] = [];
updateData.forEach((item) => { updateData.forEach((item) => {
......
export { createImgPreview } from './src/functional'; export { createImgPreview } from './src/functional';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
export const ImagePreview = createAsyncComponent(() => import('./src/index.vue'));
<template>
<PreviewGroup :class="prefixCls">
<slot v-if="!imageList || $slots.default" />
<template v-else>
<template v-for="item in getImageList" :key="item.src">
<Image v-bind="item">
<template #placeholder v-if="item.placeholder">
<Image v-bind="item" :src="item.placeholder" :preview="false" />
</template>
</Image>
</template>
</template>
</PreviewGroup>
</template>
<script lang="ts">
import type { PropType } from 'vue';
import { defineComponent, computed } from 'vue';
import { Image } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { propTypes } from '/@/utils/propTypes';
import { ImageItem } from './types';
import { isString } from '/@/utils/is';
export default defineComponent({
name: 'ImagePreview',
components: {
Image,
PreviewGroup: Image.PreviewGroup,
},
props: {
functional: propTypes.bool,
imageList: {
type: Array as PropType<ImageItem[]>,
},
},
setup(props) {
const { prefixCls } = useDesign('image-preview');
const getImageList = computed(() => {
const { imageList } = props;
if (!imageList) {
return [];
}
return imageList.map((item) => {
if (isString(item)) {
return {
src: item,
placeholder: false,
};
}
return item;
});
});
return { prefixCls, getImageList };
},
});
</script>
<style lang="less">
@import (reference) '../../../design/index.less';
@prefix-cls: ~'@{namespace}-image-preview';
.@{prefix-cls} {
.ant-image-preview-operations {
background: rgba(0, 0, 0, 0.4);
}
}
</style>
...@@ -10,3 +10,21 @@ export interface Props { ...@@ -10,3 +10,21 @@ export interface Props {
imageList: string[]; imageList: string[];
index: number; index: number;
} }
export interface ImageProps {
alt?: string;
fallback?: string;
src: string;
width: string | number;
height?: string | number;
placeholder?: string | boolean;
preview?:
| boolean
| {
visible?: boolean;
onVisibleChange?: (visible: boolean, prevVisible: boolean) => void;
getContainer: string | HTMLElement | (() => HTMLElement);
};
}
export type ImageItem = string | ImageProps;
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
export { default as BasicTable } from './src/BasicTable.vue'; export { default as BasicTable } from './src/BasicTable.vue';
export { default as TableAction } from './src/components/TableAction'; export { default as TableAction } from './src/components/TableAction.vue';
export { default as TableImg } from './src/components/TableImg.vue'; // export { default as TableImg } from './src/components/TableImg.vue';
export { renderEditableCell, renderEditableRow } from './src/components/renderEditable'; export { renderEditableCell, renderEditableRow } from './src/components/renderEditable';
export { default as EditTableHeaderIcon } from './src/components/EditTableHeaderIcon.vue'; export { default as EditTableHeaderIcon } from './src/components/EditTableHeaderIcon.vue';
export const TableImg = createAsyncComponent(() => import('./src/components/TableImg.vue'));
// export const TableAction = createAsyncComponent(() => import('./src/components/TableAction.vue'));
export * from './src/types/table'; export * from './src/types/table';
export * from './src/types/pagination'; export * from './src/types/pagination';
export * from './src/types/tableAction'; export * from './src/types/tableAction';
......
import { defineComponent, PropType } from 'vue';
import { Dropdown, Menu, Popconfirm } from 'ant-design-vue';
import Icon from '/@/components/Icon/index';
import { DownOutlined } from '@ant-design/icons-vue';
import { ActionItem } from '/@/components/Table';
import { Button } from '/@/components/Button';
import { snowUuid } from '/@/utils/uuid';
const prefixCls = 'basic-table-action';
export default defineComponent({
name: 'TableAction',
props: {
actions: {
type: Array as PropType<ActionItem[]>,
default: null,
},
dropDownActions: {
type: Array as PropType<ActionItem[]>,
default: null,
},
moreText: {
type: String as PropType<string>,
default: '更多',
},
},
setup(props) {
function renderButton(action: ActionItem) {
const { disabled = false, label, icon, color = '', type = 'link', ...actionProps } = action;
const button = (
<Button
type={type}
size="small"
disabled={disabled}
color={color}
{...actionProps}
key={`${snowUuid()}`}
>
{() => (
<>
{icon && <Icon icon={icon} class="mr-1" />}
{label}
</>
)}
</Button>
);
return button;
}
function renderPopConfirm(action: ActionItem) {
const { popConfirm = null } = action;
if (!popConfirm) {
return renderButton(action);
}
const {
title,
okText = '确定',
cancelText = '取消',
confirm = () => {},
cancel = () => {},
icon = '',
} = popConfirm;
return (
<Popconfirm
key={`${snowUuid()}`}
title={title}
onConfirm={confirm}
onCancel={cancel}
okText={okText}
cancelText={cancelText}
icon={icon}
>
{() => renderButton(action)}
</Popconfirm>
);
}
const dropdownDefaultSLot = () => (
<Button type="link" size="small">
{{
default: () => (
<>
{props.moreText}
<DownOutlined />
</>
),
}}
</Button>
);
// 增加按钮的TYPE和COLOR
return () => {
const { dropDownActions = [], actions } = props;
return (
<div class={prefixCls}>
{actions &&
actions.map((action) => {
return renderPopConfirm(action);
})}
{dropDownActions && dropDownActions.length && (
<Dropdown overlayClassName="basic-tale-action-dropdown">
{{
default: dropdownDefaultSLot,
overlay: () => {
return (
<Menu>
{{
default: () => {
return dropDownActions.map((action) => {
const { disabled = false } = action;
action.ghost = true;
return (
<Menu.Item key={`${snowUuid()}`} disabled={disabled}>
{() => {
return renderPopConfirm(action);
}}
</Menu.Item>
);
});
},
}}
</Menu>
);
},
}}
</Dropdown>
)}
</div>
);
};
},
});
<template>
<div :class="[prefixCls, getAlign]">
<template v-for="(action, index) in getActions" :key="`${index}`">
<PopConfirmButton v-bind="action">
<Icon :icon="action.icon" class="mr-1" v-if="action.icon" />
{{ action.label }}
</PopConfirmButton>
<Divider type="vertical" v-if="divider && index < getActions.length" />
</template>
<Dropdown :trigger="['hover']" :dropMenuList="getDropList">
<slot name="more" />
<a-button type="link" size="small" v-if="!$slots.more">
<MoreOutlined class="icon-more" />
</a-button>
</Dropdown>
</div>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue';
import Icon from '/@/components/Icon/index';
import { ActionItem } from '/@/components/Table';
import { PopConfirmButton } from '/@/components/Button';
import { Divider } from 'ant-design-vue';
import { Dropdown } from '/@/components/Dropdown';
import { useDesign } from '/@/hooks/web/useDesign';
import { MoreOutlined } from '@ant-design/icons-vue';
import { propTypes } from '/@/utils/propTypes';
import { useTableContext } from '../hooks/useTableContext';
import { ACTION_COLUMN_FLAG } from '../const';
export default defineComponent({
name: 'TableAction',
components: { Icon, PopConfirmButton, Divider, Dropdown, MoreOutlined },
props: {
actions: {
type: Array as PropType<ActionItem[]>,
default: null,
},
dropDownActions: {
type: Array as PropType<ActionItem[]>,
default: null,
},
divider: propTypes.bool.def(true),
},
setup(props) {
const { prefixCls } = useDesign('basic-table-action');
const table = useTableContext();
const getActions = computed(() => {
return props.actions.map((action) => {
const { popConfirm } = action;
return {
...action,
...(popConfirm || {}),
onConfirm: popConfirm?.confirm,
onCancel: popConfirm?.cancel,
enable: !!popConfirm,
type: 'link',
size: 'small',
};
});
});
const getDropList = computed(() => {
return props.dropDownActions.map((action, index) => {
const { label } = action;
return {
...action,
text: label,
divider: index < props.dropDownActions.length - 1 ? props.divider : false,
};
});
});
const getAlign = computed(() => {
const columns = table.getColumns();
const actionColumn = columns.find((item) => item.flag === ACTION_COLUMN_FLAG);
return actionColumn?.align ?? 'left';
});
return { prefixCls, getActions, getDropList, getAlign };
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-basic-table-action';
.@{prefix-cls} {
display: flex;
align-items: center;
&.left {
justify-content: flex-start;
}
&.center {
justify-content: center;
}
&.right {
justify-content: flex-end;
}
button {
display: flex;
align-items: center;
span {
margin-left: 0 !important;
}
}
.ant-divider,
.ant-divider-vertical {
margin: 0 2px;
}
.icon-more {
transform: rotate(90deg);
svg {
font-size: 1.1em;
font-weight: 700;
}
}
}
</style>
<template>
<Table
v-if="summaryFunc"
:showHeader="false"
:bordered="false"
:pagination="false"
:dataSource="getDataSource"
:rowKey="(r) => r[rowKey]"
:columns="getColumns"
tableLayout="fixed"
:scroll="scroll"
/>
</template>
<script lang="ts">
import type { PropType } from 'vue';
import { defineComponent, unref, computed, toRaw } from 'vue';
import { Table } from 'ant-design-vue';
import { cloneDeep } from 'lodash-es';
import { isFunction } from '/@/utils/is';
import type { BasicColumn } from '../types/table';
import { INDEX_COLUMN_FLAG } from '../const';
import { propTypes } from '/@/utils/propTypes';
import { useTableContext } from '../hooks/useTableContext';
const SUMMARY_ROW_KEY = '_row';
const SUMMARY_INDEX_KEY = '_index';
export default defineComponent({
name: 'BasicTableFooter',
components: { Table },
props: {
summaryFunc: {
type: Function as PropType<Fn>,
},
scroll: {
type: Object as PropType<Recordable>,
},
rowKey: propTypes.string.def('key'),
},
setup(props) {
const table = useTableContext();
const getDataSource = computed((): Recordable[] => {
const { summaryFunc } = props;
if (!isFunction(summaryFunc)) {
return [];
}
let dataSource = toRaw(unref(table.getDataSource()));
dataSource = summaryFunc(dataSource);
dataSource.forEach((item, i) => {
item[props.rowKey] = `${i}`;
});
return dataSource;
});
const getColumns = computed(() => {
const dataSource = unref(getDataSource);
const columns: BasicColumn[] = cloneDeep(table.getColumns());
const index = columns.findIndex((item) => item.flag === INDEX_COLUMN_FLAG);
const hasRowSummary = dataSource.some((item) => Reflect.has(item, SUMMARY_ROW_KEY));
const hasIndexSummary = dataSource.some((item) => Reflect.has(item, SUMMARY_INDEX_KEY));
if (index !== -1) {
if (hasIndexSummary) {
columns[index].customRender = ({ record }) => record[SUMMARY_INDEX_KEY];
columns[index].ellipsis = false;
} else {
Reflect.deleteProperty(columns[index], 'customRender');
}
}
if (table.getRowSelection() && hasRowSummary) {
columns.unshift({
width: 60,
title: 'selection',
key: 'selectionKey',
align: 'center',
customRender: ({ record }) => record[SUMMARY_ROW_KEY],
});
}
return columns;
});
return { getColumns, getDataSource };
},
});
</script>
<template>
<slot name="tableTitle" v-if="$slots.tableTitle" />
<TableTitle :helpMessage="titleHelpMessage" :title="title" v-if="!$slots.tableTitle && title" />
<div :class="`${prefixCls}__toolbar`">
<slot name="toolbar" />
<Divider type="vertical" v-if="$slots.toolbar" />
<TableSetting :setting="tableSetting" v-if="showTableSetting" />
</div>
</template>
<script lang="ts">
import type { TableSetting } from '../types/table';
import type { PropType } from 'vue';
import { Divider } from 'ant-design-vue';
import { defineComponent } from 'vue';
import { useDesign } from '/@/hooks/web/useDesign';
import TableSettingComp from './settings/index.vue';
import TableTitle from './TableTitle.vue';
export default defineComponent({
name: 'BasicTableHeader',
components: {
Divider,
TableTitle,
TableSetting: TableSettingComp,
},
props: {
title: {
type: [Function, String] as PropType<string | ((data: Recordable) => string)>,
},
tableSetting: {
type: Object as PropType<TableSetting>,
},
showTableSetting: {
type: Boolean,
},
titleHelpMessage: {
type: [String, Array] as PropType<string | string[]>,
default: '',
},
},
setup() {
const { prefixCls } = useDesign('basic-table-header');
return { prefixCls };
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-basic-table-header';
.@{prefix-cls} {
&__toolbar {
flex: 1;
display: flex;
align-items: center;
justify-content: flex-end;
> * {
margin-right: 8px;
}
}
}
</style>
<template> <template>
<div class="basic-table-img__preview" v-if="imgList && imgList.length"> <div :class="prefixCls" v-if="imgList && imgList.length">
<template v-for="(img, index) in imgList" :key="img"> <PreviewGroup>
<img :width="size" @click="handlePreview(index)" :src="img" /> <template v-for="img in imgList" :key="img">
</template> <Image :width="size" :src="img" />
</template>
</PreviewGroup>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from 'vue'; import { defineComponent, PropType } from 'vue';
import { createImgPreview } from '/@/components/Preview/index'; import { useDesign } from '/@/hooks/web/useDesign';
import { Image } from 'ant-design-vue';
export default defineComponent({ export default defineComponent({
name: 'TableAction', name: 'TableImage',
components: { Image, PreviewGroup: Image.PreviewGroup },
props: { props: {
imgList: { imgList: {
type: Array as PropType<string[]>, type: Array as PropType<string[]>,
...@@ -21,16 +26,25 @@ ...@@ -21,16 +26,25 @@
default: 40, default: 40,
}, },
}, },
setup(props) { setup() {
function handlePreview(index: number) { const { prefixCls } = useDesign('basic-table-img');
const { imgList } = props; return { prefixCls };
createImgPreview({
imageList: imgList as string[],
index: index,
});
}
return { handlePreview };
}, },
}); });
</script> </script>
<style lang="less">
@prefix-cls: ~'@{namespace}-basic-table-img';
.@{prefix-cls} {
display: flex;
.ant-image {
margin-right: 4px;
cursor: zoom-in;
img {
border-radius: 2px;
}
}
}
</style>
<template>
<div class="table-settings">
<Divider type="vertical" />
<Tooltip placement="top" v-if="getSetting.redo">
<template #title>
<span>{{ t('component.table.settingRedo') }}</span>
</template>
<RedoOutlined @click="redo" />
</Tooltip>
<Tooltip placement="top" v-if="getSetting.size">
<template #title>
<span>{{ t('component.table.settingDens') }}</span>
</template>
<Dropdown placement="bottomCenter" :trigger="['click']">
<ColumnHeightOutlined />
<template #overlay>
<Menu @click="handleTitleClick" selectable v-model:selectedKeys="selectedKeysRef">
<MenuItem key="default">
<span>{{ t('component.table.settingDensDefault') }}</span>
</MenuItem>
<MenuItem key="middle">
<span>{{ t('component.table.settingDensMiddle') }}</span>
</MenuItem>
<MenuItem key="small">
<span>{{ t('component.table.settingDensSmall') }}</span>
</MenuItem>
</Menu>
</template>
</Dropdown>
</Tooltip>
<Tooltip placement="top" v-if="getSetting.setting">
<template #title>
<span>{{ t('component.table.settingColumn') }}</span>
</template>
<Popover
placement="bottomLeft"
trigger="click"
overlayClassName="table-settings__cloumn-list"
>
<template #content>
<CheckboxGroup v-model:value="checkedList" @change="onChange">
<template v-for="item in plainOptions" :key="item.value">
<div class="table-settings__check-item">
<Checkbox :value="item.value">
{{ item.label }}
</Checkbox>
</div>
</template>
</CheckboxGroup>
</template>
<template #title>
<div class="table-settings__popover-title">
<Checkbox
:indeterminate="indeterminate"
v-model:checked="checkAll"
@change="onCheckAllChange"
>
{{ t('component.table.settingColumnShow') }}
</Checkbox>
<a-button size="small" type="link" @click="reset">
{{ t('component.table.settingReset') }}</a-button
>
</div>
</template>
<SettingOutlined />
</Popover>
</Tooltip>
<Tooltip placement="top" v-if="getSetting.fullScreen">
<template #title>
<span>{{ t('component.table.settingFullScreen') }}</span>
</template>
<FullscreenOutlined @click="handleFullScreen" v-if="!isFullscreenRef" />
<FullscreenExitOutlined @click="handleFullScreen" v-else />
</Tooltip>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, toRefs, PropType, computed, watchEffect } from 'vue';
import { injectTable } from '../hooks/useProvinceTable';
import { Tooltip, Divider, Dropdown, Menu, Popover, Checkbox } from 'ant-design-vue';
import {
RedoOutlined,
ColumnHeightOutlined,
FullscreenOutlined,
FullscreenExitOutlined,
SettingOutlined,
} from '@ant-design/icons-vue';
import { useFullscreen } from '/@/hooks/web/useFullScreen';
import type { SizeType, TableSetting } from '../types/table';
import { useI18n } from '/@/hooks/web/useI18n';
interface Options {
label: string;
value: string;
}
interface State {
indeterminate: boolean;
checkAll: boolean;
// defaultColumns: BasicColumn[];
// columns: BasicColumn[];
checkedList: string[];
defaultCheckList: string[];
}
export default defineComponent({
name: 'TableSetting',
components: {
RedoOutlined,
ColumnHeightOutlined,
FullscreenExitOutlined,
FullscreenOutlined,
SettingOutlined,
Popover,
Tooltip,
Divider,
Dropdown,
Checkbox,
CheckboxGroup: Checkbox.Group,
Menu,
MenuItem: Menu.Item,
},
props: {
setting: {
type: Object as PropType<TableSetting>,
default: {},
},
},
setup(props) {
const table = injectTable();
const { toggleFullscreen, isFullscreenRef } = useFullscreen(table.wrapRef);
const selectedKeysRef = ref<SizeType[]>([table.getSize()]);
const plainOptions = ref<Options[]>([]);
const state = reactive<State>({
indeterminate: false,
checkAll: true,
checkedList: [],
defaultCheckList: [],
});
const { t } = useI18n();
watchEffect(() => {
const columns = table.getColumns();
if (columns.length) {
init();
}
});
function init() {
let ret: Options[] = [];
table.getColumns({ ignoreIndex: true, ignoreAction: true }).forEach((item) => {
ret.push({
label: item.title as string,
value: (item.dataIndex || item.title) as string,
});
});
if (!plainOptions.value.length) {
plainOptions.value = ret;
}
const checkList = table
.getColumns()
.map((item) => item.dataIndex || item.title) as string[];
state.checkedList = checkList;
state.defaultCheckList = checkList;
}
function handleTitleClick({ key }: { key: SizeType }) {
selectedKeysRef.value = [key];
table.setProps({
size: key,
});
}
function handleFullScreen() {
toggleFullscreen();
}
function onCheckAllChange(e: ChangeEvent) {
state.indeterminate = false;
const checkList = plainOptions.value.map((item) => item.value);
if (e.target.checked) {
state.checkedList = checkList;
table.setColumns(checkList);
} else {
state.checkedList = [];
table.setColumns([]);
}
}
function onChange(checkedList: string[]) {
const len = plainOptions.value.length;
state.indeterminate = !!checkedList.length && checkedList.length < len;
state.checkAll = checkedList.length === len;
table.setColumns(checkedList);
}
function reset() {
if (state.checkAll) return;
state.checkedList = [...state.defaultCheckList];
state.checkAll = true;
state.indeterminate = false;
table.setColumns(state.defaultCheckList);
}
const getSetting = computed(
(): TableSetting => {
return {
redo: true,
size: true,
setting: true,
fullScreen: true,
...props.setting,
};
}
);
return {
redo: () => table.reload(),
handleTitleClick,
selectedKeysRef,
handleFullScreen,
isFullscreenRef,
onCheckAllChange,
onChange,
plainOptions,
reset,
getSetting,
...toRefs(state),
t,
};
},
});
</script>
<style lang="less">
@import (reference) '../../../../design/index.less';
.table-settings {
& > * {
margin-right: 12px;
}
svg {
width: 1.2em;
height: 1.2em;
}
&__popover-title {
display: flex;
align-items: center;
justify-content: space-between;
}
&__check-item {
width: 100%;
padding: 4px 16px 4px 16px;
.ant-checkbox-wrapper {
width: 100%;
}
&:hover {
background: fade(@primary-color, 10%);
}
}
&__cloumn-list {
.ant-popover-inner-content {
max-height: 360px;
padding-right: 0;
padding-left: 0;
overflow: auto;
}
.ant-checkbox-group {
width: 100%;
}
}
}
</style>
<template> <template>
<BasicTitle class="basic-table-title" v-if="tableTitle" :helpMessage="helpMessage"> <BasicTitle :class="prefixCls" v-if="getTitle" :helpMessage="helpMessage">
{{ tableTitle }} {{ getTitle }}
</BasicTitle> </BasicTitle>
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, PropType } from 'vue'; import { computed, defineComponent, PropType } from 'vue';
import { BasicTitle } from '/@/components/Basic/index'; import { BasicTitle } from '/@/components/Basic/index';
import { useDesign } from '/@/hooks/web/useDesign';
import { isFunction } from '/@/utils/is'; import { isFunction } from '/@/utils/is';
export default defineComponent({ export default defineComponent({
name: 'TableTitle', name: 'BasicTableTitle',
components: { BasicTitle }, components: { BasicTitle },
props: { props: {
title: { title: {
...@@ -23,7 +24,9 @@ ...@@ -23,7 +24,9 @@
}, },
}, },
setup(props) { setup(props) {
const tableTitle = computed(() => { const { prefixCls } = useDesign('basic-table-title');
const getTitle = computed(() => {
const { title, getSelectRows = () => {} } = props; const { title, getSelectRows = () => {} } = props;
let tit = title; let tit = title;
...@@ -35,7 +38,16 @@ ...@@ -35,7 +38,16 @@
return tit; return tit;
}); });
return { tableTitle }; return { getTitle, prefixCls };
}, },
}); });
</script> </script>
<style lang="less">
@prefix-cls: ~'@{namespace}-basic-table-title';
.@{prefix-cls} {
display: flex;
justify-content: space-between;
align-items: center;
}
</style>
import { Table } from 'ant-design-vue';
import { cloneDeep } from 'lodash-es';
import { unref, ComputedRef } from 'vue';
import { isFunction } from '/@/utils/is';
import type { BasicColumn, TableRowSelection } from '../types/table';
export default ({
scroll = {},
columnsRef,
summaryFunc,
rowKey = 'key',
dataSourceRef,
rowSelectionRef,
}: {
scroll: { x?: number | true; y?: number };
columnsRef: ComputedRef<BasicColumn[]>;
summaryFunc: any;
rowKey?: string;
dataSourceRef: ComputedRef<any[]>;
rowSelectionRef: ComputedRef<TableRowSelection | null>;
}) => {
if (!summaryFunc) {
return;
}
const dataSource: any[] = isFunction(summaryFunc) ? summaryFunc(unref(dataSourceRef)) : [];
const columns: BasicColumn[] = cloneDeep(unref(columnsRef));
const index = columns.findIndex((item) => item.flag === 'INDEX');
const hasRowSummary = dataSource.some((item) => Reflect.has(item, '_row'));
const hasIndexSummary = dataSource.some((item) => Reflect.has(item, '_index'));
if (index !== -1) {
if (hasIndexSummary) {
columns[index].customRender = ({ record }) => record._index;
columns[index].ellipsis = false;
} else {
Reflect.deleteProperty(columns[index], 'customRender');
}
}
if (unref(rowSelectionRef) && hasRowSummary) {
columns.unshift({
width: 60,
title: 'selection',
key: 'selectionKey',
align: 'center',
customRender: ({ record }) => record._row,
});
}
dataSource.forEach((item, i) => {
item[rowKey] = i;
});
return (
<Table
showHeader={false}
bordered={false}
pagination={false}
dataSource={dataSource}
rowKey={rowKey}
columns={columns}
tableLayout="fixed"
scroll={scroll as any}
/>
);
};
import { Slots } from 'vue';
import TableTitle from './TableTitle.vue';
import { getSlot } from '/@/utils/helper/tsxHelper';
import TableSettingComp from './TableSetting.vue';
import type { TableSetting } from '../types/table';
export default (
title: any,
titleHelpMessage: string | string[],
slots: Slots,
showTableSetting: boolean,
tableSetting: TableSetting
) => {
return (
<>
{getSlot(slots, 'tableTitle') ||
(title && <TableTitle helpMessage={titleHelpMessage} title={title} />) || (
<span>&nbsp;</span>
)}
{
<div class="basic-table-toolbar">
{slots.toolbar && getSlot(slots, 'toolbar')}
{showTableSetting && <TableSettingComp setting={tableSetting} />}
</div>
}
</>
);
};
<template>
<Tooltip placement="top">
<template #title>
<span>{{ t('component.table.settingFullScreen') }}</span>
</template>
<FullscreenOutlined @click="handleFullScreen" v-if="!isFullscreenRef" />
<FullscreenExitOutlined @click="handleFullScreen" v-else />
</Tooltip>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { useTableContext } from '../../hooks/useTableContext';
import { Tooltip } from 'ant-design-vue';
import { FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons-vue';
import { useFullscreen } from '/@/hooks/web/useFullScreen';
import { useI18n } from '/@/hooks/web/useI18n';
export default defineComponent({
name: 'FullScreenSetting',
components: {
FullscreenExitOutlined,
FullscreenOutlined,
Tooltip,
},
setup() {
const table = useTableContext();
const { t } = useI18n();
const { toggleFullscreen, isFullscreenRef } = useFullscreen(table.wrapRef);
function handleFullScreen() {
toggleFullscreen();
}
return {
handleFullScreen,
isFullscreenRef,
t,
};
},
});
</script>
<template>
<Tooltip placement="top">
<template #title>
<span>{{ t('component.table.settingRedo') }}</span>
</template>
<RedoOutlined @click="redo" />
</Tooltip>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { useTableContext } from '../../hooks/useTableContext';
import { Tooltip } from 'ant-design-vue';
import { RedoOutlined } from '@ant-design/icons-vue';
import { useI18n } from '/@/hooks/web/useI18n';
export default defineComponent({
name: 'RedoSetting',
components: {
RedoOutlined,
Tooltip,
},
setup() {
const table = useTableContext();
const { t } = useI18n();
function redo() {
table.reload();
}
return {
redo,
t,
};
},
});
</script>
<template>
<Tooltip placement="top">
<template #title>
<span>{{ t('component.table.settingDens') }}</span>
</template>
<Dropdown placement="bottomCenter" :trigger="['click']" :getPopupContainer="getPopupContainer">
<ColumnHeightOutlined />
<template #overlay>
<Menu @click="handleTitleClick" selectable v-model:selectedKeys="selectedKeysRef">
<MenuItem key="default">
<span>{{ t('component.table.settingDensDefault') }}</span>
</MenuItem>
<MenuItem key="middle">
<span>{{ t('component.table.settingDensMiddle') }}</span>
</MenuItem>
<MenuItem key="small">
<span>{{ t('component.table.settingDensSmall') }}</span>
</MenuItem>
</Menu>
</template>
</Dropdown>
</Tooltip>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useTableContext } from '../../hooks/useTableContext';
import { Tooltip, Dropdown, Menu } from 'ant-design-vue';
import { ColumnHeightOutlined } from '@ant-design/icons-vue';
import { useI18n } from '/@/hooks/web/useI18n';
import { getPopupContainer } from '/@/utils';
import type { SizeType } from '../../types/table';
export default defineComponent({
name: 'SizeSetting',
components: {
ColumnHeightOutlined,
Tooltip,
Dropdown,
Menu,
MenuItem: Menu.Item,
},
setup() {
const table = useTableContext();
const { t } = useI18n();
const selectedKeysRef = ref<SizeType[]>([table.getSize()]);
function handleTitleClick({ key }: { key: SizeType }) {
selectedKeysRef.value = [key];
table.setProps({
size: key,
});
}
return {
handleTitleClick,
selectedKeysRef,
getPopupContainer,
t,
};
},
});
</script>
<template>
<div class="table-settings">
<RedoSetting v-if="getSetting.size" />
<SizeSetting v-if="getSetting.redo" />
<ColumnSetting v-if="getSetting.setting" />
<FullScreenSetting v-if="getSetting.fullScreen" />
</div>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue';
import type { TableSetting } from '../../types/table';
import { useI18n } from '/@/hooks/web/useI18n';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
import ColumnSetting from './ColumnSetting.vue';
export default defineComponent({
name: 'TableSetting',
components: {
ColumnSetting,
SizeSetting: createAsyncComponent(() => import('./SizeSetting.vue')),
RedoSetting: createAsyncComponent(() => import('./RedoSetting.vue')),
FullScreenSetting: createAsyncComponent(() => import('./FullScreenSetting.vue')),
},
props: {
setting: {
type: Object as PropType<TableSetting>,
default: {},
},
},
setup(props) {
const { t } = useI18n();
const getSetting = computed(
(): TableSetting => {
return {
redo: true,
size: true,
setting: true,
fullScreen: true,
...props.setting,
};
}
);
return { getSetting, t };
},
});
</script>
<style lang="less">
.table-settings {
& > * {
margin-right: 12px;
}
svg {
width: 1.3em;
height: 1.3em;
}
}
</style>
import { BasicColumn, BasicTableProps, GetColumnsParams } from '../types/table'; import { BasicColumn, BasicTableProps, GetColumnsParams } from '../types/table';
import { PaginationProps } from '../types/pagination'; import { PaginationProps } from '../types/pagination';
import { unref, ComputedRef, Ref, computed, watchEffect, ref, toRaw } from 'vue'; import { unref, ComputedRef, Ref, computed, watchEffect, ref, toRaw } from 'vue';
import { isBoolean, isArray, isObject } from '/@/utils/is'; import { isBoolean, isArray, isString } from '/@/utils/is';
import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const'; import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { isEqual, cloneDeep } from 'lodash-es';
const { t } = useI18n(); const { t } = useI18n();
...@@ -107,27 +108,31 @@ export function useColumns( ...@@ -107,27 +108,31 @@ export function useColumns(
const getColumnsRef = computed(() => { const getColumnsRef = computed(() => {
const columns = unref(columnsRef); const columns = unref(columnsRef);
if (!columns) {
return [];
}
handleIndexColumn(propsRef, getPaginationRef, columns); handleIndexColumn(propsRef, getPaginationRef, columns);
handleActionColumn(propsRef, columns); handleActionColumn(propsRef, columns);
if (!columns) {
return [];
}
return columns; return columns;
}); });
const getSortFixedColumns = computed(() => {
return useFixedColumn(unref(getColumnsRef));
});
watchEffect(() => { watchEffect(() => {
const columns = toRaw(unref(propsRef).columns); const columns = toRaw(unref(propsRef).columns);
columnsRef.value = columns; columnsRef.value = columns;
cacheColumns = columns; cacheColumns = columns?.filter((item) => !item.flag) ?? [];
}); });
/** /**
* set columns * set columns
* @param columns key|column * @param columnList key|column
*/ */
function setColumns(columns: Partial<BasicColumn>[] | string[]) { function setColumns(columnList: Partial<BasicColumn>[] | string[]) {
const columns = cloneDeep(columnList);
if (!isArray(columns)) return; if (!isArray(columns)) return;
if (columns.length <= 0) { if (columns.length <= 0) {
...@@ -137,20 +142,36 @@ export function useColumns( ...@@ -137,20 +142,36 @@ export function useColumns(
const firstColumn = columns[0]; const firstColumn = columns[0];
if (isObject(firstColumn)) { const cacheKeys = cacheColumns.map((item) => item.dataIndex);
if (!isString(firstColumn)) {
columnsRef.value = columns as BasicColumn[]; columnsRef.value = columns as BasicColumn[];
} else { } else {
const newColumns = cacheColumns.filter( const columnKeys = columns as string[];
(item) => const newColumns: BasicColumn[] = [];
(item.dataIndex || `${item.key}`) && cacheColumns.forEach((item) => {
(columns as string[]).includes(`${item.key}`! || item.dataIndex!) if (columnKeys.includes(`${item.key}`! || item.dataIndex!)) {
); newColumns.push({
...item,
defaultHidden: false,
});
}
});
// Sort according to another array
if (!isEqual(cacheKeys, columns)) {
newColumns.sort((prev, next) => {
return (
columnKeys.indexOf(prev.dataIndex as string) -
columnKeys.indexOf(next.dataIndex as string)
);
});
}
columnsRef.value = newColumns; columnsRef.value = newColumns;
} }
} }
function getColumns(opt?: GetColumnsParams) { function getColumns(opt?: GetColumnsParams) {
const { ignoreIndex, ignoreAction } = opt || {}; const { ignoreIndex, ignoreAction, sort } = opt || {};
let columns = toRaw(unref(getColumnsRef)); let columns = toRaw(unref(getColumnsRef));
if (ignoreIndex) { if (ignoreIndex) {
columns = columns.filter((item) => item.flag !== INDEX_COLUMN_FLAG); columns = columns.filter((item) => item.flag !== INDEX_COLUMN_FLAG);
...@@ -158,8 +179,38 @@ export function useColumns( ...@@ -158,8 +179,38 @@ export function useColumns(
if (ignoreAction) { if (ignoreAction) {
columns = columns.filter((item) => item.flag !== ACTION_COLUMN_FLAG); columns = columns.filter((item) => item.flag !== ACTION_COLUMN_FLAG);
} }
if (sort) {
columns = useFixedColumn(columns);
}
return columns; return columns;
} }
function getCacheColumns() {
return cacheColumns;
}
return { getColumnsRef, getCacheColumns, getColumns, setColumns, getSortFixedColumns };
}
export function useFixedColumn(columns: BasicColumn[]) {
const fixedLeftColumns: BasicColumn[] = [];
const fixedRightColumns: BasicColumn[] = [];
const defColumns: BasicColumn[] = [];
for (const column of columns) {
if (column.fixed === 'left') {
fixedLeftColumns.push(column);
continue;
}
if (column.fixed === 'right') {
fixedRightColumns.push(column);
continue;
}
defColumns.push(column);
}
const resultColumns = [...fixedLeftColumns, ...defColumns, ...fixedRightColumns].filter(
(item) => !item.defaultHidden
);
return { getColumnsRef, getColumns, setColumns }; return resultColumns;
} }
...@@ -53,7 +53,12 @@ export function useRowSelection(propsRef: ComputedRef<BasicTableProps>, emit: Em ...@@ -53,7 +53,12 @@ export function useRowSelection(propsRef: ComputedRef<BasicTableProps>, emit: Em
return unref(selectedRowRef) as T[]; return unref(selectedRowRef) as T[];
} }
function getRowSelection() {
return unref(getRowSelectionRef)!;
}
return { return {
getRowSelection,
getRowSelectionRef, getRowSelectionRef,
getSelectRows, getSelectRows,
getSelectRowKeys, getSelectRowKeys,
......
import type { Ref } from 'vue';
import type { BasicTableProps, TableActionType } from '../types/table';
import { provide, inject, ComputedRef } from 'vue';
const key = Symbol('basic-table');
type Instance = TableActionType & {
wrapRef: Ref<Nullable<HTMLElement>>;
getBindValues: ComputedRef<Recordable>;
};
type RetInstance = Omit<Instance, 'getBindValues'> & {
getBindValues: ComputedRef<BasicTableProps>;
};
export function createTableContext(instance: Instance) {
provide(key, instance);
}
export function useTableContext(): RetInstance {
return inject(key) as RetInstance;
}
import type { ComputedRef, Ref } from 'vue';
import type { BasicTableProps } from '../types/table';
import { unref, computed, h, nextTick, watchEffect } from 'vue';
import TableFooter from '../components/TableFooter.vue';
import { useEventListener } from '/@/hooks/event/useEventListener';
export function useTableFooter(
propsRef: ComputedRef<BasicTableProps>,
scrollRef: ComputedRef<{
x: string | number | true;
y: Nullable<number>;
scrollToFirstRowOnChange: boolean;
}>,
tableElRef: Ref<ComponentRef>,
getDataSourceRef: ComputedRef<Recordable>
) {
const getIsEmptyData = computed(() => {
return (unref(getDataSourceRef) || []).length === 0;
});
const getFooterProps = computed((): Recordable | undefined => {
const { summaryFunc, showSummary } = unref(propsRef);
return showSummary && !unref(getIsEmptyData)
? () => h(TableFooter, { summaryFunc, scroll: unref(scrollRef) })
: undefined;
});
watchEffect(() => {
handleSummary();
});
function handleSummary() {
const { showSummary } = unref(propsRef);
if (!showSummary || unref(getIsEmptyData)) return;
nextTick(() => {
const tableEl = unref(tableElRef);
if (!tableEl) return;
const bodyDomList = tableEl.$el.querySelectorAll('.ant-table-body');
const bodyDom = bodyDomList[0];
useEventListener({
el: bodyDom,
name: 'scroll',
listener: () => {
const footerBodyDom = tableEl.$el.querySelector(
'.ant-table-footer .ant-table-body'
) as HTMLDivElement;
if (!footerBodyDom || !bodyDom) return;
footerBodyDom.scrollLeft = bodyDom.scrollLeft;
},
wait: 0,
options: true,
});
});
}
return { getFooterProps };
}
import type { ComputedRef, Slots } from 'vue';
import type { BasicTableProps, FetchParams } from '../types/table';
import { unref, computed } from 'vue';
import type { FormProps } from '/@/components/Form';
import { isFunction } from '/@/utils/is';
export function useTableForm(
propsRef: ComputedRef<BasicTableProps>,
slots: Slots,
fetch: (opt?: FetchParams | undefined) => Promise<void>
) {
const getFormProps = computed(
(): Partial<FormProps> => {
const { formConfig } = unref(propsRef);
return {
showAdvancedButton: true,
...formConfig,
compact: true,
};
}
);
const getFormSlotKeys = computed(() => {
const keys = Object.keys(slots);
return keys.map((item) => (item.startsWith('form-') ? item : null)).filter(Boolean);
});
function replaceFormSlotKey(key: string) {
if (!key) return '';
return key?.replace?.(/form\-/, '') ?? '';
}
function handleSearchInfoChange(info: Recordable) {
const { handleSearchInfoFn } = unref(propsRef);
if (handleSearchInfoFn && isFunction(handleSearchInfoFn)) {
info = handleSearchInfoFn(info) || info;
}
fetch({ searchInfo: info, page: 1 });
}
return {
getFormProps,
replaceFormSlotKey,
getFormSlotKeys,
handleSearchInfoChange,
};
}
import type { ComputedRef, Slots } from 'vue';
import type { BasicTableProps } from '../types/table';
import { unref, computed, h } from 'vue';
import { isString } from '/@/utils/is';
import TableHeader from '../components/TableHeader.vue';
import { getSlot } from '../../../../utils/helper/tsxHelper';
export function useTableHeader(propsRef: ComputedRef<BasicTableProps>, 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,
},
{
...(slots.toolbar
? {
toolbar: () => getSlot(slots, 'toolbar'),
}
: {}),
...(slots.tableTitle
? {
tableTitle: () => getSlot(slots, 'tableTitle'),
}
: {}),
}
),
};
}
);
return { getHeaderProps };
}
import type { BasicTableProps } from '../types/table'; import type { BasicTableProps, TableRowSelection } from '../types/table';
import type { Ref, ComputedRef } from 'vue'; import type { Ref, ComputedRef } from 'vue';
import { computed, unref, ref, nextTick, watchEffect } from 'vue'; import { computed, unref, ref, nextTick, watchEffect } from 'vue';
...@@ -7,22 +7,29 @@ import { isBoolean } from '/@/utils/is'; ...@@ -7,22 +7,29 @@ import { isBoolean } from '/@/utils/is';
import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
import { useModalContext } from '/@/components/Modal'; import { useModalContext } from '/@/components/Modal';
import { useDebounce } from '/@/hooks/core/useDebounce';
import type { BasicColumn } from '/@/components/Table';
export function useTableScroll( export function useTableScroll(
propsRef: ComputedRef<BasicTableProps>, propsRef: ComputedRef<BasicTableProps>,
tableElRef: Ref<ComponentRef> tableElRef: Ref<ComponentRef>,
columnsRef: ComputedRef<BasicColumn[]>,
rowSelectionRef: ComputedRef<TableRowSelection<any> | null>
) { ) {
const tableHeightRef: Ref<Nullable<number>> = ref(null); const tableHeightRef: Ref<Nullable<number>> = ref(null);
const modalFn = useModalContext(); const modalFn = useModalContext();
// const [debounceCalcTableHeight] = useDebounce(calcTableHeight, 80);
const [debounceRedoHeight] = useDebounce(redoHeight, 250);
const getCanResize = computed(() => { const getCanResize = computed(() => {
const { canResize, scroll } = unref(propsRef); const { canResize, scroll } = unref(propsRef);
return canResize && !(scroll || {}).y; return canResize && !(scroll || {}).y;
}); });
watchEffect(() => { watchEffect(() => {
redoHeight(); unref(getCanResize) && debounceRedoHeight();
}); });
function redoHeight() { function redoHeight() {
...@@ -33,6 +40,12 @@ export function useTableScroll( ...@@ -33,6 +40,12 @@ export function useTableScroll(
} }
} }
function setHeight(heigh: number) {
tableHeightRef.value = heigh;
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
modalFn?.redoModalHeight?.();
}
// No need to repeat queries // No need to repeat queries
let paginationEl: HTMLElement | null; let paginationEl: HTMLElement | null;
let footerEl: HTMLElement | null; let footerEl: HTMLElement | null;
...@@ -87,7 +100,7 @@ export function useTableScroll( ...@@ -87,7 +100,7 @@ export function useTableScroll(
headerHeight = (headEl as HTMLElement).offsetHeight; headerHeight = (headEl as HTMLElement).offsetHeight;
} }
const height = let height =
bottomIncludeBody - bottomIncludeBody -
(resizeHeightOffset || 0) - (resizeHeightOffset || 0) -
paddingHeight - paddingHeight -
...@@ -96,21 +109,41 @@ export function useTableScroll( ...@@ -96,21 +109,41 @@ export function useTableScroll(
footerHeight - footerHeight -
headerHeight; headerHeight;
setTimeout(() => { height = (height > maxHeight! ? (maxHeight as number) : height) ?? height;
tableHeightRef.value = (height > maxHeight! ? (maxHeight as number) : height) ?? height; setHeight(height);
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
modalFn?.redoModalHeight?.();
}, 0);
} }
useWindowSizeFn(calcTableHeight, 100); useWindowSizeFn(calcTableHeight, 200);
const getScrollX = computed(() => {
let width = 0;
if (unref(rowSelectionRef)) {
width += 60;
}
// TODO props
const NORMAL_WIDTH = 150;
const columns = unref(columnsRef);
columns.forEach((item) => {
width += Number.parseInt(item.width as string) || 0;
});
const unsetWidthColumns = columns.filter((item) => !Reflect.has(item, 'width'));
const len = unsetWidthColumns.length;
if (len !== 0) {
width += len * NORMAL_WIDTH;
}
return width;
});
const getScrollRef = computed(() => { const getScrollRef = computed(() => {
const tableHeight = unref(tableHeightRef); const tableHeight = unref(tableHeightRef);
const { canResize, scroll } = unref(propsRef); const { canResize, scroll } = unref(propsRef);
return { return {
x: '100%', x: unref(getScrollX),
y: canResize ? tableHeight : null, y: canResize ? tableHeight : null,
scrollToFirstRowOnChange: false, scrollToFirstRowOnChange: false,
...scroll, ...scroll,
......
...@@ -2,14 +2,14 @@ import type { ComputedRef } from 'vue'; ...@@ -2,14 +2,14 @@ import type { ComputedRef } from 'vue';
import type { BasicTableProps, TableCustomRecord } from '../types/table'; import type { BasicTableProps, TableCustomRecord } from '../types/table';
import { unref } from 'vue'; import { unref } from 'vue';
import { isFunction } from '/@/utils/is'; import { isFunction } from '/@/utils/is';
export function useTableStyle(propsRef: ComputedRef<BasicTableProps>) { export function useTableStyle(propsRef: ComputedRef<BasicTableProps>, prefixCls: string) {
function getRowClassName(record: TableCustomRecord, index: number) { function getRowClassName(record: TableCustomRecord, index: number) {
const { striped, rowClassName } = unref(propsRef); const { striped, rowClassName } = unref(propsRef);
if (!striped) return; if (!striped) return;
if (rowClassName && isFunction(rowClassName)) { if (rowClassName && isFunction(rowClassName)) {
return rowClassName(record); return rowClassName(record);
} }
return (index || 0) % 2 === 1 ? 'basic-table-row__striped' : ''; return (index || 0) % 2 === 1 ? `${prefixCls}-row__striped` : '';
} }
return { return {
......
...@@ -75,7 +75,7 @@ export const basicProps = { ...@@ -75,7 +75,7 @@ export const basicProps = {
}, },
columns: { columns: {
type: [Array] as PropType<BasicColumn[]>, type: [Array] as PropType<BasicColumn[]>,
default: null, default: () => [],
}, },
showIndexColumn: propTypes.bool.def(true), showIndexColumn: propTypes.bool.def(true),
indexColumnProps: { indexColumnProps: {
...@@ -95,7 +95,7 @@ export const basicProps = { ...@@ -95,7 +95,7 @@ export const basicProps = {
default: null, default: null,
}, },
title: { title: {
type: [String, Function] as PropType<string | ((data: any) => any)>, type: [String, Function] as PropType<string | ((data: Recordable) => string)>,
default: null, default: null,
}, },
titleHelpMessage: { titleHelpMessage: {
......
@import (reference) '../../../../design/index.less';
@prefix-cls: ~'editable-cell'; @prefix-cls: ~'editable-cell';
.@{prefix-cls} { .@{prefix-cls} {
......
@import (reference) '../../../../design/index.less';
@border-color: #cecece4d; @border-color: #cecece4d;
.basic-table { @prefix-cls: ~'@{namespace}-basic-table';
&-title {
display: flex; .@{prefix-cls} {
justify-content: space-between; &-form-container {
align-items: center; padding: 16px;
.ant-form {
padding: 20px 20px 4px 12px;
margin-bottom: 18px;
background: #fff;
border-radius: 4px;
}
.ant-table-wrapper {
border-radius: 2px;
}
} }
&-row__striped { &-row__striped {
...@@ -22,28 +32,16 @@ ...@@ -22,28 +32,16 @@
} }
} }
&-action { &--inset {
display: flex; .ant-table-wrapper {
padding: 0;
button {
display: flex;
align-items: center;
}
}
&-toolbar {
display: flex;
align-items: center;
> * {
margin-right: 10px;
} }
} }
.ant-table-wrapper { .ant-table-wrapper {
padding: 8px; padding: 8px;
background: #fff; background: #fff;
border-radius: 2px; border-radius: 4px;
.ant-table-title { .ant-table-title {
padding: 0 0 8px 0 !important; padding: 0 0 8px 0 !important;
...@@ -54,12 +52,6 @@ ...@@ -54,12 +52,6 @@
} }
} }
&.inset {
.ant-table-wrapper {
padding: 0;
}
}
// //
.ant-table { .ant-table {
border: none; border: none;
...@@ -194,18 +186,3 @@ ...@@ -194,18 +186,3 @@
} }
} }
} }
.table-form-container {
padding: 16px;
.ant-form {
padding: 20px 20px 4px 12px;
margin-bottom: 18px;
background: #fff;
border-radius: 2px;
}
.ant-table-wrapper {
border-radius: 2px;
}
}
...@@ -82,6 +82,7 @@ export interface FetchParams { ...@@ -82,6 +82,7 @@ export interface FetchParams {
export interface GetColumnsParams { export interface GetColumnsParams {
ignoreIndex?: boolean; ignoreIndex?: boolean;
ignoreAction?: boolean; ignoreAction?: boolean;
sort?: boolean;
} }
export type SizeType = 'default' | 'middle' | 'small' | 'large'; export type SizeType = 'default' | 'middle' | 'small' | 'large';
...@@ -93,16 +94,18 @@ export interface TableActionType { ...@@ -93,16 +94,18 @@ export interface TableActionType {
getSelectRowKeys: () => string[]; getSelectRowKeys: () => string[];
deleteSelectRowByKey: (key: string) => void; deleteSelectRowByKey: (key: string) => void;
setPagination: (info: Partial<PaginationProps>) => void; setPagination: (info: Partial<PaginationProps>) => void;
setTableData: <T = any>(values: T[]) => void; setTableData: <T = Recordable>(values: T[]) => void;
getColumns: (opt?: GetColumnsParams) => BasicColumn[]; getColumns: (opt?: GetColumnsParams) => BasicColumn[];
setColumns: (columns: BasicColumn[] | string[]) => void; setColumns: (columns: BasicColumn[] | string[]) => void;
getDataSource: <T = any>() => T[]; getDataSource: <T = Recordable>() => T[];
setLoading: (loading: boolean) => void; setLoading: (loading: boolean) => void;
setProps: (props: Partial<BasicTableProps>) => void; setProps: (props: Partial<BasicTableProps>) => void;
redoHeight: () => void; redoHeight: () => void;
setSelectedRowKeys: (rowKeys: string[] | number[]) => void; setSelectedRowKeys: (rowKeys: string[] | number[]) => void;
getPaginationRef: () => PaginationProps | boolean; getPaginationRef: () => PaginationProps | boolean;
getSize: () => SizeType; getSize: () => SizeType;
getRowSelection: () => TableRowSelection<Recordable>;
getCacheColumns: () => BasicColumn[];
} }
export interface FetchSetting { export interface FetchSetting {
...@@ -308,7 +311,7 @@ export interface BasicTableProps<T = any> { ...@@ -308,7 +311,7 @@ export interface BasicTableProps<T = any> {
* Table title renderer * Table title renderer
* @type Function | ScopedSlot * @type Function | ScopedSlot
*/ */
title?: VNodeChild | JSX.Element; title?: VNodeChild | JSX.Element | string | ((data: Recordable) => string);
/** /**
* Set props on per header row * Set props on per header row
...@@ -378,4 +381,6 @@ export interface BasicColumn extends ColumnProps { ...@@ -378,4 +381,6 @@ export interface BasicColumn extends ColumnProps {
flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION'; flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION';
slots?: Indexable; slots?: Indexable;
defaultHidden?: boolean;
} }
...@@ -5,6 +5,8 @@ export interface ActionItem extends ButtonProps { ...@@ -5,6 +5,8 @@ export interface ActionItem extends ButtonProps {
color?: 'success' | 'error' | 'warning'; color?: 'success' | 'error' | 'warning';
icon?: string; icon?: string;
popConfirm?: PopConfirm; popConfirm?: PopConfirm;
disabled?: boolean;
divider?: boolean;
} }
export interface PopConfirm { export interface PopConfirm {
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
} }
} }
.ant-image-preview-operations {
background: rgba(0, 0, 0, 0.3);
}
// ================================= // =================================
// ==============descriptions======= // ==============descriptions=======
// ================================= // =================================
......
@import 'color.less';
@import 'var/index.less';
@import 'mixins.less';
@import './transition/index.less'; @import 'transition/index.less';
@import 'var/index.less'; @import 'var/index.less';
@import 'public.less'; @import 'public.less';
@import 'mixins.less'; @import 'mixins.less';
@import 'ant/index.less'; @import 'ant/index.less';
@import './global.less'; @import 'global.less';
*, *,
*::before, *::before,
......
...@@ -34,3 +34,9 @@ ...@@ -34,3 +34,9 @@
// left-menu // left-menu
@app-menu-item-height: 42px; @app-menu-item-height: 42px;
.bem(@n;@content) {
@{namespace}-@{n} {
@content();
}
}
import type { UnwrapRef } from 'vue'; import type { UnwrapRef } from 'vue';
import { reactive, readonly, computed, getCurrentInstance } from 'vue'; import { reactive, readonly, computed, getCurrentInstance, watchEffect } from 'vue';
import { isEqual } from 'lodash-es'; import { isEqual } from 'lodash-es';
...@@ -20,6 +20,11 @@ export function useRuleFormItem<T extends Indexable>( ...@@ -20,6 +20,11 @@ export function useRuleFormItem<T extends Indexable>(
const setState = (val: UnwrapRef<T[keyof T]>) => { const setState = (val: UnwrapRef<T[keyof T]>) => {
innerState.value = val as T[keyof T]; innerState.value = val as T[keyof T];
}; };
watchEffect(() => {
innerState.value = props[key];
});
const state = computed({ const state = computed({
get() { get() {
return innerState.value; return innerState.value;
......
...@@ -25,7 +25,6 @@ export function createContext<T>( ...@@ -25,7 +25,6 @@ export function createContext<T>(
const { readonly = true, createProvider = false } = options; const { readonly = true, createProvider = false } = options;
const state = reactive(context); const state = reactive(context);
const provideData = readonly ? defineReadonly(state) : state; const provideData = readonly ? defineReadonly(state) : state;
!createProvider && provide(key, provideData); !createProvider && provide(key, provideData);
......
...@@ -17,7 +17,7 @@ type FSEPropName = ...@@ -17,7 +17,7 @@ type FSEPropName =
| 'fullscreenElement'; | 'fullscreenElement';
export function useFullscreen( export function useFullscreen(
target: Ref<Nullable<HTMLElement>> = ref(document.documentElement), target: Ref<Nullable<HTMLElement>> | Nullable<HTMLElement> = ref(document.documentElement),
options?: FullscreenOptions options?: FullscreenOptions
) { ) {
const isFullscreenRef = ref(false); const isFullscreenRef = ref(false);
...@@ -43,7 +43,7 @@ export function useFullscreen( ...@@ -43,7 +43,7 @@ export function useFullscreen(
} }
function enterFullscreen(): Promise<void> { function enterFullscreen(): Promise<void> {
isFullscreenRef.value = true; isFullscreenRef.value = true;
return (target.value as any)[RFC_METHOD_NAME](options); return (unref(target) as any)[RFC_METHOD_NAME](options);
} }
function exitFullscreen(): Promise<void> { function exitFullscreen(): Promise<void> {
...@@ -55,7 +55,9 @@ export function useFullscreen( ...@@ -55,7 +55,9 @@ export function useFullscreen(
return unref(target) === (document as any)[FSE_PROP_NAME]; return unref(target) === (document as any)[FSE_PROP_NAME];
} }
function toggleFullscreen(): Promise<void> { async function toggleFullscreen(): Promise<void> {
if (!unref(target)) return;
if (isFullscreen()) { if (isFullscreen()) {
return exitFullscreen(); return exitFullscreen();
} else { } else {
......
import Sortable from 'sortablejs';
import { nextTick, unref } from 'vue';
import type { Ref } from 'vue';
export function useSortable(el: HTMLElement | Ref<HTMLElement>, options?: Sortable.Options) {
function initSortable() {
nextTick(() => {
if (!el) return;
Sortable.create(unref(el), {
animation: 500,
delay: 400,
delayOnTouchOnly: true,
...options,
});
});
}
return { initSortable };
}
import Sortable from 'sortablejs'; import { toRaw, ref, nextTick } from 'vue';
import { toRaw, ref, nextTick, onMounted } from 'vue';
import { RouteLocationNormalized } from 'vue-router'; import { RouteLocationNormalized } from 'vue-router';
import { useProjectSetting } from '/@/hooks/setting'; import { useProjectSetting } from '/@/hooks/setting';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import { useSortable } from '/@/hooks/web/useSortable';
import router from '/@/router'; import router from '/@/router';
import { tabStore } from '/@/store/modules/tab'; import { tabStore } from '/@/store/modules/tab';
import { isNullAndUnDef } from '/@/utils/is'; import { isNullAndUnDef } from '/@/utils/is';
...@@ -50,36 +50,25 @@ export function useTabsDrag(affixTextList: string[]) { ...@@ -50,36 +50,25 @@ export function useTabsDrag(affixTextList: string[]) {
const { multiTabsSetting } = useProjectSetting(); const { multiTabsSetting } = useProjectSetting();
const { prefixCls } = useDesign('multiple-tabs'); const { prefixCls } = useDesign('multiple-tabs');
nextTick(() => {
function initSortableTabs() {
if (!multiTabsSetting.canDrag) return; if (!multiTabsSetting.canDrag) return;
nextTick(() => { const el = document.querySelectorAll(`.${prefixCls} .ant-tabs-nav > div`)?.[0] as HTMLElement;
const el = document.querySelectorAll(`.${prefixCls} .ant-tabs-nav > div`)?.[0] as HTMLElement; const { initSortable } = useSortable(el, {
filter: (e: ChangeEvent) => {
if (!el) return; const text = e?.target?.innerText;
Sortable.create(el, { if (!text) return false;
animation: 500, return affixTextList.includes(text);
delay: 400, },
delayOnTouchOnly: true, onEnd: (evt) => {
filter: (e: ChangeEvent) => { const { oldIndex, newIndex } = evt;
const text = e?.target?.innerText;
if (!text) return false;
return affixTextList.includes(text);
},
onEnd: (evt) => {
const { oldIndex, newIndex } = evt;
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex) { if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex) {
return; return;
} }
tabStore.commitSortTabs({ oldIndex, newIndex }); tabStore.commitSortTabs({ oldIndex, newIndex });
}, },
});
}); });
} initSortable();
onMounted(() => {
initSortableTabs();
}); });
} }
...@@ -5,4 +5,7 @@ export default { ...@@ -5,4 +5,7 @@ export default {
toSearch: 'to search', toSearch: 'to search',
toNavigate: 'to navigate', toNavigate: 'to navigate',
toClose: 'to close', toClose: 'to close',
okText: 'Confirm',
cancelText: 'Cancel',
}; };
...@@ -6,7 +6,11 @@ export default { ...@@ -6,7 +6,11 @@ export default {
settingDensSmall: 'Compact', settingDensSmall: 'Compact',
settingColumn: 'Column settings', settingColumn: 'Column settings',
settingColumnShow: 'Column display', settingColumnShow: 'Column display',
settingIndexColumnShow: 'Index Column',
settingSelectColumnShow: 'Selection Column',
settingReset: 'Reset', settingReset: 'Reset',
settingFixedLeft: 'Fixed Left',
settingFixedRight: 'Fixed Right',
settingFullScreen: 'Full Screen', settingFullScreen: 'Full Screen',
index: 'Index', index: 'Index',
......
...@@ -5,4 +5,6 @@ export default { ...@@ -5,4 +5,6 @@ export default {
toSearch: '确认', toSearch: '确认',
toNavigate: '切换', toNavigate: '切换',
toClose: '关闭', toClose: '关闭',
okText: '确认',
cancelText: '取消',
}; };
...@@ -7,6 +7,10 @@ export default { ...@@ -7,6 +7,10 @@ export default {
settingColumn: '列设置', settingColumn: '列设置',
settingColumnShow: '列展示', settingColumnShow: '列展示',
settingReset: '重置', settingReset: '重置',
settingIndexColumnShow: '序号列',
settingSelectColumnShow: '勾选列',
settingFixedLeft: '固定到左侧',
settingFixedRight: '固定到右侧',
settingFullScreen: '全屏', settingFullScreen: '全屏',
index: '序号', index: '序号',
......
...@@ -11,7 +11,6 @@ import { PROJ_CFG_KEY } from '/@/enums/cacheEnum'; ...@@ -11,7 +11,6 @@ import { PROJ_CFG_KEY } from '/@/enums/cacheEnum';
import projectSetting from '/@/settings/projectSetting'; import projectSetting from '/@/settings/projectSetting';
import { getLocal } from '/@/utils/helper/persistent'; import { getLocal } from '/@/utils/helper/persistent';
import { isUnDef, isNull } from '/@/utils/is';
import { import {
updateGrayMode, updateGrayMode,
updateColorWeak, updateColorWeak,
...@@ -76,16 +75,3 @@ export function initAppConfigStore() { ...@@ -76,16 +75,3 @@ export function initAppConfigStore() {
} }
appStore.commitProjectConfigState(projCfg); appStore.commitProjectConfigState(projCfg);
} }
// antdv Config Provider
export function getConfigProvider() {
function transformCellText({ text }: { text: string }) {
if (isNull(text) || isUnDef(text)) {
return ' - ';
}
return text;
}
return {
transformCellText,
};
}
...@@ -182,7 +182,7 @@ class Tab extends VuexModule { ...@@ -182,7 +182,7 @@ class Tab extends VuexModule {
@Action @Action
addTabAction(route: RouteLocationNormalized) { addTabAction(route: RouteLocationNormalized) {
const { path, name } = route; const { path, name } = route;
// 404 页面不需要添加tab // 404 The page does not need to add a tab
if ( if (
path === PageEnum.ERROR_PAGE || path === PageEnum.ERROR_PAGE ||
!name || !name ||
......
...@@ -106,12 +106,13 @@ class User extends VuexModule { ...@@ -106,12 +106,13 @@ class User extends VuexModule {
const data = await loginApi(loginParams, mode); const data = await loginApi(loginParams, mode);
const { token, userId } = data; const { token, userId } = data;
// get user info
const userInfo = await this.getUserInfoAction({ userId });
// save token // save token
this.commitTokenState(token); this.commitTokenState(token);
// get user info
const userInfo = await this.getUserInfoAction({ userId });
// const name = FULL_PAGE_NOT_FOUND_ROUTE.name; // const name = FULL_PAGE_NOT_FOUND_ROUTE.name;
// name && router.removeRoute(name); // name && router.removeRoute(name);
goHome && (await router.replace(PageEnum.BASE_HOME)); goHome && (await router.replace(PageEnum.BASE_HOME));
......
...@@ -8,10 +8,7 @@ export const now = () => Date.now(); ...@@ -8,10 +8,7 @@ export const now = () => Date.now();
* @description: Set ui mount node * @description: Set ui mount node
*/ */
export function getPopupContainer(node?: HTMLElement): HTMLElement { export function getPopupContainer(node?: HTMLElement): HTMLElement {
if (node) { return (node?.parentNode as HTMLElement) ?? document.body;
return node.parentNode as HTMLElement;
}
return document.body;
} }
/** /**
......
...@@ -224,6 +224,7 @@ ...@@ -224,6 +224,7 @@
colProps: { colProps: {
span: 8, span: 8,
}, },
defaultValue: '0',
}, },
{ {
field: 'field20', field: 'field20',
......
<template> <template>
<BasicTable @register="registerTable" /> <BasicTable @register="registerTable">
<template #form-custom> custom-slot</template>
</BasicTable>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
...@@ -18,6 +20,7 @@ ...@@ -18,6 +20,7 @@
useSearchForm: true, useSearchForm: true,
formConfig: getFormConfig(), formConfig: getFormConfig(),
showTableSetting: true, showTableSetting: true,
rowSelection: { type: 'checkbox' },
}); });
return { return {
......
...@@ -6,7 +6,8 @@ export function getBasicColumns(): BasicColumn[] { ...@@ -6,7 +6,8 @@ export function getBasicColumns(): BasicColumn[] {
{ {
title: 'ID', title: 'ID',
dataIndex: 'id', dataIndex: 'id',
width: 150, fixed: 'left',
width: 400,
}, },
{ {
title: '姓名', title: '姓名',
...@@ -21,6 +22,7 @@ export function getBasicColumns(): BasicColumn[] { ...@@ -21,6 +22,7 @@ export function getBasicColumns(): BasicColumn[] {
title: '编号', title: '编号',
dataIndex: 'no', dataIndex: 'no',
width: 150, width: 150,
defaultHidden: true,
}, },
{ {
title: '开始时间', title: '开始时间',
...@@ -42,6 +44,8 @@ export function getBasicShortColumns(): BasicColumn[] { ...@@ -42,6 +44,8 @@ export function getBasicShortColumns(): BasicColumn[] {
title: 'ID', title: 'ID',
width: 150, width: 150,
dataIndex: 'id', dataIndex: 'id',
sorter: true,
sortOrder: 'ascend',
}, },
{ {
title: '姓名', title: '姓名',
...@@ -118,6 +122,7 @@ export function getCustomHeaderColumns(): BasicColumn[] { ...@@ -118,6 +122,7 @@ export function getCustomHeaderColumns(): BasicColumn[] {
{ {
// title: '地址', // title: '地址',
dataIndex: 'address', dataIndex: 'address',
width: 120,
slots: { title: 'customAddress' }, slots: { title: 'customAddress' },
sorter: true, sorter: true,
}, },
...@@ -236,6 +241,7 @@ export function getFormConfig(): Partial<FormProps> { ...@@ -236,6 +241,7 @@ export function getFormConfig(): Partial<FormProps> {
label: `字段33`, label: `字段33`,
component: 'Select', component: 'Select',
defaultValue: '1', defaultValue: '1',
slot: 'custom',
componentProps: { componentProps: {
options: [ options: [
{ {
......
...@@ -78,7 +78,11 @@ export default (mode: 'development' | 'production'): UserConfig => { ...@@ -78,7 +78,11 @@ export default (mode: 'development' | 'production'): UserConfig => {
cssPreprocessOptions: { cssPreprocessOptions: {
less: { less: {
modifyVars: modifyVars, modifyVars: {
// reference : Avoid repeated references
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
...modifyVars,
},
javascriptEnabled: true, javascriptEnabled: true,
}, },
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论