entityactionbtn 已改成 acttionBtnPanel

This commit is contained in:
Wang Kejun 2023-02-21 15:17:18 +08:00
parent 4ffcb85bdd
commit 36c8bc85ba
14 changed files with 0 additions and 279 deletions

View File

@ -1,3 +0,0 @@
/// <reference types="react" />
declare const _default: import("react").ComponentType<any>;
export default _default;

View File

@ -1,14 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = OakComponent({
entity: function () {
var entity = this.props.entity;
return entity;
},
isList: false,
actions: function () {
var actions = this.props.actions;
return actions;
},
methods: {},
});

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,2 +0,0 @@

View File

@ -1,3 +0,0 @@
<view>
待开发
</view>

View File

@ -1,27 +0,0 @@
/// <reference types="react" />
import { ButtonProps, SpaceProps } from 'antd';
import { WebComponentProps } from 'oak-frontend-base';
import { EntityDict } from '../../general-app-domain';
declare type Item = {
label?: string;
action?: string;
auth: boolean;
type?: 'a' | 'button';
index?: number;
alerted?: boolean;
alertTitle?: string;
alertContent?: string;
confirmText?: string;
cancelText?: string;
custom?: any;
callBack?: (index: number) => void;
onClick?: () => void;
buttonProps?: Omit<ButtonProps, "onClick">;
};
export default function Render(props: WebComponentProps<EntityDict, keyof EntityDict, false, {
entity: string;
actions: string[];
items: Item[];
spaceProps: SpaceProps;
}, {}>): JSX.Element;
export {};

View File

@ -1,70 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var confirm = antd_1.Modal.confirm;
var commonAction = ['create', 'update', 'remove', 'confirm', 'cancel', 'grant', 'revoke'];
function ItemComponent(props) {
var type = props.type, entity = props.entity, label = props.label, action = props.action, buttonProps = props.buttonProps, custom = props.custom, t = props.t, onClick = props.onClick;
var text;
if (action) {
if (commonAction.includes(action)) {
text = t("common:action.".concat(action));
}
else {
text = t("".concat(entity, ":action.").concat(action));
}
}
else {
text = label;
}
if (type === 'button') {
return ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({}, buttonProps, { onClick: onClick }, { children: text })));
}
if (custom) {
return ((0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ onClick: onClick }, { children: custom })));
}
return ((0, jsx_runtime_1.jsx)("a", tslib_1.__assign({ onClick: onClick }, { children: text })));
}
function Render(props) {
var methods = props.methods, data = props.data;
var t = methods.t;
var items = data.items, oakLegalActions = data.oakLegalActions, spaceProps = data.spaceProps, entity = data.entity;
return ((0, jsx_runtime_1.jsx)(antd_1.Space, tslib_1.__assign({}, spaceProps, { children: items && items.map(function (ele, index) {
var _a = ele.auth, auth = _a === void 0 ? true : _a;
if (!auth ||
(auth &&
(oakLegalActions === null || oakLegalActions === void 0 ? void 0 : oakLegalActions.includes(ele.action)))) {
var onClick = function () {
if (ele.onClick) {
ele.onClick();
return;
}
methods.execute(ele.action);
};
if (ele.alerted) {
onClick = function () {
confirm({
title: ele.alertTitle,
content: ele.alertContent,
okText: ele.confirmText || '确定',
cancelText: ele.cancelText || '取消',
onOk: function () {
if (ele.onClick) {
ele.onClick();
return;
}
methods.execute(ele.action);
if (ele.callBack) {
ele.callBack(index);
}
},
});
};
}
return ((0, jsx_runtime_1.jsx)(ItemComponent, tslib_1.__assign({}, ele, { entity: entity, t: t, onClick: onClick })));
}
}) })));
}
exports.default = Render;

View File

@ -1,5 +0,0 @@
{
"component": true,
"usingComponents": {
}
}

View File

@ -1,2 +0,0 @@

View File

@ -1,14 +0,0 @@
export default OakComponent({
entity() {
const { entity } = this.props;
return entity;
},
isList: false,
actions() {
const { actions } = this.props;
return actions
},
methods: {
},
});

View File

@ -1,3 +0,0 @@
<view>
待开发
</view>

View File

@ -1,132 +0,0 @@
import React, {useEffect} from 'react';
import { Space, Button, Modal, ButtonProps, SpaceProps } from 'antd';
import { WebComponentProps } from 'oak-frontend-base';
import { EntityDict } from '../../general-app-domain';
import { DefaultOptionType } from 'antd/es/select';
const { confirm } = Modal;
type Item = {
label?: string;
action?: string;
auth: boolean;
type?: 'a' | 'button';
index?: number;
alerted?: boolean;
alertTitle?: string;
alertContent?: string;
confirmText?: string;
cancelText?: string;
custom?: any;
callBack?: (index: number) => void;
onClick?: () => void;
buttonProps?: Omit<ButtonProps, "onClick">;
}
const commonAction = ['create', 'update', 'remove', 'confirm', 'cancel', 'grant', 'revoke'];
function ItemComponent(props: Item & { entity: string; t: (value: string) => string; onClick: () => void }) {
const { type, entity, label, action, buttonProps, custom, t, onClick } = props;
let text: string | undefined;
if (action) {
if (commonAction.includes(action)) {
text = t(`common:action.${action}`);
}
else {
text = t(`${entity}:action.${action}`);
}
}
else {
text = label;
}
if (type === 'button') {
return (
<Button {...buttonProps} onClick={onClick}>
{text}
</Button>
)
}
if (custom) {
return (
<div onClick={onClick}>
{custom}
</div>
)
}
return (
<a onClick={onClick}>
{text}
</a>
)
}
export default function Render(
props: WebComponentProps<
EntityDict,
keyof EntityDict,
false,
{
entity: string;
actions: string[];
items: Item[];
spaceProps: SpaceProps,
},
{
}
>
) {
const { methods, data } = props;
const { t } = methods;
const { items, oakLegalActions, spaceProps, entity } = data;
return (
<Space {...spaceProps}>
{items && items.map((ele, index: number) => {
const { auth = true} = ele;
if (
!auth ||
(auth &&
oakLegalActions?.includes(
ele.action as EntityDict[keyof EntityDict]['Action']
))
) {
let onClick = () => {
if (ele.onClick) {
ele.onClick();
return;
}
methods.execute(
ele.action as EntityDict[keyof EntityDict]['Action']
);
};
if (ele.alerted) {
onClick = () => {
confirm({
title: ele.alertTitle,
content: ele.alertContent,
okText: ele.confirmText || '确定',
cancelText: ele.cancelText || '取消',
onOk: () => {
if (ele.onClick) {
ele.onClick();
return;
}
methods.execute(
ele.action as EntityDict[keyof EntityDict]['Action']
);
if (ele.callBack) {
ele.callBack(index);
}
},
});
};
}
return (
<ItemComponent
{...ele}
entity={entity}
t={t}
onClick={onClick}
/>
);
}
})}
</Space>
);
}