增加参数 custom-config.storage.fixed、增加方法 setColumnFixed、clearColumnFixed

This commit is contained in:
xuliangzhan
2023-06-08 08:31:09 +08:00
parent 26871e614a
commit 2715801ffd
6 changed files with 168 additions and 9 deletions

View File

@@ -0,0 +1,52 @@
name: Bug report
description: 反馈问题
labels: bug
body:
- type: input
id: issue_link
attributes:
label: "可复现的链接:"
description: "一个最小化的重现示例能让我们精确地定位问题,从而快速解决问题。如何创建,点击 v3:[codesandbox](https://codesandbox.io/s/vue-template-916h0)、[jsfiddle](https://jsfiddle.net/86p7Ltny/)、[jsrun](https://jsrun.net/vIyKp/edit) 或 v4:[codesandbox](https://codesandbox.io/s/vxe-table-wentiyanshi-forked-54v2j)、[jsfiddle](https://jsfiddle.net/9qoghkbj/)、[jsrun](https://jsrun.net/K5IKp/edit),将代码示例编辑后保存。"
validations:
required: true
- type: textarea
id: issue_describe
attributes:
label: "问题描述与截图:"
validations:
required: true
- type: markdown
attributes:
value: "在发布问题之前,请仔细阅读所填写的步骤,以确保是详细和清晰的。"
- type: input
id: issue_expect
attributes:
label: "期望的结果:"
- type: input
id: issue_os_version
attributes:
label: "操作系统:"
placeholder: "例如:window10"
validations:
required: true
- type: input
id: issue_browser_version
attributes:
label: "浏览器版本:"
placeholder: "例如:chrome 95.0.4638.69"
validations:
required: true
- type: input
id: issue_vue_version
attributes:
label: "vue 版本:"
placeholder: "例如:2.6.0"
validations:
required: true
- type: input
id: issue_vxe_version
attributes:
label: "vxe-table 版本:"
placeholder: "例如:3.4.0"
validations:
required: true

View File

@@ -0,0 +1,27 @@
name: Feature request
description: 功能需求
labels: enhancement
body:
- type: textarea
id: issue_describe
attributes:
label: "这个需求解决了什么问题:"
validations:
required: true
- type: markdown
attributes:
value: "请先查看[最新文档](https://xuliangzhan_admin.gitee.io/vxe-table/#/table/api),确定该功能是否已有实现"
- type: textarea
id: issue_api_describe
attributes:
label: "建议的 API 是什么样的:"
- type: markdown
attributes:
value: "描述一下希望该功能如何调用"
- type: textarea
id: issue_alternative_solution
attributes:
label: "是否已有其他不错的替代方案:"
- type: markdown
attributes:
value: "如果有其他已实现的方案,可以通过链接或截图描述一下"

View File

@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "4.4.2-beta.2",
"version": "4.4.2-beta.4",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器等...",
"scripts": {
"update": "npm install --legacy-peer-deps",

View File

@@ -104,6 +104,7 @@ export class ColumnInfo {
// 内部属性(一旦被使用,将导致不可升级版本)
halfVisible: false,
defaultVisible: visible,
defaultFixed: _vm.fixed,
checked: false,
halfChecked: false,
disabled: false,

View File

@@ -849,6 +849,7 @@ export default defineComponent({
field?: VxeColumnPropTypes.Field
resizeWidth?: number
visible?: boolean
fixed?: string
}
} = {}
if (!id) {
@@ -868,7 +869,15 @@ export default defineComponent({
if (isCustomFixed) {
const columnFixedStorage = getCustomStorageMap(fixedStorageKey)[id]
if (columnFixedStorage) {
// 开发中...
const colFixeds = columnFixedStorage.split(',')
colFixeds.forEach((fixConf: any) => {
const [field, fixed] = fixConf.split('|')
if (customMap[field]) {
customMap[field].fixed = fixed
} else {
customMap[field] = { field, fixed }
}
})
}
}
// 自定义顺序
@@ -910,7 +919,7 @@ export default defineComponent({
keyMap[colKey] = column
}
})
XEUtils.each(customMap, ({ visible, resizeWidth }, field) => {
XEUtils.each(customMap, ({ visible, resizeWidth, fixed }, field) => {
const column = keyMap[field]
if (column) {
if (XEUtils.isNumber(resizeWidth)) {
@@ -919,6 +928,9 @@ export default defineComponent({
if (XEUtils.isBoolean(visible)) {
column.visible = visible
}
if (fixed) {
column.fixed = fixed
}
}
})
}
@@ -3059,25 +3071,55 @@ export default defineComponent({
footerData: footerTableData.slice(0)
}
},
/**
* 设置为固定列
*/
setColumnFixed (fieldOrColumn, fixed) {
const column = handleFieldOrColumn($xetable, fieldOrColumn)
if (column && column.fixed !== fixed) {
XEUtils.eachTree([column], (column) => {
column.fixed = fixed
})
tablePrivateMethods.saveCustomFixed()
return tableMethods.refreshColumn()
}
return nextTick()
},
/**
* 取消指定固定列
*/
clearColumnFixed (fieldOrColumn) {
const column = handleFieldOrColumn($xetable, fieldOrColumn)
if (column && column.fixed) {
XEUtils.eachTree([column], (column) => {
column.fixed = null
})
tablePrivateMethods.saveCustomFixed()
return tableMethods.refreshColumn()
}
return nextTick()
},
/**
* 隐藏指定列
*/
hideColumn (fieldOrColumn) {
const column = handleFieldOrColumn($xetable, fieldOrColumn)
if (column) {
if (column && column.visible) {
column.visible = false
return tablePrivateMethods.handleCustom()
}
return tablePrivateMethods.handleCustom()
return nextTick()
},
/**
* 显示指定列
*/
showColumn (fieldOrColumn) {
const column = handleFieldOrColumn($xetable, fieldOrColumn)
if (column) {
if (column && !column.visible) {
column.visible = true
return tablePrivateMethods.handleCustom()
}
return tablePrivateMethods.handleCustom()
return nextTick()
},
setColumnWidth (fieldOrColumn, width) {
const column = handleFieldOrColumn($xetable, fieldOrColumn)
@@ -4850,13 +4892,38 @@ export default defineComponent({
localStorage.setItem(resizableStorageKey, XEUtils.toJSONString(columnWidthStorageMap))
}
},
saveCustomFixed () {
const { id, customConfig } = props
const { collectColumn } = internalData
const customOpts = computeCustomOpts.value
const { storage } = customOpts
const isCustomFixed = storage === true || (storage && storage.fixed)
if (customConfig && isCustomFixed) {
const columnFixedStorageMap = getCustomStorageMap(fixedStorageKey)
const colFixeds: any[] = []
if (!id) {
errLog('vxe.error.reqProp', ['id'])
return
}
XEUtils.eachTree(collectColumn, (column) => {
if (column.fixed && column.fixed !== column.defaultFixed) {
const colKey = column.getKey()
if (colKey) {
colFixeds.push(`${colKey}|${column.fixed}`)
}
}
})
columnFixedStorageMap[id] = colFixeds.join(',') || undefined
localStorage.setItem(fixedStorageKey, XEUtils.toJSONString(columnFixedStorageMap))
}
},
saveCustomVisible () {
const { id, customConfig } = props
const { collectColumn } = internalData
const customOpts = computeCustomOpts.value
const { checkMethod, storage } = customOpts
const isVisible = storage === true || (storage && storage.visible)
if (customConfig && isVisible) {
const isCustomVisible = storage === true || (storage && storage.visible)
if (customConfig && isCustomVisible) {
const columnVisibleStorageMap = getCustomStorageMap(visibleStorageKey)
const colHides: any[] = []
const colShows: any[] = []

12
types/table.d.ts vendored
View File

@@ -307,6 +307,16 @@ export interface TablePublicMethods<DT = VxeTableDataRow> {
tableData: DT[]
footerData: DT[][]
}
/**
* 设置指定列为固定列
* @param columnOrField 列对象或字段名
*/
setColumnFixed(fieldOrColumn: VxeColumnPropTypes.Field | VxeTableDefines.ColumnInfo<any>, fixed: VxeColumnPropTypes.Fixed): Promise<void>
/**
* 取消指定的固定列
* @param columnOrField 列对象或字段名
*/
clearColumnFixed(fieldOrColumn: VxeColumnPropTypes.Field | VxeTableDefines.ColumnInfo<any>): Promise<void>
/**
* 隐藏指定列
* @param columnOrField 列对象或字段名
@@ -720,6 +730,7 @@ export interface TablePrivateMethods<D = VxeTableDataRow> {
cacheRowMap(isSource?: boolean): void
saveCustomResizable(isReset?: boolean): void
saveCustomVisible(): void
saveCustomFixed(): void
analyColumnWidth(): void
checkSelectionStatus(): void
handleSelectRow(params: any, value: any, isForce?: boolean): void
@@ -2324,6 +2335,7 @@ export namespace VxeTableDefines {
colSpan: number
halfVisible: boolean
defaultVisible: any
defaultFixed: any
checked: boolean
halfChecked: boolean
disabled: boolean