Skip to content

Commit

Permalink
releases 4.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Nov 7, 2024
1 parent 9f88b48 commit ad99b67
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 218 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "4.8.4",
"version": "4.8.5",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down Expand Up @@ -28,7 +28,7 @@
"style": "lib/style.css",
"typings": "types/index.d.ts",
"dependencies": {
"vxe-pc-ui": "^4.2.44"
"vxe-pc-ui": "^4.2.45"
},
"devDependencies": {
"@types/resize-observer-browser": "^0.1.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export default defineComponent({
$xeTable.openExport(btnParams)
break
case 'reset_custom':
return $xeTable.resetColumn(true)
return $xeTable.resetCustom(true)
case '_init':
case 'reload':
case 'query': {
Expand Down
139 changes: 136 additions & 3 deletions packages/table/module/custom/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XEUtils from 'xe-utils'

import type { TableCustomMethods, TableCustomPrivateMethods, VxeColumnPropTypes, VxeTableDefines } from '../../../../types'

const tableCustomMethodKeys: (keyof TableCustomMethods)[] = ['openCustom', 'closeCustom']
const tableCustomMethodKeys: (keyof TableCustomMethods)[] = ['openCustom', 'closeCustom', 'saveCustom', 'cancelCustom', 'resetCustom', 'toggleCustomAllCheckbox', 'setCustomAllCheckbox']

VxeUI.hooks.add('tableCustomModule', {
setupTable ($xeTable) {
Expand All @@ -22,7 +22,7 @@ VxeUI.hooks.add('tableCustomModule', {
if (el) {
tableHeight = el.clientHeight - 28
}
customStore.maxHeight = Math.max(4, tableHeight)
customStore.maxHeight = Math.max(88, tableHeight)
}

const openCustom = () => {
Expand Down Expand Up @@ -63,9 +63,142 @@ VxeUI.hooks.add('tableCustomModule', {
return nextTick()
}

const saveCustom = () => {
const { customColumnList } = reactData
const customOpts = computeCustomOpts.value
const { allowVisible, allowSort, allowFixed, allowResizable } = customOpts
XEUtils.eachTree(customColumnList, (column, index, items, path, parent) => {
if (parent) {
// 更新子列信息
column.fixed = parent.fixed
} else {
if (allowSort) {
const sortIndex = index + 1
column.renderSortNumber = sortIndex
}
if (allowFixed) {
column.fixed = column.renderFixed
}
}
if (allowResizable) {
if (column.renderVisible && (!column.children || column.children.length)) {
if (column.renderResizeWidth !== column.renderWidth) {
column.resizeWidth = column.renderResizeWidth
column.renderWidth = column.renderResizeWidth
}
}
}
if (allowVisible) {
column.visible = column.renderVisible
}
})
return $xeTable.saveCustomStore('confirm')
}

const cancelCustom = () => {
const { customColumnList, customStore } = reactData
const { oldSortMaps, oldFixedMaps, oldVisibleMaps } = customStore
const customOpts = computeCustomOpts.value
const { allowVisible, allowSort, allowFixed, allowResizable } = customOpts
XEUtils.eachTree(customColumnList, column => {
const colid = column.getKey()
const visible = !!oldVisibleMaps[colid]
const fixed = oldFixedMaps[colid] || ''
if (allowVisible) {
column.renderVisible = visible
column.visible = visible
}
if (allowFixed) {
column.renderFixed = fixed
column.fixed = fixed
}
if (allowSort) {
column.renderSortNumber = oldSortMaps[colid] || 0
}
if (allowResizable) {
column.renderResizeWidth = column.renderWidth
}
}, { children: 'children' })
return nextTick()
}

const setCustomAllCheckbox = (checked: boolean) => {
const { customStore } = reactData
const { customColumnList } = reactData
const customOpts = computeCustomOpts.value
const { checkMethod, visibleMethod } = customOpts
const isAll = !!checked
if (customOpts.immediate) {
XEUtils.eachTree(customColumnList, (column) => {
if (visibleMethod && !visibleMethod({ column })) {
return
}
if (checkMethod && !checkMethod({ column })) {
return
}
column.visible = isAll
column.renderVisible = isAll
column.halfVisible = false
})
customStore.isAll = isAll
$xeTable.handleCustom()
$xeTable.saveCustomStore('update:visible')
} else {
XEUtils.eachTree(customColumnList, (column) => {
if (visibleMethod && !visibleMethod({ column })) {
return
}
if (checkMethod && !checkMethod({ column })) {
return
}
column.renderVisible = isAll
column.halfVisible = false
})
customStore.isAll = isAll
}
$xeTable.checkCustomStatus()
return nextTick()
}

const customMethods: TableCustomMethods = {
openCustom,
closeCustom
closeCustom,
saveCustom,
cancelCustom,
resetCustom (options) {
const { collectColumn } = internalData
const customOpts = computeCustomOpts.value
const { checkMethod } = customOpts
const opts: VxeTableDefines.VxeTableCustomStorageObj = Object.assign({
visible: true,
resizable: options === true,
fixed: options === true,
sort: options === true
}, options)
XEUtils.eachTree(collectColumn, (column) => {
if (opts.resizable) {
column.resizeWidth = 0
}
if (opts.fixed) {
column.fixed = column.defaultFixed
}
if (opts.sort) {
column.renderSortNumber = column.sortNumber
}
if (!checkMethod || checkMethod({ column })) {
column.visible = column.defaultVisible
}
column.renderResizeWidth = column.renderWidth
})
$xeTable.saveCustomStore('reset')
return $xeTable.handleCustom()
},
toggleCustomAllCheckbox () {
const { customStore } = reactData
const isAll = !customStore.isAll
return setCustomAllCheckbox(isAll)
},
setCustomAllCheckbox
}

const checkCustomStatus = () => {
Expand Down
Loading

0 comments on commit ad99b67

Please sign in to comment.