diff --git a/examples/main.ts b/examples/main.ts index 28f8be11cb..0e77f1bf10 100644 --- a/examples/main.ts +++ b/examples/main.ts @@ -1,4 +1,4 @@ -import { createApp, h } from 'vue' +import { createApp } from 'vue' import App from './App.vue' import router from './router' @@ -14,18 +14,6 @@ import './style/index.scss' VxeUI.setI18n('en-US', enUS) -VxeUI.renderer.add('CellImage', { - renderTableDefault (_renderOpts, params) { - const { props } = _renderOpts - const { column, row } = params - return h(VxeUI.VxeImage, { - width: '100%', - ...props, - src: row[column.field] - }) - } -}) - createApp(App) .use(router) .use(VxeUI) diff --git a/examples/views/table/TableTest9.vue b/examples/views/table/TableTest9.vue index 48d6a91422..0d407f8c1e 100644 --- a/examples/views/table/TableTest9.vue +++ b/examples/views/table/TableTest9.vue @@ -7,11 +7,12 @@ show-overflow height="800" :loading="loading" - :column-config="{resizable: true}" + :column-config="{resizable: true,drag: true}" + :row-config="{drag: true}" :scroll-x="{enabled: true, gt: 0}" :scroll-y="{enabled: true, gt: 0}" :data="tableData"> - + diff --git a/package.json b/package.json index 282d7f06ba..fe68a660a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table", - "version": "4.9.26-beta.1", + "version": "4.9.26", "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、拖拽排序,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...", "scripts": { "update": "npm install --legacy-peer-deps", @@ -28,7 +28,7 @@ "style": "lib/style.css", "typings": "types/index.d.ts", "dependencies": { - "vxe-pc-ui": "^4.3.30" + "vxe-pc-ui": "^4.3.31" }, "devDependencies": { "@types/resize-observer-browser": "^0.1.11", diff --git a/packages/table/src/table.ts b/packages/table/src/table.ts index 7869633d5a..c820ddc8da 100644 --- a/packages/table/src/table.ts +++ b/packages/table/src/table.ts @@ -18,7 +18,7 @@ import TableImportPanelComponent from '../module/export/import-panel' import TableExportPanelComponent from '../module/export/export-panel' import TableMenuPanelComponent from '../module/menu/panel' -import type { VxeLoadingComponent, VxeTooltipInstance, VxeTooltipComponent, VxeTabsConstructor, VxeTabsPrivateMethods, ValueOf, VxeComponentSlotType } from 'vxe-pc-ui' +import type { VxeLoadingComponent, VxeTooltipInstance, VxeTooltipComponent, VxeTabsConstructor, VxeTabsPrivateMethods, ValueOf, VxeComponentSlotType, VxeComponentStyleType } from 'vxe-pc-ui' import type { VxeGridConstructor, VxeGridPrivateMethods, VxeTableConstructor, TableReactData, TableInternalData, VxeTablePropTypes, VxeToolbarConstructor, TablePrivateMethods, VxeTablePrivateRef, VxeTablePrivateComputed, VxeTablePrivateMethods, TableMethods, VxeTableMethods, VxeTableDefines, VxeTableEmits, VxeTableProps, VxeColumnPropTypes } from '../../../types' const { getConfig, getIcon, getI18n, renderer, formats, createEvent, globalResize, interceptor, hooks, globalEvents, GLOBAL_EVENT_KEYS, useFns, renderEmptyElement } = VxeUI @@ -683,6 +683,16 @@ export default defineComponent({ } }) + const computeTableStyle = computed(() => { + const { tableData } = reactData + const columnOpts = computeColumnOpts.value + const stys: VxeComponentStyleType = {} + if (columnOpts.drag) { + stys['--vxe-ui-table-drag-column-move-delay'] = `${Math.max(0.06, Math.min(0.3, tableData.length / 800))}s` + } + return stys + }) + const refMaps: VxeTablePrivateRef = { refElem, refTooltip, @@ -4203,11 +4213,25 @@ export default defineComponent({ * @param {Array/Row} rows 行数据 * @param {Boolean} value 是否选中 */ - setCheckboxRow (rows, value) { + setCheckboxRow (rows, checked) { if (rows && !XEUtils.isArray(rows)) { rows = [rows] } - return handleCheckedCheckboxRow(rows, value, true) + return handleCheckedCheckboxRow(rows, checked, true) + }, + setCheckboxRowKey (keys: any, checked) { + const { fullAllDataRowIdData } = internalData + if (!XEUtils.isArray(keys)) { + keys = [keys] + } + const rows: any = [] + keys.forEach((rowid: string) => { + const rowRest = fullAllDataRowIdData[rowid] + if (rowRest) { + rows.push(rowRest.row) + } + }) + return handleCheckedCheckboxRow(rows, checked, true) }, isCheckedByCheckboxRow (row) { const { selectCheckboxMaps } = reactData @@ -4218,9 +4242,27 @@ export default defineComponent({ } return !!selectCheckboxMaps[getRowid($xeTable, row)] }, + isCheckedByCheckboxRowKey (rowid: any) { + const { selectCheckboxMaps } = reactData + const { fullAllDataRowIdData } = internalData + const checkboxOpts = computeCheckboxOpts.value + const { checkField } = checkboxOpts + if (checkField) { + const rowRest = fullAllDataRowIdData[rowid] + if (rowRest) { + return XEUtils.get(rowRest.row, checkField) + } + return false + } + return !!selectCheckboxMaps[rowid] + }, isIndeterminateByCheckboxRow (row) { const { treeIndeterminateMaps } = reactData - return !!treeIndeterminateMaps[getRowid($xeTable, row)] && !tableMethods.isCheckedByCheckboxRow(row) + return !!treeIndeterminateMaps[getRowid($xeTable, row)] && !$xeTable.isCheckedByCheckboxRow(row) + }, + isIndeterminateByCheckboxRowKey (rowid: any) { + const { treeIndeterminateMaps } = reactData + return !!treeIndeterminateMaps[rowid] && !$xeTable.isCheckedByCheckboxRowKey(rowid) }, /** * 多选,切换某一行的选中状态 @@ -4376,7 +4418,18 @@ export default defineComponent({ return nextTick() }, isCheckedByRadioRow (row) { - return $xeTable.eqRow(reactData.selectRadioRow, row) + const { selectRadioRow } = reactData + if (row && selectRadioRow) { + return $xeTable.eqRow(selectRadioRow, row) + } + return false + }, + isCheckedByRadioRowKey (key) { + const { selectRadioRow } = reactData + if (selectRadioRow) { + return key === getRowid($xeTable, selectRadioRow) + } + return false }, /** * 用于单选行,设置某一行为选中状态 @@ -4385,6 +4438,18 @@ export default defineComponent({ setRadioRow (row) { return handleCheckedRadioRow(row, true) }, + /** + * 用于单选行,设置某一行为选中状态 + * @param key 行主键 + */ + setRadioRowKey (rowid: any) { + const { fullAllDataRowIdData } = internalData + const rowRest = fullAllDataRowIdData[rowid] + if (rowRest) { + return handleCheckedRadioRow(rowRest.row, true) + } + return nextTick() + }, /** * 用于当前行,手动清空当前高亮的状态 */ @@ -8118,6 +8183,7 @@ export default defineComponent({ const virtualScrollBars = computeVirtualScrollBars.value const resizableOpts = computeResizableOpts.value const isArea = mouseConfig && mouseOpts.area + const tableStyle = computeTableStyle.value return h('div', { ref: refElem, class: ['vxe-table', 'vxe-table--render-default', `tid_${xID}`, `border--${tableBorder}`, { @@ -8151,9 +8217,7 @@ export default defineComponent({ 'is--virtual-x': scrollXLoad, 'is--virtual-y': scrollYLoad }], - style: { - '--vxe-ui-table-drag-column-move-delay': `${Math.max(0.05, Math.min(0.3, tableData.length / 800))}s` - }, + style: tableStyle, spellcheck: false, onKeydown: keydownEvent }, [