Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
ee7c31db
提交
ee7c31db
authored
8月 27, 2021
作者:
无木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(table): add `onValid` for editRow
为table的可编辑行添加校验方法
上级
a36825a6
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
40 行增加
和
11 行删除
+40
-11
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+3
-1
EditableCell.vue
...components/Table/src/components/editable/EditableCell.vue
+1
-7
index.ts
src/components/Table/src/components/editable/index.ts
+13
-0
EditRowTable.vue
src/views/demo/table/EditRowTable.vue
+23
-3
没有找到文件。
CHANGELOG.zh_CN.md
浏览文件 @
ee7c31db
### ✨ Features
### ✨ Features
-
**BasicForm**
表单组件新增
`Divider`
,用于较长表单的区域分割
-
**BasicForm**
表单组件新增
`Divider`
,用于较长表单的区域分割
-
**BasicTable**
单元格编辑新增提交回调,将根据回调函数返回的结果来决定是否将数据提交到表格
-
**BasicTable**
-
单元格编辑新增提交回调,将根据回调函数返回的结果来决定是否将数据提交到表格
-
行编辑添加校验方法,允许只校验而不提交值,以便异步保存数据成功后才提交倒表格
### 🐛 Bug Fixes
### 🐛 Bug Fixes
...
...
src/components/Table/src/components/editable/EditableCell.vue
浏览文件 @
ee7c31db
...
@@ -364,13 +364,7 @@
...
@@ -364,13 +364,7 @@
/* eslint-disable */
/* eslint-disable */
props
.
record
.
onSubmitEdit
=
async
()
=>
{
props
.
record
.
onSubmitEdit
=
async
()
=>
{
if
(
isArray
(
props
.
record
?.
submitCbs
))
{
if
(
isArray
(
props
.
record
?.
submitCbs
))
{
const
validFns
=
(
props
.
record
?.
validCbs
||
[]).
map
((
fn
)
=>
fn
());
if
(
!
props
.
record
?.
onValid
?.())
return
;
const
res
=
await
Promise
.
all
(
validFns
);
const
pass
=
res
.
every
((
item
)
=>
!!
item
);
if
(
!
pass
)
return
;
const
submitFns
=
props
.
record
?.
submitCbs
||
[];
const
submitFns
=
props
.
record
?.
submitCbs
||
[];
submitFns
.
forEach
((
fn
)
=>
fn
(
false
,
false
));
submitFns
.
forEach
((
fn
)
=>
fn
(
false
,
false
));
table
.
emit
?.(
'edit-row-end'
);
table
.
emit
?.(
'edit-row-end'
);
...
...
src/components/Table/src/components/editable/index.ts
浏览文件 @
ee7c31db
...
@@ -3,6 +3,7 @@ import type { BasicColumn } from '/@/components/Table/src/types/table';
...
@@ -3,6 +3,7 @@ import type { BasicColumn } from '/@/components/Table/src/types/table';
import
{
h
,
Ref
}
from
'vue'
;
import
{
h
,
Ref
}
from
'vue'
;
import
EditableCell
from
'./EditableCell.vue'
;
import
EditableCell
from
'./EditableCell.vue'
;
import
{
isArray
}
from
'/@/utils/is'
;
interface
Params
{
interface
Params
{
text
:
string
;
text
:
string
;
...
@@ -12,12 +13,23 @@ interface Params {
...
@@ -12,12 +13,23 @@ interface Params {
export
function
renderEditCell
(
column
:
BasicColumn
)
{
export
function
renderEditCell
(
column
:
BasicColumn
)
{
return
({
text
:
value
,
record
,
index
}:
Params
)
=>
{
return
({
text
:
value
,
record
,
index
}:
Params
)
=>
{
record
.
onValid
=
async
()
=>
{
if
(
isArray
(
record
?.
validCbs
))
{
const
validFns
=
(
record
?.
validCbs
||
[]).
map
((
fn
)
=>
fn
());
const
res
=
await
Promise
.
all
(
validFns
);
return
res
.
every
((
item
)
=>
!!
item
);
}
else
{
return
false
;
}
};
record
.
onEdit
=
async
(
edit
:
boolean
,
submit
=
false
)
=>
{
record
.
onEdit
=
async
(
edit
:
boolean
,
submit
=
false
)
=>
{
if
(
!
submit
)
{
if
(
!
submit
)
{
record
.
editable
=
edit
;
record
.
editable
=
edit
;
}
}
if
(
!
edit
&&
submit
)
{
if
(
!
edit
&&
submit
)
{
if
(
!
(
await
record
.
onValid
()))
return
false
;
const
res
=
await
record
.
onSubmitEdit
?.();
const
res
=
await
record
.
onSubmitEdit
?.();
if
(
res
)
{
if
(
res
)
{
record
.
editable
=
false
;
record
.
editable
=
false
;
...
@@ -44,6 +56,7 @@ export function renderEditCell(column: BasicColumn) {
...
@@ -44,6 +56,7 @@ export function renderEditCell(column: BasicColumn) {
export
type
EditRecordRow
<
T
=
Recordable
>
=
Partial
<
export
type
EditRecordRow
<
T
=
Recordable
>
=
Partial
<
{
{
onEdit
:
(
editable
:
boolean
,
submit
?:
boolean
)
=>
Promise
<
boolean
>
;
onEdit
:
(
editable
:
boolean
,
submit
?:
boolean
)
=>
Promise
<
boolean
>
;
onValid
:
()
=>
Promise
<
boolean
>
;
editable
:
boolean
;
editable
:
boolean
;
onCancel
:
Fn
;
onCancel
:
Fn
;
onSubmit
:
Fn
;
onSubmit
:
Fn
;
...
...
src/views/demo/table/EditRowTable.vue
浏览文件 @
ee7c31db
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
import
{
demoListApi
}
from
'/@/api/demo/table'
;
import
{
demoListApi
}
from
'/@/api/demo/table'
;
import
{
treeOptionsListApi
}
from
'/@/api/demo/tree'
;
import
{
treeOptionsListApi
}
from
'/@/api/demo/tree'
;
import
{
cloneDeep
}
from
'lodash-es'
;
import
{
useMessage
}
from
'/@/hooks/web/useMessage'
;
const
columns
:
BasicColumn
[]
=
[
const
columns
:
BasicColumn
[]
=
[
{
{
...
@@ -162,6 +164,7 @@
...
@@ -162,6 +164,7 @@
export
default
defineComponent
({
export
default
defineComponent
({
components
:
{
BasicTable
,
TableAction
},
components
:
{
BasicTable
,
TableAction
},
setup
()
{
setup
()
{
const
{
createMessage
:
msg
}
=
useMessage
();
const
currentEditKeyRef
=
ref
(
''
);
const
currentEditKeyRef
=
ref
(
''
);
const
[
registerTable
]
=
useTable
({
const
[
registerTable
]
=
useTable
({
title
:
'可编辑行示例'
,
title
:
'可编辑行示例'
,
...
@@ -192,9 +195,26 @@
...
@@ -192,9 +195,26 @@
}
}
async
function
handleSave
(
record
:
EditRecordRow
)
{
async
function
handleSave
(
record
:
EditRecordRow
)
{
const
pass
=
await
record
.
onEdit
?.(
false
,
true
);
// 校验
if
(
pass
)
{
msg
.
loading
({
content
:
'正在保存...'
,
duration
:
0
,
key
:
'saving'
});
currentEditKeyRef
.
value
=
''
;
const
valid
=
await
record
.
onValid
?.();
if
(
valid
)
{
try
{
const
data
=
cloneDeep
(
record
.
editValueRefs
);
console
.
log
(
data
);
//TODO 此处将数据提交给服务器保存
// ...
// 保存之后提交编辑状态
const
pass
=
await
record
.
onEdit
?.(
false
,
true
);
if
(
pass
)
{
currentEditKeyRef
.
value
=
''
;
}
msg
.
success
({
content
:
'数据已保存'
,
key
:
'saving'
});
}
catch
(
error
)
{
msg
.
error
({
content
:
'保存失败'
,
key
:
'saving'
});
}
}
else
{
msg
.
error
({
content
:
'请填写正确的数据'
,
key
:
'saving'
});
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论