Skip to content

Commit

Permalink
releases 4.10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Feb 11, 2025
1 parent a0b777f commit 9315367
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 265 deletions.
276 changes: 99 additions & 177 deletions examples/views/grid/GridTest.vue
Original file line number Diff line number Diff line change
@@ -1,203 +1,125 @@
<template>
<div>
<vxe-select v-model="rowSize" :options="dataOptions" @change="loadData()"></vxe-select>
<vxe-grid v-bind="gridOptions"></vxe-grid>
<vxe-grid ref="gridRef" v-bind="gridOptions">
<template #action="{ row }">
<template v-if="hasEditStatus(row)">
<vxe-button @click="saveRowEvent(row)">保存</vxe-button>
<vxe-button @click="cancelRowEvent()">取消</vxe-button>
</template>
<template v-else>
<vxe-button @click="editRowEvent(row)">编辑</vxe-button>
</template>
</template>
</vxe-grid>
</div>
</template>

<script lang="ts" setup>
import { ref, reactive, nextTick } from 'vue'
import { ref, reactive } from 'vue'
import { VxeUI } from '../../../packages'
import { VxeGridProps, VxeColumnPropTypes } from '../../../types'
import { VxeGridInstance, VxeGridProps } from '../../../types'
interface RowVO {
id: number
[key: string]: string | number | boolean | any[]
id: number;
name: string;
role: string;
sex: string;
age: number;
address: string;
}
const rowSize = ref(100)
const dataOptions = ref([
{ label: '加载 3 行', value: 3 },
{ label: '加载 20 行', value: 20 },
{ label: '加载 100 行', value: 100 },
{ label: '加载 500 行', value: 500 },
{ label: '加载 1000 行', value: 1000 },
{ label: '加载 5000 行', value: 5000 },
{ label: '加载 10000 行', value: 10000 },
{ label: '加载 30000 行', value: 30000 }
])
const imgUrlCellRender = reactive<VxeColumnPropTypes.CellRender>({
name: 'VxeImage',
props: {
width: 36,
height: 36
}
})
const gridRef = ref<VxeGridInstance<RowVO>>()
const gridOptions = reactive<VxeGridProps<RowVO>>({
border: true,
showOverflow: true,
loading: false,
height: 800,
columnConfig: {
resizable: true
},
scrollX: {
enabled: true,
gt: 0
height: 400,
editConfig: {
trigger: 'click',
mode: 'row'
},
scrollY: {
enabled: true,
gt: 0
editRules: {
name: [{ required: true, message: '请填写名称', trigger: 'blur' }]
},
columns: [
{ type: 'checkbox', width: 60 },
{ title: '列0', field: 'col0', width: 100 },
{ title: '列1', field: 'imgUrl', width: 80, cellRender: imgUrlCellRender },
{ title: '列2', field: 'col2', width: 160 },
{ title: '列3', field: 'col3', width: 200 },
{ title: '列4', field: 'col4', width: 140 },
{ title: '列5', field: 'col5', width: 300 },
{ title: '列6', field: 'col6', width: 160 },
{ title: '列7', field: 'col7', width: 120 },
{ title: '列8', field: 'col8', width: 400 },
{ title: '列9', field: 'col9', width: 160 },
{ title: '列10', field: 'col10', width: 160 },
{ title: '列11', field: 'col11', width: 180 },
{ title: '列12', field: 'col12', width: 160 },
{ title: '列13', field: 'col13', width: 80 },
{ title: '列14', field: 'col14', width: 120 },
{ title: '列15', field: 'col15', width: 360 },
{ title: '列16', field: 'col16', width: 150 },
{ title: '列17', field: 'col17', width: 380 },
{ title: '列18', field: 'col18', width: 100 },
{ title: '列19', field: 'col19', width: 290 },
{ title: '列20', field: 'col20', width: 80 },
{ title: '列21', field: 'col21', width: 100 },
{ title: '列22', field: 'col22', width: 120 },
{ title: '列23', field: 'col23', width: 270 },
{ title: '列24', field: 'col24', width: 330 },
{ title: '列25', field: 'col25', width: 460 },
{ title: '列26', field: 'col26', width: 280 },
{ title: '列27', field: 'col27', width: 220 },
{ title: '列28', field: 'col28', width: 120 },
{ title: '列29', field: 'col29', width: 180 },
{ title: '列30', field: 'col30', width: 500 },
{ title: '列31', field: 'col31', width: 600 },
{ title: '列32', field: 'col32', width: 100 },
{ title: '列33', field: 'col33', width: 490 },
{ title: '列34', field: 'col34', width: 100 },
{ title: '列35', field: 'col35', width: 150 },
{ title: '列36', field: 'col36', width: 800 },
{ title: '列37', field: 'col37', width: 400 },
{ title: '列38', field: 'col38', width: 800 },
{ title: '列39', field: 'col39', width: 360 },
{ title: '列40', field: 'col40', width: 420 },
{ title: '列41', field: 'col41', width: 100 },
{ title: '列42', field: 'col42', width: 120 },
{ title: '列43', field: 'col43', width: 280 },
{ title: '列44', field: 'col44', width: 170 },
{ title: '列45', field: 'col45', width: 370 },
{ title: '列46', field: 'col46', width: 420 },
{ title: '列47', field: 'col47', width: 170 },
{ title: '列48', field: 'col48', width: 400 },
{ title: '列49', field: 'col49', width: 220 },
{ title: '列50', field: 'col50', width: 170 },
{ title: '列51', field: 'col51', width: 160 },
{ title: '列52', field: 'col52', width: 500 },
{ title: '列53', field: 'col53', width: 280 },
{ title: '列54', field: 'col54', width: 170 },
{ title: '列55', field: 'col55', width: 370 },
{ title: '列56', field: 'col56', width: 120 },
{ title: '列57', field: 'col57', width: 170 },
{ title: '列58', field: 'col58', width: 400 },
{ title: '列59', field: 'col59', width: 220 },
{ title: '列60', field: 'col60', width: 650 },
{ title: '列61', field: 'col61', width: 600 },
{ title: '列62', field: 'col62', width: 100 },
{ title: '列63', field: 'col63', width: 490 },
{ title: '列64', field: 'col64', width: 100 },
{ title: '列65', field: 'col65', width: 150 },
{ title: '列66', field: 'col66', width: 800 },
{ title: '列67', field: 'col67', width: 400 },
{ title: '列68', field: 'col68', width: 800 },
{ title: '列69', field: 'col69', width: 360 },
{ title: '列70', field: 'col70', width: 650 },
{ title: '列71', field: 'col71', width: 600 },
{ title: '列72', field: 'col72', width: 100 },
{ title: '列73', field: 'col73', width: 490 },
{ title: '列74', field: 'col74', width: 100 },
{ title: '列75', field: 'col75', width: 150 },
{ title: '列76', field: 'col76', width: 800 },
{ title: '列77', field: 'col77', width: 400 },
{ title: '列78', field: 'col78', width: 800 },
{ title: '列79', field: 'col79', width: 360 },
{ title: '列80', field: 'col80', width: 650 },
{ title: '列81', field: 'col81', width: 600 },
{ title: '列82', field: 'col82', width: 100 },
{ title: '列83', field: 'col83', width: 490 },
{ title: '列84', field: 'col84', width: 100 },
{ title: '列85', field: 'col85', width: 150 },
{ title: '列86', field: 'col86', width: 800 },
{ title: '列87', field: 'col87', width: 400 },
{ title: '列88', field: 'col88', width: 800 },
{ title: '列89', field: 'col89', width: 360 },
{ title: '列90', field: 'col90', width: 650 },
{ title: '列91', field: 'col91', width: 600 },
{ title: '列92', field: 'col92', width: 100 },
{ title: '列93', field: 'col93', width: 490 },
{ title: '列94', field: 'col94', width: 100 },
{ title: '列95', field: 'col95', width: 150 },
{ title: '列96', field: 'col96', width: 800 },
{ title: '列97', field: 'col97', width: 400 },
{ title: '列98', field: 'col98', width: 800 },
{ title: '列99', field: 'col99', width: 360 },
{ title: '列100', field: 'col100', width: 360 }
{ type: 'seq', width: 70 },
{ field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
{ field: 'sex', title: 'Sex', editRender: { name: 'VxeInput' } },
{ field: 'age', title: 'Age', editRender: { name: 'VxeInput' } },
{ title: '操作', slots: { default: 'action' } }
],
data: []
data: [
{
id: 10001,
name: 'Test1',
role: 'Develop',
sex: 'Man',
age: 28,
address: 'test abc'
},
{
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: 24,
address: 'Shanghai'
}
]
})
// 模拟行数据
const loadData = () => {
gridOptions.loading = true
setTimeout(() => {
const dataList: RowVO[] = []
for (let i = 0; i < rowSize.value; i++) {
const item: RowVO = {
id: 10000 + i,
imgUrl: i % 3 === 0 ? 'https://vxeui.com/resource/img/546.gif' : 'https://vxeui.com/resource/img/673.gif'
}
for (let j = 0; j < 100; j++) {
if (i % 9 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容9内容9 内容9内容9内容9 内容9内容9内容9内容9 内容9内容9内容9内容9 内容9内容9内容9 内容9内容9`
} else if (i % 8 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容8内容8内容8内容8`
} else if (i % 7 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容7内容7`
} else if (i % 6 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容6内容6内容6内容6内容6内容6内容6内容6`
} else if (i % 5 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容5内容5内容5内容5内容5`
} else if (i % 4 === 0) {
item[`col${j}`] = `值_${i}_${j} 内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4`
} else {
item[`col${j}`] = `值_${i}_${j}`
}
}
dataList.push(item)
}
const hasEditStatus = (row: RowVO) => {
const $grid = gridRef.value
if ($grid) {
return $grid.isEditByRow(row)
}
}
const editRowEvent = (row: RowVO) => {
const $grid = gridRef.value
if ($grid) {
$grid.setEditRow(row)
}
}
const startTime = Date.now()
gridOptions.data = dataList
gridOptions.loading = false
nextTick(() => {
VxeUI.modal.message({
content: `加载时间 ${Date.now() - startTime} 毫秒`,
status: 'success'
})
const saveRowEvent = (row: RowVO) => {
const $grid = gridRef.value
if ($grid) {
$grid.clearEdit().then(() => {
gridOptions.loading = true
setTimeout(() => {
gridOptions.loading = false
VxeUI.modal.message({
content: `保存成功!name=${row.name}`,
status: 'success'
})
}, 300)
})
}, 350)
}
}
loadData()
const cancelRowEvent = () => {
const $grid = gridRef.value
if ($grid) {
$grid.clearEdit()
}
}
</script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "4.10.11",
"version": "4.10.12",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、拖拽排序,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down
15 changes: 7 additions & 8 deletions packages/table/module/edit/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,20 @@ hooks.add('tableEditModule', {
$columnIndex: $xeTable.getVMColumnIndex(column)
}, evnt || null)
}
nextTick(() => {
if (mouseConfig && mouseOpts.area && $xeTable.handleRecalculateCellAreas) {
return $xeTable.handleRecalculateCellAreas()
}
})
focused.row = null
focused.column = null
if (validOpts.autoClear) {
if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
if ($xeTable.clearValidate) {
return $xeTable.clearValidate()
}
}
}
focused.row = null
focused.column = null
return nextTick()
return nextTick().then(() => {
if (mouseConfig && mouseOpts.area && $xeTable.handleRecalculateCellAreas) {
return $xeTable.handleRecalculateCellAreas()
}
})
}

editMethods = {
Expand Down
11 changes: 11 additions & 0 deletions packages/table/module/validator/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ hooks.add('tableValidatorModule', {
const beginValidate = (rows: any, cols: VxeTableDefines.ColumnInfo[] | null, cb: any, isFull?: boolean): Promise<any> => {
const validRest: any = {}
const { editRules, treeConfig } = props
const { editStore, pendingRowMaps } = reactData
const { afterFullData } = internalData
const { removeMaps } = editStore
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const validOpts = computeValidOpts.value
Expand Down Expand Up @@ -143,6 +145,15 @@ hooks.add('tableValidatorModule', {
if (editRules) {
const columns = cols && cols.length ? cols : $xeTable.getColumns()
const handleVaild = (row: any) => {
const rowid = getRowid($xeTable, row)
// 是否删除
if (removeMaps[rowid]) {
return
}
// 是否标记删除
if (pendingRowMaps[rowid]) {
return
}
if (isFull || !validRuleErr) {
const colVailds: any[] = []
columns.forEach((column) => {
Expand Down
Loading

0 comments on commit 9315367

Please sign in to comment.