fastlion-amis
Version:
一种MIS页面生成工具
299 lines (298 loc) • 15.1 kB
JavaScript
"use strict";
/**
* @file Alert
* @author fex
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FinnalAlert = exports.prompt = exports.confirm = exports.alert = exports.setRenderSchemaFn = exports.Alert = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var react_dom_1 = require("react-dom");
var Modal_1 = (0, tslib_1.__importDefault)(require("./Modal"));
var Button_1 = (0, tslib_1.__importDefault)(require("./Button"));
var theme_1 = require("../theme");
var locale_1 = require("../locale");
var Html_1 = (0, tslib_1.__importDefault)(require("./Html"));
var helper_1 = require("../utils/helper");
var antd_1 = require("antd");
var tools_1 = require("../utils/shell/tools");
var icons_1 = require("./icons");
var utils_1 = require("../renderers/Lion/utils/utils");
var utils_2 = require("./Mobileprocess/utils");
var Alert = /** @class */ (function (_super) {
(0, tslib_1.__extends)(Alert, _super);
function Alert(props) {
var _this = _super.call(this, props) || this;
_this.state = {
show: false,
title: '',
content: '',
confirm: false,
showCancel: true
};
_this.handleKeyPress = function (e) {
if (e.key === 'Enter' && !_this.state.prompt) {
_this.handleConfirm();
}
};
_this.close = _this.close.bind(_this);
_this.handleConfirm = _this.handleConfirm.bind(_this);
_this.handleCancel = _this.handleCancel.bind(_this);
_this.modalRef = _this.modalRef.bind(_this);
_this.handleFormSubmit = _this.handleFormSubmit.bind(_this);
_this.scopeRef = _this.scopeRef.bind(_this);
Alert.instance = _this;
return _this;
}
Alert.getInstance = function () {
if (!Alert.instance) {
console.warn('Alert 组件应该没有被渲染,所以隐性的渲染到 body 了');
var container = document.body;
var div = document.createElement('div');
container.appendChild(div);
(0, react_dom_1.render)(react_1.default.createElement(exports.FinnalAlert, null), div);
}
return Alert.instance;
};
Alert.prototype.componentDidMount = function () {
this._body && (this._body.innerHTML = this.state.content);
this._modal && document.body.addEventListener('keyup', this.handleKeyPress);
};
Alert.prototype.componentDidUpdate = function (prevProps, prevState) {
if (prevState.content !== this.state.content) {
this._body && (this._body.innerHTML = this.state.content);
}
};
Alert.prototype.componentWillUnmount = function () {
Alert.instance = null;
document.body.removeEventListener('keyup', this.handleKeyPress);
};
Alert.prototype.scopeRef = function (schemaSope) {
this.schemaSope = schemaSope;
};
Alert.prototype.handleConfirm = function () {
var _a;
var form = (_a = this.schemaSope) === null || _a === void 0 ? void 0 : _a.getComponentByName('form');
if (form) {
form.doAction({ type: 'submit' });
}
else {
this.close(true);
}
};
Alert.prototype.handleCancel = function () {
this.close(false);
};
Alert.prototype.close = function (confirmed) {
var _this = this;
var isConfirm = this.state.confirm || this.state.prompt;
this.setState({
show: false,
prompt: false,
confirm: false,
showCancel: true
}, isConfirm ? function () { return _this._resolve(confirmed); } /*this._reject()*/ : undefined);
};
Alert.prototype.reAddlisten = function () {
var _this = this;
// 防止打开稍微延时就引起了输入造成闪动
this._modal && document.body.removeEventListener('keyup', this.handleKeyPress);
setTimeout(function () {
_this._modal && document.body.addEventListener('keyup', _this.handleKeyPress);
}, 200);
};
Alert.prototype.alert = function (content, title) {
this.reAddlisten();
this.setState({
title: title,
content: content,
show: true,
confirm: false
});
};
Alert.prototype.confirm = function (content, title, confirmText, showCancel) {
var _this = this;
if (showCancel === void 0) { showCancel = true; }
this.reAddlisten();
this.setState({
title: title,
content: content,
show: true,
confirm: true,
confirmText: confirmText,
showCancel: showCancel
});
return new Promise(function (resolve) {
_this._resolve = resolve;
});
};
Alert.prototype.prompt = function (controls, defaultValue, title, confirmText) {
var _this = this;
if (title === void 0) { title = 'placeholder.enter'; }
if (confirmText === void 0) { confirmText = 'confirm'; }
if (typeof controls === 'string') {
// 兼容浏览器标准用法。
controls = [
{
name: 'text',
label: controls,
type: 'text'
}
];
if (typeof defaultValue === 'string') {
defaultValue = {
text: defaultValue
};
}
}
else if (!Array.isArray(controls)) {
controls = [controls];
}
this.setState({
title: title,
controls: controls,
show: true,
prompt: true,
value: defaultValue,
confirmText: confirmText
});
return new Promise(function (resolve) {
_this._resolve = resolve;
});
};
Alert.prototype.modalRef = function (ref) {
this._modal = ref;
};
Alert.prototype.handleFormSubmit = function (values) {
this.close(values);
};
Alert.prototype.handleSignature = function (body) {
var _this = this;
var _a;
var __ = this.props.translate;
var approverList = body.approverList, beforeTip = body.beforeTip;
var columns = [
{
title: __('Alert.sequence'),
dataIndex: 'index',
key: 'index',
width: '20%'
},
{
title: __('Alert.people'),
dataIndex: 'userName',
key: 'userName',
width: '30%'
},
{
title: __('Alert.role'),
dataIndex: 'taskName',
key: 'taskName',
width: '30%'
},
{
title: __('Alert.type'),
dataIndex: 'taskType',
key: 'taskType',
width: '20%'
}
];
var data = approverList.map(function (item) { return item; });
var dataSource = (_a = data === null || data === void 0 ? void 0 : data.sort(function (a, b) { return a.taskSeq - b.taskSeq; })) === null || _a === void 0 ? void 0 : _a.map(function (item) {
return {
index: item.taskSeq,
userName: item.userName + "(" + item.userId + ")",
taskType: item.taskType == 0 ? '或签' : '会签',
taskName: item.taskName,
taskSeq: item.taskSeq
};
});
return react_1.default.createElement(react_1.default.Fragment, null, (0, helper_1.isMobile)() ? react_1.default.createElement(antd_1.Drawer, { className: 'process_drawer', closable: false, width: "100%", visible: this.state.show, mask: false, destroyOnClose: true, zIndex: 1011, bodyStyle: { backgroundColor: '#fff' }, getContainer: this.props.container, footer: react_1.default.createElement("div", { style: { textAlign: 'right' } },
react_1.default.createElement(Button_1.default, { onClick: function () { return _this.handleCancel(); } }, "\u53D6\u6D88"),
react_1.default.createElement("span", null, " "),
react_1.default.createElement(Button_1.default, { level: 'primary', onClick: function () { return _this.handleConfirm(); } }, "\u786E\u5B9A\u9001\u7B7E")) },
(0, utils_2.handleHeader)(function () { return _this.handleCancel(); }, tools_1.tools.isComWx ? '' : '送签'),
react_1.default.createElement("div", { style: { overflow: "auto", flex: 1, padding: '10px 20px' } },
beforeTip && react_1.default.createElement("div", null, beforeTip),
react_1.default.createElement(antd_1.List, { itemLayout: "horizontal", dataSource: dataSource, renderItem: function (item, index) { return (react_1.default.createElement(antd_1.List.Item, { key: index },
react_1.default.createElement(antd_1.List.Item.Meta, { avatar: item.index, title: react_1.default.createElement("div", { style: {
fontSize: '14px',
color: "#000000e6"
} }, item.userName), description: react_1.default.createElement("div", { style: { fontSize: '12px' } }, item.taskName) }),
react_1.default.createElement("div", { style: { fontSize: '12px', color: "#00000066" } }, item.taskType))); } }))) :
react_1.default.createElement(react_1.default.Fragment, null,
beforeTip && react_1.default.createElement("div", null, beforeTip),
react_1.default.createElement("div", { style: { border: "1px solid rgba(0, 0, 0, 0.05)", borderBottom: 'none' } },
react_1.default.createElement(antd_1.Table, { columns: columns, size: 'small', dataSource: dataSource, pagination: false }))));
};
Alert.prototype.render = function () {
var _a;
var _this = this;
var _b, _c, _d;
var _e = this.props, container = _e.container, cancelText = _e.cancelText, confirmText = _e.confirmText, title = _e.title, confirmBtnLevel = _e.confirmBtnLevel, alertBtnLevel = _e.alertBtnLevel, cx = _e.classnames, className = _e.className;
var theme = this.props.theme || 'cxd';
if (theme === 'default') {
theme = 'cxd';
}
var data = (_b = this.state.content) === null || _b === void 0 ? void 0 : _b.data;
var __ = this.props.translate;
var finalConfirmText = data ? __('Flow.confirm.signature.submission') : __((_c = this.state.confirmText) !== null && _c !== void 0 ? _c : confirmText);
var finalTitle = data ? __('Flow.send.for.signature') : __((_d = this.state.title) !== null && _d !== void 0 ? _d : title);
return data && (0, helper_1.isMobile)() ? react_1.default.createElement(react_1.default.Fragment, null, this.handleSignature(data)) : (react_1.default.createElement(Modal_1.default, { show: this.state.show, onHide: this.handleCancel, container: document.getElementById('amis-modal-container') || container, ref: this.modalRef, style: { zIndex: '1010' }, closeOnEsc: true, className: cx((_a = {},
_a["Modal--center"] = data,
_a), className) },
finalTitle ? (react_1.default.createElement("div", { className: cx('Modal-header') },
react_1.default.createElement("div", { className: cx('Modal-title') }, finalTitle))) : null,
react_1.default.createElement("div", { className: cx('Modal-body') }, this.state.prompt ? (renderForm(this.state.controls, this.state.value, this.handleFormSubmit, this.scopeRef, theme, true, true)) : (react_1.default.createElement(react_1.default.Fragment, null, data ?
this.handleSignature(data) : react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(Html_1.default, { html: this.state.content }),
react_1.default.createElement(icons_1.Icon, { icon: "copy", className: "icon", style: { fontSize: '14px', cursor: 'pointer', marginLeft: '5px' }, onClick: function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, utils_1.copy)(this.state.content)];
case 1:
_a.sent();
antd_1.message.success(__('System.copy'));
return [2 /*return*/];
}
});
}); } }))))),
finalConfirmText ? (react_1.default.createElement("div", { className: cx('Modal-footer') },
(this.state.confirm || this.state.prompt) ? (this.state.showCancel ? react_1.default.createElement(Button_1.default, { onClick: this.handleCancel }, __(cancelText)) : null) : null,
react_1.default.createElement(Button_1.default, { level: this.state.confirm || this.state.prompt
? (data || !this.state.showCancel ? alertBtnLevel : confirmBtnLevel)
: alertBtnLevel, onClick: this.handleConfirm }, finalConfirmText))) : null));
};
Alert.instance = null;
Alert.defaultProps = {
confirmText: 'confirm',
cancelText: 'cancel',
title: 'Alert.info',
alertBtnLevel: 'primary',
confirmBtnLevel: 'danger'
};
return Alert;
}(react_1.default.Component));
exports.Alert = Alert;
var renderSchemaFn;
function setRenderSchemaFn(fn) {
renderSchemaFn = fn;
}
exports.setRenderSchemaFn = setRenderSchemaFn;
function renderForm(controls, value, callback, scopeRef, theme, inModal, autoFocus) {
if (value === void 0) { value = {}; }
return renderSchemaFn === null || renderSchemaFn === void 0 ? void 0 : renderSchemaFn(controls, value, callback, scopeRef, theme, inModal, autoFocus);
}
var alert = function (content, title) { return Alert.getInstance().alert(content, title); };
exports.alert = alert;
var confirm = function (content, title, confirmText, showCancel) {
return Alert.getInstance().confirm(content, title, confirmText, showCancel);
};
exports.confirm = confirm;
var prompt = function (controls, defaultvalue, title, confirmText) {
return Alert.getInstance().prompt(controls, defaultvalue, title, confirmText);
};
exports.prompt = prompt;
exports.FinnalAlert = (0, theme_1.themeable)((0, locale_1.localeable)(Alert));
exports.default = exports.FinnalAlert;
//# sourceMappingURL=./components/Alert.js.map