|
@ -123,7 +123,7 @@ import GridBody from './GridBody.vue'; |
|
|
import GridPagination from './GridPagination.vue'; |
|
|
import GridPagination from './GridPagination.vue'; |
|
|
import GridEditor from './GridEditor.vue'; |
|
|
import GridEditor from './GridEditor.vue'; |
|
|
import GridView from './GridView.vue'; |
|
|
import GridView from './GridView.vue'; |
|
|
import { selectedMode as selectedMode_ } from './ts/grid.ts'; |
|
|
import { selectedMode as selectedMode_, getMergeColumns, sortByProperties } from './ts/grid.ts'; |
|
|
|
|
|
|
|
|
import { columnDefaultProps } from './ts/grid.ts'; |
|
|
import { columnDefaultProps } from './ts/grid.ts'; |
|
|
|
|
|
|
|
@ -177,6 +177,13 @@ const props = defineProps({ |
|
|
foreignKey: { type: String, default: 'parent' }, // 数据外键(常规表格模式时,该字段暂时无用,将来可用作多个表格的数据关系字段。树形表格模式时,该字段为构建树数据的关系字段) |
|
|
foreignKey: { type: String, default: 'parent' }, // 数据外键(常规表格模式时,该字段暂时无用,将来可用作多个表格的数据关系字段。树形表格模式时,该字段为构建树数据的关系字段) |
|
|
refreshData: { type: Boolean, default: false }, // 新增、删除、修改成功后是否刷新数据列表,默认不刷新但是新增修改后台必须返回对应的行数据对象,删除则必须返回删除的记录集primaryKey集合。 |
|
|
refreshData: { type: Boolean, default: false }, // 新增、删除、修改成功后是否刷新数据列表,默认不刷新但是新增修改后台必须返回对应的行数据对象,删除则必须返回删除的记录集primaryKey集合。 |
|
|
dbClickOperation: { type: String, default: 'view' }, // 默认的双击操作:可填写内置或自定义按钮name,执行的操作为按钮对应的click,固定值提供:expand(展开双击的行)、none(双击不执行任何动作) |
|
|
dbClickOperation: { type: String, default: 'view' }, // 默认的双击操作:可填写内置或自定义按钮name,执行的操作为按钮对应的click,固定值提供:expand(展开双击的行)、none(双击不执行任何动作) |
|
|
|
|
|
appendRows: { |
|
|
|
|
|
// 表格追加行,添加到当前表格数据行尾,可添加多行,支持跨行跨列配置,用于添加合计或者额外信息。 |
|
|
|
|
|
type: Array, |
|
|
|
|
|
default: () => { |
|
|
|
|
|
return []; |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
sortBy: { |
|
|
sortBy: { |
|
|
type: Array, |
|
|
type: Array, |
|
|
default: () => { |
|
|
default: () => { |
|
@ -321,7 +328,8 @@ const rawColumns = ref(props.columns); |
|
|
const tableColumnsMap = ref(arrayToMap('name', rawColumns.value)); |
|
|
const tableColumnsMap = ref(arrayToMap('name', rawColumns.value)); |
|
|
const rowKey_ = '_rowKey_'; // 行数据中前端附加的UUID字段名 |
|
|
const rowKey_ = '_rowKey_'; // 行数据中前端附加的UUID字段名 |
|
|
const queryFormFieldsMap = arrayToMap('name', props.queryFormFields); |
|
|
const queryFormFieldsMap = arrayToMap('name', props.queryFormFields); |
|
|
const tableColumns = ref(columnDefaultProps(rawColumns.value)); |
|
|
const tableColumns = ref(columnDefaultProps(rawColumns.value, props.sortNo)); |
|
|
|
|
|
const mergeColumns = getMergeColumns(tableColumns.value); |
|
|
const url = { |
|
|
const url = { |
|
|
dataUrl: props.dataUrl, |
|
|
dataUrl: props.dataUrl, |
|
|
fetchDataUrl: props.fetchDataUrl, |
|
|
fetchDataUrl: props.fetchDataUrl, |
|
@ -338,7 +346,7 @@ watch( |
|
|
() => props.columns, |
|
|
() => props.columns, |
|
|
(newVal, oldVal) => { |
|
|
(newVal, oldVal) => { |
|
|
rawColumns.value = newVal; |
|
|
rawColumns.value = newVal; |
|
|
tableColumns.value = columnDefaultProps(rawColumns.value); |
|
|
tableColumns.value = columnDefaultProps(rawColumns.value, props.sortNo); |
|
|
table.columns = tableColumns.value; |
|
|
table.columns = tableColumns.value; |
|
|
if (tableColumns.value && tableColumns.value.length > rawColumns.value.length) { |
|
|
if (tableColumns.value && tableColumns.value.length > rawColumns.value.length) { |
|
|
headerRef.value?.handlerMoreRowColumnTitle(); |
|
|
headerRef.value?.handlerMoreRowColumnTitle(); |
|
@ -382,6 +390,7 @@ const table = reactive({ |
|
|
inFullscreen: false, // 表格当前是否为全屏模式 |
|
|
inFullscreen: false, // 表格当前是否为全屏模式 |
|
|
bodyEditStatus: 'none', // 表格内容区编辑状态:none(不处于编辑状态)、rowEdit(行编辑状态)、rowsEdit(所有行编辑状态) |
|
|
bodyEditStatus: 'none', // 表格内容区编辑状态:none(不处于编辑状态)、rowEdit(行编辑状态)、rowsEdit(所有行编辑状态) |
|
|
cellSelected: {}, // 单元格选中记录 |
|
|
cellSelected: {}, // 单元格选中记录 |
|
|
|
|
|
mergeRecords: {}, // 行数据合并记录 |
|
|
}); |
|
|
}); |
|
|
provide('table', table); |
|
|
provide('table', table); |
|
|
|
|
|
|
|
@ -559,7 +568,7 @@ const tableFullscreenFun = (value) => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const rowClick = (evt: any, row: any, index: any) => { |
|
|
const rowClick = (evt: any, row: any, index: any) => { |
|
|
if (table.bodyEditStatus === 'none') { |
|
|
if (table.bodyEditStatus === 'none' && props.selectedMode !== selectedMode_.none) { |
|
|
// 非树形表格行点击选中与checkbox绑定,即行选中时checkbox也勾选,checkbox勾选时行选中。 |
|
|
// 非树形表格行点击选中与checkbox绑定,即行选中时checkbox也勾选,checkbox勾选时行选中。 |
|
|
if (!evt.ctrlKey) { |
|
|
if (!evt.ctrlKey) { |
|
|
clearSelected(); |
|
|
clearSelected(); |
|
@ -574,7 +583,7 @@ const rowClick = (evt: any, row: any, index: any) => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
const rowDbClick = (evt, row, index) => { |
|
|
const rowDbClick = (evt, row, index) => { |
|
|
if (table.bodyEditStatus === 'none') { |
|
|
if (table.bodyEditStatus === 'none' && props.selectedMode !== selectedMode_.none) { |
|
|
if (props.onRowDbClick) { |
|
|
if (props.onRowDbClick) { |
|
|
emit('rowDbClick', { grid: instance, evt, row, index }); |
|
|
emit('rowDbClick', { grid: instance, evt, row, index }); |
|
|
} else if (props.dbClickOperation === 'view') { |
|
|
} else if (props.dbClickOperation === 'view') { |
|
@ -618,13 +627,7 @@ const onResize = () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
type CriteriaType = { |
|
|
|
|
|
fieldName: string; |
|
|
|
|
|
operator: OperatorTypeEnum; |
|
|
|
|
|
value: any; |
|
|
|
|
|
}; |
|
|
|
|
|
let queryCriteria = { ...props.queryCriteria }; |
|
|
let queryCriteria = { ...props.queryCriteria }; |
|
|
|
|
|
|
|
|
const buildCriteria = (value, fieldName) => { |
|
|
const buildCriteria = (value, fieldName) => { |
|
|
const queryOperator = queryFormFieldsMap.get(fieldName)['queryOperator']; |
|
|
const queryOperator = queryFormFieldsMap.get(fieldName)['queryOperator']; |
|
|
if (!Tools.isEmpty(queryOperator)) { |
|
|
if (!Tools.isEmpty(queryOperator)) { |
|
@ -879,9 +882,15 @@ const initRowDataExtraProperty = (rowData) => { |
|
|
* @param rows 数据行集合 |
|
|
* @param rows 数据行集合 |
|
|
*/ |
|
|
*/ |
|
|
const setRowDataExtraProperty = (rows: []) => { |
|
|
const setRowDataExtraProperty = (rows: []) => { |
|
|
|
|
|
if (mergeColumns.length > 0 && !props.tree) { |
|
|
|
|
|
// 如果存在需要合并的字段,并且不是树表格,重新对数据进行排序 |
|
|
|
|
|
table.mergeRecords = {}; |
|
|
|
|
|
sortByProperties(rows, mergeColumns); |
|
|
|
|
|
} |
|
|
if (rows && rows.length > 0) { |
|
|
if (rows && rows.length > 0) { |
|
|
rows.forEach((item: any, index) => { |
|
|
rows.forEach((item: any, index) => { |
|
|
initRowDataExtraProperty(item); |
|
|
initRowDataExtraProperty(item); |
|
|
|
|
|
addMergeRecords(item); |
|
|
if (item[rowDataExtraPropertyName.ticked] === true) { |
|
|
if (item[rowDataExtraPropertyName.ticked] === true) { |
|
|
item[rowDataExtraPropertyName.tickedCount] = 1; |
|
|
item[rowDataExtraPropertyName.tickedCount] = 1; |
|
|
} else if (item[rowDataExtraPropertyName.tickedCount] === false) { |
|
|
} else if (item[rowDataExtraPropertyName.tickedCount] === false) { |
|
@ -921,6 +930,26 @@ const setOldValue = (rowData) => { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
/** |
|
|
|
|
|
* name: { 上海: [2,4], 北京: [3,5,1] } |
|
|
|
|
|
* desc: { 天安门: [5,1] } |
|
|
|
|
|
*/ |
|
|
|
|
|
const addMergeRecords = (rowData) => { |
|
|
|
|
|
if (mergeColumns.length > 0 && !props.tree) { |
|
|
|
|
|
mergeColumns.forEach((columnName) => { |
|
|
|
|
|
const tmpArr = [rowData[rowDataExtraPropertyName.rowKey]]; |
|
|
|
|
|
if (table.mergeRecords[columnName]) { |
|
|
|
|
|
if (table.mergeRecords[columnName][rowData[columnName]]) { |
|
|
|
|
|
table.mergeRecords[columnName][rowData[columnName]].push(rowData[rowDataExtraPropertyName.rowKey]); |
|
|
|
|
|
} else { |
|
|
|
|
|
table.mergeRecords[columnName][rowData[columnName]] = tmpArr; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
table.mergeRecords[columnName] = { [rowData[columnName]]: tmpArr }; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
watchEffect(() => { |
|
|
watchEffect(() => { |
|
|
url.dataUrl = props.dataUrl; |
|
|
url.dataUrl = props.dataUrl; |
|
|