From 48ab779bf49fee1147f4a264d44e19c2c723e2f2 Mon Sep 17 00:00:00 2001 From: buqiyuan <1743369777@qq.com> Date: Sun, 25 Feb 2024 21:54:26 +0800 Subject: [PATCH] chore: hide some table search item --- .env.development | 2 +- .env.production | 2 +- .../basic/context-menu/src/ContextMenu.vue | 128 ++++-------------- .../context-menu/src/createContextMenu.ts | 5 +- .../basic/context-menu/src/typing.ts | 4 +- .../dynamic-table/src/hooks/useColumns.ts | 8 +- .../src/hooks/useExportData2Excel.ts | 6 +- .../core/dynamic-table/src/types/column.ts | 2 + src/views/demos/tables/lol-table/index.vue | 13 +- src/views/demos/tables/wzry-table/columns.tsx | 5 - src/views/system/menu/columns.tsx | 3 + src/views/system/role/columns.tsx | 15 ++ 12 files changed, 71 insertions(+), 122 deletions(-) diff --git a/.env.development b/.env.development index 00f3fa10c..76dead825 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ # 只在开发模式中被载入 ENV = 'development' -# 网站前缀 +# 公共基础路径, 所有资源的路径都将据此配置重写。 VITE_BASE_URL = / # base api url diff --git a/.env.production b/.env.production index 8db41913b..bb1e2465a 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,7 @@ ENV = 'production' VITE_BASE_API_URL = 'https://nest-api.buqiyuan.site' # VITE_BASE_API_URL = 'http://127.0.0.1:7001' -# 网站前缀 +# 公共基础路径, 所有资源的路径都将据此配置重写。 VITE_BASE_URL = /vue3-antdv-admin/ VITE_DROP_CONSOLE = true diff --git a/src/components/basic/context-menu/src/ContextMenu.vue b/src/components/basic/context-menu/src/ContextMenu.vue index dd8d1d2d5..4dfd97599 100644 --- a/src/components/basic/context-menu/src/ContextMenu.vue +++ b/src/components/basic/context-menu/src/ContextMenu.vue @@ -1,12 +1,10 @@ - diff --git a/src/components/basic/context-menu/src/createContextMenu.ts b/src/components/basic/context-menu/src/createContextMenu.ts index 94353e111..d82d4f90b 100644 --- a/src/components/basic/context-menu/src/createContextMenu.ts +++ b/src/components/basic/context-menu/src/createContextMenu.ts @@ -23,7 +23,9 @@ export const createContextMenu = function (options: CreateContextOptions) { const body = document.body; const container = document.createElement('div'); - const propsData: Partial = {}; + const propsData: Partial = { + getPopupContainer: () => container, + }; if (options.styles) { propsData.styles = options.styles; } @@ -57,6 +59,7 @@ export const createContextMenu = function (options: CreateContextOptions) { }; menuManager.resolve = function (arg) { + vm.component?.exposed?.close(); remove(); resolve(arg); }; diff --git a/src/components/basic/context-menu/src/typing.ts b/src/components/basic/context-menu/src/typing.ts index 63d3d37fe..1f61cf559 100644 --- a/src/components/basic/context-menu/src/typing.ts +++ b/src/components/basic/context-menu/src/typing.ts @@ -1,3 +1,5 @@ +import type { DropdownProps } from 'ant-design-vue/es/dropdown'; + export interface Axis { x: number; y: number; @@ -19,7 +21,7 @@ export interface CreateContextOptions { items?: ContextMenuItem[]; } -export interface ContextMenuProps { +export interface ContextMenuProps extends DropdownProps { event?: MouseEvent; styles?: any; items: ContextMenuItem[]; diff --git a/src/components/core/dynamic-table/src/hooks/useColumns.ts b/src/components/core/dynamic-table/src/hooks/useColumns.ts index 530ca2401..9b4cf42d9 100644 --- a/src/components/core/dynamic-table/src/hooks/useColumns.ts +++ b/src/components/core/dynamic-table/src/hooks/useColumns.ts @@ -2,7 +2,7 @@ import { ref, watchEffect, unref, useSlots, h } from 'vue'; import { cloneDeep, isFunction, mergeWith } from 'lodash-es'; import { Input } from 'ant-design-vue'; import { EditableCell } from '../components'; -import { ColumnKeyFlag, type CustomRenderParams } from '../types/column'; +import { ColumnKeyFlag, columnKeyFlags, type CustomRenderParams } from '../types/column'; import tableConfig from '../dynamic-table.config'; import type { Slots } from 'vue'; import type { @@ -33,13 +33,13 @@ export const useColumns = ({ state, methods, props, tableAction }: UseTableColum watchEffect(() => { const innerProps = { ...unref(getProps) }; - const ColumnKeyFlags = Object.keys(ColumnKeyFlag); + const columns = cloneDeep(innerProps!.columns!.filter((n) => !n.hideInTable)); // 是否添加序号列 if (innerProps?.showIndex) { columns.unshift({ - dataIndex: 'ACTION', + dataIndex: ColumnKeyFlag.INDEX, title: '序号', width: 60, align: 'center', @@ -79,7 +79,7 @@ export const useColumns = ({ state, methods, props, tableAction }: UseTableColum const isShowEditable = (isEditableRow || isEditableCell) && isCellEditable && - !ColumnKeyFlags.includes(columnKey); + !columnKeyFlags.includes(columnKey); return isShowEditable ? h( diff --git a/src/components/core/dynamic-table/src/hooks/useExportData2Excel.ts b/src/components/core/dynamic-table/src/hooks/useExportData2Excel.ts index 5e2ca9635..28bc3ab56 100644 --- a/src/components/core/dynamic-table/src/hooks/useExportData2Excel.ts +++ b/src/components/core/dynamic-table/src/hooks/useExportData2Excel.ts @@ -1,4 +1,5 @@ import { get, isEmpty } from 'lodash-es'; +import { columnKeyFlags } from '../types'; import type { DynamicTableProps } from '../dynamic-table'; import type { TableMethods, TableState } from './index'; import { exportJson2Excel } from '@/utils/Export2Excel'; @@ -20,7 +21,10 @@ export const useExportData2Excel = ({ props, state, methods }: UseExportData2Exc const { getColumnKey } = methods; const { tableData } = state; - const theaders = columns.filter((n) => getColumnKey(n) && getColumnKey(n) !== 'INDEX'); + const theaders = columns.filter((n) => { + const key = getColumnKey(n); + return key && !columnKeyFlags.includes(key); + }); if (exportFormatter) { const { header, data } = exportFormatter(theaders, tableData.value); diff --git a/src/components/core/dynamic-table/src/types/column.ts b/src/components/core/dynamic-table/src/types/column.ts index 8fbb599c3..897f2fc00 100644 --- a/src/components/core/dynamic-table/src/types/column.ts +++ b/src/components/core/dynamic-table/src/types/column.ts @@ -64,4 +64,6 @@ export enum ColumnKeyFlag { ACTION = 'ACTION', INDEX = 'INDEX', } + +export const columnKeyFlags = Object.values(ColumnKeyFlag) as string[]; export type ColumnKeyFlagType = `${ColumnKeyFlag}`; diff --git a/src/views/demos/tables/lol-table/index.vue b/src/views/demos/tables/lol-table/index.vue index a59b95b2c..c039dca87 100644 --- a/src/views/demos/tables/lol-table/index.vue +++ b/src/views/demos/tables/lol-table/index.vue @@ -10,7 +10,7 @@ :data-request="getLolHeroList" :columns="columns" row-key="heroid" - export-file-name="表格自带导出" + export-file-name="英雄联盟" :custom-row="customRow" > @@ -27,7 +27,7 @@ import { useRouter } from 'vue-router'; import { Alert, Card } from 'ant-design-vue'; import { columns } from './columns'; - import { useTable } from '@/components/core/dynamic-table'; + import { columnKeyFlags, useTable } from '@/components/core/dynamic-table'; import { getLolHeroList } from '@/api/demo/hero'; import { useContextMenu } from '@/hooks/functions/useContextMenu'; import { useExportExcelModal, jsonToSheetXlsx, aoaToSheetXlsx } from '@/components/basic/excel'; @@ -36,20 +36,19 @@ name: 'DemosTablesLolTable', }); - const [DynamicTable] = useTable(); + const [DynamicTable, dynamicTableInstance] = useTable(); const router = useRouter(); const [createContextMenu] = useContextMenu(); const exportExcelModal = useExportExcelModal(); - const tableData: any[] = []; const aoaToExcel = () => { - const colFilters = columns.filter((n) => n.dataIndex !== 'INDEX'); + const colFilters = columns.filter((n) => !columnKeyFlags.includes(n.dataIndex as string)); const colFilterKeys = colFilters.map((n) => n.dataIndex); // 保证data顺序与header一致 aoaToSheetXlsx({ - data: tableData + data: dynamicTableInstance.tableData .map((item) => { return colFilterKeys.reduce((p, k: string) => { p[k] = Array.isArray(item[k]) ? item[k].toString() : item[k]; @@ -68,7 +67,7 @@ onOk: ({ filename, bookType }) => { // 默认Object.keys(data[0])作为header jsonToSheetXlsx({ - data: tableData, + data: dynamicTableInstance.tableData, filename, write2excelOpts: { bookType, diff --git a/src/views/demos/tables/wzry-table/columns.tsx b/src/views/demos/tables/wzry-table/columns.tsx index d387b1f27..c5c6912c6 100644 --- a/src/views/demos/tables/wzry-table/columns.tsx +++ b/src/views/demos/tables/wzry-table/columns.tsx @@ -4,7 +4,6 @@ import type { TableColumn } from '@/components/core/dynamic-table'; export const columns: TableColumn[] = [ { title: '头像', - width: 100, hideInSearch: true, dataIndex: 'faceimg', @@ -14,17 +13,14 @@ export const columns: TableColumn[] = [ }, { title: '英雄名称', - dataIndex: 'cname', }, { title: '英雄称号', - dataIndex: 'title', }, { title: '定位', - dataIndex: 'occupation', }, { @@ -57,7 +53,6 @@ export const columns: TableColumn[] = [ }, { title: '操作', - width: 120, dataIndex: 'ACTION', actions: ({ record }) => [ diff --git a/src/views/system/menu/columns.tsx b/src/views/system/menu/columns.tsx index 5943c986a..5ce3d9a24 100644 --- a/src/views/system/menu/columns.tsx +++ b/src/views/system/menu/columns.tsx @@ -59,6 +59,7 @@ export const baseColumns: TableColumnItem[] = [ title: '权限标识', width: 180, dataIndex: 'permission', + hideInSearch: true, customRender: ({ record }) => record.permission && {record.permission}, }, @@ -79,6 +80,7 @@ export const baseColumns: TableColumnItem[] = [ title: '是否显示', dataIndex: 'show', width: 80, + hideInSearch: true, customRender: ({ record }) => { const show = record.show; const enable = ~~show === 1; @@ -91,6 +93,7 @@ export const baseColumns: TableColumnItem[] = [ title: '状态', dataIndex: 'status', width: 80, + hideInSearch: true, customRender: ({ record }) => { const status = record.status; const enable = ~~status === 1; diff --git a/src/views/system/role/columns.tsx b/src/views/system/role/columns.tsx index 4c08757e4..3377a0bb8 100644 --- a/src/views/system/role/columns.tsx +++ b/src/views/system/role/columns.tsx @@ -26,6 +26,21 @@ export const baseColumns: TableColumnItem[] = [ title: '状态', dataIndex: 'status', width: 80, + formItemProps: { + component: 'Select', + componentProps: { + options: [ + { + label: '启用', + value: 1, + }, + { + label: '禁用', + value: 0, + }, + ], + }, + }, customRender: ({ record }) => { const enable = ~~record.status === 1; return {enable ? '启用' : '停用'};