@ovine/core
Version:
Build flexible admin system with json.
74 lines (73 loc) • 4.21 kB
JavaScript
/**
* 权限配置
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Renderer, filter } from 'amis';
import { isEffectiveApi } from 'amis/lib/utils/api';
import React from 'react';
import LimitSetting, { LimitSettingProps, AuthLimitData } from "../limit_setting";
let LibLimitSetting = class LibLimitSetting extends React.Component {
render() {
const { button = {}, modal = {}, name = 'limit', env, data, initApi, api, messages, saveConfirmText, useAllLimit, getLimit, render, } = this.props;
const actionType = button.actionType || 'dialog';
const buttonProps = Object.assign({ actionType, type: 'action', label: '设置权限' }, button);
const modalProps = Object.assign({ title: '设置权限', size: 'lg', showCloseButton: false, actions: [] }, modal);
const limitComponent = {
component: (amisProps) => {
const { data: limitData } = amisProps;
const initData = Object.assign(Object.assign({}, data), limitData);
const onSave = (authData) => {
const fetchData = Object.assign(Object.assign({}, initData), authData);
if (isEffectiveApi(api, fetchData)) {
env
.fetcher(api, fetchData)
.then((res) => {
const { status, msg } = res;
const hasError = status !== 0;
if (!hasError) {
env.notify('success', (messages === null || messages === void 0 ? void 0 : messages.saveSuccess) || '保存成功');
if (this.props.reload) {
this.props.onQuery();
}
}
else {
env.notify('error', (messages === null || messages === void 0 ? void 0 : messages.saveFailed) || msg || '保存失败');
}
})
.catch(() => {
env.notify('error', (messages === null || messages === void 0 ? void 0 : messages.saveFailed) || '保存失败');
});
}
if (this.props.onSaveClick) {
this.props.onSaveClick(authData);
}
};
return (React.createElement(LimitSetting, Object.assign({}, amisProps, { className: `limit-drawer-${isEffectiveApi(initApi) ? 'service' : 'normal'} `, limit: getLimit ? getLimit(limitData) : limitData[name] || '', saveConfirmText: filter(saveConfirmText, initData), onSaveClick: onSave, useAllLimit: useAllLimit, onCancel: this.props.onCancelClick })));
},
};
const schema = Object.assign(Object.assign({}, buttonProps), { [actionType]: Object.assign(Object.assign({}, modalProps), { body: !isEffectiveApi(initApi)
? limitComponent
: {
type: 'service',
className: 'h-full',
messages: {
fetchFailed: messages === null || messages === void 0 ? void 0 : messages.initFailed,
},
api: initApi,
body: limitComponent,
} }) });
return render('body', schema);
}
};
LibLimitSetting = __decorate([
Renderer({
test: /(^|\/)lib-limit-setting$/,
name: 'lib-limit-setting',
})
], LibLimitSetting);
export { LibLimitSetting };