fix actions为undefined时处理

This commit is contained in:
wkj 2024-04-30 10:55:58 +08:00
parent 2b308dfb27
commit 1c5800eb93
2 changed files with 29 additions and 4 deletions

View File

@ -15,7 +15,7 @@ export default OakComponent({
moreItems: [], moreItems: [],
}, },
lifetimes: { lifetimes: {
// 在Tabel组件render之后 才走进这个组件,应该不会存在没有数据的问题 // 在Table组件render之后 才走进这个组件,应该不会存在没有数据的问题
async ready() { async ready() {
const schema = this.features.cache.getSchema(); const schema = this.features.cache.getSchema();
// 小程序这里还要跑一下 // 小程序这里还要跑一下
@ -27,6 +27,17 @@ export default OakComponent({
}); });
}, },
}, },
listeners: {
actions(prev, next) {
if ((prev.actions && !next.actions) ||
(!prev.actions && next.actions) ||
(prev.actions &&
next.actions &&
prev.actions.length !== next.actions.length)) {
this.makeItems();
}
}
},
methods: { methods: {
makeItems(isMobile) { makeItems(isMobile) {
const { schema } = this.state; const { schema } = this.state;
@ -40,7 +51,7 @@ export default OakComponent({
column = 2; column = 2;
} }
if (extraActions?.length || actions?.length) { if (extraActions?.length || actions?.length) {
const actions2 = [...actions || []]; const actions2 = [...(actions || [])];
if (extraActions) { if (extraActions) {
// 用户传的action默认排在前面 // 用户传的action默认排在前面
const extraActions2 = extraActions.filter((ele) => ele.show); const extraActions2 = extraActions.filter((ele) => ele.show);

View File

@ -3,6 +3,7 @@ import { ED, OakExtraActionProps } from '../../types/AbstractComponent';
import { resolvePath } from '../../utils/usefulFn'; import { resolvePath } from '../../utils/usefulFn';
import { StorageSchema } from 'oak-domain/lib/types/Storage'; import { StorageSchema } from 'oak-domain/lib/types/Storage';
import { ActionDef } from '../../types/Page'; import { ActionDef } from '../../types/Page';
import { actions } from 'oak-domain/lib/base-app-domain/User/Action';
export default OakComponent({ export default OakComponent({
isList: false, isList: false,
@ -32,7 +33,7 @@ export default OakComponent({
}[], }[],
}, },
lifetimes: { lifetimes: {
// 在Tabel组件render之后 才走进这个组件,应该不会存在没有数据的问题 // 在Table组件render之后 才走进这个组件,应该不会存在没有数据的问题
async ready() { async ready() {
const schema = this.features.cache.getSchema(); const schema = this.features.cache.getSchema();
// 小程序这里还要跑一下 // 小程序这里还要跑一下
@ -44,6 +45,19 @@ export default OakComponent({
}); });
}, },
}, },
listeners: {
actions(prev, next) {
if (
(prev.actions && !next.actions) ||
(!prev.actions && next.actions) ||
(prev.actions &&
next.actions &&
prev.actions.length !== next.actions.length)
) {
this.makeItems();
}
}
},
methods: { methods: {
makeItems(isMobile?: boolean) { makeItems(isMobile?: boolean) {
const { schema } = this.state; const { schema } = this.state;
@ -58,7 +72,7 @@ export default OakComponent({
column = 2; column = 2;
} }
if (extraActions?.length || actions?.length) { if (extraActions?.length || actions?.length) {
const actions2 = [...actions || []]; const actions2 = [...(actions || [])];
if (extraActions) { if (extraActions) {
// 用户传的action默认排在前面 // 用户传的action默认排在前面
const extraActions2 = extraActions.filter((ele) => ele.show); const extraActions2 = extraActions.filter((ele) => ele.show);