ming-demo3
Version:
mdf metaui web
335 lines (294 loc) • 12.1 kB
JavaScript
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireWildcard(require("react"));
var _baseui = require("@mdf/baseui");
var _SvgIcon = _interopRequireDefault(require("@mdf/metaui-web/lib/components/common/SvgIcon"));
var eChartCommon = _interopRequireWildcard(require("../eChartCommon"));
var eChartProxy = _interopRequireWildcard(require("../eChartProxy"));
var _eChartPanelDisplay = _interopRequireDefault(require("./eChartPanelDisplay"));
var eChartDemoData = _interopRequireWildcard(require("../eChartDemoData"));
var TabPane = _baseui.Tabs.TabPane;
var eChartCarousel = function (_React$Component) {
(0, _inherits2["default"])(eChartCarousel, _React$Component);
function eChartCarousel(props) {
var _this;
(0, _classCallCheck2["default"])(this, eChartCarousel);
_this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(eChartCarousel).call(this, props));
_this.state = {
isInDesign: false,
panelIds: [],
carouselTemplates: [],
clientWidth: 100,
clientHeight: 100,
activeTabKey: 0,
bPause: false
};
return _this;
}
(0, _createClass2["default"])(eChartCarousel, [{
key: "render",
value: function render() {
var self = this;
var carouselTemplates = this.state.carouselTemplates;
if (carouselTemplates.length == 0) {
return _react["default"].createElement("div", null);
} else {
var arr = [];
var style_outer = {
width: this.state.clientWidth,
height: this.state.clientHeight
};
var style_inner = {
width: this.state.clientWidth,
height: this.state.clientHeight
};
eChartCommon.LogChartInfo("大屏轮播: eChartCarousel Render isInDesign = " + self.state.isInDesign + " clientWidth & clientHeight", JSON.stringify(style_outer), 15);
carouselTemplates.forEach(function (template, index) {
arr.push(_react["default"].createElement(TabPane, {
tab: "Tab_" + index,
key: "Tab_" + index,
style: style_inner,
className: "eChartCarousel_Inner_" + index + " eChartCarousel_TabPane",
forceRender: false
}, _react["default"].createElement(_eChartPanelDisplay["default"], {
panelConfig: template,
isInDesign: self.state.isInDesign,
doFunc: function doFunc(funcName, params) {
return self.doFunc(funcName, params);
}
})));
});
eChartCommon.LogChartInfo("大屏轮播: Render activeTabKey ", "Tab_" + self.state.activeTabKey, 15);
return _react["default"].createElement("div", {
style: style_outer,
className: "eChartCarousel_Outer"
}, _react["default"].createElement(_baseui.Tabs, {
animated: false,
className: "eChartCarousel_Tabs",
activeKey: "Tab_" + self.state.activeTabKey
}, arr));
}
}
}, {
key: "beforeChange",
value: function beforeChange() {
eChartCommon.LogChartInfo("大屏轮播: 切换 beforeChange ", "", 15);
}
}, {
key: "afterChange",
value: function afterChange() {
eChartCommon.LogChartInfo("大屏轮播: 切换 afterChange ", "", 15);
}
}, {
key: "doFunc",
value: function doFunc(funcName, params) {
if (funcName == "pauseCarouse") {
this.pauseCarouse(params);
}
}
}, {
key: "pauseCarouse",
value: function pauseCarouse(params) {
if (params != "") {
this.setState({
bPause: true
});
} else {
this.setState({
bPause: false
});
}
}
}, {
key: "resetWidthAndHeight",
value: function resetWidthAndHeight(carouselTemplates) {
var self = this;
var clientWidth = document.body.clientWidth;
var clientHeight = document.body.clientHeight;
var arr = _.isEmpty(carouselTemplates) ? self.state.carouselTemplates : carouselTemplates;
if (_.isEmpty(arr) == false) {
var editPanel = arr[0];
if (editPanel.type == "2") {
if (clientHeight < clientWidth) clientHeight = clientWidth;else clientWidth = clientHeight;
clientHeight = clientHeight * editPanel.height2 / 2;
}
}
this.state.clientWidth = clientWidth;
this.state.clientHeight = clientHeight;
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
var _this2 = this;
var self = this;
window.addEventListener('resize', function () {
return _this2.onWindowResize();
});
this.state.isInDesign = false;
var panelId = 0;
var type = -1;
var params = new cb.utils.queryString(self.props.location.search);
if (params && params.query) {
this.state.isInDesign = params.query && params.query.isInDesign == "1";
panelId = params.query && params.query.panelId;
type = params.query && params.query.type;
}
if (this.state.isInDesign) {
if (panelId) {
var param = {
reportViewId: panelId
};
var callback = function callback(json) {
if (json.code === 200) {
var data = json.data;
if (data) {
var editPanel = eChartCommon.restoreEditPanel(data.pageLayout, data.items, "query", panelId);
var carouselTemplates = [editPanel];
var panelIds = [panelId];
self.resetWidthAndHeight(carouselTemplates);
self.setState({
panelIds: panelIds,
carouselTemplates: carouselTemplates
});
}
}
};
eChartProxy.doProxy(eChartProxy.url.getReportView, 'GET', param, callback);
} else if (window.opener) {
window.opener.cb.events.un('setPreviewPanel');
window.opener.cb.events.on('setPreviewPanel', function (args) {
var template = args.template;
var carouselTemplates = [template];
var panelIds = [template.id];
self.resetWidthAndHeight(carouselTemplates);
self.setState({
panelIds: panelIds,
carouselTemplates: carouselTemplates
});
});
window.opener.cb.events.execute("getPreviewPanel");
}
} else {
this.getAuthedTemplate();
}
}
}, {
key: "setAutoPlay",
value: function setAutoPlay() {
var self = this;
var screenPlayTime = cb.rest.AppContext.option.screenPlayTime ? cb.rest.AppContext.option.screenPlayTime : 120;
if (eChartDemoData.demoConfig.isTestCarousel) screenPlayTime = 5;
eChartCommon.LogChartInfo("大屏轮播: Carousel render 显示轮播时间 " + screenPlayTime + "秒,系统设置轮播时间。cb.rest.AppContext.option.screenPlayTime ", cb.rest.AppContext.option.screenPlayTime || "空", 15);
if (self._timer == undefined) {
self._timer = setInterval(function () {
if (self.state.bPause == false) {
var activeTabKey = self.state.activeTabKey + 1;
if (activeTabKey >= self.state.carouselTemplates.length) activeTabKey = 0;
self.setState({
activeTabKey: activeTabKey
});
}
}, screenPlayTime * 1000);
}
}
}, {
key: "getAuthedTemplate",
value: function getAuthedTemplate() {
var self = this;
var callback = function callback(json) {
if (json.code === 200 && json.data) {
eChartCommon.LogChartInfo("大屏轮播:获取系统有权限的所有看板。 json.data.kanbans ", JSON.stringify(json.data.kanbans), 15);
var kanbans = _.filter(json.data.kanbans, function (o) {
return o.type == 1;
});
eChartCommon.LogChartInfo("大屏轮播:获取系统有权限的type=1看板。 kanbans ", JSON.stringify(kanbans), 15);
var panelIds = [];
kanbans.forEach(function (ele) {
panelIds.push(ele.id);
});
panelIds = _.uniq(panelIds);
if (eChartDemoData.demoConfig.isTestCarousel) {
panelIds = [13559, 13560, 13561, 13562, 13563, 13564];
panelIds = [13559, 13560, 13561];
}
if (panelIds && panelIds.length > 0) {
var _callback = function _callback(json) {
if (json.code === 200) {
if (json.data && json.data.length > 0) {
var carouselTemplates = [];
eChartCommon.LogChartInfo("大屏轮播:获取模板配置信息。返回 json.data.length ", json.data.length, 15);
json.data.forEach(function (ele, index) {
var editPanel = eChartCommon.restoreEditPanel(ele.pageLayout, ele.items, "query");
carouselTemplates.push(editPanel);
eChartCommon.LogChartInfo("大屏轮播:获取模板完毕。模板ID=", ele.id + " name = " + ele.name, 15);
});
eChartCommon.LogChartInfo("大屏轮播:开始轮播。大屏数量 ", carouselTemplates.length, 15);
self.resetWidthAndHeight(carouselTemplates);
self.setState({
panelIds: panelIds,
carouselTemplates: carouselTemplates,
activeTabKey: 0
});
if (self.state.isInDesign == false && carouselTemplates.length > 1) self.setAutoPlay();
} else {
eChartCommon.LogChartInfo("大屏轮播:没有找到能够展示的大屏。模板ID ", JSON.stringify(panelIds), 999);
}
} else {
eChartCommon.LogChartInfo("大屏轮播:获取模板列表信息出错。模板 panelIds = " + JSON.stringify(panelIds) + " json.message ", json.message, 999);
}
};
eChartProxy.doProxy(eChartProxy.url.getReportViews, 'GET', {
ids: panelIds
}, _callback);
} else {
eChartCommon.LogChartInfo("大屏轮播:请检查当前操作员是否有模板权限 ", "", 999);
self.closeWindow(3);
}
} else {
eChartCommon.LogChartInfo("大屏轮播:调用服务出错 json.message", json.message, 999);
cb.utils.alert(json.message, 'error');
self.closeWindow(3);
}
};
eChartProxy.doProxy(eChartProxy.url.getLayoutByUserId, 'GET', {}, callback);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var self = this;
if (self._timer) {
clearInterval(self._timer);
self._timer = null;
}
;
window.removeEventListener('resize', this.onWindowResize);
self._unmount = true;
}
}, {
key: "onWindowResize",
value: function onWindowResize() {
this.resetWidthAndHeight();
this.setState();
}
}, {
key: "closeWindow",
value: function closeWindow(num) {
setTimeout(function () {
window.close();
}, num * 1000);
}
}]);
return eChartCarousel;
}(_react["default"].Component);
exports["default"] = eChartCarousel;
//# sourceMappingURL=eChartCarousel.js.map
;