修复已知问题

This commit is contained in:
xuliangzhan
2020-12-08 19:35:03 +08:00
parent 34bddad040
commit 75e7f241ce
11 changed files with 122 additions and 132 deletions

View File

@@ -1739,7 +1739,7 @@ const apis = [
name: 'copyMethod',
desc: '重写单元格复制取值的方法,将单元格复制到剪贴板',
version: 'pro',
type: '(params: { row, column }) => string',
type: '(params: { row, column, cellValue }) => string',
enum: '',
defVal: '',
list: []
@@ -3532,12 +3532,12 @@ const apis = [
list: []
},
{
name: 'isFilter(column)',
name: 'isFilter(fieldOrColumn)',
desc: '判断指定列是否为筛选状态,如果为空则判断所有列',
version: '',
type: 'Boolean',
enum: '',
defVal: 'column?: string | ColumnInfo',
defVal: 'fieldOrColumn?: string | ColumnInfo',
list: []
},
{
@@ -3559,21 +3559,21 @@ const apis = [
list: []
},
{
name: 'setActiveCell(row, field)',
name: 'setActiveCell(row, fieldOrColumn)',
desc: '用于 edit-config激活单元格编辑',
version: '',
type: 'Promise<any>',
enum: '',
defVal: 'row: Row, field: string',
defVal: 'row: Row, fieldOrColumn: string | ColumnInfo',
list: []
},
{
name: 'setSelectCell(row, field)',
name: 'setSelectCell(row, fieldOrColumn)',
desc: '用于 mouse-config.selected选中指定的单元格',
version: '',
type: 'Promise<any>',
enum: '',
defVal: 'row: Row, field: string',
defVal: 'row: Row, fieldOrColumn: string | ColumnInfo',
list: []
},
{
@@ -3829,21 +3829,21 @@ const apis = [
list: []
},
{
name: 'clearSort()',
name: 'clearSort(fieldOrColumn)',
desc: '手动清空排序条件,数据会恢复成未排序的状态',
version: '',
type: 'Promise<any>',
enum: '',
defVal: '',
defVal: 'fieldOrColumn?: string | ColumnConfig',
list: []
},
{
name: 'clearFilter(column)',
name: 'clearFilter(fieldOrColumn)',
desc: '手动清空筛选条件(如果不传 column 则清空所有筛选条件),数据会恢复成未筛选的状态',
version: '',
type: 'Promise<any>',
enum: '',
defVal: 'column?: ColumnConfig',
defVal: 'fieldOrColumn?: string | ColumnConfig',
list: []
},
{
@@ -4063,12 +4063,12 @@ const apis = [
list: []
},
{
name: 'isSort(column)',
name: 'isSort(fieldOrColumn)',
desc: '判断指定列是否为排序状态,如果为空则判断所有列',
version: '',
type: 'Boolean',
enum: '',
defVal: 'column?: string | ColumnInfo',
defVal: 'fieldOrColumn?: string | ColumnInfo',
list: []
},
{

View File

@@ -1,6 +1,6 @@
<template>
<div>
<p class="tip">行分组例如按日期分组显示<span class="red">具体请自行实现该示例仅供参考</span></p>
<p class="tip">行分组<span class="red">具体请自行实现该示例仅供参考</span></p>
<vxe-table
resizable

View File

@@ -97,14 +97,16 @@ export default {
this.loading = true
setTimeout(() => {
this.tableData = [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'vxe-table 从入门到放弃' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women ', age: 23, address: 'vxe-table 从入门到放弃' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Women ', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: 'Women ', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 10007, name: 'Test7', role: 'Test', sex: 'Man ', age: 29, address: 'vxe-table 从入门到放弃' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: 'Man ', age: 35, address: 'vxe-table 从入门到放弃' }
{ id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'vxe-table 从入门到放弃' },
{ id: 10002, name: 'Test2', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: '0', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: '1', age: 23, address: 'vxe-table 从入门到放弃' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: '1', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 10007, name: 'Test7', role: 'Test', sex: '0', age: 29, address: 'vxe-table 从入门到放弃' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: '0', age: 35, address: 'vxe-table 从入门到放弃' },
{ id: 10009, name: 'Test9', role: 'Test', sex: '1', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 100010, name: 'Test10', role: 'Develop', sex: '0', age: 28, address: 'vxe-table 从入门到放弃' }
]
this.loading = false
}, 500)
@@ -127,14 +129,16 @@ export default {
this.loading = true
setTimeout(() => {
this.tableData = [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'vxe-table 从入门到放弃' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women ', age: 23, address: 'vxe-table 从入门到放弃' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Women ', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: 'Women ', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 10007, name: 'Test7', role: 'Test', sex: 'Man ', age: 29, address: 'vxe-table 从入门到放弃' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: 'Man ', age: 35, address: 'vxe-table 从入门到放弃' }
{ id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'vxe-table 从入门到放弃' },
{ id: 10002, name: 'Test2', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: '0', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: '1', age: 23, address: 'vxe-table 从入门到放弃' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: '1', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 10007, name: 'Test7', role: 'Test', sex: '0', age: 29, address: 'vxe-table 从入门到放弃' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: '0', age: 35, address: 'vxe-table 从入门到放弃' },
{ id: 10009, name: 'Test9', role: 'Test', sex: '1', age: 21, address: 'vxe-table 从入门到放弃' },
{ id: 100010, name: 'Test10', role: 'Develop', sex: '0', age: 28, address: 'vxe-table 从入门到放弃' }
]
this.loading = false
}, 500)

View File

@@ -89,7 +89,7 @@
"xe-ajax": "^4.0.5",
"xe-ajax-mock": "^1.12.0",
"xe-clipboard": "^1.10.0",
"xe-utils": "^3.0.3",
"xe-utils": "^3.0.4",
"xlsx": "^0.16.8"
},
"peerDependencies": {

View File

@@ -409,33 +409,31 @@ export default {
* 激活行编辑
*/
_setActiveRow (row) {
return this.setActiveCell(row, XEUtils.find(this.visibleColumn, column => column.editRender).property)
return this.setActiveCell(row, XEUtils.find(this.visibleColumn, column => column.editRender))
},
/**
* 激活单元格编辑
*/
_setActiveCell (row, field) {
return this.scrollToRow(row, true).then(() => {
if (row && field) {
const column = XEUtils.find(this.visibleColumn, column => column.property === field)
if (column && column.editRender) {
const cell = this.getCell(row, column)
if (cell) {
this.handleActived({ row, rowIndex: this.getRowIndex(row), column, columnIndex: this.getColumnIndex(column), cell, $table: this })
this.lastCallTime = Date.now()
}
_setActiveCell (row, fieldOrColumn) {
const column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
if (row && column && column.editRender) {
return this.scrollToRow(row, true).then(() => {
const cell = this.getCell(row, column)
if (cell) {
this.handleActived({ row, rowIndex: this.getRowIndex(row), column, columnIndex: this.getColumnIndex(column), cell, $table: this })
this.lastCallTime = Date.now()
}
}
return this.$nextTick()
})
})
}
return this.$nextTick()
},
/**
* 只对 trigger=dblclick 有效,选中单元格
*/
_setSelectCell (row, field) {
_setSelectCell (row, fieldOrColumn) {
const { tableData, editOpts, visibleColumn } = this
if (row && field && editOpts.trigger !== 'manual') {
const column = XEUtils.find(visibleColumn, column => column.property === field)
const column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
if (row && column && editOpts.trigger !== 'manual') {
const rowIndex = tableData.indexOf(row)
if (rowIndex > -1 && column) {
const cell = this.getCell(row, column)

View File

@@ -110,7 +110,7 @@ function getLabelData ($xetable, opts, columns, datas) {
if (opts.original) {
cellValue = UtilTools.getCellValue(row, column)
} else {
cellValue = UtilTools.getCellLabel(row, column, { $table: $xetable })
cellValue = $xetable.getCellLabel(row, column)
if (column.type === 'html') {
htmlCellElem.innerHTML = cellValue
cellValue = htmlCellElem.innerText.trim()
@@ -165,7 +165,7 @@ function getLabelData ($xetable, opts, columns, datas) {
if (opts.original) {
cellValue = UtilTools.getCellValue(row, column)
} else {
cellValue = UtilTools.getCellLabel(row, column, { $table: $xetable })
cellValue = $xetable.getCellLabel(row, column)
if (column.type === 'html') {
htmlCellElem.innerHTML = cellValue
cellValue = htmlCellElem.innerText.trim()

View File

@@ -175,19 +175,20 @@ export default {
/**
* 清空指定列的筛选条件
* 如果为空则清空所有列的筛选条件
* @param {String} column 列
* @param {String} fieldOrColumn 列
*/
_clearFilter (column) {
if (arguments.length && XEUtils.isString(column)) {
column = this.getColumnByField(column)
}
const filterStore = this.filterStore
if (column) {
this.handleClearFilter(column)
_clearFilter (fieldOrColumn) {
const { filterStore } = this
let column
if (fieldOrColumn) {
column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
if (column) {
this.handleClearFilter(column)
}
} else {
this.visibleColumn.forEach(this.handleClearFilter)
}
if (!column || column !== filterStore.column) {
if (!fieldOrColumn || column !== filterStore.column) {
Object.assign(filterStore, {
isAllSelected: false,
isIndeterminate: false,

View File

@@ -210,7 +210,7 @@ function renderColumn (h, _vm, $xetable, $seq, seq, rowid, fixedType, rowLevel,
'c--ellipsis': showEllipsis
}],
attrs: {
title: showTitle ? UtilTools.getCellLabel(row, column, params) : null
title: showTitle ? $xetable.getCellLabel(row, column) : null
}
}, column.renderCell(h, params))
)

View File

@@ -77,8 +77,8 @@ function getFooterContent (h, params) {
}
function getDefaultCellLabel (params) {
const { row, column } = params
return UtilTools.formatText(UtilTools.getCellLabel(row, column, params), 1)
const { $table, row, column } = params
return UtilTools.formatText($table.getCellLabel(row, column), 1)
}
export const Cell = {

View File

@@ -4,8 +4,9 @@ import Cell from './cell'
import VXETable from '../../v-x-e-table'
import { UtilTools, DomTools } from '../../tools'
import { clearTableAllStatus } from './util'
import formats from '../../v-x-e-table/src/formats'
const { getRowid, getRowkey, setCellValue, getCellLabel, hasChildrenList, getColumnList } = UtilTools
const { getRowid, getRowkey, setCellValue, hasChildrenList, getColumnList } = UtilTools
const { browse, calcHeight, hasClass, addClass, removeClass, getEventTargetNode } = DomTools
const isWebkit = browse['-webkit'] && !browse.edge
@@ -965,15 +966,9 @@ const Methods = {
const sortRests = allSortMethod({ data: tableData, column: firstOrderColumn.column, property: firstOrderColumn.property, order: firstOrderColumn.order, sortList: orderColumns, $table: this })
tableData = XEUtils.isArray(sortRests) ? sortRests : tableData
} else {
const params = { $table: this }
// 兼容 v4
if (sortMultiple) {
tableData = XEUtils.orderBy(tableData, orderColumns.map(({ column, property, order }) => {
return {
field: (column.sortBy ? (XEUtils.isArray(column.sortBy) ? column.sortBy[0] : column.sortBy) : null) || (column.formatter ? (row) => getCellLabel(row, column, params) : property),
order
}
}))
tableData = XEUtils.orderBy(tableData, orderColumns.map(({ column, property, order }) => [(column.sortBy ? (XEUtils.isArray(column.sortBy) ? column.sortBy[0] : column.sortBy) : null) || (column.formatter ? (row) => this.getCellLabel(row, column) : property), order]))
} else {
// 兼容 v2在 v4 中废弃, sortBy 不能为数组
let sortByConfs
@@ -985,12 +980,7 @@ const Methods = {
}
})
}
tableData = XEUtils.orderBy(tableData, sortByConfs || [firstOrderColumn].map(({ column, property, order }) => {
return {
field: column.formatter ? (row) => getCellLabel(row, column, params) : property,
order
}
}))
tableData = XEUtils.orderBy(tableData, sortByConfs || [firstOrderColumn].map(({ column, property, order }) => [column.formatter ? (row) => this.getCellLabel(row, column) : property, order]))
}
}
}
@@ -3028,13 +3018,13 @@ const Methods = {
* 如果为空则清空所有列的排序条件
* @param {String} column 列或字段名
*/
clearSort (column) {
clearSort (fieldOrColumn) {
const { sortOpts } = this
if (column && XEUtils.isString(column)) {
column = this.getColumnByField(column)
}
if (column) {
column.order = null
if (fieldOrColumn) {
const column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
if (column) {
column.order = null
}
} else {
clearAllSort(this)
}
@@ -3048,11 +3038,10 @@ const Methods = {
UtilTools.warn('vxe.error.delFunc', ['getSortColumn', 'getSortColumns'])
return XEUtils.find(this.visibleColumn, column => (column.sortable || column.remoteSort) && column.order)
},
isSort (columnOrField) {
let column
if (columnOrField) {
column = XEUtils.isString(columnOrField) ? this.getColumnByField(columnOrField) : columnOrField
return column && column.sortable && column.order
isSort (fieldOrColumn) {
if (fieldOrColumn) {
const column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
return column && column.sortable && !!column.order
}
return this.getSortColumns().length > 0
},
@@ -3081,15 +3070,14 @@ const Methods = {
},
/**
* 判断指定列是否为筛选状态,如果为空则判断所有列
* @param {String} field 字段名
* @param {String} fieldOrColumn 字段名
*/
isFilter (columnOrField) {
let column
if (columnOrField) {
column = XEUtils.isString(columnOrField) ? this.getColumnByField(columnOrField) : columnOrField
return column && column.filters && column.filters.some(option => option.checked)
isFilter (fieldOrColumn) {
const column = XEUtils.isString(fieldOrColumn) ? this.getColumnByField(fieldOrColumn) : fieldOrColumn
if (column) {
return column.filters && column.filters.some(option => option.checked)
}
return this.getCheckedFilters().length
return this.getCheckedFilters().length > 0
},
/**
* 判断展开行是否懒加载完成
@@ -3935,6 +3923,43 @@ const Methods = {
return bodyElem.$el.querySelector(`.vxe-body--row[rowid="${rowid}"] .${column.id}`)
}
return null
},
getCellLabel (row, column) {
const formatter = column.formatter
const cellValue = UtilTools.getCellValue(row, column)
let cellLabel = cellValue
if (formatter) {
let rest, formatData
const { fullAllDataRowMap } = this
const colid = column.id
const cacheFormat = fullAllDataRowMap.has(row)
const formatParams = { cellValue, row, column }
if (cacheFormat) {
rest = fullAllDataRowMap.get(row)
formatData = rest.formatData
if (!formatData) {
formatData = fullAllDataRowMap.get(row).formatData = {}
}
if (rest && formatData[colid]) {
if (formatData[colid].value === cellValue) {
return formatData[colid].label
}
}
}
if (XEUtils.isString(formatter)) {
const globalFunc = formats.get(formatter)
cellLabel = globalFunc ? globalFunc(formatParams) : ''
} else if (XEUtils.isArray(formatter)) {
const globalFunc = formats.get(formatter[0])
cellLabel = globalFunc ? globalFunc(formatParams, ...formatter.slice(1)) : ''
} else {
cellLabel = formatter(formatParams)
}
if (formatData) {
formatData[colid] = { value: cellValue, label: cellLabel }
}
}
return cellLabel
}
/*************************
* Publish methods

View File

@@ -197,44 +197,6 @@ export const UtilTools = {
getCellValue (row, column) {
return XEUtils.get(row, column.property)
},
getCellLabel (row, column, params) {
const { formatter } = column
const cellValue = UtilTools.getCellValue(row, column)
let cellLabel = cellValue
if (params && formatter) {
let rest, formatData
const { $table } = params
const colid = column.id
const fullAllDataRowMap = $table.fullAllDataRowMap
const cacheFormat = fullAllDataRowMap.has(row)
const formatParams = { cellValue, row, column }
if (cacheFormat) {
rest = fullAllDataRowMap.get(row)
formatData = rest.formatData
if (!formatData) {
formatData = fullAllDataRowMap.get(row).formatData = {}
}
if (rest && formatData[colid]) {
if (formatData[colid].value === cellValue) {
return formatData[colid].label
}
}
}
if (XEUtils.isString(formatter)) {
const globalFunc = formats.get(formatter)
cellLabel = globalFunc ? globalFunc(formatParams) : ''
} else if (XEUtils.isArray(formatter)) {
const globalFunc = formats.get(formatter[0])
cellLabel = globalFunc ? globalFunc(formatParams, ...formatter.slice(1)) : ''
} else {
cellLabel = formatter(formatParams)
}
if (formatData) {
formatData[colid] = { value: cellValue, label: cellLabel }
}
}
return cellLabel
},
setCellValue (row, column, value) {
return XEUtils.set(row, column.property, value)
},