Skip to content

Commit 7b9bfdc

Browse files
committed
releases 4.18.0
1 parent c58d32b commit 7b9bfdc

File tree

9 files changed

+119
-51
lines changed

9 files changed

+119
-51
lines changed

examples/views/grid/GridTest5.vue

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
<template>
22
<div>
3-
<vxe-grid v-bind="gridOptions"></vxe-grid>
3+
<div>
4+
<vxe-radio-group v-model="gridOptions.validConfig.theme">
5+
<vxe-radio-button checked-value="normal" content="简化"></vxe-radio-button>
6+
<vxe-radio-button checked-value="beautify" content="高亮"></vxe-radio-button>
7+
</vxe-radio-group>
8+
9+
<vxe-button @click="validEvent">校验变动数据</vxe-button>
10+
<vxe-button @click="fullValidEvent">校验全量数据</vxe-button>
11+
</div>
12+
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
413
</div>
514
</template>
615

716
<script lang="ts" setup>
8-
import { reactive } from 'vue'
9-
import type { VxeGridProps } from '../../../types'
17+
import { ref, reactive } from 'vue'
18+
import { VxeUI } from '../../../packages'
19+
import { VxeGridProps, VxeTablePropTypes, VxeGridInstance } from '../../../types'
1020
1121
interface RowVO {
1222
id: number
@@ -17,27 +27,71 @@ interface RowVO {
1727
address: string
1828
}
1929
20-
const gridOptions = reactive<VxeGridProps<RowVO>>({
21-
customConfig: {
22-
mode: 'modal',
23-
checkMethod ({ column }) {
24-
return !['seq', 'name'].includes(column.field)
25-
}
30+
const gridRef = ref<VxeGridInstance<RowVO>>()
31+
32+
const gridOptions = reactive<VxeGridProps<RowVO> & { validConfig: VxeTablePropTypes.ValidConfig }>({
33+
border: true,
34+
showOverflow: true,
35+
keepSource: true,
36+
height: 300,
37+
editConfig: {
38+
trigger: 'click',
39+
mode: 'row',
40+
showStatus: true
2641
},
27-
toolbarConfig: {
28-
custom: true
42+
validConfig: {
43+
msgMode: 'full',
44+
theme: 'beautify',
45+
showErrorBackground: true
46+
},
47+
editRules: {
48+
name: [
49+
{ required: true, message: '必须填写' }
50+
],
51+
role: [
52+
{ required: true, message: '必须填写' }
53+
]
2954
},
3055
columns: [
31-
{ field: 'seq', type: 'seq', width: 70 },
32-
{ field: 'name', title: 'Name' },
33-
{ field: 'sex', title: 'Sex' },
34-
{ field: 'age', title: 'Age' }
56+
{ type: 'checkbox', width: 60 },
57+
{ type: 'seq', width: 70 },
58+
{ field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
59+
{ field: 'role', title: 'Role', editRender: { name: 'VxeInput' } },
60+
{ field: 'sex', title: 'Sex', editRender: { name: 'VxeInput' } },
61+
{ field: 'age', title: 'Age', editRender: { name: 'VxeInput' } },
62+
{ field: 'date', title: 'Date', editRender: { name: 'VxeInput' } }
3563
],
3664
data: [
37-
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
38-
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
39-
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
40-
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
65+
{ id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'test abc' },
66+
{ id: 10002, name: '', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
67+
{ id: 10003, name: 'Test3', role: 'PM', sex: '', age: 32, address: 'Shanghai' },
68+
{ id: 10004, name: 'Test4', role: 'Designer', sex: '', age: 23, address: 'test abc' },
69+
{ id: 10005, name: '', role: '', sex: '1', age: 30, address: 'Shanghai' },
70+
{ id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'test abc' }
4171
]
4272
})
73+
74+
const validEvent = async () => {
75+
const $grid = gridRef.value
76+
if ($grid) {
77+
const errMap = await $grid.fullValidate()
78+
if (errMap) {
79+
VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
80+
} else {
81+
VxeUI.modal.message({ status: 'success', content: '校验成功!' })
82+
}
83+
}
84+
}
85+
86+
const fullValidEvent = async () => {
87+
const $grid = gridRef.value
88+
if ($grid) {
89+
const errMap = await $grid.fullValidate(true)
90+
if (errMap) {
91+
VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
92+
} else {
93+
VxeUI.modal.message({ status: 'success', content: '校验成功!' })
94+
}
95+
}
96+
}
4397
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vxe-table",
3-
"version": "4.18.0-beta.0",
3+
"version": "4.18.0-beta.1",
44
"description": "A PC-end table component based on Vxe UI, supporting copy-paste, data pivot table, and high-performance virtual list table solution.",
55
"scripts": {
66
"update": "npm install --legacy-peer-deps",

packages/table/src/body.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default defineVxeComponent({
172172
const cellAlign = align || (compConf ? compConf.tableCellAlign : '') || allAlign
173173
const cellVerticalAlign = XEUtils.eqNull(verticalAlign) ? allVerticalAlign : verticalAlign
174174
const errorValidItem = validErrorMaps[`${rowid}:${colid}`]
175-
const showValidTip = editRules && validOpts.showMessage && (validOpts.message === 'default' ? (height || tableData.length > 1) : validOpts.message === 'inline')
175+
const showValidTip = editRules && validOpts.showErrorMessage && (validOpts.message === 'default' ? (height || tableData.length > 1) : validOpts.message === 'inline')
176176
const tdAttrs: any = { colid }
177177
const cellParams: VxeTableDefines.CellRenderBodyParams & {
178178
$table: VxeTableConstructor<any> & VxeTablePrivateMethods
@@ -469,6 +469,7 @@ export default defineVxeComponent({
469469
'col--dirty': isDirty,
470470
'col--active': editConfig && isEdit && (actived.row === row && (actived.column === column || editOpts.mode === 'row')),
471471
'col--valid-error': !!errorValidItem,
472+
'show--valid-bg': errorValidItem && validOpts.showErrorBackground,
472473
'col--current': currentColumn === column
473474
},
474475
getPropClass(compCellClassName, cellParams),

packages/table/src/table.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { h, ComponentPublicInstance, reactive, ref, Ref, provide, inject, nextTick, Teleport, onActivated, onDeactivated, onBeforeUnmount, onUnmounted, watch, computed, onMounted } from 'vue'
22
import { defineVxeComponent } from '../../ui/src/comp'
33
import XEUtils from 'xe-utils'
4-
import { initTpImg, getTpImg, isPx, isScale, hasClass, addClass, removeClass, getEventTargetNode, getPaddingTopBottomSize, setScrollTop, setScrollLeft, toCssUnit, hasControlKey, checkTargetElement } from '../../ui/src/dom'
4+
import { initTpImg, getTpImg, isPx, isScale, hasClass, addClass, removeClass, scrollTopTo, getEventTargetNode, getPaddingTopBottomSize, setScrollTop, setScrollLeft, toCssUnit, hasControlKey, checkTargetElement } from '../../ui/src/dom'
55
import { getLastZIndex, nextZIndex, hasChildrenList, getFuncText, isEnableConf, formatText, eqEmptyValue } from '../../ui/src/utils'
66
import { VxeUI } from '../../ui'
77
import { createReactData, createInternalData, getRowUniqueId, clearTableAllStatus, getColumnList, toFilters, hasDeepKey, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleRowidOrRow, handleFieldOrColumn, toTreePathSeq, restoreScrollLocation, getRootColumn, getRefElem, getColReMinWidth, createHandleUpdateRowId, createHandleGetRowId, getCalcHeight, getCellRestHeight, getLastChildColumn } from './util'
@@ -147,7 +147,12 @@ export default defineVxeComponent({
147147
})
148148

149149
const computeValidOpts = computed(() => {
150-
return Object.assign({}, getConfig().table.validConfig, props.validConfig)
150+
const opts = Object.assign({}, getConfig().table.validConfig, props.validConfig)
151+
// 兼容老版本
152+
if (XEUtils.isBoolean(opts.showMessage)) {
153+
opts.showErrorMessage = opts.showMessage
154+
}
155+
return opts
151156
})
152157

153158
/**
@@ -4434,28 +4439,6 @@ export default defineVxeComponent({
44344439
})
44354440
}
44364441

4437-
const wheelScrollTopTo = (diffNum: number, cb: (progress: number) => void) => {
4438-
const duration = Math.abs(diffNum)
4439-
const startTime = performance.now()
4440-
let countTop = 0
4441-
const step = (timestamp: number) => {
4442-
let progress = (timestamp - startTime) / duration
4443-
if (progress < 0) {
4444-
progress = 0
4445-
} else if (progress > 1) {
4446-
progress = 1
4447-
}
4448-
const easedProgress = Math.pow(progress, 2)
4449-
const offsetTop = Math.floor((diffNum * easedProgress)) - countTop
4450-
countTop += offsetTop
4451-
cb(offsetTop)
4452-
if (progress < 1) {
4453-
requestAnimationFrame(step)
4454-
}
4455-
}
4456-
requestAnimationFrame(step)
4457-
}
4458-
44594442
const syncGanttScrollTop = (scrollTop: number) => {
44604443
const $xeGanttView = internalData.xeGanttView
44614444
if ($xeGanttView) {
@@ -11809,7 +11792,7 @@ export default defineVxeComponent({
1180911792
fixed: ''
1181011793
})
1181111794
} else {
11812-
wheelScrollTopTo(scrollTop - currScrollTop, (offsetTop: number) => {
11795+
scrollTopTo(scrollTop - currScrollTop, (offsetTop: number) => {
1181311796
internalData.inWheelScroll = true
1181411797
const currTopNum = bodyScrollElem.scrollTop + offsetTop
1181511798
setScrollTop(yHandleEl, currTopNum)
@@ -13017,7 +13000,7 @@ export default defineVxeComponent({
1301713000
/**
1301813001
* 校验提示
1301913002
*/
13020-
props.editRules && validOpts.showMessage && (validOpts.message === 'default' ? !height : validOpts.message === 'tooltip')
13003+
props.editRules && validOpts.showErrorMessage && (validOpts.message === 'default' ? !height : validOpts.message === 'tooltip')
1302113004
? h(VxeUITooltipComponent, {
1302213005
key: 'vtp',
1302313006
ref: refValidTooltip,

packages/ui/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ VxeUI.setConfig({
7575
enterable: true
7676
},
7777
validConfig: {
78-
showMessage: true,
78+
showErrorMessage: true,
7979
autoClear: true,
8080
autoPos: true,
8181
message: 'inline',

packages/ui/src/dom.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,25 @@ export function triggerEvent (targetElem: Element, type: string) {
212212
export function isNodeElement (elem: any): elem is HTMLElement {
213213
return elem && elem.nodeType === 1
214214
}
215+
216+
export function scrollTopTo (diffNum: number, cb: (progress: number) => void) {
217+
const duration = Math.abs(diffNum)
218+
const startTime = performance.now()
219+
let countTop = 0
220+
const step = (timestamp: number) => {
221+
let progress = (timestamp - startTime) / duration
222+
if (progress < 0) {
223+
progress = 0
224+
} else if (progress > 1) {
225+
progress = 1
226+
}
227+
const easedProgress = Math.pow(progress, 2)
228+
const offsetTop = Math.floor((diffNum * easedProgress)) - countTop
229+
countTop += offsetTop
230+
cb(offsetTop)
231+
if (progress < 1) {
232+
requestAnimationFrame(step)
233+
}
234+
}
235+
requestAnimationFrame(step)
236+
}

packages/ui/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ export function formatText (value: any, placeholder?: any) {
5050
export function eqEmptyValue (cellValue: any) {
5151
return cellValue === '' || XEUtils.eqNull(cellValue)
5252
}
53+
54+
export function getDefaultConfig (val1: any, def1: any) {
55+
return XEUtils.eqNull(val1) ? def1 : val1
56+
}

styles/components/table.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,13 +2454,16 @@ $btnThemeList: (
24542454
}
24552455
.vxe-cell--valid-error-theme-normal {
24562456
color: var(--vxe-ui-table-validate-error-color);
2457-
background-color: var(--vxe-ui-table-validate-error-background-color);
2457+
background-color: var(--vxe-ui-table-validate-error-theme-normal-background-color);
24582458
}
24592459
&.col--active,
24602460
&.col--selected {
24612461
position: relative;
24622462
}
24632463
&.col--valid-error {
2464+
&.show--valid-bg {
2465+
background-color: var(--vxe-ui-table-validate-error-cell-background-color);
2466+
}
24642467
.vxe-default-input,
24652468
.vxe-default-textarea,
24662469
.vxe-default-select {
@@ -2651,7 +2654,7 @@ div.vxe-table--tooltip-wrapper {
26512654
&.vxe-table--valid-error {
26522655
padding: 0;
26532656
color: var(--vxe-ui-table-validate-error-color);
2654-
background-color: var(--vxe-ui-table-validate-error-background-color);
2657+
background-color: var(--vxe-ui-table-validate-error-theme-normal-background-color);
26552658
&.old-cell-valid {
26562659
padding: 8px 12px;
26572660
background-color: #f56c6c;

styles/theme/base.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
--vxe-ui-table-menu-background-color: #fff;
8181

8282
--vxe-ui-table-validate-error-color: #f56c6c;
83-
--vxe-ui-table-validate-error-background-color: var(--vxe-ui-layout-background-color);
83+
--vxe-ui-table-validate-error-cell-background-color: rgba(245, 108,108, 0.1);
84+
--vxe-ui-table-validate-error-theme-normal-background-color: var(--vxe-ui-layout-background-color);
8485

8586
/*toolbar*/
8687
--vxe-ui-toolbar-custom-active-background-color: #D9DADB;

0 commit comments

Comments
 (0)