UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

116 lines (115 loc) 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimelineRenderer = exports.TimelineCmpt = void 0; var tslib_1 = require("tslib"); var react_1 = tslib_1.__importDefault(require("react")); var factory_1 = require("../factory"); var Timeline_1 = tslib_1.__importDefault(require("../components/Timeline")); var Scoped_1 = require("../Scoped"); var antd_1 = require("antd"); var tpl_1 = require("../utils/tpl"); function TimelineCmpt(props) { var items = props.items, mode = props.mode, direction = props.direction, reverse = props.reverse, data = props.data, // config, // source, render = props.render; // 获取源数据 var timelineItemsRow = items || []; // 渲染内容 var resolveRender = function (region, val) { return typeof val === 'string' ? (0, tpl_1.filter)(val, data) : (val && render(region, val)); }; // 处理源数据 var resolveTimelineItems = timelineItemsRow === null || timelineItemsRow === void 0 ? void 0 : timelineItemsRow.map(function (timelineItem) { return tslib_1.__assign(tslib_1.__assign({}, timelineItem), { icon: resolveRender('icon', timelineItem.icon), title: resolveRender('title', timelineItem.title) }); }); return (react_1.default.createElement(Timeline_1.default, { items: resolveTimelineItems, direction: direction, reverse: reverse, mode: mode })); } exports.TimelineCmpt = TimelineCmpt; var TimelineRender = /** @class */ (function (_super) { tslib_1.__extends(TimelineRender, _super); function TimelineRender(props) { var _this = _super.call(this, props) || this; _this.handleGetTimeLineData = _this.handleGetTimeLineData.bind(_this); _this.reload = _this.reload.bind(_this); _this.state = { timeLineItems: [], fetchLoading: false }; return _this; } TimelineRender.prototype.componentDidMount = function () { this.handleGetTimeLineData(); }; TimelineRender.prototype.reload = function (subpath, query, ctx, isItemAction) { this.handleGetTimeLineData({ subpath: subpath, query: query, ctx: ctx, isItemAction: isItemAction }); }; // 获取时间轴数据 TimelineRender.prototype.handleGetTimeLineData = function (props) { var _a; if (props === void 0) { props = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var query, _b, ctx, _c, __super, rest, _d, env, api, store, res, timelineItemsRow; return tslib_1.__generator(this, function (_e) { switch (_e.label) { case 0: query = props.query, _b = props.ctx, ctx = _b === void 0 ? {} : _b; _c = ctx || {}, __super = _c.__super, rest = tslib_1.__rest(_c, ["__super"]); _d = this.props, env = _d.env, api = _d.api, store = _d.store; _e.label = 1; case 1: _e.trys.push([1, , 3, 4]); this.setState({ fetchLoading: true }); return [4 /*yield*/, env.fetcher(api, Object.assign({}, store === null || store === void 0 ? void 0 : store.data, query, rest))]; case 2: res = _e.sent(); timelineItemsRow = ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || []; this.setState({ timeLineItems: timelineItemsRow }); return [3 /*break*/, 4]; case 3: this.setState({ fetchLoading: false }); return [7 /*endfinally*/]; case 4: return [2 /*return*/]; } }); }); }; TimelineRender.prototype.render = function () { var _a = this.props, config = _a.config, deferLoad = _a.deferLoad, loading = _a.loading, updateConfig = _a.updateConfig, env = _a.env, api = _a.api, rest = tslib_1.__rest(_a, ["config", "deferLoad", "loading", "updateConfig", "env", "api"]); return react_1.default.createElement(antd_1.Spin, { spinning: this.state.fetchLoading }, this.state.fetchLoading ? react_1.default.createElement("div", { style: { height: 60 } }) : react_1.default.createElement(TimelineCmpt, tslib_1.__assign({ config: config, items: this.state.timeLineItems }, rest))); }; return TimelineRender; }(react_1.default.Component)); exports.default = TimelineRender; var TimelineRenderer = /** @class */ (function (_super) { tslib_1.__extends(TimelineRenderer, _super); function TimelineRenderer(props, context) { var _this = _super.call(this, props) || this; var scoped = context; scoped.registerComponent(_this, context); return _this; } TimelineRenderer.prototype.componentWillUnmount = function () { var _a; (_a = _super.prototype.componentWillUnmount) === null || _a === void 0 ? void 0 : _a.call(this); var scoped = this.context; scoped.unRegisterComponent(this); }; var _a; TimelineRenderer.contextType = Scoped_1.ScopedContext; TimelineRenderer = tslib_1.__decorate([ (0, factory_1.Renderer)({ type: 'timeline' }), tslib_1.__metadata("design:paramtypes", [Object, typeof (_a = typeof Scoped_1.IScopedContext !== "undefined" && Scoped_1.IScopedContext) === "function" ? _a : Object]) ], TimelineRenderer); return TimelineRenderer; }(TimelineRender)); exports.TimelineRenderer = TimelineRenderer; //# sourceMappingURL=./renderers/Timeline.js.map